Welcome, Unregistered.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Reply
Old 22-Jun-2009, 00:31   #1
nobond
Junior Member
 
Join Date: May 2006
Posts: 97
Default opengl vbo basic question

I am trying to draw a cube with the VBO. Normally i can have 8 vertices and then using the index buffer, finally gldrawelement to do the final draw. The question is
if I am trying to using a face normal here. It seemed that I can not have an easy way to use the same index buffer to index the vertex array and the face normal?!

The only way i come up with is to duplicate the vertex from 8 to 36(12 triangles), so i repeat the vertex and normal where necessary. Is it sound silly or is therea better way to do this? The same idea apply to the texture as well. I think it is hard to use the same index buffer indexing both the pos array and tex co-ordiante array?
nobond is offline   Reply With Quote
Old 22-Jun-2009, 01:51   #2
rpg.314
Senior Member
 
Join Date: Jul 2008
Location: /
Posts: 4,070
Send a message via Skype™ to rpg.314
Default

I don't get it when you say "same index buffer".

With vbo's, vertex coordinates, texture coordinates, and normals come together and form a packet. (ie, you can put them in a struct for simplicity). Now when you use an index buffer, the entire packet (or struct if you prefer) will be sent to the gpu. I don't think that there is any way to use buffer a for vertices and buffer b for normals.
__________________
The views presented here are my own and not my employer's.
Quote:
Originally Posted by Alexko View Post
So in a nutshell, model [BLANK] will have [BLANK], up to [BLANK], and even [BLANK] for a power consumption of just [BLANK]. Impressive.
rpg.314 is offline   Reply With Quote
Old 22-Jun-2009, 10:41   #3
nobond
Junior Member
 
Join Date: May 2006
Posts: 97
Default

For instance for a cube, you will have to use 36 vertices rather than 8 vertices? I mean only 8 of them have unique position info. But they have different texture/normal. So I have to put them into different "vertices" anyway?





Quote:
Originally Posted by rpg.314 View Post
I don't get it when you say "same index buffer".

With vbo's, vertex coordinates, texture coordinates, and normals come together and form a packet. (ie, you can put them in a struct for simplicity). Now when you use an index buffer, the entire packet (or struct if you prefer) will be sent to the gpu. I don't think that there is any way to use buffer a for vertices and buffer b for normals.
nobond is offline   Reply With Quote
Old 22-Jun-2009, 10:44   #4
ProsperLOADED
Junior Member
 
Join Date: Jan 2008
Posts: 13
Default

Quote:
Originally Posted by nobond View Post
The only way i come up with is to duplicate the vertex from 8 to 36(12 triangles), so i repeat the vertex and normal where necessary. Is it sound silly or is therea better way to do this? The same idea apply to the texture as well. I think it is hard to use the same index buffer indexing both the pos array and tex co-ordiante array?
AFAIK, this is how it must be done, you have to duplicate vertices if the same position must be used with different normals and/or texture coordinates. But notice that the cube is an extreme case : in most models, you don't have that many vertices to duplicate.
ProsperLOADED is offline   Reply With Quote
Old 22-Jun-2009, 10:48   #5
nobond
Junior Member
 
Join Date: May 2006
Posts: 97
Default

Great, that clear my mind. thanks
nobond is offline   Reply With Quote
Old 22-Jun-2009, 13:02   #6
Novum
Member
 
Join Date: Jun 2006
Location: Germany
Posts: 284
Default

Interestingly the Wii and Gamecube GPUs can actually use different indices for different data
Novum is offline   Reply With Quote
Old 22-Jun-2009, 14:07   #7
nobond
Junior Member
 
Join Date: May 2006
Posts: 97
Default

that is purely a driver thing. I think . HW even does not need to know it.
Quote:

Interestingly the Wii and Gamecube GPUs can actually use different indices for different data
nobond is offline   Reply With Quote
Old 22-Jun-2009, 21:27   #8
Humus
Crazy coder
 
Join Date: Feb 2002
Location: Stockholm, Sweden
Posts: 3,216
Send a message via ICQ to Humus Send a message via MSN to Humus
Default

Quote:
Originally Posted by nobond View Post
The only way i come up with is to duplicate the vertex from 8 to 36(12 triangles), so i repeat the vertex and normal where necessary. Is it sound silly or is therea better way to do this?
Actually you only need 24 vertices. 4 per quad, 6 quads. You need 6x6=36 indices though, or if you use a triangle strip I think you can get it down 18 with the help of a couple of degenerate triangles.

Anyhow, while in this particular case you could've saved some by using multiple index buffers (if it was supported in hardware) normally that's not the case. Usually you lose more on the index storage than you gain in tighter vertex storage if you use multiple index buffers. Not to mention that it makes the hardware implementation much harder, in particular the posttransform cache since you'd now have to match a list of indices (variable size too!) to the cached result.
__________________
[ Visit my site ]
I speak for myself and only myself.
Humus is offline   Reply With Quote
Old 22-Jun-2009, 23:16   #9
nobond
Junior Member
 
Join Date: May 2006
Posts: 97
Default

Yup. Triangle Strip Looks like a sensible thing since quad is not supported in ogl-es as well .


Quote:
Originally Posted by Humus View Post
Actually you only need 24 vertices. 4 per quad, 6 quads. You need 6x6=36 indices though, or if you use a triangle strip I think you can get it down 18 with the help of a couple of degenerate triangles.

Anyhow, while in this particular case you could've saved some by using multiple index buffers (if it was supported in hardware) normally that's not the case. Usually you lose more on the index storage than you gain in tighter vertex storage if you use multiple index buffers. Not to mention that it makes the hardware implementation much harder, in particular the posttransform cache since you'd now have to match a list of indices (variable size too!) to the cached result.
nobond is offline   Reply With Quote
Old 23-Jun-2009, 00:55   #10
Novum
Member
 
Join Date: Jun 2006
Location: Germany
Posts: 284
Default

Quote:
Originally Posted by nobond View Post
that is purely a driver thing. I think . HW even does not need to know it.
Yes it does.
Novum is offline   Reply With Quote
Old 09-Jul-2009, 16:13   #11
onesvenus
Junior Member
 
Join Date: Oct 2004
Posts: 25
Default

I was looking to post a new thread but I think that this would be a perfect place to ask as it's realted to the OP.

I'm using a texture atlas to texture my model. As you surely know I need a different u/v set of coordinates for every vertex/face pair. I want to use an index buffer to try to lower the number of vertices sent to the GPU but I don't know how to do this.

Does anybody know if I can create two index buffers, one for the faces, and the other one for the texture coordinates?
onesvenus is offline   Reply With Quote
Old 09-Jul-2009, 22:01   #12
Humus
Crazy coder
 
Join Date: Feb 2002
Location: Stockholm, Sweden
Posts: 3,216
Send a message via ICQ to Humus Send a message via MSN to Humus
Default

Not possible. The only thing close to it would be to create a vertex buffer containing the indices, then fetch the attributes manually in the vertex shader using the indices.
__________________
[ Visit my site ]
I speak for myself and only myself.
Humus is offline   Reply With Quote
Old 10-Jul-2009, 10:32   #13
onesvenus
Junior Member
 
Join Date: Oct 2004
Posts: 25
Default

Quote:
Originally Posted by Humus View Post
Not possible. The only thing close to it would be to create a vertex buffer containing the indices, then fetch the attributes manually in the vertex shader using the indices.
And how would I do that? I have never done something like this on the vertex shader.
Now that you say that's not possible I'll look into alternatives.
The problem is that I have some very large models with lots of textures (I'm talking about ~2M tris with ~100MB of DXT1 compressed textures each). There is no way I could simplify more this models and I need to have them loaded on the GPU because I need to be able to change between them as fast as possible (without loading in between). So on startup time I load every model (using VBO) and the compressed textures and paint the first model. The problem is that when I want to change to another one the GPU waits blocked on the glDrawRange... call. I suppose that happens because as all the models doesn't fit on the VRAM it must transfer them from RAM to VRAM when needed. If you have any idea of how overcome this problem, I'd be very grateful.
I'm working on a GTX280 GPU.
onesvenus is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 00:53.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.