[solved] [batching] How to transform drawing primitives

So I have a problem, In my eyes, doing this:

someBatch.begin();
someBatch.add(10, 10, 10, myMesh);
someBatch.end();

Is super super bad… I’d prefer if it was

someBatch.begin();
someBatch.add(myMesh);
someBatch.end();

And used a matrix inside the mesh to change it’s positions/texcoords like so:

public class MeshBatch ...

public void add(Mesh mesh){
       for(Vertex v : mesh.getVertices){
             v.position = v.position.mul(mesh.vertTransform);
             v.texUV    = v.texCoord.mul(mesh.texTransform);
       }
       //... Add values to buffer
}

...

Would doing the above operation be bad on the CPU? Is there another possible way (if so, please explain)?

Thanks in advance!

So… Does anyone have a solution?

So why is [icode]someBatch.add(10, 10, 10, myMesh);[/icode] “super bad?” What are do those parameters even mean?

Normally, you would have all the transform information contained in a Matrix which is called the model view matrix. In the vertex shader, you would multiply the vertex by the model view matrix. There is no harm in doing it on the cpu, but if the gpu is not doing anything, then why not use it?

The problem with batching is that you can’t really batch together meshes with different transforms because you have to modify the modelview matrix between draws, which is not batching. So if you want to do something like that then the best option really depends on what gives the best performance and is easiest to implement.

You can either compute the transforms cpu side as you have said. Or it might give better performance to give up on batching all together. Ultimately batching is a performance improvement and if your requirements mean that it isn’t increasing performance then what is the point.

The 10s are positions, I meant it would be easier to transform the mesh with a matrix.

The problem with batching is you can’t specify matrices for individual ‘meshes’. It puts all the vertex data into one buffer and uses it in a single draw call. Therefore any matrix transforms on the vertices would transform all the meshes in that draw call.

I did plan on drawing allot of meshes, and it would help if I did it in one draw call. Either way, its good to give the people the option to use batching if they want. So CPU-side it is :wink:

Thanks!