I tried to get the maximum out of my Library and just created insane amounts of sprites wandering over the screen.
With 5000 Sprites I got down to 15-20fps which is the bottom line of a playable Game.
So, I need some performance Tipps.
Here is the drawing Code:
void NLSpriteList::renderObject()
{
m_texture->attach();
m_shader->attach();
glBindVertexArray(m_vao);
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
// Enable Attribute Sets
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
// Draw
glDrawArrays(GL_TRIANGLES, 0, m_list.size()*6);
// Disable Attribute Sets
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
// Unbind
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
m_shader->detach();
m_texture->detach();
}
void NLSpriteList::update(u32 delta, u32 time)
{
if ( m_vao == 0 || m_vbo == 0 )
this->createBatch();
//m_list.sort(NLBatchedSprite::OrderByZ());
// Update data
NLVertexData* data = createData(delta, time);
// Bind
glBindVertexArray(m_vao);
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
// Enable Attribute Sets
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
// Send Vertex data
glBufferData(GL_ARRAY_BUFFER, 6*m_list.size()*sizeof(NLVertexData), data, GL_STREAM_DRAW);
// Disable Attribute Sets
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
// Unbind
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// Delete buffer
delete [] data;
}
NLVertexData* NLSpriteList::createData(u32 delta, u32 time)
{
NLVertexData* buffer = new NLVertexData[m_list.size()*6];
memset(buffer, 0, sizeof(buffer));
TSpriteList::iterator it = m_list.begin();
int i = 0;
for ( it; it != m_list.end(); it++ )
{
NLBatchedSprite& s = *it;
s.update(delta, time);
memcpy(&buffer, &it->m_vertices, sizeof(NLVertexData)*6);
i += 6;
}
return buffer;
}
As you can see, I send the vertices each frame. Okay, in this case it is needed since I have transformations every frame and I do transforms on the cpu.
Any hints?
Oh and there are no texture-/shaderchanges during the rendering, OpenGL Calls are constant 31 per Frame and no glGet/Redundant state changes.
Picture was taken on an AMD 2600+ DualCore with ATI HD4890 with 11.4 drivers.