So i need some advices how people are usually organizing their data, here is what i thought:
Let say there might be 100 enemy ships (tops) shown on screen, and each of those can fire at least 2 rockets/bullets with relatively fast fire rate, then i have asteroids, particle effects, fonts...and what not.
So i thought to avoid lots of draw calls i would make one dynamic vertex buffer for all that stuff and play with initial/maximum vertex count until satisfied.
Also i would pack textures into atlases, as much as possible to further reduce DC.
Then i would have something like this:
struct Drawer
{
VertexBuffer VBuffer;
IndexBuffer IBuffer;
int maxVertCnt;
vector< vertex > vVerts; // all verts in scene
void addVertex( vertex v ) { vVerts.push_back(v); }
void drawAll()
{
setVB( vBuffer );
setIB( IBuffer );
vertex* pV;
VBuffer->lock(&pV);
for(i = 0; i < vVerts.size(); ++i)
{
...// set pV
if( i > maxVertCnt )
{
// unlock -> draw -> lock
}
}
VBuffer->unlock();
...
vVerts.clear(); // clear to be ready for next frame
}
};
struct Sprite
{
vec2 pos;
vec2 dim;
...
vector< vertex > vVerts; // could be array of 4 verts
void update( dt )
{
// here i rotate vertices, move/animate texcoords...
...
// then add to drawer
for(i = 0; i < vVerts.size(); ++i)
drawer->addVertex( vVerts[i] );
}
};
Then i have simple vertex/pixel shader, just passing texcoords and colors... i update vertices on the cpu because there are various animation types (loop, once, ping-pong, different texture frames matrix sizes, based on input...).I hope you understand what i meant because sometimes i cannot explain myself well with words.
Thank you for your time.
EDIT:
Actually i need to have some object in between sprite and drawer based on texture used:
struct Drawer
{
VertexBuffer VBuffer;
IndexBuffer IBuffer;
int maxVertCnt;
void drawBatch(const FooBar& foo)
{
setVB( vBuffer );
setIB( IBuffer );
vertex* pV;
VBuffer->lock(&pV);
for(i = 0; i < foo.vVerts.size(); ++i)
{
...// set pV
if( i > maxVertCnt )
{
// unlock -> draw -> lock
}
}
VBuffer->unlock();
...
}
};
struct FooBar // how to call you?
{
Texture texture;
vector< vertex > vVerts;
void addVertex( vertex v ) { vVerts.push_back(v); }
};
struct Sprite
{
vec2 pos;
vec2 dim;
FooBar* foo;
...
vector< vertex > vVerts; // could be array of 4 verts
void update( dt )
{
// here i rotate vertices, move/animate texcoords...
...
// then add to foobar
for(i = 0; i < vVerts.size(); ++i)
foo->addVertex( vVerts[i] );
}
};
stuct SceneManager
{
vector< FooBar > foos;
void drawAll()
{
setShader(...);
for(i = 0; i < foos.size(); ++i)
{
setTexture( foos[i].texture );
drawer->drawBatch( foos[i] );
}
}
};