Main Menu

VBO question

Started by Kokoni, July 10, 2006, 20:17:08

Previous topic - Next topic

Kokoni

Hi everbody,

My OpenGL knowledge is limited. Anyways, I would like to use dynamic VBO.
Consulting gamedev forum and this one, I understand it is recomanded to create two VBO :
- The first one with vertex, normals, textures coords, like pricec suggested in the thread http://lwjgl.org/forum/viewtopic.php?t=757&highlight=vbo  :
Quote
Niels, what you should be doing is packing vertex data thus:

x,y,z,nx,ny,nz,tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3

You write all the data but once, linearly, from start to finish, every frame, optionally skipping data that has not changed.

- The second contains index.


My questions are :

1. How can I implement the first VBO, I mean in opengl : should I use glBufferSubDataARB ? like it is shown in http://www.spec.org/gpc/opc.static/vbo_whitepaper.html

2. I think the second VBO can help me to solve my first question, but I don't know how. (due probably to my lack of knowledge).

3. As dynamic VBO, the first one change every time, I think I have to create and bind a new vbo every time, is it exact ?

Thanks in advance.

Kokoni

Some usefull links to help me to deal with my questions ?

Sardtok

igg -- Take me off for great justice?

ndhb

Hi Kokoni. I'm new to VBO's myself.

I followed the steps in the wiki and it worked for me:

http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/opengl/basicvbo

It doesn't go into the details, but it will get you started.

Yes, you need to bind the buffers every time you render (you probably dont want to / shouldn't create a new VBO every frame though). Don't worry about the binding state change it's very cheap (the "work" is in done glXXXPointers which you cant avoid).

Kokoni

Thanks all for yours answers.  I'm going to try to learn more about VBO throught the links you have provided me.

darkprophet

Here you go: http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/opengl/speedyvbo

Wrote a nice tutorial for you. Let me know if its helpful or not...

DP

Kokoni

Darkprophet,

You are great ! You have full answered my first question and also create a good tutorial for everybody.

I have a doubt, I often read we need a second vbo which contains index. With your way to implement/rendre the interleaved vbo, what is the aim of such "index vbo" ? to speed up  :?:

darkprophet

You do need a second VBO that contains the indices whether the other mesh components have been interleaved or not. This is because indices are special and when buffering, you must use GL_ELEMENT_ARRAY_BUFFER_ARB instead of GL_ARRAY_BUFFER_ARB.

As for the 3rd question, if the entire buffer changes, use glBufferDataARB, if only a certain known portion of the VBO changes, then use glMapDataARB. But there is no need to create a VBO every frame, but you do need to bind it everyframe.

DP

Kokoni

I'm back from a long period without programming my 3D Java engine  ;)

I'm trying to set up the interleaved VBO from your tutorial, here is my render() method :
   public void render() {
      
        GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
        GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
        GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
       
      ARBVertexBufferObject.glBindBufferARB( ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, iVBOID );
      setupGLPointer();

      GL12.glDrawRangeElements(GL11.GL_TRIANGLES, 0, maxIndex, indexBufferSize,GL11.GL_UNSIGNED_INT, 0);
   }


Of course I assume I populated the buffer with this code :
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, data, ARBVertexBufferObject.GL_STATIC_READ_ARB);

My question is : does it make sense ? Do I have to setup the GL pointers (like discribded in the speedy vbo tutorial) at every render step ?

All comments are of course welcomed (my return is hard!) Thanks in advance,
Kokoni.

ndhb

QuoteDo I have to setup the GL pointers (like discribded in the speedy vbo tutorial) at every render step ?

Not necessarily, if you want a shortcut to enabling several arrays at once and callling gl*Pointer, look at the function call glInterleavedArrays. You put all your vertex attributes (Vertex, Normal, Color) in a previously defined format (see specification below) and it takes care of the glEnableClientState(*) and gl*Pointer calls. You must follow one of the defined formats for this function to work (if that is not possible for some reason, then you have to do it manually for each attribute and in your own prefered order).

http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/interleavedarrays.html

In general, keep the specification for VBO close and look at the example usage: http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt

- Nicolai de Haan Brøgger

HangDude

note that if you can render without providing indices using glDrawArrays(). In that case you only need a single VBO containing the vertex data. I'm not quite sure if this is faster or slower than providing indices. It doesn't allow to share vertices tough (vertices used by multiple triangles).

greets,
phil