Sign in to follow this  
caywen

OpenGL glDrawElements and vertex transformation

Recommended Posts

Hi all, I'm writing a new terrain engine for my game, and I have a question that will determine how I structure things. Let's say I have a vertex buffer of 1000 vertices. Let's say I am calling glDrawElements using indexed triangles into that vertex buffer. If I call glDrawElements 10 times, each time referencing a different set of 100 different vertices inside the vertex buffer, will the entire 1000 vertices be transformed 10 different times? How does OpenGL, or the hardware, handle transformation of vertices in this case? Any information would be much appreciated! Thanks, Kevin

Share this post


Link to post
Share on other sites
Oops! I meant to say glDrawElements instead of glDrawPrimitive.

Just to be clearer, let's say I'm doing something like this:

float vertexdata[1000 * 3]; // 1000 x, y, z coordinates
...
glVertexPointer(3, GL_FLOAT, 0, vertexdata);

for(int i = 0; i < 10; i++)
{
unsigned short indices[100 * 3];
...
glDrawElements(GL_TRIANGLES, 100, GL_UNSIGNED_SHORT, indices);
}



Will this cause 1000 vertex transformations or 10000 transformations?

Share this post


Link to post
Share on other sites
Quote:
Original post by bubu LV
Only those vertices that are used by glDrawPrimitive call will be transformed.


I see, that helps a lot. Thanks bubu. I do have a followup question, too:

If I then call glDrawElements 10 times, but all using the same vertex indices, then the same vertices will be transformed an extra 9 times, right? That is, if the hardware doesn't have some kind of caching mechanism in place?

Share this post


Link to post
Share on other sites
if your not using shaders then each vertex that is sent will be transformed everytime, send the same vertex twice it will be transformed twice. Ionly mention shaders sicne you could have a shader that doens't do any transformation.

Share this post


Link to post
Share on other sites
Quote:
Original post by caywen
If I then call glDrawElements 10 times, but all using the same vertex indices, then the same vertices will be transformed an extra 9 times, right? That is, if the hardware doesn't have some kind of caching mechanism in place?
There is a vertex cache, but I have doubts that it offers much good across multiple draw calls.

It isn't really clear to me why you would need to render the same set of vertex data 10 times in a row - at least not without changing the transformation matrices or other states in-between. Can you give an example of why you need to do this?

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Quote:
Original post by caywen
If I then call glDrawElements 10 times, but all using the same vertex indices, then the same vertices will be transformed an extra 9 times, right? That is, if the hardware doesn't have some kind of caching mechanism in place?
There is a vertex cache, but I have doubts that it offers much good across multiple draw calls.

It isn't really clear to me why you would need to render the same set of vertex data 10 times in a row - at least not without changing the transformation matrices or other states in-between. Can you give an example of why you need to do this?


Well, if I was limited in texture units, and I needed to issue multiple calls to render multiple passes, I would do such a thing, right?

Actually, in my case, I'm creating a splat-based terrain system, and my idea was to upload the terrain vertex data once, and then multiple splats that have indices into the terrain vertices. Because the splats can be semi-transparent, many of them overlap in their geometry significantly.

At least, that's my current thinking, and I'm open to any better suggestions on terrain rendering. However, as this is an iPhone app, I'm a bit constrained on hardware.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nanoha
if your not using shaders then each vertex that is sent will be transformed everytime, send the same vertex twice it will be transformed twice. Ionly mention shaders sicne you could have a shader that doens't do any transformation.


Thanks a lot for the reply. Since this has to work on 1st gen iPhone (I think 3G's PVR SGX has shaders?) I think I have to rely on more old school techniques.

Share this post


Link to post
Share on other sites
hmm depending on how many passes you do, it might be faster to make a copy of your vertices and rpe multiply everything but I think this would only work if you have shaders availible (so you could remove the normal transformations from taking place). Mind then your shifting the load off the gpu to the cpu, no idea how iphones work, wheather they have a seperate cpu/gpu or whether its all cpu and software.

if its cpu (software rendering), you can use shaders and your redrawing vertices each pass significantly then pre multiplying might be an option, otherwise I think you'll just have to stick to what your doing currently.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nanoha
if its cpu (software rendering), you can use shaders and your redrawing vertices each pass significantly then pre multiplying might be an option, otherwise I think you'll just have to stick to what your doing currently.


iPhones have GL ES 1.1 so there are no shaders. The next iPhone will have GL ES 2.0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this