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

Author Topic: How does the Draw() work?  (Read 3511 times)

0 Members and 1 Guest are viewing this topic.

shiroaisu

  • Newbie
  • *
  • Posts: 28
    • View Profile
How does the Draw() work?
« on: November 09, 2011, 10:43:28 pm »
Hi

I wanted to know in what circumstances does Draw() actualy draws something on screen.

For example, i made a test with 600 sprites (all with the same image) and when i drawned them all in one location:

Code: [Select]
for (unsigned int i = 0; i < 600; ++i) ship[i].SetPosition(100, 100);

I had better framerate (arround 700 fps) than when i tried to draw them in diferent locations:

Code: [Select]
for (unsigned int i = 0; i < 600; ++i) ship[i].SetPosition(i, 100);

Does that mean that Draw() skips some sprites when they are in the same positions?


And also, if i have a sprite that is offscreen and i call Draw() on it will the Draw() try to draw the sprite or will it recognize that the sprite is not inside the window and skip the drawing process??
Should i then use x and y checks before i try to draw something to see if it actualy is on screen to avoid any unnecessary processing?

thanks for the attention[/quote]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How does the Draw() work?
« Reply #1 on: November 09, 2011, 10:52:25 pm »
SFML doesn't optimize anything, each call to Draw draws something. How many FPS do you get with your second code?
Laurent Gomila - SFML developer

shiroaisu

  • Newbie
  • *
  • Posts: 28
    • View Profile
How does the Draw() work?
« Reply #2 on: November 09, 2011, 10:56:09 pm »
Quote from: "Laurent"
SFML doesn't optimize anything, each call to Draw draws something. How many FPS do you get with your second code?


oh sory i forgot to include that, when i drawned them in diferent positions i had... 550 fps average, so i found that a little strange, i really cant find an explanation for it, but if you want i can post here the full code (its just a small test i made so...).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How does the Draw() work?
« Reply #3 on: November 09, 2011, 11:01:59 pm »
It's not very surprising, the graphics card has many mystic behaviours, and you often get different results with no apparent reason.

So don't bother too much about that.
Laurent Gomila - SFML developer

shiroaisu

  • Newbie
  • *
  • Posts: 28
    • View Profile
How does the Draw() work?
« Reply #4 on: November 09, 2011, 11:33:39 pm »
I see. oh well...

anyway, thanks for the help :)

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
Re: How does the Draw() work?
« Reply #5 on: November 10, 2011, 12:41:21 am »
Quote from: "shiroaisu"
And also, if i have a sprite that is offscreen and i call Draw() on it will the Draw() try to draw the sprite or will it recognize that the sprite is not inside the window and skip the drawing process??
Should i then use x and y checks before i try to draw something to see if it actualy is on screen to avoid any unnecessary processing?

I think it does it automatically. In fact, I proved and FPS gets down when sprites are out of view.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How does the Draw() work?
« Reply #6 on: November 10, 2011, 07:36:37 am »
Quote
I think it does it automatically

There's no pixel written for objects that are out of screen, so yes they are skipped at some moment in the rendering pipeline ;)
But it happens very late, and eliminating them before even sending them to the graphics card can still be a huge improvement.
Laurent Gomila - SFML developer

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
How does the Draw() work?
« Reply #7 on: November 10, 2011, 07:46:38 pm »
Why sfml then doesen't do it?
You just need to test for intersection with the view rect for every sprite before making the actual draw calls.

Haze

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Github Profile
How does the Draw() work?
« Reply #8 on: November 11, 2011, 12:40:15 am »
Quote from: "P@u1"
Why sfml then doesen't do it?
You just need to test for intersection with the view rect for every sprite before making the actual draw calls.

I guess this would be an unnecessary (and time-consuming) operation if your application doesn't draw objects outside the screen.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How does the Draw() work?
« Reply #9 on: November 11, 2011, 10:40:02 am »
Quote
I guess this would be an unnecessary (and time-consuming) operation if your application doesn't draw objects outside the screen.

Indeed.

And an intersection test would be more expensive than you think, because both the view and the objects can be rotated. It's not trivial.
Laurent Gomila - SFML developer

 

anything