Stupid_2D's picture

Managing VBOs

Hellly everyone,
Its hard for me to find a way to write this down (language wise and logical) but i give it a try.

I have problems finding a good "architecture" which lets me have the desired freedom of manipulating things.
At the moment I have a static Class for my VBOs where I store every VBO in a List

This kinda works but now i notice that its a pain to do things like rotate a single VBO and Mouseselection. The rendering usually is a foreach which goes through the list and basically draws every VBO then.

Which makes me start questioning if this is the right approach.

Lets say I have gameobjects (like a simple cube which has some values like 2D Coordinates and stuff a game needs), how to I properly add a "rendering object" ?
I mean how does the connection between the game and the rendering logic look like ?

I know this is kind of general, but I cant find a way to make it more specific.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tksuoran's picture

My current approach:

- Model has Frame transformation in 3D, and Batch (or list of Batches)
- Batch has Mesh and Material
- Mesh has 2 BufferRanges, one for index buffer and one for vertex buffer
- BufferRange specifies a range in one Buffer object
- Buffer is wrapper for GL buffer object
- Material has Program and values for uniforms (using uniform buffer)

To render a Model, set the current transform and render all batches in it. To render a Batch, apply it's Material and index and vertex buffers from the mesh. I have buffer ranges, as you can put multiple meshes per vertex (or index) buffer, reducing need to setup attribute pointers / vertex array objects.

To optimize things, sort objects, by material/program at least, so you don't have to bind material uniform buffer unless material changes, and you don't have to use program unless it changes.

Stupid_2D's picture

Well thanks for your reply.

But to be honest, i dont know what batches or Meshes are. In general i dont know at all what you try to tell me. Guess i need to do more studies -.-

Damn I am still at the surface -.-

Stupid_2D's picture

Ok,
I ask this question again,

is there any better way instead of translate and rotate to change positions of VBOs without using Push and PopMatrix for every single vbo ?

I just thought i introduce a stack, where the game pushes all elements which should be drawen and the render does everything else.
First renders with unique color + manipulations like translate and rotate for picking and in the second render does the same but with normal colors.

So obviusly, since every vbo has a different position and some are moving i need lots of GL.PushMatrix and Gl.PopMatrix

tksuoran's picture

Do you currently use GL.Translate, Rotate and Scale?

It would be better to manage all transformations yourself (using a Matrix4 class/struct). Then all you need is GL.LoadMatrix(), or use uniforms or uniform buffers.

Stupid_2D's picture

Can you point me to a simple example. I kinda know what you talk about but I have no clue how to do it :)

And thank you for your patience so far.

tksuoran's picture

Arcsynthesis tutorial around Chapter 6. But it might be all worth reading.

Stupid_2D's picture

Woah thats alot material right there. Thanks!

Stupid_2D's picture

I cant bring uniformbuffers to work, can you give me a simple example how to do it ?
I think this is the correct tutorial for it, but im to dumb to understand
http://www.arcsynthesis.org/gltut/Positioning/Tut07%20Shared%20Uniforms....

What I tried doing was adding the uniform stuff to my VBO. So i do something like:

foreach(vbo v in vbos)
{
    LoadUinform
    RenderForSelection
}
foreach(vbo v in vbos)
{
   LoadUniform
   RenderScene
}

This is my current state:

foreach(VBO vbo in vbos)
{
    GL.PushMatrix();			
    GL.Translate(vbo.Translation);
    GL.Rotate(vbo.Rotation,0,0,1);
    VBOHelpber.Draw(vbo);
    GL.PopMatrix()
}