Vertex Buffer Command

BlitzMax Forums/OpenGL Module/Vertex Buffer Command

PaulJG(Posted 2005) [#1]
Has anyone had any luck using the Vertex Buffer Extension, or for that matter.. can you use it in B.Max ??

This is the bit that I dont understand:
GLuint buffer = 0;
glGenBuffersARB(1, &buffer);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(data), data, GL_STATIC_DRAW_ARB);

I can see what its doing in C, but using B.Max !?


Tom(Posted 2005) [#2]
I've not checked out VBOs yet, but I think Terrabits 3D Level Demo uses them (if supported), check this post:

http://www.blitzbasic.com/Community/posts.php?topic=41577

As for the code, GLuint is an Unsigned INT, in max just use an INT

At a guess, the code means something like this:

Local buffer:Int = 0
glGenBuffersARB(1, VarPtr(buffer)) 'Get a buffer name (name = a pointer)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer) 'Tell GL buffer is of type 'GL_ARRAY_BUFFER_ARB'
glBufferDataARB(GL_ARRAY_BUFFER_ARB, SizeOf(data), data, GL_STATIC_DRAW_ARB) 'Point the buffer to some data

If 'data' is a vertex array, I'm not sure if SizeOf(data) would need to be 'data.length' instead.

Tom


PaulJG(Posted 2005) [#3]
Thanks Tom, thats a good place for me to start.


PaulJG(Posted 2005) [#4]
After a few days of head scratching, finally got this baby up and running..

Here's a small example that might come in useful:

What is it ?, and why do you need it ??

The vertex data is stored in the graphics card memory, rather than the systems - (which is transfered across every time its used). Huge speedups can be had.. the only downside being its quite a new command, so some of the older graphics cards might not be able to support it.


Tom(Posted 2005) [#5]
Cheers Paul.


b.t.w, here's how to check for supported extentions:


'Anywhere after bglCreateContext()
If Not ExtensionSupported("GL_ARB_vertex_buffer_object") RuntimeError "VBOs not supported" 'Or use vertex arrays instead e.t.c


...

Function ExtensionSupported(ext$) 'thanks to Lee for this one
	Local RetStr:String=String.FromCString$(Byte Ptr(glGetString( GL_EXTENSIONS )))
	If Instr(retstr$,ext$)<>0 Return True
	Return False
End Function



col(Posted 2005) [#6]
Well done Tom. This is a handy little function.

Thanks.