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

Author Topic: sf::RenderImage::Create extremely slow  (Read 15156 times)

0 Members and 1 Guest are viewing this topic.

krisando

  • Newbie
  • *
  • Posts: 20
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #30 on: July 16, 2011, 01:14:10 pm »
Would the SFML library have to be profiled when compiled or could the compiler manage itself.

There isn't a great deal of code in the Create() function, so it may just be unfeasible to make this any faster, the calls to the libraries SFML relies on may just be a tad slow. =[

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #31 on: July 21, 2011, 08:23:45 am »
Is there a chance this could be sped up at all?

This does need to be addressed, It's incredibly slow. I can sit at a stable 500fps  then dip all the way down to 17/18 on some quite capable hardware. SDL 1.2 can achieve with its software blitting surfaces nicely.

Haikarainen

  • Guest
sf::RenderImage::Create extremely slow
« Reply #32 on: July 21, 2011, 08:38:53 am »
Quote from: "Turbine"
Is there a chance this could be sped up at all?

This does need to be addressed, It's incredibly slow. I can sit at a stable 500fps  then dip all the way down to 17/18 on some quite capable hardware. SDL 1.2 can achieve with its software blitting surfaces nicely.


Compile and run my benchmark that i replied with 1 page before in this thread. If you get significantly slower results, it's your code that is faulty.
Are you sure you dont sf::Image::Create() several frames in a row?

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #33 on: July 21, 2011, 09:20:22 am »
Yes, It is necessary to be able to do this, for this specific task.

I wouldn't be replying here if that faulty line of code weren't RenderImage's Create().

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderImage::Create extremely slow
« Reply #34 on: July 21, 2011, 09:48:49 am »
Quote
Yes, It is necessary to be able to do this, for this specific task.

Can you tell us more precisely how you use RenderImage?
Laurent Gomila - SFML developer

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #35 on: July 21, 2011, 10:10:33 am »
A primitive test to see if it could handle the drawing efficiently when resized in runtime.
Code: [Select]

sf::RenderImage surface;
sf::Sprite surfaceSprite;
sf::Vector2i pos;  //Store mouse position, checks if changed

sf::RenderWindow window(sf::VideoMode(800, 600));
window.SetFramerateLimit(60);

while (window.IsOpened())
{
   sf::Event event;
   while (window.PollEvent(event))
   {
      // Window closed or escape key pressed : exit
      if (event.Type == sf::Event::Closed)
      {
         window.Close();
         break;
      }
   }

   window.Clear();

   //Surface test
   if (pos != sf::Mouse::GetPosition(window))  //Change if mouse moved
   {
      pos = sf::Mouse::GetPosition(window);
      surface.Create(pos.x, pos.y);  //This line
      surface.Clear(sf::Color::White);
      surface.Display();
   }

   surfaceSprite.SetImage(surface.GetImage());
   window.Draw(surfaceSprite);

   //Draw fps
   int temp = window.GetFrameTime();
   if (temp > 0)
   {
      char out[3];
      int fps = 1000 / temp;   //Some computers 1 / time works, for this pc only 1000 gives accurate amount
      itoa(fps, out, 10);
      sf::Text text(out);
      window.Draw(text);
   }

   //
   window.Display();
}


Reallocating an area for a surface per frame may be extreme, but achieving 17-18 of these a second is quite limiting. Just need a way to resize in a reasonable amount of time.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderImage::Create extremely slow
« Reply #36 on: July 21, 2011, 10:14:42 am »
Ok I see. RenderImages are not meant to be created every frame (or every mouse move), this is really a slow operation -- it allocates and initializes a rendering texture on the graphics card. That's the cost of having accelerated draw-to-texture. In comparison, SDL is fast to create a surface but then slow to draw to it.

A better strategy for your example would be to create the surface with the same size as the window, and simply adjusting the subrect of the sprite when the mouse moves. The render-image doesn't need to be resized when you just want to show a smaller area of it ;)
Laurent Gomila - SFML developer

krisando

  • Newbie
  • *
  • Posts: 20
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #37 on: July 21, 2011, 12:04:50 pm »
Ah thankyou, that's a really neat idea. :)

Would I run into any problems with texture size limits, like 512x512 on Intel?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderImage::Create extremely slow
« Reply #38 on: July 21, 2011, 12:21:44 pm »
Indeed, the RenderImage size must not be greater than Image::GetMaximumSize().
Laurent Gomila - SFML developer

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #39 on: July 21, 2011, 09:53:23 pm »
It's good that there's a function which is aware of this limit, very helpful, thanks.

Ryder

  • Newbie
  • *
  • Posts: 5
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #40 on: July 24, 2011, 01:47:04 pm »
Having a similar issue, I added some traces in RenderImage::Create().
The slow operation is the call to XGetWindowAttributes() in GlxContext::CreateContext() which tooks 170ms.

I'm using the last git version (99b33e8) with Intel HD Graphics 3000.
Also, RenderImage does not seem work at all (which is not uncommon with Intel graphics, according to other topics).
For instance, the following code produces a black PNG image instead of a blue one:
Code: [Select]
sf::RenderImage img;
img.Create(32, 32);
img.SetActive(true);
img.Clear(sf::Color::Blue);
img.Display();
img.GetImage().SaveToFile("a.png");


On Windows 7, everything works fine, RenderImage is not slow and images are rendered as expected.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderImage::Create extremely slow
« Reply #41 on: July 24, 2011, 03:27:32 pm »
Quote
The slow operation is the call to XGetWindowAttributes() in GlxContext::CreateContext() which tooks 170ms.

Thanks, that's good to know.

I don't consider this a problem, but... XGetWindowAttributes won't be called anymore when I fix another bug, so render-image creation will be a little faster one day ;)
Laurent Gomila - SFML developer