Developer Documentation

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
45
46
47 //=============================================================================
48 //
49 // CLASS TextureNode
50 //
51 //=============================================================================
52
53
54 #ifndef ACG_TEXTURE_NODE_HH
55 #define ACG_TEXTURE_NODE_HH
56
57
58 //== INCLUDES =================================================================
59
60
61 #include "BaseNode.hh"
62
63 #include <ACG/GL/globjects.hh>
64
65 #include <string>
66 #include <QImage>
67
68
69 //== NAMESPACES ===============================================================
70
71 namespace ACG {
72 namespace SceneGraph {
73
74
75 //== CLASS DEFINITION =========================================================
76
77
87 class ACGDLLEXPORT TextureNode : public BaseNode
88 {
89 public:
90
92 TextureNode( BaseNode* _parent = 0,
93 const std::string& _name = "<TextureNode>",
94 bool _texture_repeat = true,
95 GLint _texture_filter = GL_LINEAR );
96
98 virtual ~TextureNode();
99
101 ACG_CLASSNAME(TextureNode);
102
104 bool alpha() { return alpha_; }
105
107 void set_alpha(bool _status) { alpha_ = _status; }
108
110 bool repeat() { return texture_repeat_; }
111
113 void set_repeat(bool _status) { texture_repeat_ = _status; }
114
116 GLint filter() { return texture_filter_; }
117
119 void set_filter( GLint _filter ) { texture_filter_ = _filter; }
120
121 void set_texture_mode( GLenum _mode) { tex_mode_ = _mode; }
122
124 void enable_mipmapping();
125
127 void disable_mipmapping();
128
130 bool mipmapping() const { return mipmapping_; }
131
132
133 //===========================================================================
136 //===========================================================================
137
140 //===========================================================================
143 //===========================================================================
144
145 public:
146
147
151 GLuint add_texture(const QImage& _image);
152
153 private:
156 void applyTextureParameters( int _id );
157
160 void applyGLSettings( );
161
164 //===========================================================================
167 //===========================================================================
168
169 public :
170
176 bool activateTexture(GLuint _id);
177
183 GLuint activeTexture();
184
190 bool read(const char* _filename);
191
197 void set_texture(const QImage& _image);
198
206 void set_texture(const float * _image, int _width, int _height);
207
208
216 void set_texture(const unsigned char * _image, int _width, int _height);
217
220 //===========================================================================
223 //===========================================================================
224
225 public :
226
232 bool read(const char* _filename, GLuint _id );
233
239 void set_texture(const QImage& _image, GLuint _id);
240
248 void set_texture(const float * _image, int _width, int _height, GLuint _id);
249
250
258 void set_texture(const unsigned char * _image, int _width, int _height, GLuint _id);
259
262 //===========================================================================
265 //===========================================================================
266
267 public:
270 void enter(GLState& _state, const DrawModes::DrawMode& _drawmode) override;
271
274 void leave(GLState& _state, const DrawModes::DrawMode& _drawmode) override;
275
278 void enterPick(GLState& _state, PickTarget _target, const DrawModes::DrawMode& _drawMode ) override;
279
282 void leavePick(GLState& _state, PickTarget _target, const DrawModes::DrawMode& _drawMode ) override;
283
286 private:
287
288 class TextureInfo {
289 public:
290 TextureInfo():
291 // id(0),
292 tex(0),
293 mipmapAvailable(false)
294 // width(0),
295 // height(0)
296 {}
297
298 Texture2D* tex;
299 // GLuint id;
300 // GLenum target;
301 bool mipmapAvailable;
302 // int width;
303 // int height;
304 };
305
306 void setTextureDataGL ( GLuint _textureId,
307 GLenum _target,
308 GLint _width ,
309 GLint _height,
310 GLenum _format ,
311 GLenum _type,
312 const void * _data) ;
313
314 std::vector<TextureInfo> textures_;
315 bool alpha_;
316 bool texture_repeat_;
317 GLenum tex_mode_;
318 GLint texture_filter_;
319
320 bool mipmapping_globally_active_;
321 bool last_mipmapping_status_;
322 bool mipmapping_;
323
329 void checkEmpty();
330
336 int available( GLuint _id );
337
340 void updateMipmaps(bool _mipmap);
341
346 int activeTexture_;
347
352 DrawModes::DrawMode open_volume_mesh_texture_draw_modes_;
353 };
354
355
356 //=============================================================================
357 } // namespace SceneGraph
358 } // namespace ACG
359 //=============================================================================
360 #endif // ACG_TEXTURE_NODE_HH defined
361 //=============================================================================
362
ACG::SceneGraph::TextureNode
Definition: TextureNode.hh:87
ACG::GLState
Definition: GLState.hh:213
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::SceneGraph::TextureNode::set_filter
void set_filter(GLint _filter)
set texture filter
Definition: TextureNode.hh:119
ACG::SceneGraph::TextureNode::open_volume_mesh_texture_draw_modes_
DrawModes::DrawMode open_volume_mesh_texture_draw_modes_
OpenVolumeMesh DrawModes using textures.
Definition: TextureNode.hh:352
ACG::SceneGraph::TextureNode::filter
GLint filter()
get texture filter
Definition: TextureNode.hh:116
ACG::Texture2D
Definition: globjects.hh:391
ACG::SceneGraph::TextureNode::repeat
bool repeat()
get texture repeat status
Definition: TextureNode.hh:110
SceneGraph
Definition: QtPrincipalAxisDialog.hh:67
ACG::SceneGraph::TextureNode::TextureInfo
Definition: TextureNode.hh:288
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
ACG::SceneGraph::TextureNode::alpha
bool alpha()
get transparency status
Definition: TextureNode.hh:104
ACG::SceneGraph::TextureNode::activeTexture_
int activeTexture_
currently active texture
Definition: TextureNode.hh:346
ACG::SceneGraph::TextureNode::set_alpha
void set_alpha(bool _status)
set transparency status
Definition: TextureNode.hh:107
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
ACG::SceneGraph::TextureNode::mipmapping
bool mipmapping() const
Get mipmapping status.
Definition: TextureNode.hh:130
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:288
ACG::SceneGraph::TextureNode::set_repeat
void set_repeat(bool _status)
set texture repeat status
Definition: TextureNode.hh:113