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

Author Topic: Maximized Window causes fps drop  (Read 2576 times)

0 Members and 1 Guest are viewing this topic.

lrx

  • Newbie
  • *
  • Posts: 29
    • View Profile
Maximized Window causes fps drop
« on: August 03, 2012, 06:26:27 am »
Hello
While working on my project I've encountered strange phenomenon.

With almost empty window I get few thousands of fps, however the very moment I maximize it, fps drops to around 200. I find this to be awkward and disturbing. Is there any particular reason for this happening?

W7 x64
VS2010
SFML2 RC
Nvidia

#include <SFML/Graphics.hpp>
#include <iostream>

void Draw(sf::RenderWindow* win)
{
        win->setActive(true);

        int fps = 0;
        sf::Text fpsText;
        sf::Clock clk;
        std::string str;
        char temp[20];

        while(win->isOpen())
        {
                fps = 1/clk.getElapsedTime().asSeconds();
                       
                clk.restart();
                       
                sprintf(temp, "%d", fps);
                str = temp;
                fpsText.setString(str);
       
                win->clear();
                win->draw(fpsText);
                win->display();
        }
};

int main()
{
        sf::RenderWindow window;

        window.create(sf::VideoMode(1680, 1050),"");
       
        window.setVerticalSyncEnabled(false);
       
        //Drawing thread
        window.setActive(false);
        sf::Thread eventPull(&Draw, &window);
        eventPull.launch();
       
       
        while(window.isOpen())
        {
                sf::Event event;
                while(window.pollEvent(event)); //needed to maximize
        }

        return 0;
}

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Maximized Window causes fps drop
« Reply #1 on: August 03, 2012, 06:52:46 am »
Could be this: http://en.sfml-dev.org/forums/index.php?topic=8566

It could also be the OS scheduler screwing up because you use 2 threads that both want 100% CPU time.

It could also be that some "optimization" that is meant for "normal" games (you know what I mean) screws SFML up because it doesn't do things like "normal" games. It most probably tries to optimize anything that takes exclusive control of the screen.

Really hard to say but your best bet is still playing around with the code a bit and seeing how that changes what you observe. I don't know what sense it makes to start a second thread for your main loop and put the original thread into busy wait but I guess it is also an option...
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

lrx

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Maximized Window causes fps drop
« Reply #2 on: August 03, 2012, 07:01:57 am »
Logic behind putting second thread there was to gain 3000 fps which is lost just by having event pulling in same loop as drawing :)
Effect is nearly identical with this code, although drop is from around 1000 to 200 on my machine.
But I see your point, it might be OS not SFML :)
#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window;

        window.create(sf::VideoMode(1680, 1050),"");
       
        window.setVerticalSyncEnabled(false);
       
        int fps = 0;
        sf::Text fpsText;
        sf::Clock clk;
        std::string str;
        char temp[20];

        while(window.isOpen())
        {
                sf::Event event;
                while(window.pollEvent(event));//needed to maximize

                fps = 1/clk.getElapsedTime().asSeconds();
                       
                clk.restart();
                       
                sprintf(temp, "%d", fps);
                str = temp;
                fpsText.setString(str);
       
                window.clear();
                window.draw(fpsText);
                window.display();
               
        }

        return 0;
}
« Last Edit: August 03, 2012, 07:04:21 am by lrx »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Maximized Window causes fps drop
« Reply #3 on: August 03, 2012, 07:06:14 am »
You can always profile your code in fullscreen and windowed and see which hotspot is created in the former case. I highly doubt that the slowdown is spread over all sections of the code.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

lrx

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Maximized Window causes fps drop
« Reply #4 on: August 03, 2012, 07:32:46 am »
I'm not used to use profilers but from what it shown me I gather in fault here is ntdll.dll