30 #include "vertexBufferState.h"
34 VertexBufferState::VertexBufferState(
const GLEWContext* glewContext )
36 , _glewContext( glewContext )
37 , _renderMode( RENDER_MODE_DISPLAY_LIST )
39 , _useFrustumCulling( true )
44 MESHASSERT( glewContext );
47 void VertexBufferState::setRenderMode(
const RenderMode mode )
49 if( _renderMode == mode )
55 if( _renderMode == RENDER_MODE_BUFFER_OBJECT && !GLEW_VERSION_1_5 )
57 MESHINFO <<
"VBO not available, using display lists" << std::endl;
58 _renderMode = RENDER_MODE_DISPLAY_LIST;
62 void VertexBufferState::resetRegion()
64 _region[0] = std::numeric_limits< float >::max();
65 _region[1] = std::numeric_limits< float >::max();
66 _region[2] = -std::numeric_limits< float >::max();
67 _region[3] = -std::numeric_limits< float >::max();
70 void VertexBufferState::updateRegion(
const BoundingBox& box )
72 const Vertex corners[8] = { Vertex( box[0][0], box[0][1], box[0][2] ),
73 Vertex( box[1][0], box[0][1], box[0][2] ),
74 Vertex( box[0][0], box[1][1], box[0][2] ),
75 Vertex( box[1][0], box[1][1], box[0][2] ),
76 Vertex( box[0][0], box[0][1], box[1][2] ),
77 Vertex( box[1][0], box[0][1], box[1][2] ),
78 Vertex( box[0][0], box[1][1], box[1][2] ),
79 Vertex( box[1][0], box[1][1], box[1][2] ) };
81 Vector4f region( std::numeric_limits< float >::max(),
82 std::numeric_limits< float >::max(),
83 -std::numeric_limits< float >::max(),
84 -std::numeric_limits< float >::max( ));
86 for(
size_t i = 0; i < 8; ++i )
89 region[0] = std::min( corner[0], region[0] );
90 region[1] = std::min( corner[1], region[1] );
91 region[2] = std::max( corner[0], region[2] );
92 region[3] = std::max( corner[1], region[3] );
96 const Vector4f normalized( region[0] * .5f + .5f,
97 region[1] * .5f + .5f,
98 ( region[2] - region[0] ) * .5f,
99 ( region[3] - region[1] ) * .5f );
101 declareRegion( normalized );
108 Vector4f VertexBufferState::getRegion()
const
111 return Vector4f::ZERO;
116 GLuint VertexBufferStateSimple::getDisplayList(
const void* key )
118 if( _displayLists.find( key ) == _displayLists.end() )
120 return _displayLists[key];
123 GLuint VertexBufferStateSimple::newDisplayList(
const void* key )
125 _displayLists[key] = glGenLists( 1 );
126 return _displayLists[key];
129 GLuint VertexBufferStateSimple::getBufferObject(
const void* key )
131 if( _bufferObjects.find( key ) == _bufferObjects.end() )
133 return _bufferObjects[key];
136 GLuint VertexBufferStateSimple::newBufferObject(
const void* key )
138 if( !GLEW_VERSION_1_5 )
140 glGenBuffers( 1, &_bufferObjects[key] );
141 return _bufferObjects[key];
144 void VertexBufferStateSimple::deleteAll()
146 for( GLMapCIter i = _displayLists.begin(); i != _displayLists.end(); ++i )
147 glDeleteLists( i->second, 1 );
149 for( GLMapCIter i = _bufferObjects.begin(); i != _bufferObjects.end(); ++i )
150 glDeleteBuffers( 1, &(i->second) );
152 _displayLists.clear();
153 _bufferObjects.clear();
Matrix4f _pmvMatrix
projection * modelView matrix
Vector4f _region
normalized x1 y1 x2 y2 region from cullDraw
vmml::matrix< 4, 4, float > Matrix4f
A 4x4 float matrix.
vmml::vector< 4, float > Vector4f
A four-component float vector.