Hi! I'm using the current precompiled SFML 2 RC (SJLJ) from the SFML website. I'm on a Win7 notebook with a AMD Radeon HD 6970M graphics card. Compiler is TDM-GCC 4.6.1.
In the following code I have a shape that gets drawn 'numDrawTiles' times per frame. I have VSync turned on.
The number of times the shape is drawn per frame increases every frame by one.
When the counter reaches about 987 draws per frame the framerate drops to 1FPS or lower instantly. When the counter reaches 1020 suddenly the program runs at 60FPS again. The next drop appears at about 2200 draws, this time however the "recovery time" is longer. After that it's back to normal ~60FPS again.
If I use setFramerateLimit(60) or disable VSync and do not limit the framerate the FPS drop is much less noticeable but still there.
My first assumption was that it might have to do with VSync, however this is not the case as stated above. For the record: I was able to draw about 8000 shapes per frame with approximately 30FPS so this is no usual FPS drop due to too many draw calls. I do also know that this is not the optimal way to draw many similar objects.
Code is below. Any ideas where this is coming from?
#include <SFML/Graphics.hpp>
// main rendering window
sf::RenderWindow mainWindow;
int main() {
mainWindow.create(sf::VideoMode(640, 480), "Test");
// mainWindow.setFramerateLimit(60);
mainWindow.setVerticalSyncEnabled(true);
sf::RectangleShape shape( sf::Vector2f(40, 40) );
shape.setFillColor(sf::Color::Green);
sf::Text counter;
counter.setColor(sf::Color::Red);
counter.setScale(3,3);
unsigned long int tileCounter = 0;
unsigned long int numDrawTiles = 1;
while ( mainWindow.isOpen() == true )
{
sf::Event event;
while (mainWindow.pollEvent(event))
{
switch (event.type)
{
// window closed
case sf::Event::Closed:
mainWindow.close();
break;
// we don't process other types of events
default:
break;
}
}
mainWindow.clear();
tileCounter = 0;
for(unsigned int i=0; i<numDrawTiles; ++i) {
shape.setPosition( 320, 240 );
mainWindow.draw(shape);
++tileCounter;
}
++numDrawTiles;
char buffer[12];
itoa(tileCounter, buffer, 10);
counter.setString(buffer);
mainWindow.draw(counter);
mainWindow.display();
}
return 0;
}