Hello,
I will try to explain what I have discovered so far.
First the root "problems" :
First :
Every call to your graphic card driver has a "cost", in number of cycle, the more cycle the worst.
Here is the average diff. api call cost :
http://www.gamedev.net/community/forums/topic.asp?topic_id=260153The aim here is to limit the number of calls in one single frame.
Second :
Our actual graphic cards are really powerful, if we don't give them enough work to do at once, its a waste of power : The GPU will be most of the time in Idle state waiting for data to process. We can call this problem "CPU or driver bound".
Let's take a quick and easy exemple :
We have 1 object composed of 2 squares (Quad1 and Quad2), each square has his own texture.
We want to render 500 times this object.
The "wrong" way :
Foreach (object in objectcollection)
{
Device.SetStreamSource = object.Quad1.VertexBuffer
Device.SetTexture = object.Quad1.Texture
Draw call
Device.SetStreamSource = object.Quad2.VertexBuffer
Device.SetTexture = object.Quad2.Texture
Draw call
}
Result for 500 objects : 1000 SetStreamSource, 1000 SetTexture, 1000 Draw call !
Now an exemple of static batching (static because, its good for objects that are not subject to move and state changes in the world space, like a terrain) :
At initialisation step :
Array MyQuadBufferObject
VertexBuffer myBigVertexBuffer
Foreach (object in objectcollection)
{
MyQuadBufferObject.add(object.myQuad1);
MyQuadBufferObject.add(object.myQuad2);
}
MyQuadBufferObject.sort by QuadType;
Send all objects into myBigVertexBuffer;
Processing step :
Device.SetStreamSource = myBigVertexBuffer.VertexBuffer
Foreach (object in MyQuadBufferObject)
{
if (object is the same type as the previous one)
{
Count the number of objects;
}
else
{
Device.SetTexture = Previousobject.Texture
Draw call (With offseting in the myBigVertexBuffer)
}
}
In this case, we should only have 1 SetStreamSource, 2 SetTextures and 2 Draw call. For the same result !!
For the moment I have put in place 2 type of batching :
Static one (Objects that are not moving or changing a lot)
Dynamic one (for object that are moving a lot)
It's a very interesting subject, and I think you should think of it before going too far with the engine (Could make you view of the structure of your engine change with the batching implementation).
I you want I can forward you my current project (not a lot done, but the base for static and dynamic buffer are in it, with your Hazy mind engine as base root).
ps : Sorry for my poor english

See you !