Skip to main content
GameDev.net gamedev.net
🔒 Locked

VBOs and std::vector

Started by Ainokea Feb 27, 2005 at 6:24 PM 6 replies 850+ views
Original Post
Ainokea
Ainokea
Previously I used to use pointers to contain things like vertex data instead of vectors, I would do something like this:

Vertex *verts;

//instead of something like this:
std::vector<Vertex> verts;

Then it would be easy to work with VBOs because I could do something like this:

glBufferDataARB(GL_ARRAY_BUFFER_ARB,numVerts*3*sizeof(float),verts,GL_STATIC_DRAW_ARB);


But if I where to store my vertex data inside of a vector I don't know what I would pass off to the function where I previously would have put verts.
______________With the flesh of a cow.
_the_phantom_
_the_phantom_
the std::vector is garrenteed (as per the last spec update) to have contigous memory allocation, so you pass the address of the first element as the source for the data (as &verts[0], might require some casting).

I've used it myself a few times now, works perfectly, you can even use the size function of the container to setup the data size properly [grin] (verts.size()*sizeof(Vertex) gives you the total memory size)
nts
nts
you need a pointer to the data, the following should work

void* ptr = &verts[0];   // or use verts.at(0)


gets a pointer to the first element and assuming everything is stored sequentially (AFAIK it is) then that should act exactly like the verts array you used before.

HTH
Ainokea
Ainokea
Thanks! Ratings++ to both of you, unless I did it already!
______________With the flesh of a cow.
Icy Earth
Icy Earth
dont forget &verts.front() i prefer that myself so i thought id throw it out there :-)

-Dan
Ainokea
Ainokea
Quote:
Original post by Icy Earth
dont forget &verts.front() i prefer that myself so i thought id throw it out there :-)

-Dan

I actually did that anyways, thanks anyways and ratings++ too!
______________With the flesh of a cow.
WilyCoder
WilyCoder
I've always wondered what a void pointer is....

Is it a pointer to an abstract piece of data?

When using them, should you also use a variable to conatin the stepping size?
Ademan555
Ademan555
a void pointer should be thought of like a pointer in assembly, what it points to is undefined, it has no type untill you cast it to give it a type, incrementing it moves it one machine unit (byte)

hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.