H3D API  2.4.1
H3DDisplayListObject.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 __H3DDISPLAYLISTOBJECT_H__
30 #define __H3DDISPLAYLISTOBJECT_H__
31 
32 #include <GL/glew.h>
33 #include <H3D/H3DApi.h>
34 #include <H3D/Field.h>
35 #include <H3D/Instantiate.h>
36 #include <H3D/FieldTemplates.h>
37 #include <H3D/SFBool.h>
38 #include <H3D/SFTime.h>
39 
40 namespace H3D {
41  class GraphicsOptions;
42 
54  class H3DAPI_API H3DDisplayListObject {
55  public:
56 
60  class H3DAPI_API DisplayList : public Field {
61  protected:
65  class IsActive: public AutoUpdate< TypedField< SFBool, SFTime > > {
66  public:
69  active( true ) {}
70 
72  virtual void update() {
73  value = active;
74  active = false;
75  }
76 
77  friend class DisplayList;
78 
79  protected:
81  void callListCalled() {
82  setValue( true );
83  active = true;
84  }
85  bool active;
86  };
87 
88  public:
91  typedef enum {
93  ON,
95  OFF,
97  OPTIONS
98  } CacheMode;
99 
103 
105  DisplayList();
106 
109  if( display_list ) glDeleteLists( display_list, 1 );
110  }
111 
114  cache_mode = m;
115  }
116 
119  return cache_mode;
120  }
121 
124  frustum_culling_mode = m;
125  }
126 
129  return frustum_culling_mode;
130  }
131 
133  virtual bool usingCaching();
134 
136  bool usingFrustumCulling();
137 
140  bool isOutsideViewFrustum();
141 
143  static void rebuildAllDisplayLists();
144 
147  virtual unsigned int cachingDelay();
148 
150  void breakCache();
151 
153  virtual void update();
154 
156  virtual void propagateEvent( Event e );
157 
160  virtual void callList( bool build_list = true );
161 
164  inline Field *getEventPointer() {
165  return event.ptr;
166  }
167 
170  inline bool hasCausedEvent( Field *f ) {
171  return event_fields.find( f ) != event_fields.end();
172  }
173 
174 #ifdef DEPRECATE_DISPLAYLIST_EVENT_COLLECT
177 #else
180 #endif
181  template< class FieldType >
182  inline bool hasCausedEvent( H3DUniquePtr< FieldType > &f ) {
183  return hasCausedEvent( f.get() );
184  }
185 
188  inline size_t nrPendingEvents() {
189  return event_fields.size();
190  }
191 
193  void initGraphicOption();
194 
195  protected:
196  bool childrenCachesReady( bool consider_active_field );
197 
200  inline virtual bool haveValidDisplayList() {
201  return have_valid_display_list;
202  }
203 
210  bool tryBuildDisplayList( bool cache_broken );
211 
212  protected:
215  set< Field * > event_fields;
216 
218  unsigned int delay_cache_counter;
219 
221  GLuint display_list;
222 
225 
228 
231 
234  H3DUniquePtr< IsActive > isActive;
235 
238  static H3DUniquePtr< Field > break_list_field;
239 
242 
244  static const int cache_delay_default = 3;
245 
248 
249  friend class H3DDisplayListObject;
250  };
251 
253  H3DDisplayListObject( Inst< DisplayList > _displayList = 0 );
254 
256  H3DUniquePtr< DisplayList > displayList;
257 
258  };
259 }
260 
261 #endif
Contains different templates to modify field behaviour.
Contains the Field class.
Base header file that handles all configuration related settings.
Contains the Inst struct.
Contains the SFBool field class.
Contains the SFTime field class.
The Field class.
Definition: Field.h:46
Specifies parameters to use for graphical rendering of nodes.
Definition: GraphicsOptions.h:47
The IsActive field is updated each scenegraph loop, since Scene::time is routed to it to see if the c...
Definition: H3DDisplayListObject.h:65
IsActive()
Constructor.
Definition: H3DDisplayListObject.h:68
void callListCalled()
Should be called from callList().
Definition: H3DDisplayListObject.h:81
virtual void update()
Updates the value of the field.
Definition: H3DDisplayListObject.h:72
We use the Field's lazy evaluation mechanisms to manage the GL display lists for rendering,...
Definition: H3DDisplayListObject.h:60
size_t nrPendingEvents()
Returns the number of input fields that has generated an event to this field since the last call to t...
Definition: H3DDisplayListObject.h:188
GraphicsOptions * graphic_options_previous
previous graphic option
Definition: H3DDisplayListObject.h:241
void setFrustumCullingMode(FrustumCullingMode m)
Set the frustum culling mode.
Definition: H3DDisplayListObject.h:123
CacheMode getCacheMode()
Get the cache mode.
Definition: H3DDisplayListObject.h:118
CacheMode
The entries in CacheMode enumerator is used for checking if caching should be done or not.
Definition: H3DDisplayListObject.h:91
@ ON
Caching is on.
Definition: H3DDisplayListObject.h:93
@ OFF
Caching is off.
Definition: H3DDisplayListObject.h:95
bool have_valid_display_list
True if the display list has been built successfully.
Definition: H3DDisplayListObject.h:230
set< Field * > event_fields
The fields that has generated an event since the last call to update()
Definition: H3DDisplayListObject.h:215
static H3DUniquePtr< Field > break_list_field
This field is routed to all instances of DisplayList and can be used to force a rebuild of all displa...
Definition: H3DDisplayListObject.h:238
FrustumCullingMode frustum_culling_mode
The mode for view frustum culling.
Definition: H3DDisplayListObject.h:227
Field * getEventPointer()
Gets the pointer to the last field that created an event to this field
Definition: H3DDisplayListObject.h:164
H3DUniquePtr< IsActive > isActive
The isActive field is true if the callList() function has been called in the last scenegraph loop,...
Definition: H3DDisplayListObject.h:234
bool hasCausedEvent(Field *f)
Returns true if the Field given has generated an event to this field since the last call to the updat...
Definition: H3DDisplayListObject.h:170
bool reset_delay_cache_counter
flag to require resetting delay_cache_counter
Definition: H3DDisplayListObject.h:247
CacheMode FrustumCullingMode
The entries in FrustumCullingMode enumerator is used for checking if view frustum culling should be d...
Definition: H3DDisplayListObject.h:102
GLuint display_list
OpenGL display list identifier.
Definition: H3DDisplayListObject.h:221
CacheMode cache_mode
The mode for caching.
Definition: H3DDisplayListObject.h:224
~DisplayList()
Destructor.
Definition: H3DDisplayListObject.h:108
FrustumCullingMode getFrustumCullingMode()
Get the frustum culling mode.
Definition: H3DDisplayListObject.h:128
virtual bool haveValidDisplayList()
Returns true if we have a valid display list built that can be called.
Definition: H3DDisplayListObject.h:200
unsigned int delay_cache_counter
Display lists will not be built as long as this counter > 0.
Definition: H3DDisplayListObject.h:218
bool hasCausedEvent(H3DUniquePtr< FieldType > &f)
Returns true if the Field given has generated an event to this field since the last call to the updat...
Definition: H3DDisplayListObject.h:182
void setCacheMode(CacheMode m)
Set the cache mode.
Definition: H3DDisplayListObject.h:113
This abstract interface class is the base class for all node types that wants to create an OpenGL dis...
Definition: H3DDisplayListObject.h:54
H3DUniquePtr< DisplayList > displayList
The DisplayList instance handling the OpenGL caching of this object.
Definition: H3DDisplayListObject.h:256
H3D API namespace.
Definition: Anchor.h:38
The AutoUpdate field is a template to force the BaseField to update itself as soon as an event is rec...
Definition: FieldTemplates.h:130