TextureData.hh 6.97 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision: 5183 $
//   $Author: wilden $
//   $Date: 2009-03-03 12:51:24 +0100 (Tue, 03 Mar 2009) $
//
//=============================================================================

32
33
34
#ifndef TEXTUREDATA_HH
#define TEXTUREDATA_HH

Jan Möbius's avatar
Jan Möbius committed
35
36
37
#include <OpenFlipper/common/perObjectData.hh>

#include <QString>
38
#include <QStringList>
39
#include <QImage>
40
#include <ACG/GL/gl.hh>
Jan Möbius's avatar
Jan Möbius committed
41
42
#include <vector>
#include <map>
43
44
#include <float.h>
#include <iostream>
Jan Möbius's avatar
Jan Möbius committed
45

46
enum TextureType { UNSET         = 1 << 0,
Jan Möbius's avatar
Jan Möbius committed
47
                   /// Texture Coordinates are stored on a per Vertex basis
48
                   VERTEXBASED   = 1 << 1,
Jan Möbius's avatar
Jan Möbius committed
49
                   /// Texture Coordinates are stored on a per Halfedge basis ( per vertex per face )
50
                   HALFEDGEBASED = 1 << 2,
Jan Möbius's avatar
Jan Möbius committed
51
52
53
54
                   /// Texture coordinates are autogenerated by OpenGL for Environment map
                   ENVIRONMENT   = 1 << 3,
                   /// MultiTexture Mode
                   MULTITEXTURE  = 1 << 4 };
Jan Möbius's avatar
Jan Möbius committed
55

56
57
58
59
60
61
62
63
64
65
66
class TexParameters
{
  public:
    TexParameters() :
          scale ( true ),
          clamp_min ( FLT_MIN ),
          clamp_max ( FLT_MAX ),
          clamp ( false ),
          repeat ( false ),
          center ( false ),
          abs ( false ),
67
          max_val ( 1.0 ) {};
68
69
70
71
72

    bool scale;

    double clamp_min;
    double clamp_max;
Jan Möbius's avatar
Jan Möbius committed
73

74
75
    bool clamp;
    bool repeat;
Jan Möbius's avatar
Jan Möbius committed
76

77
    bool center;
Jan Möbius's avatar
Jan Möbius committed
78

79
    bool abs;
Jan Möbius's avatar
Jan Möbius committed
80

81
    double max_val;
Jan Möbius's avatar
Jan Möbius committed
82
83
};

84
85
86
87
class Texture {
  public :
    Texture();

88

89
90
91
    void filename( QString _name ) { filename_ = _name; };
    QString filename() { return filename_; };

92

93
94
95
    void id( int _id ) { id_ = _id; };
    int id() { return id_; };

96

97
98
99
    void glName( GLuint _glName ) { glName_ = _glName; };
    GLuint glName() { return glName_; };

100

101
102
103
    void name( QString _name ) { name_ = _name; };
    QString name() { return name_; };

104

105
106
107
    void dimension( uint _dimension ) { dimension_ = _dimension; };
    uint dimension( ) { return dimension_; };

108

109
110
111
112
113
    void enabled( bool _enabled ) { enabled_ = _enabled; };
    bool enabled() { return enabled_; };
    void enable(){ enabled_ = true; };
    void disable(){ enabled_ = false; };

114
115
116
117
118
119
120
121
    void hidden( bool _hidden ) { hidden_ = _hidden; };
    bool hidden() { return hidden_; };
    void hide() { hidden_ = true; };

    void dirty( bool _dirty ) { dirty_ = _dirty; };
    bool dirty() { return dirty_; };
    void clean() { dirty_ = false; };
    void setDirty() { dirty_ = true; };
122
123


124
125
    void type( TextureType _type ) { type_ = _type; };
    TextureType type( ) { return type_; };
126

127

128
129
130
131
132
133
134
135
136
137
138
139
    QString indexMappingProperty() { return indexMappingProperty_; };
    void indexMappingProperty( QString _property ) { indexMappingProperty_ = _property; };


    /// Parameters of the texture
    TexParameters parameters;

    /// The image used as the texture
    QImage textureImage;

    /// If this is a multiTexture, the list will contain all textures for this multi Texture node.
    QStringList multiTextureList;
140

141
  private:
142
143
144
145
    /// Texture Name
    QString name_;

    /// Filename of the texture
146
147
    QString filename_;

148
    /// Texture id
149
150
    int id_;

151
    /// glName
152
153
    GLuint glName_;

154
    /// dimension
155
156
    uint dimension_;

157
    /// Status
158
159
    bool enabled_;

160
    /// Hidden flag ( If this texture belongs to a multitexture, it will be hidden in the context menu )
161
162
    bool hidden_;

163
164
165
166
    /// does this texture need an update?
    bool dirty_;

    /// Texture Type
167
    TextureType type_;
168
169
170
171
172
173

    /** If this is a multiTexture, indexMappingProperty_ will point to the property storing the mapping
     * Defaults to the f:textureindex
    */
    QString indexMappingProperty_;

Jan Möbius's avatar
Jan Möbius committed
174
175
176
177
178
179
180
};

class TextureData : public PerObjectData
{

  public :

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
      /// Constructor
      TextureData();
      /// Destructor
      ~TextureData();


      /// Check if a texture exists
      bool textureExists(QString _textureName);


      /// Check if a texture is enabled
      bool isEnabled(QString _textureName);


      /// Enable a given texture
      bool enableTexture(QString _textureName, bool _exclusive = false);

      /// Disable a given texture
      void disableTexture(QString _textureName);

      /// Add a Texture
      int addTexture ( QString _textureName , QString _filename , uint _dimension, GLuint _glName );

      /// Add a Texture ( Based on an existing specification )
      int addTexture ( Texture _texture, GLuint _glName );

207
208
209
      /// Adds a new multiTexture ( This texture will only contain a list of enabled textures for multitexturing )
      bool addMultiTexture( QString _textureName );

210
211
212
      /// Stores the given image in the texture information
      bool setImage( QString _textureName , QImage& _image );

213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
      /*
      /// Delete a given texture
      void deleteTexture(QString _textureName);

      /// get parameters of a given texture
      TexParameters textureParameters(QString _textureName);

      /// Set Parameters for a given texture
      void setTextureParameters(QString _textureName, TexParameters _params);
      */

      /// Get the texture object
      Texture& texture(QString _textureName);

      /// Get reference to the texture vector
      std::vector< Texture >& textures();


231
232
233
234
235
      /** This map maps all available textures for the object which this
       *  class belongs to to their GLuint. The MeshNode will use this
       *  map to activate one texture for each face.
       *
       */
236
237
      std::map< int, GLuint >* textureMap();

238
239
240
    /** This map is used to store the available Textures and map them to their
     *  corresponding properties.
     */
241
242
      std::map< int, std::string >* propertyMap();

Jan Möbius's avatar
Jan Möbius committed
243
244
245
246
247
  private :

    std::map< int, GLuint> textureMap_;
    std::map< int, std::string> propertyMap_;

248
    /// internal id for the next texture
Jan Möbius's avatar
Jan Möbius committed
249
250
    int nextInternalID_;

251

252
    /// vector containing all textures of an object
Jan Möbius's avatar
Jan Möbius committed
253
254
    std::vector< Texture > textures_;

255

256
    /// Get the index of a given texture
Jan Möbius's avatar
Jan Möbius committed
257
258
    int getTextureIndex(QString _textureName);

259
260
    Texture noTexture;

Jan Möbius's avatar
Jan Möbius committed
261
262
};

263
#endif //TEXTUREDATA_HH