VBO refactor.

This commit is contained in:
Martín Lucas Golini
2022-08-02 01:28:17 -03:00
parent 9bcbd4b1d3
commit 8483cb6b87
6 changed files with 299 additions and 182 deletions

View File

@@ -16,77 +16,110 @@ namespace EE { namespace Graphics {
class EE_API VertexBuffer {
public:
/** @brief Creates a new Vertex Buffer.
* @param VertexFlags The vertex flags indicates which vertex data will be used. @see
* @param vertexFlags The vertex flags indicates which vertex data will be used. @see
*VertexFlags
* @param DrawType The type of the primitive to draw.
* @param ReserveVertexSize If the vertex size is known is possible to reserve the space in
* @param drawType The type of the primitive to draw.
* @param reserveVertexSize If the vertex size is known is possible to reserve the space in
*memory to avoid resizeing the array.
* @param ReserveIndexSize If the vertex size is known is possible to reserve the space in
* @param reserveIndexSize If the vertex size is known is possible to reserve the space in
*memory for the indices to avoid resizeing the array.
* @param UsageType This indicates the kind of usage VBO will have. It's only useful if VBO
* @param usageType This indicates the kind of usage VBO will have. It's only useful if VBO
*extensions are supported ( almost for sure that it's supported ). More information here:
*http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml
*/
static VertexBuffer* New( const Uint32& VertexFlags = VERTEX_FLAGS_DEFAULT,
PrimitiveType DrawType = PRIMITIVE_QUADS,
const Int32& ReserveVertexSize = 0, const Int32& ReserveIndexSize = 0,
VertexBufferUsageType UsageType = VertexBufferUsageType::Static );
static VertexBuffer* New( const Uint32& vertexFlags = VERTEX_FLAGS_DEFAULT,
PrimitiveType drawType = PRIMITIVE_QUADS,
const Int32& reserveVertexSize = 0, const Int32& reserveIndexSize = 0,
VertexBufferUsageType usageType = VertexBufferUsageType::Static );
/** Creates the simple vertex array implementation ( without VBOs or VAO ), which it's faster
* for many cases. */
static VertexBuffer*
NewVertexArray( const Uint32& VertexFlags = VERTEX_FLAGS_DEFAULT,
PrimitiveType DrawType = PRIMITIVE_QUADS, const Int32& ReserveVertexSize = 0,
const Int32& ReserveIndexSize = 0,
VertexBufferUsageType UsageType = VertexBufferUsageType::Static );
NewVertexArray( const Uint32& vertexFlags = VERTEX_FLAGS_DEFAULT,
PrimitiveType drawType = PRIMITIVE_QUADS, const Int32& reserveVertexSize = 0,
const Int32& reserveIndexSize = 0,
VertexBufferUsageType usageType = VertexBufferUsageType::Static );
virtual ~VertexBuffer();
/** @brief Adds a vertex of the type indicated to the buffer
* @param Type Can be the position or texture coordinates.
* @param Vertex The vexter data */
void addVertex( const Uint32& Type, const Vector2f& Vertex );
* @param type Can be the position or texture coordinates.
* @param vertex The vexter data */
void addVertex( const Uint32& type, const Vector2f& vertex );
/** @brief Adds a vertex position to the buffer
* @param Vertex The vexter data */
void addVertex( const Vector2f& Vertex );
* @param vertex The vexter data */
void addVertex( const Vector2f& vertex );
/** @brief Adds a vertex texture coordinate.
* @param VertexCoord The vertex texture coordinate.
* @param TextureLevel Indicates the texture level if it's using multitextures.
* @param vertexCoord The vertex texture coordinate.
* @param textureLevel Indicates the texture level if it's using multitextures.
*/
void addTextureCoord( const Vector2f& VertexCoord, const Uint32& TextureLevel = 0 );
void addTextureCoord( const Vector2f& vertexCoord, const Uint32& textureLevel = 0 );
/** @brief Adds a color to the buffer.
* @param Color The color value.
* @param color The color value.
*/
void addColor( const Color& Color );
void addColor( const Color& color );
/** @brief Adds an index to the buffer.
* @param Index The index value.
* @param indexValue The index value.
*/
void addIndex( const Uint32& Index );
void addIndex( const Uint32& indexValue );
/** @brief Set a vertex index of the type indicated to the buffer
* @param index The array index of the vertext to set
* @param type Can be the position or texture coordinates.
* @param vertex The vexter data */
void setVertex( const Uint32& index, const Uint32& type, const Vector2f& vertex );
/** @brief Adds a vertex position to the buffer
* @param index The array index of the vertext to set
* @param vertex The vexter data */
void setVertex( const Uint32& index, const Vector2f& vertex );
/** @brief Adds a vertex texture coordinate.
* @param index The array index of the vertext to set
* @param vertexCoord The vertex texture coordinate.
* @param textureLevel Indicates the texture level if it's using multitextures.
*/
void setTextureCoord( const Uint32& index, const Vector2f& vertexCoord,
const Uint32& textureLevel = 0 );
/** @brief Adds a color to the buffer.
* @param index The array index of the vertext to set
* @param color The color value.
*/
void setColor( const Uint32& index, const Color& color );
/** @brief Adds an index to the buffer.
* @param index The array index of the vertext to set
* @param indexValue The index value.
*/
void setIndex( const Uint32& index, const Uint32& indexValue );
/** @brief Resizes the array of the type indicated.
* @param Type The type must be one of the vertex flags ( EE_VERTEX_FLAGS ).
* @param Size The size to be resized
* @param type The type must be one of the vertex flags ( @see VertexFlags ).
* @param size The size to be resized
*/
void resizeArray( const Uint32& Type, const Uint32& Size );
void resizeArray( const Uint32& type, const Uint32& size );
/** @brief Resizes the indices array.
* @param Size The new size
* @param size The new size
*/
void resizeIndices( const Uint32& Size );
void resizeIndices( const Uint32& size );
/** @return the pointer to the array of the type indicated.
* @param Type The type must be one of the vertex flags ( EE_VERTEX_FLAGS ). */
Float* getArray( const Uint32& Type );
/** @return The position array */
std::vector<Vector2f>& getPositionArray();
/** @return The color array pointer. */
Uint8* getColorArray();
std::vector<Color>& getColorArray();
/** @return The indices array pointer. */
Uint32* getIndices();
std::vector<Uint32>& getIndices();
/** @return The texture coord array from the texture level */
std::vector<Vector2f>& getTextureCoordArray( const Uint32& textureLevel );
/** @return The number of vertex added. */
Uint32 getVertexCount();
@@ -94,24 +127,18 @@ class EE_API VertexBuffer {
/** @return The number of indexes added. */
Uint32 getIndexCount();
/** @return The vector data of the type indicated.
* @param Type Can be the position or texture coordinates.
* @param Index The position in the buffer.
*/
Vector2f getVector2( const Uint32& Type, const Uint32& Index );
/** @return The color at the buffer position.
* @param Index The position in the buffer.
* @param index The position in the buffer.
*/
Color getColor( const Uint32& Index );
Color getColor( const Uint32& index );
/** @return The index at the buffer position.
* @param Index The position in the buffer.
* @param index The position in the buffer.
*/
Uint32 getIndex( const Uint32& Index );
Uint32 getIndex( const Uint32& index );
/** @brief Sets the number of elements to draw. If not set, it will draw all the elements. */
void setElementNum( Int32 Num );
void setElementNum( Int32 num );
/** @return The number of elements added. */
const Int32& getElementNum() const;
@@ -133,7 +160,7 @@ class EE_API VertexBuffer {
/** @brief Update is used in the case of some data is modified and need to be reuploaded to the
* GPU. */
virtual void update( const Uint32& Types, bool Indices ) = 0;
virtual void update( const Uint32& types, bool indices ) = 0;
/** @brief Reupload all the data to the GPU. */
virtual void reload() = 0;
@@ -146,8 +173,9 @@ class EE_API VertexBuffer {
PrimitiveType mDrawType;
VertexBufferUsageType mUsageType;
Int32 mElemDraw;
std::vector<Float> mVertexArray[VERTEX_FLAGS_COUNT - 1];
std::vector<Uint8> mColorArray;
std::vector<Vector2f> mPosArray;
std::vector<Vector2f> mTexCoordArray[4];
std::vector<Color> mColorArray;
std::vector<Uint32> mIndexArray;
VertexBuffer( const Uint32& VertexFlags = VERTEX_FLAGS_DEFAULT,

View File

@@ -11,10 +11,10 @@ namespace EE { namespace Graphics {
*/
class EE_API VertexBufferOGL : public VertexBuffer {
public:
VertexBufferOGL( const Uint32& VertexFlags = VERTEX_FLAGS_DEFAULT,
PrimitiveType DrawType = PRIMITIVE_QUADS, const Int32& ReserveVertexSize = 0,
const Int32& ReserveIndexSize = 0,
VertexBufferUsageType UsageType = VertexBufferUsageType::Static );
VertexBufferOGL( const Uint32& vertexFlags = VERTEX_FLAGS_DEFAULT,
PrimitiveType drawType = PRIMITIVE_QUADS, const Int32& reserveVertexSize = 0,
const Int32& reserveIndexSize = 0,
VertexBufferUsageType usageType = VertexBufferUsageType::Static );
void bind();
@@ -22,7 +22,7 @@ class EE_API VertexBufferOGL : public VertexBuffer {
bool compile();
void update( const Uint32& Types, bool Indices );
void update( const Uint32& types, bool indices );
void reload();

View File

@@ -12,10 +12,10 @@ namespace EE { namespace Graphics {
*/
class EE_API VertexBufferVBO : public VertexBuffer {
public:
VertexBufferVBO( const Uint32& VertexFlags = VERTEX_FLAGS_DEFAULT,
PrimitiveType DrawType = PRIMITIVE_QUADS, const Int32& ReserveVertexSize = 0,
const Int32& ReserveIndexSize = 0,
VertexBufferUsageType UsageType = VertexBufferUsageType::Static );
VertexBufferVBO( const Uint32& vertexFlags = VERTEX_FLAGS_DEFAULT,
PrimitiveType drawType = PRIMITIVE_QUADS, const Int32& reserveVertexSize = 0,
const Int32& reserveIndexSize = 0,
VertexBufferUsageType usageType = VertexBufferUsageType::Static );
virtual ~VertexBufferVBO();
@@ -25,7 +25,7 @@ class EE_API VertexBufferVBO : public VertexBuffer {
bool compile();
void update( const Uint32& Types, bool Indices );
void update( const Uint32& types, bool indices );
void reload();

View File

@@ -7,42 +7,45 @@ using namespace EE::Graphics::Private;
namespace EE { namespace Graphics {
VertexBuffer* VertexBuffer::New( const Uint32& VertexFlags, PrimitiveType DrawType,
const Int32& ReserveVertexSize, const Int32& ReserveIndexSize,
VertexBufferUsageType UsageType ) {
VertexBuffer* VertexBuffer::New( const Uint32& vertexFlags, PrimitiveType drawType,
const Int32& reserveVertexSize, const Int32& reserveIndexSize,
VertexBufferUsageType usageType ) {
if ( GLi->isExtension( EEGL_ARB_vertex_buffer_object ) )
return eeNew( VertexBufferVBO,
( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ) );
( vertexFlags, drawType, reserveVertexSize, reserveIndexSize, usageType ) );
return eeNew( VertexBufferOGL,
( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ) );
( vertexFlags, drawType, reserveVertexSize, reserveIndexSize, usageType ) );
}
VertexBuffer* VertexBuffer::NewVertexArray( const Uint32& VertexFlags, PrimitiveType DrawType,
const Int32& ReserveVertexSize,
const Int32& ReserveIndexSize,
VertexBufferUsageType UsageType ) {
VertexBuffer* VertexBuffer::NewVertexArray( const Uint32& vertexFlags, PrimitiveType drawType,
const Int32& reserveVertexSize,
const Int32& reserveIndexSize,
VertexBufferUsageType usageType ) {
return eeNew( VertexBufferOGL,
( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ) );
( vertexFlags, drawType, reserveVertexSize, reserveIndexSize, usageType ) );
}
VertexBuffer::VertexBuffer( const Uint32& VertexFlags, PrimitiveType DrawType,
const Int32& ReserveVertexSize, const Int32& ReserveIndexSize,
VertexBufferUsageType UsageType ) :
mVertexFlags( VertexFlags ), mDrawType( DrawType ), mUsageType( UsageType ), mElemDraw( -1 ) {
if ( ReserveVertexSize > 0 ) {
VertexBuffer::VertexBuffer( const Uint32& vertexFlags, PrimitiveType drawType,
const Int32& reserveVertexSize, const Int32& reserveIndexSize,
VertexBufferUsageType usageType ) :
mVertexFlags( vertexFlags ), mDrawType( drawType ), mUsageType( usageType ), mElemDraw( -1 ) {
if ( reserveVertexSize > 0 ) {
for ( Int32 i = 0; i < VERTEX_FLAGS_COUNT; i++ ) {
if ( VERTEX_FLAG_QUERY( mVertexFlags, i ) ) {
if ( i != VERTEX_FLAG_COLOR )
mVertexArray[i].reserve( ReserveVertexSize * VertexElementCount[i] );
else
mColorArray.reserve( ReserveVertexSize * VertexElementCount[i] );
if ( i == VERTEX_FLAG_POSITION ) {
mPosArray.reserve( reserveVertexSize );
} else if ( i != VERTEX_FLAG_COLOR ) {
mTexCoordArray[i - 1].reserve( reserveVertexSize );
} else {
mColorArray.reserve( reserveVertexSize );
}
}
}
}
if ( ReserveIndexSize > 0 ) {
mIndexArray.reserve( ReserveIndexSize );
if ( reserveIndexSize > 0 ) {
mIndexArray.reserve( reserveIndexSize );
}
VertexBufferManager::instance()->add( this );
@@ -52,99 +55,140 @@ VertexBuffer::~VertexBuffer() {
VertexBufferManager::instance()->remove( this );
}
void VertexBuffer::addVertex( const Uint32& Type, const Vector2f& Vertex ) {
if ( Type < VERTEX_FLAGS_COUNT_ARR ) {
mVertexArray[Type].push_back( Vertex.x );
mVertexArray[Type].push_back( Vertex.y );
void VertexBuffer::addVertex( const Uint32& type, const Vector2f& vertex ) {
eeASSERT( type < VERTEX_FLAGS_COUNT_ARR );
switch ( type ) {
case VERTEX_FLAG_POSITION:
mPosArray.push_back( vertex );
break;
case VERTEX_FLAG_TEXTURE0:
case VERTEX_FLAG_TEXTURE1:
case VERTEX_FLAG_TEXTURE2:
case VERTEX_FLAG_TEXTURE3:
mTexCoordArray[type - 1].push_back( vertex );
break;
}
}
void VertexBuffer::addVertex( const Vector2f& Vertex ) {
addVertex( VERTEX_FLAG_POSITION, Vertex );
void VertexBuffer::addVertex( const Vector2f& vertex ) {
mPosArray.push_back( vertex );
}
void VertexBuffer::addTextureCoord( const Vector2f& VertexCoord, const Uint32& TextureLevel ) {
addVertex( VERTEX_FLAG_TEXTURE0 + TextureLevel, VertexCoord );
void VertexBuffer::addTextureCoord( const Vector2f& vertexCoord, const Uint32& textureLevel ) {
eeASSERT( textureLevel < VERTEX_FLAG_TEXTURE3 );
mTexCoordArray[textureLevel].push_back( vertexCoord );
}
void VertexBuffer::addColor( const Color& Color ) {
mColorArray.push_back( Color.r );
mColorArray.push_back( Color.g );
mColorArray.push_back( Color.b );
mColorArray.push_back( Color.a );
void VertexBuffer::addColor( const Color& color ) {
mColorArray.push_back( color );
}
void VertexBuffer::addIndex( const Uint32& Index ) {
mIndexArray.push_back( Index );
void VertexBuffer::addIndex( const Uint32& indexValue ) {
mIndexArray.push_back( indexValue );
VERTEX_FLAG_SET( mVertexFlags, VERTEX_FLAG_USE_INDICES );
}
void VertexBuffer::resizeArray( const Uint32& Type, const Uint32& Size ) {
if ( Type != VERTEX_FLAG_COLOR )
mVertexArray[Type].resize( Size );
else
mColorArray.resize( Size );
void VertexBuffer::setVertex( const Uint32& index, const Uint32& type, const Vector2f& vertex ) {
switch ( type ) {
case VERTEX_FLAG_POSITION:
eeASSERT( index < mPosArray.size() );
mPosArray[index] = vertex;
break;
case VERTEX_FLAG_TEXTURE0:
case VERTEX_FLAG_TEXTURE1:
case VERTEX_FLAG_TEXTURE2:
case VERTEX_FLAG_TEXTURE3:
eeASSERT( type < VERTEX_FLAG_TEXTURE3 );
eeASSERT( index < mTexCoordArray[type - 1].size() );
mTexCoordArray[type - 1][index] = vertex;
break;
}
}
void VertexBuffer::resizeIndices( const Uint32& Size ) {
mIndexArray.resize( Size );
void VertexBuffer::setVertex( const Uint32& index, const Vector2f& vertex ) {
eeASSERT( index < mPosArray.size() );
mPosArray[index] = vertex;
}
Float* VertexBuffer::getArray( const Uint32& Type ) {
if ( Type < VERTEX_FLAGS_COUNT_ARR && mVertexArray[Type].size() )
return &mVertexArray[Type - 1][0];
return NULL;
void VertexBuffer::setTextureCoord( const Uint32& index, const Vector2f& vertexCoord,
const Uint32& textureLevel ) {
eeASSERT( textureLevel < VERTEX_FLAG_TEXTURE3 );
eeASSERT( index < mTexCoordArray[textureLevel].size() );
mTexCoordArray[textureLevel][index] = vertexCoord;
}
Uint8* VertexBuffer::getColorArray() {
if ( mColorArray.size() )
return &mColorArray[0];
return NULL;
void VertexBuffer::setColor( const Uint32& index, const Color& color ) {
eeASSERT( index < mColorArray.size() );
mColorArray[index] = color;
}
Uint32* VertexBuffer::getIndices() {
if ( mIndexArray.size() )
return &mIndexArray[0];
void VertexBuffer::setIndex( const Uint32& index, const Uint32& indexValue ) {
eeASSERT( index < mIndexArray.size() );
mIndexArray[index] = indexValue;
}
return NULL;
void VertexBuffer::resizeArray( const Uint32& type, const Uint32& size ) {
switch ( type ) {
case VERTEX_FLAG_POSITION:
mPosArray.resize( size );
break;
case VERTEX_FLAG_TEXTURE0:
case VERTEX_FLAG_TEXTURE1:
case VERTEX_FLAG_TEXTURE2:
case VERTEX_FLAG_TEXTURE3:
mTexCoordArray[type - 1].resize( size );
break;
case VERTEX_FLAG_COLOR:
mColorArray.resize( size );
break;
}
}
void VertexBuffer::resizeIndices( const Uint32& size ) {
mIndexArray.resize( size );
}
std::vector<Vector2f>& VertexBuffer::getPositionArray() {
return mPosArray;
}
std::vector<Color>& VertexBuffer::getColorArray() {
return mColorArray;
}
std::vector<Uint32>& VertexBuffer::getIndices() {
return mIndexArray;
}
std::vector<Vector2f>& VertexBuffer::getTextureCoordArray( const Uint32& textureLevel ) {
eeASSERT( textureLevel < mTexCoordArray->size() );
return mTexCoordArray[textureLevel];
}
Uint32 VertexBuffer::getVertexCount() {
return (Uint32)mVertexArray[VERTEX_FLAG_POSITION].size() /
VertexElementCount[VERTEX_FLAG_POSITION];
return mPosArray.size();
}
Uint32 VertexBuffer::getIndexCount() {
return (Uint32)mIndexArray.size();
}
Vector2f VertexBuffer::getVector2( const Uint32& Type, const Uint32& Index ) {
eeASSERT( Type < VERTEX_FLAGS_COUNT_ARR && !VERTEX_FLAG_QUERY( mVertexFlags, Type ) )
Int32 pos = Index * VertexElementCount[Type];
return Vector2f( mVertexArray[Type][pos], mVertexArray[Type][pos + 1] );
}
Color VertexBuffer::getColor( const Uint32& Index ) {
Color VertexBuffer::getColor( const Uint32& index ) {
eeASSERT( !VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_COLOR ) );
Int32 pos = Index * VertexElementCount[VERTEX_FLAG_COLOR];
Int32 pos = index * VertexElementCount[VERTEX_FLAG_COLOR];
return Color( mColorArray[pos], mColorArray[pos + 1], mColorArray[pos + 2],
mColorArray[pos + 3] );
return Color( mColorArray[pos] );
}
Uint32 VertexBuffer::getIndex( const Uint32& Index ) {
eeASSERT( Index < mIndexArray.size() );
return mIndexArray[Index];
Uint32 VertexBuffer::getIndex( const Uint32& index ) {
eeASSERT( index < mIndexArray.size() );
return mIndexArray[index];
}
void VertexBuffer::setElementNum( Int32 Num ) {
mElemDraw = Num;
void VertexBuffer::setElementNum( Int32 num ) {
mElemDraw = num;
}
const Int32& VertexBuffer::getElementNum() const {
@@ -152,9 +196,9 @@ const Int32& VertexBuffer::getElementNum() const {
}
void VertexBuffer::clear() {
for ( int i = 0; i < VERTEX_FLAGS_COUNT - 1; i++ )
mVertexArray[i].clear();
mPosArray.clear();
for ( auto& texCoord : mTexCoordArray )
texCoord.clear();
mColorArray.clear();
mIndexArray.clear();
}

View File

@@ -5,10 +5,10 @@
namespace EE { namespace Graphics {
VertexBufferOGL::VertexBufferOGL( const Uint32& VertexFlags, PrimitiveType DrawType,
const Int32& ReserveVertexSize, const Int32& ReserveIndexSize,
VertexBufferUsageType UsageType ) :
VertexBuffer( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ) {}
VertexBufferOGL::VertexBufferOGL( const Uint32& vertexFlags, PrimitiveType drawType,
const Int32& reserveVertexSize, const Int32& reserveIndexSize,
VertexBufferUsageType usageType ) :
VertexBuffer( vertexFlags, drawType, reserveVertexSize, reserveIndexSize, usageType ) {}
void VertexBufferOGL::bind() {
GlobalBatchRenderer::instance()->draw();
@@ -33,22 +33,21 @@ void VertexBufferOGL::draw() {
}
void VertexBufferOGL::setVertexStates() {
Uint32 alloc = getVertexCount() * sizeof( Float ) * 2;
Uint32 allocC = getVertexCount() * 4;
Uint32 alloc = getVertexCount() * sizeof( Vector2f );
Uint32 allocC = getVertexCount() * sizeof( Color );
/// TEXTURES
if ( GLi->isExtension( EEGL_ARB_multitexture ) ) {
for ( Int32 i = 0; i < EE_MAX_TEXTURE_UNITS; i++ ) {
if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 + i ) ) {
if ( mVertexArray[VERTEX_FLAG_TEXTURE0 + i].empty() )
if ( mTexCoordArray[VERTEX_FLAG_TEXTURE0 + i].empty() )
return;
GLi->clientActiveTexture( GL_TEXTURE0 + i );
GLi->enableClientState( GL_TEXTURE_COORD_ARRAY );
GLi->texCoordPointer( VertexElementCount[VERTEX_FLAG_TEXTURE0 + i], GL_FP,
sizeof( Float ) *
VertexElementCount[VERTEX_FLAG_TEXTURE0 + i],
&mVertexArray[VERTEX_FLAG_TEXTURE0 + i][0], alloc );
sizeof( Vector2f ),
&mTexCoordArray[VERTEX_FLAG_TEXTURE0 + i][0], alloc );
} else {
if ( 0 == i ) {
GLi->disable( GL_TEXTURE_2D );
@@ -59,12 +58,12 @@ void VertexBufferOGL::setVertexStates() {
}
} else {
if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 ) ) {
if ( mVertexArray[VERTEX_FLAG_TEXTURE0].empty() )
if ( mTexCoordArray[VERTEX_FLAG_TEXTURE0].empty() )
return;
GLi->enableClientState( GL_TEXTURE_COORD_ARRAY );
GLi->texCoordPointer( VertexElementCount[VERTEX_FLAG_TEXTURE0], GL_FP,
sizeof( Float ) * VertexElementCount[VERTEX_FLAG_TEXTURE0],
&mVertexArray[VERTEX_FLAG_TEXTURE0][0], alloc );
sizeof( Vector2f ), &mTexCoordArray[VERTEX_FLAG_TEXTURE0][0],
alloc );
} else {
GLi->disable( GL_TEXTURE_2D );
GLi->disableClientState( GL_TEXTURE_COORD_ARRAY );
@@ -73,12 +72,11 @@ void VertexBufferOGL::setVertexStates() {
/// POSITION
if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_POSITION ) ) {
if ( mVertexArray[VERTEX_FLAG_POSITION].empty() )
if ( mPosArray.empty() )
return;
GLi->enableClientState( GL_VERTEX_ARRAY );
GLi->vertexPointer( VertexElementCount[VERTEX_FLAG_POSITION], GL_FP,
sizeof( Float ) * VertexElementCount[VERTEX_FLAG_POSITION],
&mVertexArray[VERTEX_FLAG_POSITION][0], alloc );
GLi->vertexPointer( VertexElementCount[VERTEX_FLAG_POSITION], GL_FP, sizeof( Vector2f ),
&mPosArray[0], alloc );
} else {
GLi->disableClientState( GL_VERTEX_ARRAY );
}

View File

@@ -8,10 +8,10 @@
namespace EE { namespace Graphics {
VertexBufferVBO::VertexBufferVBO( const Uint32& VertexFlags, PrimitiveType DrawType,
const Int32& ReserveVertexSize, const Int32& ReserveIndexSize,
VertexBufferUsageType UsageType ) :
VertexBuffer( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ),
VertexBufferVBO::VertexBufferVBO( const Uint32& vertexFlags, PrimitiveType drawType,
const Int32& reserveVertexSize, const Int32& reserveIndexSize,
VertexBufferUsageType usageType ) :
VertexBuffer( vertexFlags, drawType, reserveVertexSize, reserveIndexSize, usageType ),
mCompiled( false ),
mBuffersSet( false ),
mTextured( false ),
@@ -72,23 +72,54 @@ bool VertexBufferVBO::compile() {
// Create the VBO vertex arrays
for ( Int32 i = 0; i < VERTEX_FLAGS_COUNT; i++ ) {
if ( VERTEX_FLAG_QUERY( mVertexFlags, i ) ) {
if ( !mVertexArray[i].empty() ) {
glGenBuffersARB( 1, (unsigned int*)&mArrayHandle[i] );
switch ( i ) {
case VERTEX_FLAG_POSITION: {
if ( mPosArray.empty() )
return false;
glBindBufferARB( GL_ARRAY_BUFFER, mArrayHandle[i] );
glGenBuffersARB( 1, (unsigned int*)&mArrayHandle[i] );
glBindBufferARB( GL_ARRAY_BUFFER, mArrayHandle[i] );
if ( mArrayHandle[i] ) {
if ( i != VERTEX_FLAG_COLOR )
glBufferDataARB( GL_ARRAY_BUFFER, mVertexArray[i].size() * sizeof( Float ),
&( mVertexArray[i][0] ), usageType );
else
glBufferDataARB( GL_ARRAY_BUFFER, mColorArray.size(), &mColorArray[0],
usageType );
} else {
return false;
if ( !mArrayHandle[i] )
return false;
glBufferDataARB( GL_ARRAY_BUFFER, mPosArray.size() * sizeof( Vector2f ),
&( mPosArray[0] ), usageType );
break;
}
} else {
return false;
case VERTEX_FLAG_TEXTURE0:
case VERTEX_FLAG_TEXTURE1:
case VERTEX_FLAG_TEXTURE2:
case VERTEX_FLAG_TEXTURE3:
if ( mTexCoordArray[i - 1].empty() )
return false;
glGenBuffersARB( 1, (unsigned int*)&mArrayHandle[i] );
glBindBufferARB( GL_ARRAY_BUFFER, mArrayHandle[i] );
if ( !mArrayHandle[i] )
return false;
glBufferDataARB( GL_ARRAY_BUFFER,
mTexCoordArray[i - 1].size() * sizeof( Vector2f ),
&mTexCoordArray[i - 1][0], usageType );
break;
case VERTEX_FLAG_COLOR: {
if ( mColorArray.empty() )
return false;
glGenBuffersARB( 1, (unsigned int*)&mArrayHandle[i] );
glBindBufferARB( GL_ARRAY_BUFFER, mArrayHandle[i] );
if ( !mArrayHandle[i] )
return false;
glBufferDataARB( GL_ARRAY_BUFFER, mColorArray.size() * sizeof( Color ),
&mColorArray[0], usageType );
break;
}
default:
break;
}
}
}
@@ -310,7 +341,7 @@ void VertexBufferVBO::setVertexStates() {
}
}
void VertexBufferVBO::update( const Uint32& Types, bool Indices ) {
void VertexBufferVBO::update( const Uint32& types, bool indices ) {
unsigned int usageType = GL_STATIC_DRAW;
if ( mUsageType == VertexBufferUsageType::Dynamic )
usageType = GL_DYNAMIC_DRAW;
@@ -318,23 +349,39 @@ void VertexBufferVBO::update( const Uint32& Types, bool Indices ) {
usageType = GL_STREAM_DRAW;
for ( Int32 i = 0; i < VERTEX_FLAGS_COUNT; i++ ) {
if ( VERTEX_FLAG_QUERY( mVertexFlags, i ) && VERTEX_FLAG_QUERY( Types, i ) ) {
if ( VERTEX_FLAG_QUERY( mVertexFlags, i ) && VERTEX_FLAG_QUERY( types, i ) ) {
glBindBufferARB( GL_ARRAY_BUFFER, mArrayHandle[i] );
if ( mArrayHandle[i] ) {
if ( i != VERTEX_FLAG_COLOR )
glBufferDataARB( GL_ARRAY_BUFFER, mVertexArray[i].size() * sizeof( Float ),
&( mVertexArray[i][0] ), usageType );
else
glBufferDataARB( GL_ARRAY_BUFFER, mColorArray.size(), &mColorArray[0],
usageType );
switch ( i ) {
case VERTEX_FLAG_POSITION: {
glBufferDataARB( GL_ARRAY_BUFFER, mPosArray.size() * sizeof( Vector2f ),
&( mPosArray[0] ), usageType );
break;
}
case VERTEX_FLAG_TEXTURE0:
case VERTEX_FLAG_TEXTURE1:
case VERTEX_FLAG_TEXTURE2:
case VERTEX_FLAG_TEXTURE3:
glBufferDataARB( GL_ARRAY_BUFFER,
mTexCoordArray[i - 1].size() * sizeof( Vector2f ),
&mTexCoordArray[i - 1][0], usageType );
break;
case VERTEX_FLAG_COLOR: {
glBufferDataARB( GL_ARRAY_BUFFER, mColorArray.size() * sizeof( Color ),
&mColorArray[0], usageType );
break;
}
default:
break;
}
}
}
}
glBindBuffer( GL_ARRAY_BUFFER, 0 );
if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_USE_INDICES ) && Indices ) {
if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_USE_INDICES ) && indices ) {
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER, mElementHandle );
glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER, getIndexCount() * sizeof( Uint32 ),