• Advertisement
Sign in to follow this  

VBO advice

This topic is 4676 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

Hiya, im concerned that ive already asked a question regarding VBO's but i promise this is my last one :) basically I can read in data into my VBOs and display this information, no probs, this took me a long time to figure out, so bear with me please if the below question is dumb... anyway - I would like to modify the VBOs and replace some of the indices stored within, however ive tried finding documentation and much of it goes straight over my head - basically im trying to get the pointer to the buffer i suppose? unless there is a better way... so i call(?) the extension - glGetBufferPointervARB = (PFNGLGETBUFFERPOINTERVARBPROC)wglGetProcAddress("glGetBufferPointervARB"); and ive already mapped the buffer, and then I try and use either - GetBufferSubDataARB or glGetBufferPointervARB but this is where I come unstuck, ive tried a variety of combinations, but cant seen to read my values back, let alone write new ones in.... im using C but i can usually understand pretty much an language to the point of being able to work with it and convert it to C (no brainf*ck...) any clues?? cheers David (the village idiot)

Share this post


Link to post
Share on other sites
Advertisement
If you're wanting to replace some data in your vbo use glBufferSubData.

An example:

unsigned short indices[3] = { 1, 2, 3 }; // Our indices.
int offset = 5; // Place data starting at 5 bytes into the vbo.

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo); // Bind the buffer.
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, sizeof(indices), &indices[0]); // Write the data.




This should be pretty fast, and is preferrable to glMapBuffer, which can cause synchronization issues.

Now, reading data back from a vbo (assuming the driver didn't stick the data in system memory) is going to be pretty damn slow, so I would advise against doing such.

Share this post


Link to post
Share on other sites
Thanks :) you wouldnt believe how close I was to the solution you provided

I realise that its going to be slow reading back information but the reason I need to if because im not creating a game, but a piece of scientific software to create 3D renders which requires an iterative approach.

all the science stuff is done its just getting my opengl thing to work and i need to read back the values to adjust them, time isnt a great issue as this is only a piece of experimental software that is only going to be required for the next 8 weeks

cheers

David

EDIT: arhh so id just do something like this to read data?



unsigned short indices[3]
int offset = 5; // Place data starting at 5 bytes into the vbo.

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo); // Bind the buffer.
glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, sizeof(indices), indices);




Share this post


Link to post
Share on other sites
Quote:
Original post by binary_bandit
all the science stuff is done its just getting my opengl thing to work and i need to read back the values to adjust them, time isnt a great issue as this is only a piece of experimental software that is only going to be required for the next 8 weeks


In that case you should just keep a local copy of the data stored in memory, modify that, then update the vbo with that whenever it's changed. There's no point in reading it back from OpenGL unless you have very, very tight system ram limitations. If you do have tight ram limitations then you probably wouldn't be able to use the ram for the temporary arrays to create the vbo in the first place.

Share this post


Link to post
Share on other sites
Quote:

im concerned that ive already asked a question regarding VBO's but i promise this is my last one :)


What a silly promise to make. These forums are here so that you may ask questions. You make it sound as if it's a bad thing. As long as your questions are well thought out and googled/forum searched in advance (when applicable), ask 35 per day. Not only is this perfectly acceptable, but encouraged, because not only are you getting the help you need in that your question is answered, but future forum searchers (once the capability is restored) and every-day readers are also benefitting from the discussion.

And furthermore, how do you know this is the last question you have? You're working in a pretty complicated arena (computer graphics). Don't presume to think that this will be the last of your questions. It most likely won't be, and you shouldn't feel bad about asking others.

Your question was asked well, I wouldn't call it dumb at all. In fact I'm giving you a bit of a rating bump because it is one of the more thought out questions seen here. You stated what you are trying to do, where you are getting stuck, what you've already tried, what your code is using, and what you think a potential solution is. That's as good of a question as you're likely to see on any forum, and chances are someone will stumble across this thread one day and gleem some knowledge off of it.

So ask your questions. Do it frequently, but intelligently (like this one), and everyone wins!

Oh yeah and sorry for not really answering your question at all. I don't really know alot about VBOs beyond their simple applications. It looks like you're in good hands, though.

Good luck with your project!

Share this post


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

  • Advertisement