Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
BaseNode.cc
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 BaseNode - IMPLEMENTATION
56 //
57 //=============================================================================
58
59
60 //== INCLUDES =================================================================
61
62 #include "BaseNode.hh"
63
64
65 //== NAMESPACES ===============================================================
66
67 namespace ACG {
68 namespace SceneGraph {
69
70
71 //== IMPLEMENTATION ==========================================================
72
73
74 unsigned int BaseNode::last_id_used__ = 0;
75
76
77 //----------------------------------------------------------------------------
78
79
80 BaseNode::
81 BaseNode(BaseNode* _parent, std::string _name)
82 : multipassStatus_(ALLPASSES),
83 multipassNode_(PASS_1),
84 parent_(_parent),
85 name_(_name),
86 status_(Active),
87 drawMode_(DrawModes::DEFAULT),
88 pickingEnabled_(true),
89 dirty_ (false),
90 traverseMode_ (BaseNode::NodeFirst),
91 uniformPool_(0),
92 renderModifier_(0)
93 {
94 id_ = ++last_id_used__;
95 if (_parent!=0) _parent->push_back(this);
96
97 DrawModes::initializeDefaultDrawModes();
98 }
99
100
101 //----------------------------------------------------------------------------
102
103
104 BaseNode::
105 BaseNode(BaseNode* _parent, BaseNode* _child, std::string _name)
106 : multipassStatus_(ALLPASSES),
107 multipassNode_(PASS_1),
108 parent_(_parent),
109 name_(_name),
110 status_(Active),
111 drawMode_(DrawModes::DEFAULT),
112 pickingEnabled_(true),
113 dirty_ (false),
114 traverseMode_ (BaseNode::NodeFirst)
115 {
116 assert(_parent != 0 && _child != 0);
117
118 id_ = ++last_id_used__;
119
120 _parent->push_back(this);
121 _child->set_parent(this);
122
123 DrawModes::initializeDefaultDrawModes();
124 }
125
126
127 //----------------------------------------------------------------------------
128
129
130 BaseNode::~BaseNode()
131 {
132 // remove myself from parent's children
133 if (parent_!=0)
134 {
135 ChildIter me(parent_->find(this));
136 assert(me != parent_->childrenEnd());
137 parent_->remove(me);
138 }
139
140
141 // remove me (as parent) from my children
142 for (BaseNode::ChildIter cIt=childrenBegin(); cIt!=childrenEnd(); ++cIt)
143 (*cIt)->parent_ = 0;
144 }
145
146
147 //----------------------------------------------------------------------------
148
149
150 void
151 BaseNode::
152 set_parent(BaseNode* _parent)
153 {
154 if (parent_)
155 {
156 ChildIter me(parent_->find(this));
157 if (me != parent_->childrenEnd())
158 parent_->remove(me);
159 }
160
161 parent_ = _parent;
162
163 if (parent_)
164 {
165 ChildIter me(parent_->find(this));
166 if (me == parent_->childrenEnd())
167 parent_->push_back(this);
168 }
169 }
170
171
172 //----------------------------------------------------------------------------
173
174
175 void
176 BaseNode::delete_subtree()
177 {
178 while (!children_.empty())
179 children_.front()->delete_subtree();
180 delete this;
181 }
182
183 //----------------------------------------------------------------------------
184
185 void
186 BaseNode::enterPick(GLState& _state, PickTarget /*_target*/, const DrawModes::DrawMode& _drawMode)
187 {
188 enter (_state, _drawMode);
189 }
190
191 //----------------------------------------------------------------------------
192
193 void
194 BaseNode::leavePick(GLState& _state, PickTarget /*_target*/, const DrawModes::DrawMode& _drawMode)
195 {
196 leave (_state, _drawMode);
197 }
198
199 //----------------------------------------------------------------------------
200
201 void BaseNode::multipassStatusSetActive(const unsigned int _i, bool _active) {
202
203 if ( _i == NOPASS ) {
204 multipassStatus_ = NOPASS;
205 } else if ( _i == ALLPASSES ) {
206 if ( _active )
207 multipassStatus_ = ALLPASSES;
208 else
209 multipassStatus_ = NOPASS;
210 } else {
211 if ( _active )
212 multipassStatus_ |= (1 << (_i == 0 ? 0 : _i - 1));
213 else
214 multipassStatus_ &= ~(1 << (_i == 0 ? 0 : _i - 1));
215 }
216
217 }
218
219 //----------------------------------------------------------------------------
220
221 bool BaseNode::multipassStatusActive(const unsigned int _i) const {
222
223 if ( multipassStatus_ == NOPASS )
224 return false;
225 else if ( multipassStatus_ & ALLPASSES )
226 return true;
227 else
228 return ((1 << (_i == 0 ? 0 : _i - 1)) & multipassStatus_) != 0;
229
230 }
231
232 //----------------------------------------------------------------------------
233
234 void BaseNode::multipassNodeSetActive(const unsigned int _i , bool _active) {
235
236 if ( _i == NOPASS ) {
237 multipassNode_ = NOPASS;
238 } else if ( _i == ALLPASSES ) {
239 if ( _active )
240 multipassNode_ = ALLPASSES;
241 else
242 multipassNode_ = NOPASS;
243 } else {
244 if ( _active )
245 multipassNode_ |= (1 << (_i == 0 ? 0 : _i - 1));
246 else
247 multipassNode_ &= ~(1 << (_i == 0 ? 0 : _i - 1));
248 }
249
250 }
251
252 //----------------------------------------------------------------------------
253
254 bool BaseNode::multipassNodeActive(const unsigned int _i) const {
255
256 if ( multipassNode_ == NOPASS )
257 return false;
258 else if ( multipassNode_ & ALLPASSES )
259 return true;
260 else
261 return ((1 << (_i == 0 ? 0 : _i - 1)) & multipassNode_) != 0;
262
263 }
264
265 //----------------------------------------------------------------------------
266
267 void BaseNode::setRenderObjectShaders( const std::string& _vertexShaderFile, const std::string& _geometryShaderFile, const std::string& _fragmentShaderFile, bool _relativePaths, ACG::SceneGraph::DrawModes::DrawModePrimitive _primitiveType ) {
268
269 ShaderSet s;
270 s.vs_ = _vertexShaderFile;
271 s.gs_ = _geometryShaderFile;
272 s.fs_ = _fragmentShaderFile;
273 s.relativePaths_ = _relativePaths;
274
275 shaderSettings_[_primitiveType] = s;
276 }
277
278 //----------------------------------------------------------------------------
279
280 void BaseNode::setRenderObjectShaders( const std::string& _vertexShaderFile, const std::string& _tessControlShaderFile, const std::string& _tessEvalShaderFile, const std::string& _geometryShaderFile, const std::string& _fragmentShaderFile, bool _relativePaths, ACG::SceneGraph::DrawModes::DrawModePrimitive _primitiveType ) {
281
282 ShaderSet s;
283 s.vs_ = _vertexShaderFile;
284 s.gs_ = _geometryShaderFile;
285 s.fs_ = _fragmentShaderFile;
286 s.tcs_ = _tessControlShaderFile;
287 s.tes_ = _tessEvalShaderFile;
288 s.relativePaths_ = _relativePaths;
289
290 shaderSettings_[_primitiveType] = s;
291 }
292
293 //----------------------------------------------------------------------------
294
295 void BaseNode::setRenderObjectTexture( int _samplerSlot, GLuint _texId, GLenum _texType ) {
296
297 ACG::RenderObject::Texture t;
298 t.id = _texId;
299 t.type = _texType;
300 t.shadow = false;
301
302 textureSettings_[_samplerSlot] = t;
303 }
304
305 //----------------------------------------------------------------------------
306
307 void BaseNode::applyRenderObjectSettings( DrawModes::DrawModePrimitive _primitive, RenderObject* _obj ) const {
308
309 // Copy texture settings
310 for (std::map<int, RenderObject::Texture>::const_iterator it = textureSettings_.begin(); it != textureSettings_.end(); ++it)
311 _obj->addTexture(it->second, size_t(it->first), false);
312
313 // Copy uniforms from provided pool
314 if (uniformPool_)
315 _obj->addUniformPool(*uniformPool_);
316
317
318 std::map<DrawModes::DrawModePrimitive, ShaderSet>::const_iterator shaderSet = shaderSettings_.find(_primitive);
319
320 bool defaultShaders = shaderSet == shaderSettings_.end();
321
322 if (!defaultShaders) {
323
324 // prepend openflipper shader dir
325 if (shaderSet->second.relativePaths_) {
326 _obj->shaderDesc.tessControlTemplateFile =
327 _obj->shaderDesc.tessEvaluationTemplateFile =
328 _obj->shaderDesc.vertexTemplateFile =
329 _obj->shaderDesc.geometryTemplateFile =
330 _obj->shaderDesc.fragmentTemplateFile = ShaderProgGenerator::getShaderDir();
331 }
332
333 _obj->shaderDesc.vertexTemplateFile += shaderSet->second.vs_.c_str();
334 _obj->shaderDesc.tessControlTemplateFile += shaderSet->second.tcs_.c_str();
335 _obj->shaderDesc.tessEvaluationTemplateFile += shaderSet->second.tes_.c_str();
336 _obj->shaderDesc.geometryTemplateFile += shaderSet->second.gs_.c_str();
337 _obj->shaderDesc.fragmentTemplateFile += shaderSet->second.fs_.c_str();
338 }
339
340 if (renderModifier_)
341 renderModifier_->apply(_obj);
342 }
343
344 //=============================================================================
345 } // namespace SceneGraph
346 } // namespace ACG
347 //=============================================================================
ACG::SceneGraph::ACG::SceneGraph::DrawModes::DrawModePrimitive
DrawModePrimitive
Primitive mode of a mesh.
Definition: MeshNode2T.cc:124
ACG::SceneGraph::ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: MeshNode2T.cc:294
ACG::SceneGraph::ACG::RenderObject::shaderDesc
ShaderGenDesc shaderDesc
Drawmode and other shader params.
Definition: MeshNode2T.cc:232
ACG
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
ACG::SceneGraph::ACG::RenderObject::Texture
Texture to be used.
Definition: MeshNode2T.cc:306
ACG::SceneGraph::ACG::SceneGraph::BaseNode::enter
virtual void enter(GLState &, const DrawModes::DrawMode &)
Definition: MeshNode2T.cc:182
ACG::SceneGraph::ACG::SceneGraph::BaseNode::leave
virtual void leave(GLState &, const DrawModes::DrawMode &)
Definition: MeshNode2T.cc:217
ACG::SceneGraph::BaseNode::BaseNode
BaseNode(BaseNode *_parent=0, std::string _name="<unknown>")
Default constructor.
ACG::SceneGraph::ACG::GLState
Definition: MeshNode2T.cc:220
ACG::SceneGraph::ACG::SceneGraph::BaseNode::renderModifier_
RenderObjectModifier * renderModifier_
render-object modifier
Definition: MeshNode2T.cc:754
ACG::SceneGraph::ACG::SceneGraph::BaseNode::multipassNodeSetActive
void multipassNodeSetActive(const unsigned int _i, bool _active)
Set Node status to traverse in a specific pass.
Definition: BaseNode.cc:234
ACG::SceneGraph::ACG::SceneGraph::BaseNode::shaderSettings_
std::map< DrawModes::DrawModePrimitive, ShaderSet > shaderSettings_
shader settings for primitive modes
Definition: MeshNode2T.cc:745
ACG::SceneGraph::ACG::SceneGraph::BaseNode::childrenEnd
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: MeshNode2T.cc:274
ACG::SceneGraph::ACG::SceneGraph::BaseNode::setRenderObjectTexture
void setRenderObjectTexture(int _samplerSlot, GLuint _texId, GLenum _texType=GL_TEXTURE_2D)
Set textures for shader based rendering.
Definition: BaseNode.cc:295
ACG::SceneGraph::ACG::SceneGraph::BaseNode::find
ChildIter find(BaseNode *_node)
Definition: MeshNode2T.cc:322
ACG::SceneGraph::ACG::SceneGraph::BaseNode::children_
std::list< BaseNode * > children_
list of children
Definition: MeshNode2T.cc:695
ACG::SceneGraph::ACG::SceneGraph::BaseNode::multipassNode_
MultipassBitMask multipassNode_
Definition: MeshNode2T.cc:672
ACG::SceneGraph::ACG::SceneGraph::BaseNode::push_back
void push_back(BaseNode *_node)
Insert _node at the end of the list of children.
Definition: MeshNode2T.cc:294
ACG::SceneGraph::ACG::SceneGraph::DrawModes::initializeDefaultDrawModes
ACGDLLEXPORT void initializeDefaultDrawModes(void)
Definition: DrawModes.cc:645
ACG::SceneGraph::ACG::SceneGraph::BaseNode::delete_subtree
void delete_subtree()
Delete the whole subtree of this node.
Definition: BaseNode.cc:176
ACG::SceneGraph::ACG::SceneGraph::BaseNode::enterPick
virtual void enterPick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
Definition: BaseNode.cc:186
ACG::SceneGraph::ACG::SceneGraph::BaseNode::ShaderSet::fs_
std::string fs_
fragment
Definition: MeshNode2T.cc:738
ACG::SceneGraph::ACG::SceneGraph::BaseNode::uniformPool_
const GLSL::UniformPool * uniformPool_
user provided uniform pool for shader constants
Definition: MeshNode2T.cc:751
ACG::SceneGraph::BaseNode::ChildIter
std::list< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:262
ACG::SceneGraph::ACG::SceneGraph::BaseNode::ShaderSet::relativePaths_
bool relativePaths_
rel or abs path
Definition: MeshNode2T.cc:741
ACG::SceneGraph::ACG::SceneGraph::BaseNode::last_id_used__
static unsigned int last_id_used__
used to provide unique IDs to nodes
Definition: MeshNode2T.cc:698
ACG::SceneGraph::ACG::SceneGraph::BaseNode::multipassStatusSetActive
void multipassStatusSetActive(const unsigned int _i, bool _active)
Set multipass status to traverse in a specific pass.
Definition: BaseNode.cc:201
ACG::SceneGraph::ACG::SceneGraph::BaseNode::ShaderSet
Definition: MeshNode2T.cc:721
ACG::SceneGraph::ACG::SceneGraph::BaseNode::ShaderSet::tes_
std::string tes_
tess-eval
Definition: MeshNode2T.cc:732
ACG::SceneGraph::ACG::SceneGraph::BaseNode::set_parent
void set_parent(BaseNode *_parent)
Set the parent of this node.
Definition: BaseNode.cc:152
ACG::SceneGraph::ACG::SceneGraph::BaseNode::textureSettings_
std::map< int, RenderObject::Texture > textureSettings_
texture settings for shader based rendering
Definition: MeshNode2T.cc:748
ACG::SceneGraph::ACG::SceneGraph::BaseNode::multipassNodeActive
bool multipassNodeActive(const unsigned int _i) const
Get Node status to traverse in a specific pass.
Definition: BaseNode.cc:254
ACG::SceneGraph::BaseNode::last_id_used__
static unsigned int last_id_used__
used to provide unique IDs to nodes
Definition: BaseNode.hh:698
ACG::SceneGraph::ACG::SceneGraph::BaseNode::ShaderSet::tcs_
std::string tcs_
tess-control
Definition: MeshNode2T.cc:729
ACG::SceneGraph::ACG::SceneGraph::BaseNode::ChildIter
std::list< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: MeshNode2T.cc:262
ACG::SceneGraph::ACG::SceneGraph::BaseNode::leavePick
virtual void leavePick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
Definition: BaseNode.cc:194
ACG::SceneGraph::ACG::RenderObject
Interface class between scenegraph and renderer.
Definition: MeshNode2T.cc:105
ACG::SceneGraph::ACG::SceneGraph::BaseNode::applyRenderObjectSettings
void applyRenderObjectSettings(DrawModes::DrawModePrimitive _primitive, RenderObject *_obj) const
Set shaders, textures and uniforms as provided by user to a render-object.
Definition: BaseNode.cc:307
ACG::SceneGraph::ACG::SceneGraph::BaseNode::ShaderSet::gs_
std::string gs_
geometry
Definition: MeshNode2T.cc:735
ACG::SceneGraph::ACG::RenderObject::addUniformPool
void addUniformPool(const GLSL::UniformPool &_pool)
add all uniforms from a pool
ACG::SceneGraph::ACG::SceneGraph::BaseNode::childrenBegin
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: MeshNode2T.cc:270
ACG::SceneGraph::ACG::RenderObjectModifier::apply
virtual void apply(RenderObject *_obj)=0
apply the modifier
ACG::SceneGraph::ACG::SceneGraph::BaseNode::setRenderObjectShaders
void setRenderObjectShaders(const std::string &_vertexShaderFile, const std::string &_geometryShaderFile, const std::string &_fragmentShaderFile, bool _relativePaths=true, DrawModes::DrawModePrimitive _primitiveType=DrawModes::PRIMITIVE_POLYGON)
Set custom shaders.
Definition: BaseNode.cc:267
ACG::SceneGraph::ACG::SceneGraph::BaseNode::remove
void remove(ChildIter _pos)
Definition: MeshNode2T.cc:306
ACG::SceneGraph::ACG::RenderObject::addTexture
void addTexture(const Texture &_t)
adds a texture to stage RenderObjects::numTextures()
Definition: MeshNode2T.cc:319
ACG::SceneGraph::ACG::SceneGraph::BaseNode::multipassStatusActive
bool multipassStatusActive(const unsigned int _i) const
Get multipass status to traverse in a specific pass.
Definition: BaseNode.cc:221
ACG::SceneGraph::ACG::SceneGraph::BaseNode::id_
unsigned int id_
ID of node.
Definition: MeshNode2T.cc:701
ACG::SceneGraph::ACG::SceneGraph::BaseNode::multipassStatus_
MultipassBitMask multipassStatus_
Definition: MeshNode2T.cc:666
ACG::SceneGraph::ACG::SceneGraph::BaseNode::parent_
BaseNode * parent_
pointer to parent node
Definition: MeshNode2T.cc:686
ACG::SceneGraph::ACG::SceneGraph::BaseNode
Definition: MeshNode2T.cc:135
ACG::SceneGraph::ACG::SceneGraph::BaseNode::BaseNode
BaseNode(BaseNode *_parent=0, std::string _name="<unknown>")
Default constructor.
Definition: BaseNode.cc:81
ACG::SceneGraph::ACG::SceneGraph::BaseNode::ShaderSet::vs_
std::string vs_
vertex shader
Definition: MeshNode2T.cc:726
ACG::SceneGraph::ACG::ShaderProgGenerator::getShaderDir
static QString getShaderDir()
ACG::SceneGraph::ACG::SceneGraph::BaseNode::~BaseNode
virtual ~BaseNode()
Destructor.
Definition: BaseNode.cc:130