Developer Documentation
TextureData.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 #ifndef TEXTUREDATA_HH
45 #define TEXTUREDATA_HH
46 
48 #include "TextureParameters.hh"
49 
50 #include <QString>
51 #include <QStringList>
52 #include <ACG/GL/gl.hh>
53 #include <vector>
54 #include <map>
55 #include <cfloat>
56 
57 
58 enum TextureType { UNSET = 1 << 0,
60  VERTEXBASED = 1 << 1,
62  HALFEDGEBASED = 1 << 2,
64  ENVIRONMENT = 1 << 3,
66  MULTITEXTURE = 1 << 4 };
67 
68 class Texture {
69  public :
70  Texture();
71 
72  // copy constructor
73  Texture( const Texture& _tex)
74  : parameters(_tex.parameters),
76  name_(_tex.name_),
79  filename_(_tex.filename_),
80  id_(_tex.id_),
81  glName_(_tex.glName_),
82  dimension_(_tex.dimension_),
83  enabled_(_tex.enabled_),
84  hidden_(_tex.hidden_),
85  dirty_(_tex.dirty_),
86  type_(_tex.type_),
88  {
89  }
90 
91 
92  void filename( QString _name ) { filename_ = _name; };
93  QString filename() { return filename_; };
94 
95 
96  void id( int _id ) { id_ = _id; };
97  int id() { return id_; };
98 
99 
100  void glName( GLuint _glName ) { glName_ = _glName; };
101  GLuint glName() { return glName_; };
102 
103 
104  void name( QString _name ) { name_ = _name; };
105  QString name() { return name_; };
106 
107  void visibleName( QString _name ) { visibleName_ = _name; };
108  QString visibleName() { return visibleName_; };
109 
110 
111  void dimension( uint _dimension ) { dimension_ = _dimension; };
112  uint dimension( ) { return dimension_; };
113 
114 
115  void enabled( bool _enabled ) { enabled_ = _enabled; };
116  bool enabled() { return enabled_; };
117  void enable(){ enabled_ = true; };
118  void disable(){ enabled_ = false; };
119 
120  void hidden( bool _hidden ) { hidden_ = _hidden; };
121  bool hidden() { return hidden_; };
122  void hide() { hidden_ = true; };
123 
124  void dirty( bool _dirty ) { dirty_ = _dirty; };
125  bool dirty() { return dirty_; };
126  void clean() { dirty_ = false; };
127  void setDirty() { dirty_ = true; };
128 
129  void textureImageId( int _id) {textureImageId_ = _id;};
130  int textureImageId() {return textureImageId_; };
131 
132 
133  void type( TextureType _type ) { type_ = _type; };
134  TextureType type( ) { return type_; };
135 
136 
137  QString indexMappingProperty() { return indexMappingProperty_; };
138  void indexMappingProperty( QString _property ) { indexMappingProperty_ = _property; };
139 
140 
143 
144 
146  QStringList multiTextureList;
147 
148  private:
150  QString name_;
151 
154 
156  QString visibleName_;
157 
159  QString filename_;
160 
162  int id_;
163 
165  GLuint glName_;
166 
169 
171  bool enabled_;
172 
174  bool hidden_;
175 
177  bool dirty_;
178 
180  TextureType type_;
181 
186 
187 };
188 
190 {
191 
192  public :
193 
195  TextureData();
197  ~TextureData();
198 
199  // copy Operator returning an exact copy of this Object
201 
202  // Create an object copy (This will call all copy constructors of the included data objects! )
203  TextureData* copy = new TextureData(*this);
204 
205  return copy;
206  }
207 
208 
210  bool textureExists(QString _textureName);
211 
212 
214  bool isEnabled(QString _textureName);
215 
216 
218  bool enableTexture(QString _textureName, bool _exclusive = false);
219 
221  void disableTexture(QString _textureName);
222 
224  int addTexture ( QString _textureName , uint _dimension, GLuint _glName ){return addTexture ( _textureName , QString("Invalid") , _dimension, _glName );}
225 
227  int addTexture ( QString _textureName , QString _filename , uint _dimension, GLuint _glName );
228 
230  int addTexture ( Texture _texture, GLuint _glName );
231 
233  bool addMultiTexture( QString _textureName );
234 
236  bool setImage( QString _textureName , int _id );
237 
238  /*
240  void deleteTexture(QString _textureName);
241 
243  TexParameters textureParameters(QString _textureName);
244 
246  void setTextureParameters(QString _textureName, TexParameters _params);
247  */
248 
250  Texture& texture(QString _textureName);
251 
253  std::vector< Texture >& textures();
254 
255 
261  std::map< int, GLuint >* textureMap();
262 
266  std::map< int, std::string >* propertyMap();
267 
268  private :
269 
270  std::map< int, GLuint> textureMap_;
271  std::map< int, std::string> propertyMap_;
272 
275 
276 
278  std::vector< Texture > textures_;
279 
280 
282  int getTextureIndex(QString _textureName);
283 
284  Texture noTexture;
285 
286 };
287 
288 #endif //TEXTUREDATA_HH
QString indexMappingProperty_
Definition: TextureData.hh:185
std::vector< Texture > textures_
vector containing all textures of an object
Definition: TextureData.hh:278
Object Payload.
GLuint glName_
glName
Definition: TextureData.hh:165
bool dirty_
does this texture need an update?
Definition: TextureData.hh:177
int id_
Texture id.
Definition: TextureData.hh:162
QString name_
Texture Name.
Definition: TextureData.hh:150
QString filename_
Filename of the texture.
Definition: TextureData.hh:159
bool enabled_
Status.
Definition: TextureData.hh:171
int nextInternalID_
internal id for the next texture
Definition: TextureData.hh:274
bool hidden_
Hidden flag ( If this texture belongs to a multitexture, it will be hidden in the context menu ) ...
Definition: TextureData.hh:174
int textureImageId_
The image used as the texture ( Ids are handled by the ImageStore )
Definition: TextureData.hh:153
QStringList multiTextureList
If this is a multiTexture, the list will contain all textures for this multi Texture node...
Definition: TextureData.hh:146
TextureType type_
Texture Type.
Definition: TextureData.hh:180
virtual PerObjectData * copyPerObjectData()
Copy Function.
Definition: TextureData.hh:200
int addTexture(QString _textureName, uint _dimension, GLuint _glName)
Add a Texture without file backing.
Definition: TextureData.hh:224
TexParameters parameters
Parameters of the texture.
Definition: TextureData.hh:138
QString visibleName_
Name visible in the gui.
Definition: TextureData.hh:156
uint dimension_
dimension
Definition: TextureData.hh:168