|
From: <axl...@us...> - 2009-11-08 15:48:45
|
Revision: 607
http://hgengine.svn.sourceforge.net/hgengine/?rev=607&view=rev
Author: axlecrusher
Date: 2009-11-08 15:48:23 +0000 (Sun, 08 Nov 2009)
Log Message:
-----------
untested vertex color arrays
Modified Paths:
--------------
Mercury2/src/MercuryVBO.cpp
Mercury2/src/MercuryVBO.h
Modified: Mercury2/src/MercuryVBO.cpp
===================================================================
--- Mercury2/src/MercuryVBO.cpp 2009-11-07 22:40:43 UTC (rev 606)
+++ Mercury2/src/MercuryVBO.cpp 2009-11-08 15:48:23 UTC (rev 607)
@@ -9,17 +9,18 @@
extern bool SHOWBOUNDINGVOLUME;
extern bool SHOWAXISES;
-MercuryVBO::MercuryVBO( const MString & key, bool bInstanced )
- :MercuryAsset( key, bInstanced ), m_initiated(false)
+MercuryVBO::MercuryVBO( const MString & key, bool bInstanced, bool useVertexColor )
+ :MercuryAsset( key, bInstanced ), m_initiated(false), m_useVertexColor(useVertexColor)
{
- m_bufferIDs[0] = m_bufferIDs[1] = 0;
- m_bDirtyIndices = m_bDirtyVertices = 0;
+ m_bufferIDs[0] = m_bufferIDs[1] = m_bufferIDs[2] = 0;
+ m_bDirtyIndices = m_bDirtyVertices = m_bDirtyVertexColor = false;
}
MercuryVBO::~MercuryVBO()
{
- if (m_bufferIDs[0]) { GLCALL( glDeleteBuffersARB(2, m_bufferIDs) ); }
- m_bufferIDs[0] = m_bufferIDs[1] = 0;
+ if (m_bufferIDs[0] > 0) { GLCALL( glDeleteBuffersARB(2, m_bufferIDs) ); }
+ if (m_bufferIDs[2] > 0) { GLCALL( glDeleteBuffersARB(1, &m_bufferIDs[2]) ); }
+ m_bufferIDs[0] = m_bufferIDs[1] = m_bufferIDs[2] = 0;
}
void MercuryVBO::Render(const MercuryNode* node)
@@ -31,38 +32,51 @@
{
m_lastVBOrendered = this;
- if ( m_bDirtyVertices )
- UpdateVertices();
- if( m_bDirtyIndices )
- UpdateIndices();
+ if ( m_bDirtyVertices ) UpdateVertices();
+ if( m_bDirtyIndices ) UpdateIndices();
+ if( m_bDirtyVertexColor ) UpdateVertexColor();
GLCALL( glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]) );
GLCALL( glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]) );
GLCALL( glVertexPointer(3, GL_FLOAT, STRIDE*sizeof(float), BUFFER_OFFSET( VERTEX_OFFSET*sizeof(float) ) ) );
+
+ if (m_useVertexColor)
+ {
+ GLCALL( glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[2]) );
+ GLCALL( glColorPointer(4, GL_FLOAT, 0, 0 ) );
+ }
+
++m_vboBinds;
}
+ GLCALL( glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) );
+
+ if (m_useVertexColor) { GLCALL( glEnableClientState( GL_COLOR_ARRAY ) ); }
+
Texture::ApplyActiveTextures(STRIDE*sizeof(float));
GLCALL( glEnableClientState( GL_NORMAL_ARRAY ) );
GLCALL( glNormalPointer(GL_FLOAT, STRIDE*sizeof(float), BUFFER_OFFSET(sizeof(float)*2)) );
GLCALL( glDrawRangeElements(GL_TRIANGLES, 0, m_indexData.Length()-1, m_indexData.Length(), GL_UNSIGNED_SHORT, NULL) );
- m_vboBatches++;
+ ++m_vboBatches;
if (m_boundingVolume && SHOWBOUNDINGVOLUME) m_boundingVolume->Render();
+
+ GLCALL( glPopClientAttrib() );
+
if ( SHOWAXISES ) DrawAxes();
}
void MercuryVBO::InitVBO()
{
- if (!m_bufferIDs[0])
- {
- GLCALL( glGenBuffersARB(2, m_bufferIDs) );
- }
+ if (!m_bufferIDs[0]) { GLCALL( glGenBuffersARB(2, m_bufferIDs) ); }
+ if (m_useVertexColor) { GLCALL( glGenBuffersARB(1, &m_bufferIDs[2]) ); }
UpdateIndices();
UpdateVertices();
+ UpdateVertexColor();
+
GLCALL( glEnableClientState(GL_VERTEX_ARRAY) );
m_initiated = true;
@@ -72,19 +86,30 @@
{
GLCALL( glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]) );
GLCALL( glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_indexData.LengthInBytes(), m_indexData.Buffer(), GL_STATIC_DRAW_ARB) );
- m_bDirtyIndices = 0;
+ m_bDirtyIndices = false;
}
void MercuryVBO::UpdateVertices()
{
GLCALL( glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]) );
GLCALL( glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertexData.LengthInBytes(), m_vertexData.Buffer(), GL_STATIC_DRAW_ARB) );
- m_bDirtyVertices = 0;
+ m_bDirtyVertices = false;
}
+void MercuryVBO::UpdateVertexColor()
+{
+ if (m_useVertexColor)
+ {
+ GLCALL( glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[2]) );
+ GLCALL( glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertexColorData.LengthInBytes(), m_vertexColorData.Buffer(), GL_STATIC_DRAW_ARB) );
+ }
+ m_bDirtyVertexColor = false;
+}
+
void MercuryVBO::AllocateVertexSpace(unsigned int count)
{
m_vertexData.Allocate(count*8);
+ if (m_useVertexColor) m_vertexColorData.Allocate(count*4);
}
void MercuryVBO::AllocateIndexSpace(unsigned int count)
Modified: Mercury2/src/MercuryVBO.h
===================================================================
--- Mercury2/src/MercuryVBO.h 2009-11-07 22:40:43 UTC (rev 606)
+++ Mercury2/src/MercuryVBO.h 2009-11-08 15:48:23 UTC (rev 607)
@@ -13,7 +13,7 @@
static const uint16_t STRIDE = 8;
static const uint16_t VERTEX_OFFSET = 5;
- MercuryVBO( const MString & key, bool bInstanced );
+ MercuryVBO( const MString & key, bool bInstanced, bool useVertexColor = false );
virtual ~MercuryVBO();
virtual void Render(const MercuryNode* node);
@@ -27,7 +27,10 @@
const float* GetVertexHandle() const { return m_vertexData.Buffer(); }
float* GetVertexHandle() { return m_vertexData.Buffer(); }
-
+
+ const float* GetVertexColorHandle() const { return m_vertexColorData.Buffer(); }
+ float* GetVertexColorHandle() { return m_vertexColorData.Buffer(); }
+
const short unsigned int* GetIndexHandle() const { return m_indexData.Buffer(); }
short unsigned int* GetIndexHandle() { return m_indexData.Buffer(); }
@@ -35,22 +38,29 @@
static void* m_lastVBOrendered;
- void DirtyVertices() { m_bDirtyVertices = 1; }
- void DirtyIndices() { m_bDirtyIndices = 1; }
+ inline void DirtyVertices() { m_bDirtyVertices = true; }
+ inline void DirtyVerexColor() { m_bDirtyVertexColor = true; }
+ inline void DirtyIndices() { m_bDirtyIndices = true; }
+
GENRTTI( MercuryVBO );
private:
virtual void InitVBO();
- unsigned int m_bufferIDs[2];
+ unsigned int m_bufferIDs[3];
bool m_initiated;
bool m_bDirtyIndices;
bool m_bDirtyVertices;
+ bool m_bDirtyVertexColor;
+
+ bool m_useVertexColor;
void UpdateVertices();
+ void UpdateVertexColor();
void UpdateIndices();
protected:
AlignedBuffer<float> m_vertexData;
+ AlignedBuffer<float> m_vertexColorData;
AlignedBuffer<uint16_t> m_indexData;
static uint32_t m_vboBatches;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|