I'm having troubles with poor performance with drawing of sprites.
I create a sprite sheet from each texture. (a vbo for each texture, which contains position and texcoords for each sprite inside the texture)
Code to draw a letter (from font):
GraphicsManager::GetInstance()->Draw("data\\gfx\\fonts\\ansi-thin.png", letter, iPos, iScale, iColor);
Code in graphics manager to draw a sprite
void GraphicsManager::Draw( string i_fileName, int i_index, Vector3D iPos, Vector2D iScale, ColorF iColor )
{
if (!_isInitialized)
return;
TextureManager::GetInstance()->BindTexture(i_fileName);
glColor4f(iColor.R, iColor.G, iColor.B, iColor.A);
glPushMatrix();
glTranslatef(iPos.X, iPos.Y, iPos.Z);
GetSpriteSheet(i_fileName)->Draw(i_index);
glPopMatrix();
}
Code in SpriteSheet for drawing
void SpriteSheet::Draw( int i_index )
{
if(!isAlreadyBound)
Bind();
glDrawArrays(GL_QUADS, i_index*4, 4);
}
Drawing only a mouse cursor sprite: 4000+ fps.
Drawing mouse cursor AND a letter from font (two texture binds, two vbo binds, two glDrawArrays calls): 2400+ fps
Draw a string of text "Mouse Screen Pos:[1,319]" and the cursor takes me down to: 680 fps.
Filling screen(800x600) with 16x16 tiles, drawing the string of text and mouse cursor makes: 20 fps.
You see that performance drops pretty damn quickly. I'd like to know what I'm doing wrong.
I did also try with ONE universal VBO created with 160 000 vertices before this code. Which had like 3-4 draw calls to that vbo. (one for each texture). Then I drew only parts of that giant VBO for each texture. depending on how many sprites we're drawn.
That didn't give me any performance either. It was because I was constantly changing the VBO (GL_DYNAMIC_DRAW).