vertexBufferState.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef MESH_VERTEXBUFFERSTATE_H
00025 #define MESH_VERTEXBUFFERSTATE_H
00026
00027
00028 #include "typedefs.h"
00029 #include <map>
00030
00031 #ifdef EQUALIZER
00032 # include <eq/client/objectManager.h>
00033 #endif // EQUALIZER
00034
00035
00036 namespace mesh
00037 {
00038
00039 class VertexBufferState
00040 {
00041 public:
00042 enum
00043 {
00044 INVALID = 0
00045 };
00046
00047 virtual bool useColors() const { return _useColors; }
00048 virtual void setColors( const bool colors ) { _useColors = colors; }
00049 virtual RenderMode getRenderMode() const { return _renderMode; }
00050 virtual void setRenderMode( const RenderMode mode )
00051 {
00052 if( _renderMode == mode )
00053 return;
00054
00055 _renderMode = mode;
00056
00057
00058 if( _renderMode == RENDER_MODE_BUFFER_OBJECT && !GLEW_VERSION_1_5 )
00059 {
00060 MESHINFO << "VBO not available, using display lists"
00061 << std::endl;
00062 _renderMode = RENDER_MODE_DISPLAY_LIST;
00063 }
00064 }
00065
00066 virtual GLuint getDisplayList( const void* key ) = 0;
00067 virtual GLuint newDisplayList( const void* key ) = 0;
00068 virtual GLuint getBufferObject( const void* key ) = 0;
00069 virtual GLuint newBufferObject( const void* key ) = 0;
00070
00071 virtual void deleteAll() = 0;
00072
00073 GLEWContext* glewGetContext() { return _glewContext; }
00074
00075 protected:
00076 VertexBufferState( GLEWContext* glewContext )
00077 : _glewContext( glewContext ), _useColors( false ),
00078 _renderMode( RENDER_MODE_DISPLAY_LIST )
00079 {
00080 MESHASSERT( glewContext );
00081 }
00082
00083 virtual ~VertexBufferState() {}
00084
00085 GLEWContext* _glewContext;
00086 bool _useColors;
00087 RenderMode _renderMode;
00088
00089 private:
00090 };
00091
00092
00093
00094 class VertexBufferStateSimple : public VertexBufferState
00095 {
00096 public:
00097 VertexBufferStateSimple( GLEWContext* glewContext )
00098 : VertexBufferState( glewContext ) {}
00099
00100 virtual GLuint getDisplayList( const void* key )
00101 {
00102 if( _displayLists.find( key ) == _displayLists.end() )
00103 return INVALID;
00104 return _displayLists[key];
00105 }
00106
00107 virtual GLuint newDisplayList( const void* key )
00108 {
00109 _displayLists[key] = glGenLists( 1 );
00110 return _displayLists[key];
00111 }
00112
00113 virtual GLuint getBufferObject( const void* key )
00114 {
00115 if( _bufferObjects.find( key ) == _bufferObjects.end() )
00116 return INVALID;
00117 return _bufferObjects[key];
00118 }
00119
00120 virtual GLuint newBufferObject( const void* key )
00121 {
00122 if( !GLEW_VERSION_1_5 )
00123 return INVALID;
00124 glGenBuffers( 1, &_bufferObjects[key] );
00125 return _bufferObjects[key];
00126 }
00127
00128 virtual void deleteAll() { }
00129
00130 private:
00131 std::map< const void*, GLuint > _displayLists;
00132 std::map< const void*, GLuint > _bufferObjects;
00133 };
00134 }
00135
00136 #ifdef EQUALIZER
00137 namespace eqPly
00138 {
00139
00140 class VertexBufferState : public mesh::VertexBufferState
00141 {
00142 public:
00143 VertexBufferState( eq::Window::ObjectManager* objectManager )
00144 : mesh::VertexBufferState( objectManager->glewGetContext( ))
00145 , _objectManager( objectManager )
00146 {}
00147
00148 virtual GLuint getDisplayList( const void* key )
00149 { return _objectManager->getList( key ); }
00150
00151 virtual GLuint newDisplayList( const void* key )
00152 { return _objectManager->newList( key ); }
00153
00154 virtual GLuint getTexture( const void* key )
00155 { return _objectManager->getTexture( key ); }
00156
00157 virtual GLuint newTexture( const void* key )
00158 { return _objectManager->newTexture( key ); }
00159
00160 virtual GLuint getBufferObject( const void* key )
00161 { return _objectManager->getBuffer( key ); }
00162
00163 virtual GLuint newBufferObject( const void* key )
00164 { return _objectManager->newBuffer( key ); }
00165
00166 virtual GLuint getProgram( const void* key )
00167 { return _objectManager->getProgram( key ); }
00168
00169 virtual GLuint newProgram( const void* key )
00170 { return _objectManager->newProgram( key ); }
00171
00172 virtual GLuint getShader( const void* key )
00173 { return _objectManager->getShader( key ); }
00174
00175 virtual GLuint newShader( const void* key, GLenum type )
00176 { return _objectManager->newShader( key, type ); }
00177
00178 virtual void deleteAll() { _objectManager->deleteAll(); }
00179
00180 private:
00181 eq::Window::ObjectManager* _objectManager;
00182 };
00183 }
00184 #endif // EQUALIZER
00185
00186
00187
00188 #endif // MESH_VERTEXBUFFERSTATE_H