Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TextureNode.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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS TextureNode
56 //
57 //=============================================================================
58 
59 
60 #ifndef ACG_TEXTURE_NODE_HH
61 #define ACG_TEXTURE_NODE_HH
62 
63 
64 //== INCLUDES =================================================================
65 
66 
67 #include "BaseNode.hh"
68 
69 #include <ACG/GL/globjects.hh>
70 
71 #include <string>
72 #include <QImage>
73 
74 
75 //== NAMESPACES ===============================================================
76 
77 namespace ACG {
78 namespace SceneGraph {
79 
80 
81 //== CLASS DEFINITION =========================================================
82 
83 
93 class ACGDLLEXPORT TextureNode : public BaseNode
94 {
95 public:
96 
98  TextureNode( BaseNode* _parent = 0,
99  const std::string& _name = "<TextureNode>",
100  bool _texture_repeat = true,
101  GLint _texture_filter = GL_LINEAR );
102 
104  virtual ~TextureNode();
105 
107  ACG_CLASSNAME(TextureNode);
108 
110  bool alpha() { return alpha_; }
111 
113  void set_alpha(bool _status) { alpha_ = _status; }
114 
116  bool repeat() { return texture_repeat_; }
117 
119  void set_repeat(bool _status) { texture_repeat_ = _status; }
120 
122  GLint filter() { return texture_filter_; }
123 
125  void set_filter( GLint _filter ) { texture_filter_ = _filter; }
126 
127  void set_texture_mode( GLenum _mode) { tex_mode_ = _mode; }
128 
130  void enable_mipmapping();
131 
133  void disable_mipmapping();
134 
136  bool mipmapping() const { return mipmapping_; }
137 
138 
139 //===========================================================================
142 //===========================================================================
143 
146 //===========================================================================
149 //===========================================================================
150 
151 public:
152 
153 
157  GLuint add_texture(const QImage& _image);
158 
159  private:
162  void applyTextureParameters( int _id );
163 
166  void applyGLSettings( );
167 
170 //===========================================================================
173 //===========================================================================
174 
175  public :
176 
182  bool activateTexture(GLuint _id);
183 
189  GLuint activeTexture();
190 
196  bool read(const char* _filename);
197 
203  void set_texture(const QImage& _image);
204 
212  void set_texture(const float * _image, int _width, int _height);
213 
214 
222  void set_texture(const unsigned char * _image, int _width, int _height);
223 
226 //===========================================================================
229 //===========================================================================
230 
231  public :
232 
238  bool read(const char* _filename, GLuint _id );
239 
245  void set_texture(const QImage& _image, GLuint _id);
246 
254  void set_texture(const float * _image, int _width, int _height, GLuint _id);
255 
256 
264  void set_texture(const unsigned char * _image, int _width, int _height, GLuint _id);
265 
268 //===========================================================================
271 //===========================================================================
272 
273 public:
276  void enter(GLState& _state, const DrawModes::DrawMode& _drawmode);
277 
280  void leave(GLState& _state, const DrawModes::DrawMode& _drawmode);
281 
284  void enterPick(GLState& _state, PickTarget _target, const DrawModes::DrawMode& _drawMode );
285 
288  void leavePick(GLState& _state, PickTarget _target, const DrawModes::DrawMode& _drawMode );
289 
292 private:
293 
294  class TextureInfo {
295  public:
296  TextureInfo():
297 // id(0),
298  tex(0),
299  mipmapAvailable(false)
300 // width(0),
301 // height(0)
302  {}
303 
304  Texture2D* tex;
305 // GLuint id;
306 // GLenum target;
307  bool mipmapAvailable;
308 // int width;
309 // int height;
310  };
311 
312  void setTextureDataGL ( GLuint _textureId,
313  GLenum _target,
314  GLint _width ,
315  GLint _height,
316  GLenum _format ,
317  GLenum _type,
318  const void * _data) ;
319 
320  std::vector<TextureInfo> textures_;
321  bool alpha_;
322  bool texture_repeat_;
323  GLenum tex_mode_;
324  GLint texture_filter_;
325 
326  bool mipmapping_globally_active_;
327  bool last_mipmapping_status_;
328  bool mipmapping_;
329 
335  void checkEmpty();
336 
342  int available( GLuint _id );
343 
346  void updateMipmaps(bool _mipmap);
347 
353 
359 };
360 
361 
362 //=============================================================================
363 } // namespace SceneGraph
364 } // namespace ACG
365 //=============================================================================
366 #endif // ACG_TEXTURE_NODE_HH defined
367 //=============================================================================
368 
void set_alpha(bool _status)
set transparency status
Definition: TextureNode.hh:113
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
GLint filter()
get texture filter
Definition: TextureNode.hh:122
bool repeat()
get texture repeat status
Definition: TextureNode.hh:116
DrawModes::DrawMode open_volume_mesh_texture_draw_modes_
OpenVolumeMesh DrawModes using textures.
Definition: TextureNode.hh:358
int activeTexture_
currently active texture
Definition: TextureNode.hh:352
void set_filter(GLint _filter)
set texture filter
Definition: TextureNode.hh:125
bool mipmapping() const
Get mipmapping status.
Definition: TextureNode.hh:136
void set_repeat(bool _status)
set texture repeat status
Definition: TextureNode.hh:119
bool alpha()
get transparency status
Definition: TextureNode.hh:110