Game Development Reference
In-Depth Information
How to do it…
1.
Our vertex arrays are hidden behind the interface of the clGLVertexArray class:
class clGLVertexArray: public iObject
{
public:
clGLVertexArray();
virtual ~clGLVertexArray();
void Draw( bool Wireframe ) const;
void SetVertexAttribs(const clPtr<clVertexAttribs>&
Attribs);
private:
void Bind() const;
GLuint FVBOID;
GLuint FVAOID;
2.
Offsets for VBO are stored through the following code:
std::vector<const void*> FAttribVBOOffset;
3.
The following are the pointers to the actual data of the attached clVertexAttribs :
std::vector<const void*> FEnumeratedStreams;
clPtr<clVertexAttribs> FAttribs;
};
4.
The clVertexAttribs should be attached to our vertex array using the
SetVertexAttribs() method:
void clGLVertexArray::SetVertexAttribs( const
clPtr<clVertexAttribs>& Attribs )
{
FAttribs = Attribs;
FEnumeratedStreams = FAttribs->EnumerateVertexStreams();
5.
We have to remove any old vertex buffer objects before using the FVBOID again in
order to allow the reuse of clGLVertexArray :
LGL3->glDeleteBuffers( 1, &FVBOID );
size_t VertexCount = FAttribs->FVertices.size();
size_t DataSize = 0;
for ( int i = 0; i != L_VS_TOTAL_ATTRIBS; i++ )
{
FAttribVBOOffset[ i ] = ( void* )DataSize;
6.
Calculate the size of a vertex buffer object and allocate it:
DataSize += FEnumeratedStreams[i] ?
sizeof( float ) * L_VS_VEC_COMPONENTS[ i ] *
 
Search WWH ::




Custom Search