TextureData.hh 9.75 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
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
32
33
34
35
36
37
38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40
41
\*===========================================================================*/

Jan Möbius's avatar
Jan Möbius committed
42

Jan Möbius's avatar
Jan Möbius committed
43

44
45
46
#ifndef TEXTUREDATA_HH
#define TEXTUREDATA_HH

Jan Möbius's avatar
Jan Möbius committed
47
#include <OpenFlipper/common/perObjectData.hh>
48
#include "TextureParameters.hh"
Jan Möbius's avatar
Jan Möbius committed
49
50

#include <QString>
51
#include <QStringList>
52
#include <ACG/GL/gl.hh>
Jan Möbius's avatar
Jan Möbius committed
53
54
#include <vector>
#include <map>
55
#include <set>
56
#include <cfloat>
57

58
enum TextureType { UNSET         = 1 << 0,
Jan Möbius's avatar
Jan Möbius committed
59
                   /// Texture Coordinates are stored on a per Vertex basis
60
                   VERTEXBASED   = 1 << 1,
Jan Möbius's avatar
Jan Möbius committed
61
                   /// Texture Coordinates are stored on a per Halfedge basis ( per vertex per face )
62
                   HALFEDGEBASED = 1 << 2,
Jan Möbius's avatar
Jan Möbius committed
63
64
65
66
                   /// 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
67

68
69
70
class Texture {
  public :
    Texture();
71

72
73
74
75
76
    // copy constructor
    Texture( const Texture& _tex)
    : parameters(_tex.parameters),
    multiTextureList(_tex.multiTextureList),
    name_(_tex.name_),
77
    textureImageId_(_tex.textureImageId_),
78
79
80
81
82
83
84
85
86
87
88
89
    visibleName_(_tex.visibleName_),
    filename_(_tex.filename_),
    id_(_tex.id_),
    glName_(_tex.glName_),
    dimension_(_tex.dimension_),
    enabled_(_tex.enabled_),
    hidden_(_tex.hidden_),
    dirty_(_tex.dirty_),
    type_(_tex.type_),
    indexMappingProperty_(_tex.indexMappingProperty_)
    {
    }
90

91

92
93
94
    void filename( QString _name ) { filename_ = _name; };
    QString filename() { return filename_; };

95

96
97
98
    void id( int _id ) { id_ = _id; };
    int id() { return id_; };

99

100
101
102
    void glName( GLuint _glName ) { glName_ = _glName; };
    GLuint glName() { return glName_; };

103

104
105
106
    void name( QString _name ) { name_ = _name; };
    QString name() { return name_; };

107
108
109
    void visibleName( QString _name ) { visibleName_ = _name; };
    QString visibleName() { return visibleName_; };

110

111
112
113
    void dimension( uint _dimension ) { dimension_ = _dimension; };
    uint dimension( ) { return dimension_; };

114

115
116
117
118
119
    void enabled( bool _enabled ) { enabled_ = _enabled; };
    bool enabled() { return enabled_; };
    void enable(){ enabled_ = true; };
    void disable(){ enabled_ = false; };

120
121
122
123
124
125
126
127
    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; };
128

129
130
131
    void textureImageId( int _id) {textureImageId_ = _id;};
    int textureImageId() {return textureImageId_; };

132

133
134
    void type( TextureType _type ) { type_ = _type; };
    TextureType type( ) { return type_; };
135

136

137
138
139
140
141
142
143
144
145
146
    QString indexMappingProperty() { return indexMappingProperty_; };
    void indexMappingProperty( QString _property ) { indexMappingProperty_ = _property; };


    /// Parameters of the texture
    TexParameters parameters;


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

148
  private:
149
150
151
    /// Texture Name
    QString name_;

152
153
154
    /// The image used as the texture ( Ids are handled by the ImageStore )
    int textureImageId_;

155
156
157
    /// Name visible in the gui
    QString visibleName_;

158
    /// Filename of the texture
159
160
    QString filename_;

161
    /// Texture id
162
163
    int id_;

164
    /// glName
165
166
    GLuint glName_;

167
    /// dimension
168
169
    uint dimension_;

170
    /// Status
171
172
    bool enabled_;

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

176
177
178
179
    /// does this texture need an update?
    bool dirty_;

    /// Texture Type
180
    TextureType type_;
181
182
183
184
185
186

    /** 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
187
188
189
190
191
192
193
};

class TextureData : public PerObjectData
{

  public :

194
195
196
197
      /// Constructor
      TextureData();
      /// Destructor
      ~TextureData();
198

199
200
      // copy Operator returning an exact copy of this Object
      virtual PerObjectData* copyPerObjectData( ) {
201

202
203
        // Create an object copy (This will call all copy constructors of the included data objects! )
        TextureData* copy = new TextureData(*this);
204

205
206
        return copy;
      }
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222


      /// 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);

223
224
      /// Add a Texture without file backing
      int addTexture ( QString _textureName , uint _dimension, GLuint _glName ){return addTexture ( _textureName , QString("Invalid") , _dimension, _glName );}
225

226
227
228
229
230
231
      /// 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 );

232
233
234
      /// Adds a new multiTexture ( This texture will only contain a list of enabled textures for multitexturing )
      bool addMultiTexture( QString _textureName );

235
      /// Stores the given image in the texture information
236
      bool setImage( QString _textureName , int _id );
237

238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
      /*
      /// 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();


256
257
258
259
260
      /** 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.
       *
       */
261
262
      std::map< int, GLuint >* textureMap();

263
264
265
    /** This map is used to store the available Textures and map them to their
     *  corresponding properties.
     */
266
267
      std::map< int, std::string >* propertyMap();

268
      void addManagedImageId(int _imageId);
Jan Möbius's avatar
Jan Möbius committed
269
  private :
270
    std::vector<int> managedImageId_;
Jan Möbius's avatar
Jan Möbius committed
271
272
273
    std::map< int, GLuint> textureMap_;
    std::map< int, std::string> propertyMap_;

274
    /// internal id for the next texture
Jan Möbius's avatar
Jan Möbius committed
275
276
    int nextInternalID_;

277

278
    /// vector containing all textures of an object
Jan Möbius's avatar
Jan Möbius committed
279
280
    std::vector< Texture > textures_;

281

282
    /// Get the index of a given texture
Jan Möbius's avatar
Jan Möbius committed
283
284
    int getTextureIndex(QString _textureName);

285
286
    Texture noTexture;

Jan Möbius's avatar
Jan Möbius committed
287
288
};

289
#endif //TEXTUREDATA_HH