SFML community forums
Help => Graphics => Topic started by: Rabenholz on November 11, 2012, 04:05:38 am
-
I've been getting really low framerates (10 fps) when drawing around 2000 sf::RectangleShapes alternating with 2000 sf::Sprites, which are all sized 8px X 12px. The drawable objects are contained in a class extending sf::Drawable and sf::Transform, with a very simple draw overload, which basically looks like this:
{
states.transform *= getTransform();
for(//... iterate through list
{
target.draw(rectangle, states);
target.draw(sprite,states);
}
}
After profiling I've noticed that that a huge amount of time is spent in sf::Transform::getInverse and new and delete calls made from sf::Transform::getInverse, which are found right after this draw call in the call stack. After looking through the SFML source code on GitHub for quite some time I haven't been able to find where this code calls getInverse().
If I comment out the calls to draw rectangles, the fps jumps up to over 200, while if I do the same for the sprites it only goes up to about 40 fps. With both removed it stays well over 500 fps.
Is there a problem with the way I am drawing these rectangles and sprites or does the problem lie elsewhere?
-
Must be something on your part: either your class or your graphics card is bad(my would slow down to 10fps or less with 2000 shapes and it's normal for it, intel express laptop integrated).
-
Oh, then I think it's probably just too much for my graphics card. 4000 shapes seemed pretty small, so I didn't think it was due to that. Seeing that I'm only using the rectangles to make solid colored squares, I'm going to see if replacing them with sprites increases my render speed.
-
If you wanted to know, replacing the sf::RectangleShapes with sf::Sprites increased the fps from 10 to 30.
-
I don't know if that's it or maybe your class is at fault. But if you have low end old laptop not meant for gaming(like I do) then yes, this can be it..
-
You should draw all your rectangles, then all your sprites. Instead of one rectangle, one sprite, one rectangle, ...
-
From what I read in the comments of the for you use a std::list. A std::vector is much faster than the list is, and making use of the reserve function of the std::vector might help with FPS drops at the start of the program.