I've been working on coding a new 3D engine in Java. For the moment at least I'm sticking to openGL...
Currently I'm reworking how meshes get transformed and then drawn. ATM each mesh created has its own VBO and IBO along with its own draw method so if I wanted to draw multiple meshes it would look like this:
mesh1 = MeshLoader.loadMesh("cube.obj");
mesh2 = MeshLoader.loadMesh("pyramid.obj");
mesh1.addToBuffers(); //adds vertex and index data to vbo and ibo
mesh2.addToBuffers();
mesh1.draw();
mesh2.draw();
The draw method defined in class Mesh enables vertex attribute arrays, binds the bufffers, and then draws elements based on the ibo.
Then I send my projection matrix (transformation and perspective) as a uniform to the vertex shader.
QUESTION:
Games are made of many many meshes and each has to be identified so that transformation can be applied. I want to be able to apply transformations (translate, rotate, scale) directly to a given mesh, independent of the other meshes. In other words I want to move mesh1 and only mesh1 5 units to the right (on its own axis) without it affecting mesh2.
How do I do all this without making a million draw calls to the gpu?
Any advice appreciated.