tags:

views:

201

answers:

2

I've read that to optimize drawing, one can draw a set of figures using the same texture in one pass.
But how do i connect my singles square together to form one figure to send to glVertexPointer.

(read in PowerVR MBX.3D Application Development Recommendations.1.0.67a - page 5)

A: 

Looks like you want to use indices? See glDrawElements.

Marcus Lindblom
+1  A: 

I take it you are pondering the "software transform" step. I assume you have some kind of vertex array for ONE square and would like to concatenate several different of instances of that array into one big array containing all the vertexes for your squares, and then finally draw the big array.

The big array in this case would then contain pre-transformed vertex data that is then sent to the GPU in one draw call. Since you know how many squares you are going to draw, say N of them. That array must be able to contain N*4*3 elements (assuming you are working in 3d and therefore have 3 coordinates per vertex).

The software transform step would then iterate over all the squares and append the transformed data into the big array, which in turn can be drawn by a call to glVertexPointer().

However, I'm a bit sceptical to this software transform step. This means you are going to take care of all these transformations on your own, which means you are not using the power of the GPU. That is you will use CPU power and not GPU power to get your transformed coordinates. Personally I'd start off by creating the texture atlas and then generate all the texture coordinates for each single square. This is only needed once, since the texture coordinates will not change. You can then use the texture coordinates by a call to glTextureCoordPointer() before you start drawing your squares (push matrix i, draw quad, pop matrix etc)

Edit:

yes this is what i want. Are you sure it's slower on the cpu ? from what they say the overhead of calling multiple times glVertexPointer and glDrawArrays would be slower.

I'm taking back my scepticism ! :) Why don't you do some measures, just for the heck of it? The trade off must at least be that you must be shuffling a whole lot more data. So if the GPU can't hold all that data, normal transformations might be a neccesity.

Oh, there's one more thing. As soon as a butterfly moves, its data has to be manually retransformed, this is not needed when you let the GPU transform the data for you. So you must flag some state for each instance when it's dirty and you need to retransform before doing the draw call.

Magnus Skog
yes this is what i want. Are you sure it's slower on the cpu ? from what they say the overhead of calling multiple times glVertexPointer and glDrawArrays would be slower.
CiNN
Any progress? :)
Magnus Skog
didn't have time to work on it yet.
CiNN