Advertisement

GL_ARB_vertex_buffer_object

Started by February 19, 2005 03:31 PM
15 comments, last by cippyboy 20 years ago
Some code I just digged out that uses indices in a VBO:
	void Mesh::SetFaces(const unsigned int *f, int count, int valence) {		assert ( 0 != f && 2 < count && 2 < valence && valence < 5 &&  "Invalid parameter." );		if (!index)			glGenBuffersARB( 1, &index );		glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, index );		unsigned short * idx = new unsigned short[count];		for ( int i = 0; i < count; ++i )			idx = f;		glBufferDataARB(			GL_ELEMENT_ARRAY_BUFFER_ARB,			count * 2,			idx,			GL_STATIC_DRAW_ARB );		delete [] idx;		mode = (valence == 3) ? GL_TRIANGLES : GL_QUADS;		numFaces = count / valence;		numIndices = count;	}	void Mesh::Render() {		if (!numFaces || !(bufferFmt & kPosition))			return;		material.Render();                // left out all buffers for clarity here		glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, index );                // index: index VBO id                // mode: GL_TRIANGLES or GL_QUADS		glDrawElements( mode, numIndices, GL_UNSIGNED_SHORT, 0 );	}


HTH,
Pat.

What a piece of crap, I don`t know what the heck is going on but I`m getting 27 FPS now :(
To give code, here`s the common functions->
void REM::CreateBuffers(){	//Vertex Array	glGenBuffers(1,&BufferID[0]);	glBindBuffer(GL_ARRAY_BUFFER_ARB,BufferID[0]);		glBufferData(GL_ARRAY_BUFFER_ARB,						sizeof(Vector3)*nrverts,						Vertices,						GL_STATIC_DRAW_ARB);	//TexCoord Array	glGenBuffers(1,&BufferID[1]);	glBindBuffer(GL_ARRAY_BUFFER_ARB,BufferID[1]);	glBufferData(GL_ARRAY_BUFFER_ARB,						sizeof(Vector2)*nrverts,						Texels[0],						GL_STATIC_DRAW_ARB);	//Normals	glGenBuffers(1,&BufferID[2]);	glBindBuffer(GL_ARRAY_BUFFER_ARB,BufferID[2]);	glBufferData(GL_ARRAY_BUFFER_ARB,						sizeof(Vector3)*nrverts,						Normals,						GL_STATIC_DRAW_ARB);	//Indices	glGenBuffers(1,&BufferID[3]);	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,BufferID[3]);	glBufferData(GL_ELEMENT_ARRAY_BUFFER_ARB,						sizeof(WORD)*nrindices,						Indices2,						GL_STATIC_DRAW_ARB);	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);	glBindBuffer(GL_ARRAY_BUFFER_ARB,0);}void REM::SetBufferArrays(){			glEnableClientState(GL_NORMAL_ARRAY);		glBindBuffer(GL_ARRAY_BUFFER_ARB,BufferID[2]);	glNormalPointer(GL_FLOAT,0,NULL);//Normals);	//		glClientActiveTextureARB(GL_TEXTURE0_ARB);	glEnableClientState(GL_TEXTURE_COORD_ARRAY);	glBindBuffer(GL_ARRAY_BUFFER_ARB,BufferID[1]);	glTexCoordPointer(2,GL_FLOAT,0,NULL);//Texels[0]);	//	glClientActiveTextureARB(GL_TEXTURE1_ARB);	glEnableClientState(GL_TEXTURE_COORD_ARRAY);	glBindBuffer(GL_ARRAY_BUFFER_ARB,BufferID[1]);	glTexCoordPointer(2,GL_FLOAT,0,NULL);//Texels[0]);	//	glClientActiveTextureARB(GL_TEXTURE2_ARB);	glEnableClientState(GL_TEXTURE_COORD_ARRAY);	glBindBuffer(GL_ARRAY_BUFFER_ARB,BufferID[1]);	glTexCoordPointer(2,GL_FLOAT,0,NULL);	//	glEnableClientState(GL_VERTEX_ARRAY);	glBindBuffer(GL_ARRAY_BUFFER_ARB,BufferID[0]);	glVertexPointer(3,GL_FLOAT,0,NULL);        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,BufferID[3]);}void REM::RenderObjects(UINT group){	for(int j=0;j<Group[group].nr;j++)	if (Object[Group[group].Object[j].Index].nrindices>0)	{											if (!use_range)		{						glDrawElements(GL_TRIANGLES,Object[Group[group].Object[j].Index].nrindices,GL_UNSIGNED_SHORT,				(char*)(NULL+Object[Group[group].Object[j].Index].offset*sizeof(WORD))				);		}		else		{						glDrawRangeElements(GL_TRIANGLES,			Object[Group[group].Object[j].Index].min_off,			Object[Group[group].Object[j].Index].max_off,			Object[Group[group].Object[j].Index].nrindices,			GL_UNSIGNED_SHORT,			(char*)(NULL+Object[Group[group].Object[j].Index].offset*sizeof(WORD))			);		}	}	}


EDIT:Made some modifications, Element Array is only binded once, so now I get from 3 to 27 FPS :D, instead of my original 160 :D

Relative Games - My apps

Advertisement
My Bad, It was some function that was eating everything, I was coming back to the old implementation and still getting the same FPS, that was kinda spoky. So actually I`m getting something like 5-7 FPS increase, from 150-152 to 157-158, is that good ?

[Edited by - cippyboy on February 21, 2005 10:11:18 AM]

Relative Games - My apps

Quote:
Original post by cippyboy
My Bad, It was some function that was eating everything, I was coming back to the old implementation and still getting the same FPS, that was kinda spoky. So actually I`m getting something like 5-7 FPS increase, from 150-152 to 157-158, is that good ?


At the moment you don't appear to be rendering all that much anyway, so your card isn't working all that hard. I suppose it could have a more noticeable effect if you were rendering more triangles.

Even if they hadn't given a performance boost, I find VBOs are a nice way to manage vertex data.
1 Succes->When Rendering Most of the objects, I have a 15 FPS increase which is pretty great :D
2 More Questions->
#1 If I add an intervealed array with a GL_N3F_V3F to put normals and vertices, can I then also add TexCoord pointers ? because of my texels per 3 texture units and so :D

#2 Like someone above said about buffers length, If I make an index+/vertex buffer system to split my buffers into 2-4 MB pieces, will that make things faster ? That reminds me of the glDrawRangeElements MAX_VERTICES and MAX_ELEMENTS limits which are 4096 vertices/indices, spliting them up like that should provide some kind of speed right ?

Relative Games - My apps

When I switched my terrain implementation from VA to VBO (rendering about 25k tris/frame), I got about a 400% speed increase. So if you're rendering a lot of geometry in a VBO friendly way, yeah it helps.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Advertisement
Well yeah but I`m doing a lot of state changes like having 3 texture units,colors, specular,alpha tests,blending,particle systems, vertex/fragment programs,object/texture animation although theyre not exactly all in my test. But for example each texture unit down gives about 10 more frame.

Relative Games - My apps

This topic is closed to new replies.

Advertisement