Hi,
First of all I am feeling like this is a question I should have been able to find the answer to either here on the forums or elsewhere by now. However I don't know if I'm just slow in my brain, bad at searching or what's going on, so anyone which have seen this question tons of times before: So sorry to ask it again.
So here's the deal. I am implementing some rendering code, nothing fancy really I'm not all that good at rendering but have some experience gained on what I guess would be called hobby-level. What I am doing right now is trying to find out the best practices around VBO (Vertex Buffer Objects) and if that even still is a good way to go for rendering.
The background is that I am writing a small script for blender to fetch the data I need (why not use an already written exporter? Well there are a couple of reasons, a few being: I want to do it because I find it fun, it helps me understand a bit better how blender work with the data, I can get exactly the data I need and nothing else organized in a way I find easy to parse...)
I am then trying to take this data and run in an openGL application.
So far all is kind of good, but I am thinking that I'm missing something, or rather I know that there are something I don't fully understand.
the way I represent data would be something like this (I am not sure about the exact implementation and this will serve only as an example)
typedef struct {
float position[3];
float uv[2];
} vertex;
GLushort *indices;
EXAMPLE:
Take a cube for example:
If I unwrap this cube (I could do it in many ways but I've chosen to try to keep it simple)
From the unwrap (I hope I got it right, but it should at least be useful to prove my point), we see that different UV-coordinates are assigned for the same vertex in different faces. This is nothing strange and I do understand why it's like this but I wanted to keep this in here for reference.
The code-example would mean that each vertex has one uv-coordinate which would make perfect sense to me if I were using a flat model with any shared vertex also sharing the texture coordinate.
So there is a contradiction in this, i.e. when I use VBO every index point at one vertex, and one vertex has one position (coordinate) and one texture coordinate, while the unwrap show that this really is rarely the case, there are vertices (v1, v2, v3 and v4 to be specific) which in fact do share the same uv-coordinate so my top face is good and will render my texture correct. And depending on how I choose the uv-coordinates for the other faces I can get one (or maybe a couple of them, not all that interesting) correct as well, but for the other faces (i.e. v5, v6, v7, v8) the uv-coordinate is different depending on which face is using them.
So finally on to the question:
What is the best practice here, as I see it there are a couple of options (might well be options I didn't even think of)?
1) write one vertex per vertex in every face, or duplicate vertices. However this would mean a great overhead since many of those duplicated vertices actually do share texture coordinates as well.
2) take it a bit further and duplicate only the vertices which doesn't share uv-coordinate. This feel like it might be it? I mean if there aren't a way to let the indexing look it up in some other way which tend to become quite messy and complicated really quick when I think about it.
3) some other way, like separating out the uv-buffer from the vertices, and run a second index pointer on them. This feel a bit messy and if I am doing this there are other rendering techniques which could do the job in a simpler way with about the same performance (I believe but it's just a guess).
So again what is the best practice, is it common to duplicate the vertices which doesn't share the UV-data?
Thanks for taking the time to read this.