Jump to content
  • Advertisement
Sign in to follow this  
avocados

vertex buffer array being overwritten

This topic is 2886 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


//init
glGenBuffers(1, VAB_name);
glBindBuffer(GL_ARRAY_BUFFER, *VAB_name);
glBufferData(GL_ARRAY_BUFFER, length_bytes, VAB_data, GL_STATIC_DRAW);

glNormalPointer( GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(0+0)));
glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(0+3)));
glVertexPointer( 3, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(0+5)));

glGenBuffers(1, VAB_name2);
glBindBuffer(GL_ARRAY_BUFFER, *VAB_name2);
glBufferData(GL_ARRAY_BUFFER, length_bytes2, VAB_data2, GL_STATIC_DRAW);

glNormalPointer( GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(0+0)));
glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(0+3)));
glVertexPointer( 3, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(0+5)));

//draw
glBindBuffer(GL_ARRAY_BUFFER, *VAB_name);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *VAB_indices_name);
glDrawElements(GL_TRIANGLE_STRIP, VAB_count, GL_UNSIGNED_INT, BUFFER_OFFSET(0));

I don't understand why that second glBufferData is overwriting the first one. Shouldn't each array buffer have their own location in memory on the GPU?

*EDIT: put gl*Pointer functions back in

ps source lang tag isn't working how i remember and the FAQ seems to be absent

Share this post


Link to post
Share on other sites
Advertisement
I'm sure it's not overwriting the first buffer, you probably just misunderstand how to use the glPointer* operations (they are global, and not per buffer). Changing the bound buffer before drawing is not how you're supposed to set the source data for glDrawElements.

Post the rest of your ... and I can correct you.

Also it's called 'code' tag now, not 'source' tag anymore.

Share this post


Link to post
Share on other sites
This is so confusing. I added the gl*Pointer functions in the draw code just before glDrawElements and now it works as expected. The first and second set of gl*Pointers can contain meaningless random offsets but the objects are not drawn if I remove them.

Why do I need to specify gl*pointers every frame if they are not changing? It seems that binding an array buffer wipes them out.

Share this post


Link to post
Share on other sites

This is so confusing. I added the gl*Pointer functions in the draw code just before glDrawElements and now it works as expected. The first and second set of gl*Pointers can contain meaningless random offsets but the objects are not drawn if I remove them.

Why do I need to specify gl*pointers every frame if they are not changing? It seems that binding an array buffer wipes them out.



You don't have 'sets' of pointers. There is only one glVertexPointer, and it is global. You don't get a separate glVertexPointer per vbo. So if you want to draw something out of VBO #1, you:

1) bind vbo #1
2) set the pointers
3) glDrawElements

If you want to draw both buffers:

1) bind vbo #1
2) set pointers
3) glDrawElements
4) bind vbo #2
5) set pointers
6) glDrawElements.

You have to set it each time you want to change to a new buffer if you're not using VAO.

I'm not sure what you mean about "random offsets", but if you are confused post your latest code snippet and I can look.

Share this post


Link to post
Share on other sites

//init
glGenBuffers(1, VAB_name);
glBindBuffer(GL_ARRAY_BUFFER, *VAB_name);
glBufferData(GL_ARRAY_BUFFER, length_bytes, VAB_data, GL_STATIC_DRAW);

//draw doesn't work without these gl*Pointers but these offsets don't point to anything
glNormalPointer( GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(77777)));
glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(88888)));
glVertexPointer( 3, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(99999)));

glGenBuffers(1, VAB_name2);
glBindBuffer(GL_ARRAY_BUFFER, *VAB_name2);
glBufferData(GL_ARRAY_BUFFER, length_bytes2, VAB_data2, GL_STATIC_DRAW);

//draw doesn't work without these gl*Pointers but these offsets don't point to anything
glNormalPointer( GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(77777)));
glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(88888)));
glVertexPointer( 3, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(99999)));

//draw
//gl*pointers must be defined every frame even though the values are always the same
glNormalPointer( GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(0)));
glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(3)));
glVertexPointer( 3, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*(5)));
glBindBuffer(GL_ARRAY_BUFFER, *VAB_name);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *VAB_indices_name);
glDrawElements(GL_TRIANGLE_STRIP, VAB_count, GL_UNSIGNED_INT, BUFFER_OFFSET(0));

Share this post


Link to post
Share on other sites

How did you define VAB_name, VAB_name2, VAB_indices_name? Can you post the code for that?


GLuint **name or GLuint name[]

Share this post


Link to post
Share on other sites
What you've posted doesn't make any sense, I think you are incorrect. You're obviously not showing us what you're really doing, because your glGenBuffers is in the same flow as your draw command. Also you do not have to define gl*pointers every frame unless you are resetting them elsewhere.

Explain what you're actually trying to do (which buffer are you trying to render from?), and post real code, and I can help you understand, but right now you're making claims that don't make sense.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!