Jump to content
  • Advertisement
Sign in to follow this  
pondwater

glBufferData and <vector>'s

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

I use three sepearte std::vector<Vector> containers (Vector is a class that represents a vector in 2, 3 or 4 space, seperate from the <vector> container class in c++) to store my model vertices, normals and texture coordinates.

Currently I convert them into a float** and then copy them into GPU memory using


glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*numVerts*3, vertices, GL_STATIC_DRAW);


I was curious, is there any way to send them straight from the container class vector? I could see the fact that they are stored in a class as a problem. What about a vector of float[3]'s?

Share this post


Link to post
Share on other sites
Advertisement
If your Vector is nothing more than a structure of two, three or four components, then you can just pass a pointer to the vector data directly.
[source]
struct Vector {
float x, y, z;
};

std::vector<Vector> myData;
[/source]
[source]
glBufferData(..., &myData[0], ...);
[/source]

Share this post


Link to post
Share on other sites
thats true, but is there anyway to pass then entire vector in a single call? I guess im asking if vectors store the memory in one continuous memory block...

Share this post


Link to post
Share on other sites
I guess im asking if vectors store the memory in one continuous memory block...

Yes, they do.

Share this post


Link to post
Share on other sites
Awesome, i guess the real magic all happens in the glVrtexAttribPointer(). Loaded my buffer objects nice and dandy once i set the proper stride and pointer!

Thanks for the help!

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!