PDA

View Full Version : Working with multiple VBO's



Robbie
12-07-2011, 02:15 PM
I have modified my code to use two different VBO's...one for the static walls, and one for the user path that changes almost every frame. This is to speed up processing on the backend, so I don't have to redo the walls every time I change paths.

I basically duplicated all of my VBO code. Problem is when I get down to my glDrawElements (which is in my render call), I can't figure out how to tell it WHICH buffer to draw from.

Do I need to do something with my ClientState or something to switch which buffer I'm drawing from?

Edit: Update: I was getting a crash because one of the buffers was being passed an empty index array. I added at least two to keep it from crashing (there's no pathing info at the start) and it now works...but its still only drawing from the second VBO.

I'm calling glDrawElements and passing it the first array of indices, and it doesn't do anything, but it is drawing the stuff from the second VBO's indices when I call glDrawElements a second time and pass it the second set of indices.

_arts_
12-07-2011, 02:57 PM
Forgot to bind the vbo ?

Here is a (random) tutorial about VBO I found: http://www.ozone3d.net/tutorials/opengl_vbo.php

Dark Photon
12-07-2011, 04:47 PM
I have modified my code to use two different VBO's...one for the static walls, and one for the user path that changes almost every frame....but its still only drawing from the second VBO.
Let's see your VBO bind, update, and batch dispatch code.

Once you get this 2-VBO approach working, be sure to bench this (with the maximum number of VBO binds) against using a single VBO. Lots of VBO binding really hurts perf. To avoid, use one VBO (or avoid buffer binds when at all possible), or use NV bindless (or display lists).

Robbie
12-08-2011, 07:48 AM
I decided based on your suggestions and further reading to avoid the multiple VBO approach, and decided to optimize my VBO recreation code. For example, I've separated the code that plots the vertices, indices, colors for the walls, and am only recreating the indices for the pathing when necessary. Problem I'm having now is that I'm unable to use the resize method of the vector class without throwing an error.

I have two structs in my header file, one for Vertex(x, y, z) and one for Color(r, g, b). Those are what I'm adding to the vertex vector array and the color vector array.



m_vertices.push_back(Vertex(1.0f, 2.0f, -1.0f));
m_colors.push_back(Color(1.0f, 1.0f, 1.0f));


I'm using:


m_vertices.resize(wallVertexCount);
m_colors.resize(wallVertexCount);

to dump all the vertex data for the paths, leaving only the vertex data for the walls in the arrays. But this throws a error C2512: 'Vertex:Vertex' : no appropriate default constructor available.

my structs look like this:


struct Vertex {
float x, y, z;
Vertex(float x, float y, float z)
{
this->x = x;
this->y = y;
this->z = z;
}
};
struct Color {
float r, g, b;
Vertex(float r, float g, float b)
{
this->r = r;
this->g = g;
this->b = b;
}
};


Do I need to modify my structs to allow the resize method to work?

tksuoran
12-08-2011, 08:03 AM
error C2512: 'Vertex:Vertex' : no appropriate default constructor available. Add default values to your constructors
Vertex(float x = 0.0f, float y = 0.0f, float z = 0.0f)

Robbie
12-08-2011, 09:20 AM
Ahh. Thanks!

I worked around it by modifying my code to modify the vertices instead of dump them and replot them. It's working quite well actually.