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

Author Topic: [SOLVED] Huge performance hit when I draw a big background.  (Read 9668 times)

0 Members and 2 Guests are viewing this topic.

Mr. Moon

  • Newbie
  • *
  • Posts: 15
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« on: August 13, 2010, 01:09:36 am »
Hi everyone!  I'm very new to SFML, pardon if I'm making a glaring error here...

Normally my game runs at about 150 fps, but as soon as I load an 800x600 PNG background, assign it to a background Sprite, and Draw() it in my game loop, the game plummets to <10 fps.

My code looks something like this:

Code: [Select]
void Game::gameMain()
{
        // Game loop
        while (!quitLevel && window.IsOpened())
        {
                // Process events
                // ...event handling...

                // This changes depending on what the current level is.  Right now it's set to level1().
                (this->*updateAndDisplay)();

                window.Display();
        }
}

void Game::level1()
{      
        // SPRITES

        static sf::Image background1Im;

        // Sprite is a derived class of sf::Sprite with a few wrapper functions included.
        static Sprite background1;

        // INITIALIZED WORLD

        if (!initializedLevel)
        {
                // Load images

                background1Im.LoadFromFile("background1.png");

                background1.SetImage(background1Im);
               
                // ...

                initializedLevel = true;
        }

       // ...

       // DRAW WORLD

//        fillScreen(50, 50, 50);
        window.Draw(background1);
}


I'm compiling in Visual Studio Express 2010 with the static libraries.  I'm running it on a pretty low-performance laptop, but I can still play 3D games, so I can't imagine that's the cause of the performance hit.

What I'm actually trying to do is cut up a 8000x600 background into 800x600 pieces (the game is a sidescroller) since SFML doesn't seem to be able to load textures that large.

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« Reply #1 on: August 13, 2010, 05:42:55 am »
Try making a program that just does this (A complete, minimal example) and see if you still get the problem.

By the way, the texture(sprite) size is limited by your hardware, not SFML.

Mr. Moon

  • Newbie
  • *
  • Posts: 15
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« Reply #2 on: August 14, 2010, 01:16:26 am »
Good idea.  Here's a minimal example:

Code: [Select]

#include "game.h"

#include <fstream>
#include <sstream>

int main()
{  
        std::ofstream fpsLog("fps.txt");

        if (fpsLog.fail())
        {
                return EXIT_FAILURE;
        }

        sf::RenderWindow window(sf::VideoMode(800, 600, 32), "test", sf::Style::Fullscreen);

        sf::Image bgIm;
        bgIm.LoadFromFile("background1test.png");

        sf::Sprite bg;
        bg.SetImage(bgIm);

        while (window.IsOpened())
        {
                // Process events
                sf::Event windowEvent;
                while (window.GetEvent(windowEvent))
                {
                        // Close window : exit
                        if (windowEvent.Type == sf::Event::Closed)
                        {
                                window.Close();
                        }

                        // A key has been pressed
                        if (windowEvent.Type == sf::Event::KeyPressed)
                        {
                                // Escape key : exit
                                if (windowEvent.Key.Code == sf::Key::Escape)
                                {
                                        window.Close();
                                }
                        }
                }

                window.Draw(bg);

                window.Display();

                // Record FPS
                std::stringstream ss;
                ss << 1.f / window.GetFrameTime() << std::endl;
                fpsLog << ss.str();
        }

        return EXIT_SUCCESS;
}


Still having the same problem.  I can't get more than 10 FPS.

File type seems to be a non-issue.  I tried saving my background as PNG, TGA, JPG, and BMP, and nothing seemed to change.

The smaller I make the background file, the higher my framerate gets.  It's as if SFML just doesn't like how big the texture is.

Any ideas...?  I would really hate to go back to SDL at this point :[ .

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« Reply #3 on: August 14, 2010, 01:48:28 am »
What's your hardware? Can you give us a profile of 10 seconds of runtime?

Also try to limit FPS to 60 in any case and report results.

Mr. Moon

  • Newbie
  • *
  • Posts: 15
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« Reply #4 on: August 14, 2010, 02:34:02 am »
Quote from: "Svenstaro"
What's your hardware? Can you give us a profile of 10 seconds of runtime?

Also try to limit FPS to 60 in any case and report results.


Dell Studio 17
CPU: Pentium Dual-Core 2.10 GHz
RAM: 2 GB
Video card: Intel Graphics Media Accelerator 4500MHD

I'm compiling with the static libraries in MSVC++ 2010 on Windows 7.

I'm not sure what you mean by profile, but in any case here's the framerate output in that time:

Code: [Select]

2.43682
5.99203
7.39104
8.39077
8.39245
8.41012
8.29009
8.20897
8.37966
8.34473
8.43425
8.31317
7.90502
8.23046
8.3182
8.40324
8.37757
8.34313
8.36165
8.36281
8.27326
8.28989
8.20495
8.37726
8.37037
8.40134
8.19397
8.30234
8.26932
8.31256
8.37822
8.39721
8.42528
8.40183
8.37096
8.23911
8.3507
8.38214
8.38018
8.35356
8.26955
8.36261
8.34848
8.21543
8.27591
8.24792
8.2015
8.25531
8.41257
8.3787
8.44075
8.40638
8.40963
8.05344
8.2814
8.28694
8.32992
8.39738
8.38547
8.40438
8.41915
8.37455
8.37936
8.22401
8.33583
8.43664
8.33304
8.13746
8.41839
8.35455
8.33725
8.29766
8.32928
8.40221
8.41683
8.43313
8.39369
8.33382
8.3833
8.39149
2.41406

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« Reply #5 on: August 14, 2010, 02:45:29 am »
I mean run your system profiler or debugger or whatever you use with to record which system call takes how much % of your total runtime. On Linux you'd use sysprof or gprof. This way we can check which part actually makes it slow.

Mr. Moon

  • Newbie
  • *
  • Posts: 15
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« Reply #6 on: August 14, 2010, 05:17:58 am »
Quote from: "Svenstaro"
I mean run your system profiler or debugger or whatever you use with to record which system call takes how much % of your total runtime. On Linux you'd use sysprof or gprof. This way we can check which part actually makes it slow.


That doesn't seem to be a feature in MSVC++ Express (which I'm not very experienced with, so perhaps I'm wrong?), so I used Very Sleepy (http://www.codersnotes.com/sleepy/sleepy). My application was taking up about 50% of my CPU cycles, and wglChoosePixelFormat was taking up almost 100% of the calls, so I analyzed that.  This http://i.imgur.com/ombmg.png was my output.

So...it seems like that OpenGL function could be the culprit?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[SOLVED] Huge performance hit when I draw a big background.
« Reply #7 on: August 14, 2010, 08:40:26 am »
I don't know if it's the same here but the only GC from Intel I've got gives me very poor performances. Try to give the exe to a friend which has some ATI/Nvidia graphic card to see if it's your hardware or not.
SFML / OS X developer

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
[SOLVED] Huge performance hit when I draw a big background.
« Reply #8 on: August 14, 2010, 09:31:02 am »
I have very little OpenGL experience, but looking at where it is called in SFML's code (latest version of 2.0), I don't think wglchoosepixelformat should be getting called that often. Then again, that is assuming I am reading this Very Sleepy output correctly.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SOLVED] Huge performance hit when I draw a big background.
« Reply #9 on: August 14, 2010, 11:29:16 am »
Do you make your performances tests in release mode (not debug)?
Laurent Gomila - SFML developer

Mr. Moon

  • Newbie
  • *
  • Posts: 15
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« Reply #10 on: August 14, 2010, 11:16:51 pm »
Admittedly my graphics card isn't great, but I can still run some decent-looking 3D games.  I can't imagine displaying a single 800x600 texture would be the sole cause of such a huge performance hit.

Quote from: "Laurent"
Do you make your performances tests in release mode (not debug)?


Usually debug mode, but I'm now in release and getting the same results.

Quote from: "Spodi"
I have very little OpenGL experience, but looking at where it is called in SFML's code (latest version of 2.0), I don't think wglchoosepixelformat should be getting called that often. Then again, that is assuming I am reading this Very Sleepy output correctly.


I should mention I'm using SFML 1.6.  Maybe this has to do with the fact that I'm using a 64-bit OS?  Someone mentioned similar problems here http://www.qtcentre.org/threads/24192-OpenGL-frame-rate and concluded that it had something to do with incorrect OGL DLLs.

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« Reply #11 on: August 14, 2010, 11:39:36 pm »
Does your performance change on Linux? If you are not familiar with Linux but this is important enough for you, pop in Ubuntu Desktop x86_64, in the live environment install build-essential and sfml from the repo and compile your code from the command line (g++ -lsfml-graphics -lsfml-window -lsfml-system -o graphics_test *.c++) and run it (./graphics_test).

Mr. Moon

  • Newbie
  • *
  • Posts: 15
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« Reply #12 on: August 15, 2010, 12:20:54 am »
Okay, my performance is back to normal again on my 32-bit Ubuntu partition.  Frame rates in excess of 500 fps.  I couldn't use the version of SFML from the site (bad archive?), so I used the version in the repos, which seems to be 1.5.

My game is intended for Windows users as well, though, so I still need to figure out what's going wrong there.  Should I try an earlier version of SFML, perhaps?

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« Reply #13 on: August 15, 2010, 01:13:22 am »
I'm almost certain that the problem is related to your crappy Intel graphics drivers for Windows. This is why I made you test it on Linux.

Mr. Moon

  • Newbie
  • *
  • Posts: 15
    • View Profile
[SOLVED] Huge performance hit when I draw a big background.
« Reply #14 on: August 15, 2010, 01:39:39 am »
Quote from: "Svenstaro"
I'm almost certain that the problem is related to your crappy Intel graphics drivers for Windows. This is why I made you test it on Linux.


So you think it's the Windows-specific drivers and not the card itself?

In that case I may just have to go back to SDL.  I'd rather foresake hardware acceleration for a game that I don't have to worry about these kinds of issues with.  I guess I just didn't realize what I was in for.