
A step towards GL3
Posted Sunday, 7 June, 2009 - 09:11 by objarniI'm a traditional OpenGL developer in the sense that I keep using immediate mode because I think it is so intuitive and easy-to-use.
I know this mode of GL operation is deprecated (maybe even removed?) with GL3, hence I am trying to "take the leap" and start using vertex array, vertex buffer objects and so on.
So I thought: can't I use the best of both worlds? Why not have a "vertex array builder" object that operates much like traditional immediate mode, and then creates/draws the vertex array for me?
My thoughts then went on to "should I create VAs or VBOs or even generate source code to draw VAs and so on"? Since I do know how VAs work already, I think this is a good start to build this "builder object".
I will begin with support for vertex position, color, normals and texture coordinate. That is the "bread and butter" of OpenGL, and I can expand on that when I need to.
Some pseudocode to show what I mean:
// code to build a multi coloured triangle vertex array VABuilder builder = new VABuilder(); builder.Color(1,0,0); builder.Vertex(0,0,0); // a red vertex builder.Vertex(100,0,0); // this vertex will be red too builder.Color(0,0,1); builder.Vertex(100,100,0); // blue [some data format I have not yet decided on] va = builder.GetVertexArray(); [ - " - ] ca = builder.GetColorArray();
- objarni's blog
- Login or register to post comments


Comments
Re: A step towards GL3
You can take a look at glim: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Numb...
It tries to do similar thing in C++.
Re: A step towards GL3
Thanks!
Re: A step towards GL3
OGRE engine also has a similar interface.
http://www.ogre3d.org/wiki/index.php/ManualObject
Re: A step towards GL3
OK I've written av 0.01 version of this, featuring double-arrays and vertices/colors only.
Some example code:
Re: A step towards GL3
Which data format of vertex arrays do you guys use for best speed/quality compromise..? I would guess short ints are "good enough" quailtywise for smaller models, while being half the size of floats, and one forth the size of doubles! In theory they should be 4x faster right? Even more obvious for normals/colors/texcoords, they really do not need to be floats/doubles, no need for such high precision.
I'm thinking of making VABuilder have one "nice, comfy" mode (doubles) and one "fast, not so comfy" mode (short ints). Maybe even split into two separate builder. Generic type T to define what data format to use..? Don't know, since might want different formats for positions/colors/texcoords/normals.
Comments? I know "measure, measure, measure" is the "answer to everything" when it comes to performance, but what is your experience?
Re: A step towards GL3
.. and I just remembered VAs do not play nice with .NET! :(
http://www.opentk.com/node/296
Have to learn VBOs. Fortunately, this is well documentet in OpenTK! :)
Re: A step towards GL3
Changing from VAs to VBOs means changing just two lines of code:
GL.BufferData()to upload the data, instead of keeping it in yourself.GL.Vertex/Normal/*Pointer()
to be a 0-based offset inside a single vertex, instead of a pointer to the actual data.That's all, actually. Bonus points if you go all the way and replace
GL.Vertex/Normal/ColorPointer()withGL.VertexAttribPointer()and a simple vertex shader.Sounds hairy at first, but the strength of the GL3 approach will become apparent once you actually implement it. True, there is an initial explosion in setup code (you need to generate objects, upload data, run a shader) but guess what: you only need to write the setup code once. The final result is both cleaner and faster than immediate mode.
Edit: once you actually go the VBO route, you'll see that there's little need for emulating immediate. Check this out:
My abstraction looks similar to this:
Re: A step towards GL3
Thanks, but shaders is too much right now. I'll be glad to get VBOs working ;)
Re: A step towards GL3
Np.
I edited my post while you were posting, yet again. :)
Re: A step towards GL3
Yeah VBOs look nice and not that much harder than VAs. Conceptually, they are just VAs "owned" by GL right?