1
Graphics / mixing opengl and sfml2 calls (found speed drops when moving from sfml1.6 to 2)
« on: May 29, 2013, 09:28:07 pm »
Greetings!
I noticed some unpleasant issue when moved from sfml1.6 to 2.0.
I have render which is mainly using standard opengl calls and sfml is handling the font drawing.
So, sfml drawing calls are mixed with native opengl, and happens in many layers of my code.
I want to keep thing separated, my code is on the left and sfml code is on the right, so i created some agregator which manage all sfml calls inside.
with using SFML2:
sf::RenderWindow window;
void SFML_Wrapper::DrawText(const std::string& str, int font_size, const Vec2<float>& pos, const Color4<int>& color)
{
sf::Text text(str, font, font_size);
text.setColor(sf::Color(color.r, color.g, color.b));
text.setPosition(pos.x, GetHeight() - pos.y);
window.pushGLStates();
window.draw(text);
window.popGLStates();
}
I know that push/popGLStates() calls are very expensive(and actually they are the root of my problem). i have a significant fps drop when text is rendering.
with using SFML1.6: i had no need to use push/popGLStates(). And my font rendering served me with good fps. I was using
window.PreserveOpenGLStates(true); which was configured once in constructor.
I guess it does something similar to push/popGLStates() in a background, but i have no so significant render speed drop as in SFML2.
Is it possible to avoid this? Or at least to get speed near to SFML1.6 without code redesign (i had an idea to agregate all text and render it at once at the end of render, but don't want to make code more complex than it actually is now). I don't want to downgrade.
Many thanks in advance!
I noticed some unpleasant issue when moved from sfml1.6 to 2.0.
I have render which is mainly using standard opengl calls and sfml is handling the font drawing.
So, sfml drawing calls are mixed with native opengl, and happens in many layers of my code.
I want to keep thing separated, my code is on the left and sfml code is on the right, so i created some agregator which manage all sfml calls inside.
with using SFML2:
sf::RenderWindow window;
void SFML_Wrapper::DrawText(const std::string& str, int font_size, const Vec2<float>& pos, const Color4<int>& color)
{
sf::Text text(str, font, font_size);
text.setColor(sf::Color(color.r, color.g, color.b));
text.setPosition(pos.x, GetHeight() - pos.y);
window.pushGLStates();
window.draw(text);
window.popGLStates();
}
I know that push/popGLStates() calls are very expensive(and actually they are the root of my problem). i have a significant fps drop when text is rendering.
with using SFML1.6: i had no need to use push/popGLStates(). And my font rendering served me with good fps. I was using
window.PreserveOpenGLStates(true); which was configured once in constructor.
I guess it does something similar to push/popGLStates() in a background, but i have no so significant render speed drop as in SFML2.
Is it possible to avoid this? Or at least to get speed near to SFML1.6 without code redesign (i had an idea to agregate all text and render it at once at the end of render, but don't want to make code more complex than it actually is now). I don't want to downgrade.
Many thanks in advance!