From: <cn...@us...> - 2009-07-15 04:23:35
|
Revision: 426 http://hgengine.svn.sourceforge.net/hgengine/?rev=426&view=rev Author: cnlohr Date: 2009-07-15 04:23:32 +0000 (Wed, 15 Jul 2009) Log Message: ----------- Make the VBO able to dirty Vertices so that they can be updated on the fly. Modified Paths: -------------- Mercury2/src/MercuryVBO.cpp Mercury2/src/MercuryVBO.h Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2009-07-15 04:23:04 UTC (rev 425) +++ Mercury2/src/MercuryVBO.cpp 2009-07-15 04:23:32 UTC (rev 426) @@ -14,6 +14,7 @@ :MercuryAsset(), m_initiated(false) { m_bufferIDs[0] = m_bufferIDs[1] = 0; + m_bDirtyIndices = m_bDirtyVertices = 0; } MercuryVBO::~MercuryVBO() @@ -27,11 +28,18 @@ uint8_t numTextures = Texture::NumberActiveTextures(); uint16_t stride = sizeof(float)*8; - if ( !m_initiated ) InitVBO(); - + if ( !m_initiated ) + InitVBO(); + if ( this != m_lastVBOrendered ) - { + { m_lastVBOrendered = this; + + if ( m_bDirtyVertices ) + UpdateVertices(); + if( m_bDirtyIndices ) + UpdateIndices(); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]); glVertexPointer(3, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*5)); @@ -58,21 +66,32 @@ void MercuryVBO::InitVBO() { - glGenBuffersARB(2, m_bufferIDs); - - //vertex VBO - glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]); - glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertexData.LengthInBytes(), m_vertexData.Buffer(), GL_STATIC_DRAW_ARB); + if (!m_bufferIDs[0]) + { + glGenBuffersARB(2, m_bufferIDs); + } - //indices VBO - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]); - glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_indexData.LengthInBytes(), m_indexData.Buffer(), GL_STATIC_DRAW_ARB); - + UpdateIndices(); + UpdateVertices(); glEnableClientState(GL_VERTEX_ARRAY); m_initiated = true; } +void MercuryVBO::UpdateIndices() +{ + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]); + glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_indexData.LengthInBytes(), m_indexData.Buffer(), GL_STATIC_DRAW_ARB); + m_bDirtyIndices = 0; +} + +void MercuryVBO::UpdateVertices() +{ + glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertexData.LengthInBytes(), m_vertexData.Buffer(), GL_STATIC_DRAW_ARB); + m_bDirtyVertices = 0; +} + void MercuryVBO::AllocateVertexSpace(unsigned int count) { m_vertexData.Allocate(count*8); Modified: Mercury2/src/MercuryVBO.h =================================================================== --- Mercury2/src/MercuryVBO.h 2009-07-15 04:23:04 UTC (rev 425) +++ Mercury2/src/MercuryVBO.h 2009-07-15 04:23:32 UTC (rev 426) @@ -26,13 +26,20 @@ short unsigned int * GetIndexHandle() { return &m_indexData[0]; } static void* m_lastVBOrendered; - + + void DirtyVertices() { m_bDirtyVertices = 1; } + void DirtyIndices() { m_bDirtyIndices = 1; } private: virtual void InitVBO(); unsigned int m_bufferIDs[2]; - bool m_initiated; + bool m_initiated; + + bool m_bDirtyIndices; + bool m_bDirtyVertices; + void UpdateVertices(); + void UpdateIndices(); protected: AlignedBuffer<float> m_vertexData; AlignedBuffer<uint16_t> m_indexData; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |