00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00027
00029 #ifndef __H3DDISPLAYLISTOBJECT_H__
00030 #define __H3DDISPLAYLISTOBJECT_H__
00031
00032 #include "H3DApi.h"
00033 #include "Field.h"
00034 #include "Instantiate.h"
00035 #include "GL/glew.h"
00036 #include "FieldTemplates.h"
00037 #include "SFBool.h"
00038 #include "SFTime.h"
00039
00040 #ifdef _MSC_VER
00041 #pragma comment( lib, "OpenGL32.lib" )
00042 #pragma comment( lib, "glu32.lib" )
00043 #pragma comment( lib, "glew32.lib" )
00044 #endif
00045
00046 namespace H3D {
00058 class H3DAPI_API H3DDisplayListObject {
00059 public:
00060
00064 class H3DAPI_API DisplayList : public Field {
00065 protected:
00069 class IsActive: public AutoUpdate< TypedField< SFBool, SFTime > > {
00070 public:
00072 IsActive():
00073 active( true ) {}
00074
00076 virtual void update() {
00077 value = active;
00078 active = false;
00079 }
00080
00081 friend class DisplayList;
00082
00083 protected:
00085 void callListCalled() {
00086 setValue( true );
00087 active = true;
00088 }
00089 bool active;
00090 };
00091
00092 public:
00093 typedef enum {
00095 ON,
00097 OFF,
00099 OPTIONS
00100 } CacheMode;
00101
00103 DisplayList();
00104
00106 ~DisplayList() {
00107 if( display_list ) glDeleteLists( display_list, 1 );
00108 }
00109
00111 void setCacheMode( CacheMode m ) {
00112 cache_mode = m;
00113 }
00114
00116 CacheMode setCacheMode( ) {
00117 return cache_mode;
00118 }
00119
00121 bool usingCaching();
00122
00125 unsigned int cachingDelay();
00126
00128 void breakCache();
00129
00131 virtual void update();
00132
00134 virtual void propagateEvent( Event e );
00135
00138 virtual void callList( bool build_list = true );
00139
00142 inline Field *getEventPointer() {
00143 return event.ptr;
00144 }
00145
00148 inline bool hasCausedEvent( Field *f ) {
00149 return event_fields.find( f ) != event_fields.end();
00150 }
00151
00154 template< class FieldType >
00155 inline bool hasCausedEvent( auto_ptr< FieldType > &f ) {
00156 return hasCausedEvent( f.get() );
00157 }
00158
00159 protected:
00160 bool childrenCachesReady( bool consider_active_field );
00161
00164 inline bool haveValidDisplayList() {
00165 return have_valid_display_list;
00166 }
00167
00174 bool tryBuildDisplayList( bool cache_broken );
00175
00176 private:
00179 set< Field * > event_fields;
00180
00182 unsigned int delay_cache_counter;
00183
00185 GLuint display_list;
00186
00188 CacheMode cache_mode;
00189
00191 bool have_valid_display_list;
00192
00195 auto_ptr< IsActive > isActive;
00196
00197 friend class H3DDisplayListObject;
00198 };
00199
00201 H3DDisplayListObject( Inst< DisplayList > _displayList = 0 );
00202
00204 auto_ptr< DisplayList > displayList;
00205 };
00206 }
00207
00208 #endif