Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [2.0] Low FPS when Drawing [SOLVED]  (Read 2271 times)

0 Members and 1 Guest are viewing this topic.

Rabenholz

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
[2.0] Low FPS when Drawing [SOLVED]
« 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?
« Last Edit: November 11, 2012, 04:25:26 am by Rabenholz »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: [2.0] Low FPS when Drawing
« Reply #1 on: November 11, 2012, 04:14:42 am »
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).
Back to C++ gamedev with SFML in May 2023

Rabenholz

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: [2.0] Low FPS when Drawing
« Reply #2 on: November 11, 2012, 04:19:10 am »
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.

Rabenholz

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: [2.0] Low FPS when Drawing
« Reply #3 on: November 11, 2012, 04:24:49 am »
If you wanted to know, replacing the sf::RectangleShapes with sf::Sprites increased the fps from 10 to 30.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: [2.0] Low FPS when Drawing [SOLVED]
« Reply #4 on: November 11, 2012, 05:02:24 am »
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..
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: [2.0] Low FPS when Drawing [SOLVED]
« Reply #5 on: November 11, 2012, 09:35:42 am »
You should draw all your rectangles, then all your sprites. Instead of one rectangle, one sprite, one rectangle, ...
Laurent Gomila - SFML developer

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: [2.0] Low FPS when Drawing [SOLVED]
« Reply #6 on: November 16, 2012, 04:33:24 am »
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.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

 

anything