nullPointer

01-31-2013, 03:38 PM

Hi,

I'm just trying with VBO and I've already did some basics with drawing points but now I want to draw triangles and I'm in a corner. Here's the problem. In most tutorials I see that vertex is defined something like this:

struct vertex

{

vec3 pos;

vec3 normal;

vec2 uv;

//plus more (?)

};

struct triangle

{

unsigned int indices[3];

};

Then you have triangles with indices to these vertices and all is well. Eg.

mesh class:

vertex * vertices;

triangle * triangles;

//or STL vectors of these

But in my engine I have data layout like this:

vertex

{

vec3 position

}

triangle

{

unsigned int vertexIndices[3];

unsigned int normalIndices[3];

unsigned int uvIndices[3];

}

The problem is when I create IBO it doesn't provide stride (if I'm correct) and in general I think it won't work with my data layout. You may ask - why did I wrote it this way? Well at first it seemed more "natural" to treat vertex only as a point in 3d space. Also it made more sense when I was writing OBJ loader, where data for a triangle/face is stored like this f 1/1/1 2/2/2 3/3/3 (so basically collect all vertices, then normals, then uvs, then triangles with indices to these guys). In addtition it worked well with immediate mode (I know, right...) and display lists (they are alright, but I'm writing vertex skinning so VBO look more "applicable" and also I want to do it the right way). The question is - can I somehow get away with this design and force OGL to use this data layout or I have to redesign it from the very bottom?

I'm just trying with VBO and I've already did some basics with drawing points but now I want to draw triangles and I'm in a corner. Here's the problem. In most tutorials I see that vertex is defined something like this:

struct vertex

{

vec3 pos;

vec3 normal;

vec2 uv;

//plus more (?)

};

struct triangle

{

unsigned int indices[3];

};

Then you have triangles with indices to these vertices and all is well. Eg.

mesh class:

vertex * vertices;

triangle * triangles;

//or STL vectors of these

But in my engine I have data layout like this:

vertex

{

vec3 position

}

triangle

{

unsigned int vertexIndices[3];

unsigned int normalIndices[3];

unsigned int uvIndices[3];

}

The problem is when I create IBO it doesn't provide stride (if I'm correct) and in general I think it won't work with my data layout. You may ask - why did I wrote it this way? Well at first it seemed more "natural" to treat vertex only as a point in 3d space. Also it made more sense when I was writing OBJ loader, where data for a triangle/face is stored like this f 1/1/1 2/2/2 3/3/3 (so basically collect all vertices, then normals, then uvs, then triangles with indices to these guys). In addtition it worked well with immediate mode (I know, right...) and display lists (they are alright, but I'm writing vertex skinning so VBO look more "applicable" and also I want to do it the right way). The question is - can I somehow get away with this design and force OGL to use this data layout or I have to redesign it from the very bottom?