Skip to main content
GameDev.net gamedev.net
🔒 Locked

VBO's

Started by Kincaid Jan 5, 2009 at 12:12 PM 15 replies 1.8k views
Original Post
Kincaid
Kincaid
im about to start implementing VBO's to speed up my redering (they're the fastest way right ?) but im not clear about the following with vbo's (and also vertex arrays), when drawing 2 triangles that share two points, you will still always need 6 vertices in memory, eventhough there are only 4 unique ones ? right ? (and thus, in editing, you must maintain/have duplicate values) thanx
Bregma
Bregma
ARe you drawing separate triangles, a triangle strip, or a triangle fan?
Stephen M. Webb
Professional Free Software Developer
swiftcoder
swiftcoder
Quote:
Original post by Kincaid
with vbo's (and also vertex arrays), when drawing 2 triangles that share two points, you will still always need 6 vertices in memory, eventhough there are only 4 unique ones ? right ?
Nope, because when rendering from VBOs you will use 'indexed triangle lists', which allow you to refer to the same vertex multiple times. duplicate positions are only necessary if you need different normal vectors or texture coordinates for the different faces.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
CableGuy
CableGuy
A point can be shared between two triangles if all of it's attributes are the same like position, texture coordinates, etc... In general when you specify an index OpenGL will take vertexArray[index],texcoordArray[index]...

Hope this helps.

EDIT: ninja'd
Kincaid
Kincaid
whats the call for that ? glIndexPointer refers to colors, and is the only thing with index I find on msdn.
swiftcoder
swiftcoder
Quote:
Original post by Kincaid
whats the call for that ? glIndexPointer refers to colors, and is the only thing with index I find on msdn.
glDrawElements.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
Kincaid
Kincaid
perfect thanx very much
Kincaid
Kincaid
lets see if im getting it..
Is this the correct/fastest way ?

lets say i have 10000 vertices. I place them all in an array and pass that to glVertexPointer (once, at init).
then, at each frame i determine some subset ofvertices, lets say n, and create an int array of n long, with indexes to the vertices.
then i call DrawElements passing the index array to render the frame

it will only execute n times?

(edit: its dynamic data, positions in the vertex array may update per frame (or not))

[Edited by - Kincaid on January 6, 2009 5:20:59 AM]
Kincaid
Kincaid
anyone ?
BlackSeeds
BlackSeeds
with glDrawElements you can draw the whole thing or a portion of the buffer

for instance:

int indexCount;
glDrawElements(GL_TRIANGLE_STRIP, indexCount, GL_UNSIGNED_INT, 0);

will draw the whole array.

where:
glDrawElements(GL_TRIANGLE_STRIP, 50, GL_UNSIGNED_INT, 0);

will draw the first 50 elements.


the above is assuming you have an index buffer created and bound.
Kincaid
Kincaid
will rendering only part of the buffer be fast?
é.g. having a buffer with 1000000 vertices, and drawing only 5 is extremely fast, or does the buffersize impact the performance of the partrendering ?
BlackSeeds
BlackSeeds
its more efficient to render it all in one go.

however some instances make this not possible.

for my level editor I use color picking, my terrain is store in a VBO with index buffer as well. when i want to find out which terrain polygon I am selecting, each polygon needs to be a different colour. and because the vertices are shared this causes colours to be interpolated across the polygon so what I do is

glColor3f(the colour id of the current tile)
glDrawElements(GL_QUADS,4,GL_UNSIGNED_INT,currentIndex);

where current index is the current tile of terrain I want to render;

this is way slower than my main terrain render which goes.

glDrawElements(GL_TRIANGLE_STRIP,vertexCount,GL_UNSIGNED_INT,0);

but because its for an editor the performance is still good to work with, but rendering the whole thing is much quicker which I do when not editing the terrain and other things.

EDIT
forgot to mention, yeah just drawing 5 elements is fine....however drawing the whole buffer in smaller elements is what makes it slow. obviosly drawing just 5 elements of 10000 will be quicker than drawing the whole thing, because your literally drawing less polygons
Kincaid
Kincaid
naturally i get that only drawing 5 is cheap(er). but is it (exactly) equaly fast when drawing 5 elements from a buffer containing 10 vertics, as it is when drawing 5 elements from a buffer with 100000 vertices.

V-man
V-man
It depends on the pre TnL cache size. If the 5 vertices are far appart or close together. There is no way to know the cache size unless you do a test. It could be large like 4KB or even 64KB. It also depends on where your performance problem is. Is it at the vertex stage? Is it later on in the fragment stage?
Kincaid
Kincaid
TnL ??

at this point im trying to get speed at vertex level (simply rendering as much
vertices as possible, as fast possible).

I have a scnene/world with (maybe) 100000 vertices, and at each frame i determine the visible subset, and render only that (a very small percentage of the whole, like 3% or something).

So i was thinking to replace all my vertices with vertex pointers that requests it's value addresses from a buffer.

something like;
at init; create new buffer [10000 vertices]
for each new triangle inserted by user;
- create a new vector, with its values referenced to the buffer.
(resize buffer on overflows, and reassign adreesses)

for every frame, always have that buffer bound, and only determine the indices to render.

but i gather (?) that thats not the way, since it is likely that vertices to be rendered ar arbitrarily spread around in the buffer, which results in slower rendering than tightly packing the thing.

i.o.w. glDrawElements with indices doesn't have constant access time on all indices, regardless of buffersize ?




thanx very much
V-man
V-man
You can read about TnL cache, GPUs, etc on the web
example:
http://www.opentk.com/doc/chapter/3/vertex_cache_optimizations

No, buffersize probably has no effect since there are no topics on it.
Kincaid
Kincaid
thanx!, ill be reading that cache stuff carefully
and try to get the buffer thing to work then.

any more tips on getting (even) more speed are always welcome, but i guess i can now finally conclude that this would be the fastest way (with optionally the cache optimizations)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.