0
\$\begingroup\$

I have a data structure like this:

typedef struct vertex_ {
float x;
float y;
float z;
float s;
float t;
}vertex;

Then I add to a list called: boost::ptr_vector<vector> vertices;

Is there a way to use vertices to provide the parameters for glBufferData?

\$\endgroup\$
  • 2
    \$\begingroup\$ Are you a C programmer who's recently picked up C++? There's really no reason to use bloated syntax like typedef struct X_ { ... } X; in C++. struct X { ... }; works just fine. \$\endgroup\$ – bcrist Jul 24 '14 at 4:47
3
\$\begingroup\$

boost::ptr_vector is, underneath the hood, a std::vector<void *>.

Not only is it not possible to use the ptr_vector to directly supply an input to glBufferData (et cetera), but it is a phenomenally bad way to store vertex data in general because of the extremely poor cache locality of the data

If you were to use std::vector<vertex> vertices; instead, you could pass the address of the first element of the vector to functions like glBufferData easily.

\$\endgroup\$
  • \$\begingroup\$ Or in C++11 and onward, v.data(), which as a bonus yields a null pointer for empty vectors instead of undefined behaviour. \$\endgroup\$ – Lars Viklund Jul 24 '14 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.