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

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

0 Members and 2 Guests are viewing this topic.

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
sf::RenderImage::Create extremely slow
« on: May 14, 2011, 08:17:05 pm »
I have a game in which I have a tile map and I want to render blood splatters to a set of RenderImages (so the blood splatters remain permanently attatched to the walls). They RenderImages are created dynamically, but the game pauses for about 1- 2 seconds every time I call .create (the dimensions are 128 x 128, so it is not that much). When not created dynamically, it takes my machine like 5 minutes to create enough textures for the entire map. What could be causing it to create the textures so extremely slowly?

Code: [Select]
// Check to see if must create a new texture (texture already in place has no dimensions)
if(pImg->GetWidth() == 0)
{
pImg->Create(128, 128, false);
pImg->Clear(sf::Color(0, 0, 0, 0));
}
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderImage::Create extremely slow
« Reply #1 on: May 14, 2011, 09:08:24 pm »
Does it really take 1 - 2 sec to create a single render image??
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
sf::RenderImage::Create extremely slow
« Reply #2 on: May 14, 2011, 09:26:35 pm »
I use it for the Lighting manager in Ruby and don't have that problem where I render the lighting effects onto a RenderImage before applying it to the screen every frame.
I would say it is some operations you do afterwards or before in conjunction with the creation of the RenderImage that takes so much time.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #3 on: May 14, 2011, 10:26:35 pm »
Yup, it actually takes 1-2 secs to create it, the whole game freezes for a bit when the render image creation code is executed.
I don't think it has anything to do with any operations before or afterwards as their aren't any besides rendering, which works at 60fps (after the images were created). The lag occurs even when I don't render to the image. If I simply comment out the image creation line it runs smoothly at 60fps all the time.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderImage::Create extremely slow
« Reply #4 on: May 14, 2011, 10:30:00 pm »
So it should be the same with this piece of code, right?
Code: [Select]
int main()
{
    sf::RenderImage rimage;
    rimage.Create(128, 128);
    return 0;
}
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
sf::RenderImage::Create extremely slow
« Reply #5 on: May 14, 2011, 10:56:37 pm »
Just tried this out in my own system:

Code: [Select]
void Game::Update( const float aDelta )
{
myRotation += 1.f * aDelta;
myTestObject.SetRotation( 0, myRotation, 0 );
myTestObject.Render();

myTestSprite.Render();

sf::RenderImage test;
test.Create( 128, 128 );
}


There might be some truth to this. It lowered my FPS from 700 to around 20-30.

EDIT: Well actually not if things are done properly. It should not be done once every frame as I've done, it should be done once every now and then, so a drop like this is acceptable. Also this lowered my framerate a lot, but if I did like 10 it was lowered to 3 FPS. So it feels inconsistent.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #6 on: May 14, 2011, 10:57:55 pm »
Yes. I had to change it to this so I could actually tell how much time went by:

Code: [Select]

int main()
{
system("pause");
    sf::RenderImage rimage;
    rimage.Create(128, 128);
system("pause");
    return 0;
}


Still a 1 - 2 sec lag.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
sf::RenderImage::Create extremely slow
« Reply #7 on: May 14, 2011, 11:00:42 pm »
Quote from: "lolz123"
Yes. I had to change it to this so I could actually tell how much time went by:

Code: [Select]

int main()
{
system("pause");
    sf::RenderImage rimage;
    rimage.Create(128, 128);
system("pause");
    return 0;
}


Still a 1 - 2 sec lag.


system("pause") is a system call so for it to go back to your process could add a lot time to the whole thing. You should use sf::Clock and print out the time it takes for it to get the real estimate.

Example:
Code: [Select]

sf::Clock clock;
sf::RenderImage image;
image.Create( 128, 128 );
std::cout << clock.GetElapsedTime() << std::endl;
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #8 on: May 14, 2011, 11:04:13 pm »
It actually gave me 2.52619 secs when I tried that.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderImage::Create extremely slow
« Reply #9 on: May 14, 2011, 11:08:58 pm »
What's your graphics card and OS? Are your graphics drivers up to date?
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
sf::RenderImage::Create extremely slow
« Reply #10 on: May 14, 2011, 11:09:17 pm »
Quote from: "lolz123"
It actually gave me 2.52619 secs when I tried that.

Without any system calls? Pheeew that is a lot. What kind of computer are you sitting on? Can I see the exact source you wrote or you wrote exactly like me?

Also for the future, you should prepare these textures on before hand. Draw them at run time but allocate them at initiation, any form of allocation at run time is just flawed and bad design. It's(new/delete/malloc/free) slow and also prohibits any threads from running, even if you don't have the OS have.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #11 on: May 14, 2011, 11:21:25 pm »
I'm running this on a laptop with a core 2 duo CPU and a HD 3670 GPU with latest drivers. I could try and throw my HD 5970 at it, but that shouldn't be necessary!

Here is the program I used, at the end the time flashes by:

Code: [Select]
int main()
{
    sf::Clock clock;
clock.Reset();
sf::RenderImage image;
image.Create( 128, 128 );
std::cout << clock.GetElapsedTime() << std::endl;

return 0;
}


Even though a system("pause") at the end wouldn't change anything, I wanted to be certain that system calls are not causing this problem.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
sf::RenderImage::Create extremely slow
« Reply #12 on: May 14, 2011, 11:27:34 pm »
No that isn't the problem... Hmmm.... It's kind of weird. I don't have that problem at my computer. What time do you get if you create the image twice?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderImage::Create extremely slow
« Reply #13 on: May 14, 2011, 11:35:17 pm »
Which revision of SFML are you using?
Laurent Gomila - SFML developer

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
sf::RenderImage::Create extremely slow
« Reply #14 on: May 14, 2011, 11:35:57 pm »
The 2nd one is slightly faster, but still ridiculously slow. It takes my 3.07967 secs to create 2 render images.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

 

anything