Perfomance problem with SDL+OpenGL

Hi, I’m still developing the PhantomSDL library =P, but I stil have
perfomance problems =S…
AFAIK, iterators are most quick and best way to iterate a list (I don’t get
very well with the STL…).

So, here is the code that gives me problems:

Instance Handler, Step Function:

std::list<PhantomSDL_CINSTANCE*>::iterator i;
for(i = mInstances.begin(); i != mInstances.end(); i++)
{
if( (*i) == NULL)
{
mLog->write(2,"[CInstanceHandler]-> NULL pointer avoided.");
continue;
}
(*i)->stepEvent();
if( (*i)->getVisible() ) (*i)->drawEvent();
}

Every stance that can be “instanced” in the Instance Handler, inherits from
PhantomSDL_CINSTANCE.
So then, the drawing event of each instance may vary, but when rendering
nothing, i do get no more than ~400 fps (focused window, 800x600x32).

This is when rendering with SDL.
When rendering with OpenGL…in the same circumstances, i get no more than
~80 fps (focused window, 800x600x32).

Can somebody tell me if this is a problem of my code, or whatever.

BTW, I have a GeForce FX 5500 256 videocard.

Thx!
Cya–
Phantom Lord
Caelis Studios —> Life’s just a game http://caelis-studio.com.ar
Caelis Studios Oficial Forums http://foro.caelis-studio.com.ar

Hi Phantom lord!

It sounds like vsync is the culprit.

When vsync is on, it only allows you to write to the screen when the monitor
is not refreshing itself which makes it so you don’t get half of one frame
and half of the other at the same time.

60 and 80 hz are common refresh rates for monitors so it really does seem
like in the GL version of your code, vsync is on while on the other, vsync
is off.

Even though with vsync on it will only show a maximum of 80 fps, most of the
time between frames is spent waiting for the vsync so don’t worry you can
ignore that it’s 80 and move forward and not run into performance problems
any faster than you would in the non gl side._____

From: sdl-bounces+atrix2=cox.net@libsdl.org
[mailto:sdl-bounces+atrix2=cox.net at libsdl.org] On Behalf Of Phantom Lord
Sent: Sunday, December 03, 2006 2:31 AM
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: [SDL] Perfomance problem with SDL+OpenGL

Hi, I’m still developing the PhantomSDL library =P, but I stil have
perfomance problems =S…

AFAIK, iterators are most quick and best way to iterate a list (I don’t get
very well with the STL…).

So, here is the code that gives me problems:

Instance Handler, Step Function:

std::list<PhantomSDL_CINSTANCE*>::iterator i;
for(i = mInstances.begin(); i != mInstances.end(); i++)
{
if( (*i) == NULL)
{
mLog->write(2,"[CInstanceHandler]-> NULL pointer avoided.");
continue;
}
(*i)->stepEvent();
if( (*i)->getVisible() ) (*i)->drawEvent();
}

Every stance that can be “instanced” in the Instance Handler, inherits from
PhantomSDL_CINSTANCE.

So then, the drawing event of each instance may vary, but when rendering
nothing, i do get no more than ~400 fps (focused window, 800x600x32).

This is when rendering with SDL.

When rendering with OpenGL…in the same circumstances, i get no more than
~80 fps (focused window, 800x600x32).

Can somebody tell me if this is a problem of my code, or whatever.

BTW, I have a GeForce FX 5500 256 videocard.

Thx!

Cya


Phantom Lord
Caelis Studios — http://caelis-studio.com.ar > Life’s just a game

Caelis Studios Oficial http://foro.caelis-studio.com.ar Forums

So, if i deactivate vsync, there wont be that perfomance problem (that is
not a problem, but a method)?.

Thx for all Alan!.
C ya

2006/12/3, Alan Wolfe :>

Hi Phantom lord!

It sounds like vsync is the culprit.

When vsync is on, it only allows you to write to the screen when the
monitor is not refreshing itself which makes it so you don’t get half of one
frame and half of the other at the same time.

60 and 80 hz are common refresh rates for monitors so it really does seem
like in the GL version of your code, vsync is on while on the other, vsync
is off.

Even though with vsync on it will only show a maximum of 80 fps, most of
the time between frames is spent waiting for the vsync so don’t worry you
can ignore that it’s 80 and move forward and not run into performance
problems any faster than you would in the non gl side.


From: sdl-bounces+atrix2=cox.net at libsdl.org [mailto:
sdl-bounces+atrix2=cox.net at libsdl.org] *On Behalf Of *Phantom Lord
Sent: Sunday, December 03, 2006 2:31 AM
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: [SDL] Perfomance problem with SDL+OpenGL

Hi, I’m still developing the PhantomSDL library =P, but I stil have
perfomance problems =S…

AFAIK, iterators are most quick and best way to iterate a list (I don’t
get very well with the STL…).

So, here is the code that gives me problems:

Instance Handler, Step Function:

std::list<PhantomSDL_CINSTANCE*>::iterator i;
for(i = mInstances.begin(); i != mInstances.end(); i++)
{
if( (*i) == NULL)
{
mLog->write(2,"[CInstanceHandler]-> NULL pointer avoided.");
continue;
}
(*i)->stepEvent();
if( (*i)->getVisible() ) (*i)->drawEvent();
}

Every stance that can be “instanced” in the Instance Handler, inherits
from PhantomSDL_CINSTANCE.

So then, the drawing event of each instance may vary, but when rendering
nothing, i do get no more than ~400 fps (focused window, 800x600x32).

This is when rendering with SDL.

When rendering with OpenGL…in the same circumstances, i get no more than
~80 fps (focused window, 800x600x32).

Can somebody tell me if this is a problem of my code, or whatever.

BTW, I have a GeForce FX 5500 256 videocard.

Thx!

Cya


Phantom Lord
Caelis Studios —> Life’s just a game http://caelis-studio.com.ar/

Caelis Studios Oficial Forums http://foro.caelis-studio.com.ar/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Phantom Lord
Caelis Studios —> From Gods Hands To Yours

This is not a performance problem! Vertical retrace syncing (aka.
vsync) prevents your program from updating the screen more often than
it is refreshed on your display. This is a good thing. If your
display runs at a refresh rate of 80Hz, it is pointless to produce
more than 80 frames per second, as it only wastes computing resources.On 12/3/06, Phantom Lord wrote:

So, if i deactivate vsync, there wont be that perfomance problem (that is
not a problem, but a method)?.

  • SR

“Simon Roby” <simon.roby at gmail.com> wrote:

This is not a performance problem! Vertical retrace syncing (aka.
vsync) prevents your program from updating the screen more often than > it is
refreshed on your display.—

I’ve seen claims that pushing frame rate to hundreds of frames/second makes a game more responsive. For a simplistic algorithm this can be the case. But if the input processing properly accounts for the possability for a ‘button’ being pressed and released during a frame, 20-30 frames/second can be suprisingly responsive. I agree that there’s no point in a frame rate faster than vertical refresh.

Thx for all guys, I’d just though that more frame rate (more than vertical
refresh) would be better! :rolleyes:

So, theres no trouble with getting that fps…

C Ya!

Sun, 3 Dec 2006 16:12:7, cal at splitreflection.com :>

“Simon Roby” <simon.roby at gmail.com> wrote:

This is not a performance problem! Vertical retrace syncing (aka.
vsync) prevents your program from updating the screen more often than >
it is
refreshed on your display.


I’ve seen claims that pushing frame rate to hundreds of frames/second
makes a game more responsive. For a simplistic algorithm this can be the
case. But if the input processing properly accounts for the possability for
a ‘button’ being pressed and released during a frame, 20-30 frames/second
can be suprisingly responsive. I agree that there’s no point in a frame
rate faster than vertical refresh.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Phantom Lord
Caelis Studios —> From Gods Hands To Yours

Hey, I don’t know if this helps, but you can try running the program without calling SDL_Flip() (or whatever screen update function you’re using, whether for SDL or OpenGL) and check the fps and compare this to the fps without the stuff you put in (drawing routine?) and without SDL_Flip(). This will avoid SDL_Flip()'s vsync at least. You won’t be able to see what’s happening, of course, so output the fps to a text file.

Thx for all guys, I’d just though that more frame rate (more than vertical refresh) would be better! :rolleyes:

So, theres no trouble with getting that fps…

C Ya!
Sun, 3 Dec 2006 16:12:7, cal at splitreflection.com :
“Simon Roby” <simon.roby at gmail.com> wrote:> This is not a performance problem! Vertical retrace syncing (aka. > vsync) prevents your program from updating the screen more often than > it isrefreshed on your display.—I’ve seen claims that pushing frame rate to hundreds of frames/second makes a game more responsive. For a simplistic algorithm this can be the case. But if the input processing properly accounts for the possability for a ‘button’ being pressed and released during a frame, 20-30 frames/second can be suprisingly responsive. I agree that there’s no point in a frame rate faster than vertical refresh. _______________________________________________SDL mailing listSDL at libsdl.orghttp://www.libsdl.org/mailman/listinfo/sdl – Phantom LordCaelis Studios —> From Gods Hands To YoursDate: Mon, 4 Dec 2006 13:46:54 +0100From: thephantomlord at gmail.comTo: cal at splitreflection.com; sdl at libsdl.orgSubject: Re: [SDL] Perfomance problem with SDL+OpenGL


Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today!
http://get.live.com/toolbar/overview

But can I show the fps in the caption of the window?

C ya

2006/12/4, Jonathan Dearborn :>

Hey, I don’t know if this helps, but you can try running the program
without calling SDL_Flip() (or whatever screen update function you’re
using, whether for SDL or OpenGL) and check the fps and compare this to the
fps without the stuff you put in (drawing routine?) and without SDL_Flip().
This will avoid SDL_Flip()'s vsync at least. You won’t be able to see
what’s happening, of course, so output the fps to a text file.


Date: Mon, 4 Dec 2006 13:46:54 +0100
From: @Phantom_Lord
To: cal at splitreflection.com; sdl at libsdl.org
Subject: Re: [SDL] Perfomance problem with SDL+OpenGL

Thx for all guys, I’d just though that more frame rate (more than vertical
refresh) would be better! :rolleyes:

So, theres no trouble with getting that fps…

C Ya!

Sun, 3 Dec 2006 16:12:7, cal at splitreflection.com <cal at splitreflection.com

:

“Simon Roby” <simon.roby at gmail.com> wrote:

This is not a performance problem! Vertical retrace syncing (aka.
vsync) prevents your program from updating the screen more often than >
it is
refreshed on your display.


I’ve seen claims that pushing frame rate to hundreds of frames/second
makes a game more responsive. For a simplistic algorithm this can be the
case. But if the input processing properly accounts for the possability for
a ‘button’ being pressed and released during a frame, 20-30 frames/second
can be suprisingly responsive. I agree that there’s no point in a frame
rate faster than vertical refresh.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Phantom Lord
Caelis Studios —> From Gods Hands To Yours


Search from any Web page with powerful protection. Get the FREE Windows
Live Toolbar Today! Try it now! http://get.live.com/toolbar/overview


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Phantom Lord
Caelis Studios —> From Gods Hands To Yours

Hey, so then, just without the rendering i get around 7000-8000 fps :D…

Anyway, the concluscion:

“When you render, the FPS correspond to the VSync Refresh rate.”

Something like that?

Cya

2006/12/5, Phantom Lord <@Phantom_Lord>:>

But can I show the fps in the caption of the window?

C ya

2006/12/4, Jonathan Dearborn :

Hey, I don’t know if this helps, but you can try running the program
without calling SDL_Flip() (or whatever screen update function you’re
using, whether for SDL or OpenGL) and check the fps and compare this to the
fps without the stuff you put in (drawing routine?) and without SDL_Flip().
This will avoid SDL_Flip()'s vsync at least. You won’t be able to see
what’s happening, of course, so output the fps to a text file.


Date: Mon, 4 Dec 2006 13:46:54 +0100
From: @Phantom_Lord
To: cal at splitreflection.com; sdl at libsdl.org
Subject: Re: [SDL] Perfomance problem with SDL+OpenGL

Thx for all guys, I’d just though that more frame rate (more than
vertical refresh) would be better! :rolleyes:

So, theres no trouble with getting that fps…

C Ya!

Sun, 3 Dec 2006 16:12:7, cal at splitreflection.com <cal at splitreflection.com

:

“Simon Roby” <simon.roby at gmail.com > wrote:

This is not a performance problem! Vertical retrace syncing (aka.
vsync) prevents your program from updating the screen more often than
it is
refreshed on your display.


I’ve seen claims that pushing frame rate to hundreds of frames/second
makes a game more responsive. For a simplistic algorithm this can be the
case. But if the input processing properly accounts for the possability for
a ‘button’ being pressed and released during a frame, 20-30 frames/second
can be suprisingly responsive. I agree that there’s no point in a frame
rate faster than vertical refresh.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Phantom Lord
Caelis Studios —> From Gods Hands To Yours


Search from any Web page with powerful protection. Get the FREE Windows
Live Toolbar Today! Try it now! http://get.live.com/toolbar/overview


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Phantom Lord
Caelis Studios —> From Gods Hands To Yours


Phantom Lord
Caelis Studios —> From Gods Hands To Yours

Not exactly. It’s really: "When you render, the FPS is limited by
the VSync Refresh rate."On 12/5/06, Phantom Lord wrote:

Hey, so then, just without the rendering i get around 7000-8000 fps :D…

Anyway, the concluscion:

“When you render, the FPS correspond to the VSync Refresh rate.”

Something like that?

Cya

  • SR

Thx you all.

2006/12/6, Simon Roby <simon.roby at gmail.com>:>

On 12/5/06, Phantom Lord <@Phantom_Lord> wrote:

Hey, so then, just without the rendering i get around 7000-8000 fps
:D…

Anyway, the concluscion:

“When you render, the FPS correspond to the VSync Refresh rate.”

Something like that?

Cya

Not exactly. It’s really: “When you render, the FPS is limited by
the VSync Refresh rate.”

  • SR

SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Phantom Lord
Caelis Studios —> From Gods Hands To Yours

Here you go. Some code to tell fps before and after Vsync (as well as control the frame rate). This is adapted from some tutorial online (either Sol’s or Marius Andra’s (cone3d))

#define DESIREDFPS 27#define WAITTIME 1000 / DESIREDFPS

/// In main()
// Main loop cout.precision(4); SDL_Event event; int frameStartTime; int frameTime; float fps; bool done = 0; while(!done) { frameStartTime = SDL_GetTicks();
/// Check for input
/// Do whatever your program does

// Without vsync    frameTime = SDL_GetTicks()-frameStartTime;        if(frameTime != 0)      fps = 1000.0f / frameTime;  //this is the framerate without vsync
else      fps = 1111.11f;    cout << "FPS w/o vsync: " << fps << endl;  /// You can use any text writer (like SFont) instead of cout    
SDL_Flip(screen);  // Send screen surface to the display            // With vsync    frameTime = SDL_GetTicks()-frameStartTime;        if(frameTime != 0)      fps = 1000.0f / frameTime;  //this is the framerate with vsync and the framebreak
else      fps = 1111.11f;    cout << "FPS with vsync: " << fps << endl;  /// You can use any text writer instead of cout    

// Frame rate control if(frameTime < WAITTIME) Sleep(WAITTIME - frameTime); // Keep framerate constant the Windows way /** Sleep() is defined in windows.h and is not platform-independent.
You can use SDL_Delay(), but that does not give time back to the OS
like Sleep() does. **/
} // END while(!done)

/// End of main()Date: Tue, 5 Dec 2006 01:35:57 +0100From: thephantomlord at gmail.comTo: sdl at libsdl.orgSubject: Re: [SDL] Perfomance problem with SDL+OpenGL
But can I show the fps in the caption of the window?

C ya
2006/12/4, Jonathan Dearborn :

Hey, I don’t know if this helps, but you can try running the program without calling SDL_Flip() (or whatever screen update function you’re using, whether for SDL or OpenGL) and check the fps and compare this to the fps without the stuff you put in (drawing routine?) and without SDL_Flip(). This will avoid SDL_Flip()'s vsync at least. You won’t be able to see what’s happening, of course, so output the fps to a text file.

Date: Mon, 4 Dec 2006 13:46:54 +0100From: thephantomlord at gmail.comTo: cal at splitreflection.com; sdl at libsdl.orgSubject: Re: [SDL] Perfomance problem with SDL+OpenGL

Thx for all guys, I’d just though that more frame rate (more than vertical refresh) would be better! :rolleyes:

So, theres no trouble with getting that fps…

C Ya!
Sun, 3 Dec 2006 16:12:7, cal at splitreflection.com < cal at splitreflection.com>:
“Simon Roby” <simon.roby at gmail.com > wrote:> This is not a performance problem! Vertical retrace syncing (aka. > vsync) prevents your program from updating the screen more often than > it isrefreshed on your display.—I’ve seen claims that pushing frame rate to hundreds of frames/second makes a game more responsive. For a simplistic algorithm this can be the case. But if the input processing properly accounts for the possability for a ‘button’ being pressed and released during a frame, 20-30 frames/second can be suprisingly responsive. I agree that there’s no point in a frame rate faster than vertical refresh. _______________________________________________SDL mailing listSDL at libsdl.orghttp://www.libsdl.org/mailman/listinfo/sdl – Phantom LordCaelis Studios —> From Gods Hands To Yours

Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today! Try it now! _______________________________________________SDL mailing listSDL at libsdl.orghttp://www.libsdl.org/mailman/listinfo/sdl-- Phantom LordCaelis Studios —> From Gods Hands To Yours


All-in-one security and maintenance for your PC.? Get a free 90-day trial!
http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail

Hello list,

About the performance problem, I’m wondering, I just spent 1h
wondering what was slowing my app, to finaly found it was:

glPushAttrib(GL_ENABLE_BIT);

I had a little error, and I was calling it 400 times per frame
instead of 1. But it reduced my fps from 400 to 30.

I’m on macosx, coding everything with Xcode.

I know it may be a bit off topic, but I wondered if SDL or maybe any
other tool where helpful for debuging those performance bottleneck.

Regards–
Kuon
CEO - Goyman.com SA
http://www.goyman.com/

“Computers should not stop working when the users’ brain does.”

-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2434 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20061210/a25755f4/attachment.bin

Hello Nicolas,

Saturday, December 9, 2006, 11:36:15 PM, you wrote:

Hello list,

About the performance problem, I’m wondering, I just spent 1h
wondering what was slowing my app, to finaly found it was:

glPushAttrib(GL_ENABLE_BIT);

I had a little error, and I was calling it 400 times per frame
instead of 1. But it reduced my fps from 400 to 30.

I’m on macosx, coding everything with Xcode.

I know it may be a bit off topic, but I wondered if SDL or maybe any
other tool where helpful for debuging those performance bottleneck.

OpenGL Profiler on the Mac should be able to tell you this.–
Best regards,
Peter mailto:@Peter_Mulholland