H3DDisplayListObject.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
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

Generated on Thu Aug 24 12:38:32 2006 for H3D API by  doxygen 1.4.5