H3D API  2.4.1
H3DMultiPassRenderObject.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __H3DMULTIPASSRENDEROBJECT_H__
30 #define __H3DMULTIPASSRENDEROBJECT_H__
31 
32 #include <H3D/X3DChildNode.h>
33 #include <H3D/X3DViewpointNode.h>
34 
35 namespace H3D {
41  class H3DAPI_API H3DMultiPassRenderObject {
42  public:
43 
46  nr_times_in_scene( 0 ) {
47  instances.push_back( this );
48  }
49 
52  instances.remove( this );
53  }
54 
60  virtual void renderPreViewpoint( X3DChildNode * /*scene_root*/,
61  X3DViewpointNode * /*vp*/ ) {}
62 
66  virtual void renderPostViewpoint( X3DChildNode * /*scene_root*/,
67  X3DViewpointNode * /*vp*/ ) {}
68 
71  virtual void renderPostScene( X3DChildNode * /*scene_root*/,
72  X3DViewpointNode * /*vp*/) {}
73 
75  virtual void traverseSG( TraverseInfo &/*ti*/ ) {
76  ++nr_times_in_scene;
77  }
78 
80  inline void resetCounter() {
81  nr_times_in_scene = 0;
82  }
83 
84 
87  X3DViewpointNode *vp ) {
88  for( list< H3DMultiPassRenderObject * >::iterator i = instances.begin();
89  i != instances.end(); ++i ) {
90  if( (*i)->nr_times_in_scene > 0 )
91  (*i)->renderPreViewpoint( n, vp );
92  }
93  }
94 
97  X3DViewpointNode *vp ) {
98  for( list< H3DMultiPassRenderObject * >::iterator i = instances.begin();
99  i != instances.end(); ++i ) {
100  if( (*i)->nr_times_in_scene > 0 )
101  (*i)->renderPostViewpoint( n, vp );
102  }
103  }
104 
107  X3DViewpointNode *vp ) {
108  for( list< H3DMultiPassRenderObject * >::iterator i = instances.begin();
109  i != instances.end(); ++i ) {
110  if( (*i)->nr_times_in_scene > 0 )
111  (*i)->renderPostScene( n, vp );
112  }
113  }
114 
116  static void resetCounters() {
117  for( list< H3DMultiPassRenderObject * >::iterator i = instances.begin();
118  i != instances.end(); ++i ) {
119  (*i)->resetCounter();
120  }
121  }
122 
128  static void setMultiPassTransparencyAll( bool b ) {
129  multi_pass_transparency = b;
130  }
131 
132  protected:
133  // All instances of H3DMultiPassRenderObject that has been created.
134  static std::list< H3DMultiPassRenderObject * > instances;
135 
136  // The number of times the node appears in the current rendered scene-graph.
137  unsigned int nr_times_in_scene;
138 
139  // Flag used to know if scene should be rendered three times. See comment
140  // for setMultiPassTransparency function.
141  // Static since it is set just before calling renderPreViewpoint
142  // and it is assumed that H3DWindowNodes are rendered sequentially (and not
143  // from different threads).
144  static bool multi_pass_transparency;
145  };
146 }
147 
148 #endif
Header file for X3DChildNode, X3D scene-graph node.
Header file for X3DViewpointNode, X3D scene-graph node.
This abstract interface is inherited by all nodes that needs to render the scene an extra time(or mor...
Definition: H3DMultiPassRenderObject.h:41
virtual void traverseSG(TraverseInfo &)
Traverse the scenegraph.
Definition: H3DMultiPassRenderObject.h:75
virtual void renderPostScene(X3DChildNode *, X3DViewpointNode *)
This function will be called after the scene has been rendered.
Definition: H3DMultiPassRenderObject.h:71
H3DMultiPassRenderObject()
Constructor.
Definition: H3DMultiPassRenderObject.h:45
virtual void renderPostViewpoint(X3DChildNode *, X3DViewpointNode *)
This function will be called after the viewpoint has been set up for the scene to be rendered and bef...
Definition: H3DMultiPassRenderObject.h:66
static void renderPostViewpointAll(X3DChildNode *n, X3DViewpointNode *vp)
Run renderPostViewpoint on all instances of H3DMultiPassRenderObject.
Definition: H3DMultiPassRenderObject.h:96
void resetCounter()
Reset the counter.
Definition: H3DMultiPassRenderObject.h:80
static void renderPreViewpointAll(X3DChildNode *n, X3DViewpointNode *vp)
Run renderPreViewpoint on all instances of H3DMultiPassRenderObject.
Definition: H3DMultiPassRenderObject.h:86
static void resetCounters()
Run resetCounter on all instances of H3DMultiPassRenderObject.
Definition: H3DMultiPassRenderObject.h:116
static void renderPostSceneAll(X3DChildNode *n, X3DViewpointNode *vp)
Run renderPostScene on all instances of H3DMultiPassRenderObject.
Definition: H3DMultiPassRenderObject.h:106
static void setMultiPassTransparencyAll(bool b)
If multi pass transparency is set to true the scene should be rendered three times graphically,...
Definition: H3DMultiPassRenderObject.h:128
virtual void renderPreViewpoint(X3DChildNode *, X3DViewpointNode *)
This function will be called before any viewpoint calls has been made when rendering the scene and be...
Definition: H3DMultiPassRenderObject.h:60
virtual ~H3DMultiPassRenderObject()
Destructor.
Definition: H3DMultiPassRenderObject.h:51
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
The X3DViewpointNode node defines a specific location in the local coordinate system from which the u...
Definition: X3DViewpointNode.h:239
H3D API namespace.
Definition: Anchor.h:38