SDL_Flip is too slow

Hi guys,
i’m using SDL for changing some pixel every 8 mili second(at most) but
SDL_Flip is too slow and i can’t get what i want. this is the setting which
i use for SDL:

SDL_Surface *screen;
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT,
SCREEN_DEPTH,SDL_HWSURFACE);

and this is my set pixel code:

Uint32 *p;
for(some iteration){
p = (Uint32 *)screen->pixels + myPixelPosition;
*p=myPixelColor;
}
after setting pixels i call :
SDL_Flip();

but this process take more than 8 mili second, what’s wrong with my code?
thanks.

screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT,
SCREEN_DEPTH,SDL_HWSURFACE);
but this process take more than 8 mili second, what’s wrong with my code?

Try to open the videomode in fullscreen (SDL_FULLSCREEN) and with double
buffer on (SDL_DOUBLEBUFFER if I remember correctly).

I’m quite sure that on your current videomode settings HWSURFACE is
ignored, and SDL_Flip() does a simple copy of your back buffer to the
window.

Also with double buffering and fullscreen only a few targets support real
hardware surfaces, also, depending on your video drivers / OS SDL_Flip may
be synchronized with the vertical blank.

Anyway refresh a pixel more often than the pyhsical monitor refresh rate
(usually 60hz these days) is a waste of resources.On Tue, May 8, 2012 at 9:47 AM, Mohsen Jamali <mohsen.aria at gmail.com> wrote:


Bye,
Gabry

Same result, is there any way to write pixel colors to video memory without
calling SDL_Flip() ?
i know that in DirectX you just set the colors of the pixels and there is
no need to call any other function like SDL_Flip().On Tue, May 8, 2012 at 1:00 PM, Gabriele Greco <gabriele.greco at darts.it>wrote:

On Tue, May 8, 2012 at 9:47 AM, Mohsen Jamali <@Mohsen_Jamali>wrote:

screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT,
SCREEN_DEPTH,SDL_HWSURFACE);
but this process take more than 8 mili second, what’s wrong with my code?

Try to open the videomode in fullscreen (SDL_FULLSCREEN) and with double
buffer on (SDL_DOUBLEBUFFER if I remember correctly).

I’m quite sure that on your current videomode settings HWSURFACE is
ignored, and SDL_Flip() does a simple copy of your back buffer to the
window.

Also with double buffering and fullscreen only a few targets support real
hardware surfaces, also, depending on your video drivers / OS SDL_Flip may
be synchronized with the vertical blank.

Anyway refresh a pixel more often than the pyhsical monitor refresh rate
(usually 60hz these days) is a waste of resources.


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi,

Video cards don’t really do pixels anymore. They are highly
asynchronous massively parallel machines. You generally want to send a
whole batch of information at a time, not individual pixels. What is
your high level goal? There might be other ways of achieving it.

Without knowing this goal, all I can ask is have you tried using
SDL_UpdateRect() rather than SDL_Flip()?On 8 May 2012 10:38, Mohsen Jamali <mohsen.aria at gmail.com> wrote:

Same result, is there any way to write pixel colors to video memory without
calling SDL_Flip() ?
i know that in DirectX you just set the colors of the pixels and there is no
need to call any other function like SDL_Flip().

Same result, is there any way to write pixel colors to video memory
without calling SDL_Flip() ?
i know that in DirectX you just set the colors of the pixels and there is
no need to call any other function like SDL_Flip().

Yes, DOS allows you to do that, as did 3dfx Glide back in 1997. DirectX 8/9
doesn’t allow this either – you call IDirect3DDevice8/9::GetBackBuffer()
and then IDirect3DSurface8/9::LockRect()/UnlockRect(). If you’re running
Windows Vista or Windows 7 and using Aero, then your windows are composited
– you’re drawing to an offscreen surface and the then OS is drawing that
on the screen. The days of peek/poke are gone unless you’re running Linux
with fbdev.

PatrickOn Tue, May 8, 2012 at 4:38 AM, Mohsen Jamali <mohsen.aria at gmail.com> wrote:

Same result, is there any way to write pixel colors to video memory without
calling SDL_Flip() ?
i know that in DirectX you just set the colors of the pixels and there is
no need to call any other function like SDL_Flip().

You need to call SDL_UpdateRect ()

And pass it the bounding rectangle of the pixels you’ve just changed.

What’s probably happening in your instance is that your writing to a
software copy of the framebuffer and the hardware can’t bouble buffer and
to the flip for you, so when flip is called it’s doing a big block-move
from the software copy to the real framebuffer - and this takes time if
it’s not accellerated. (and even if it is accellerated!)

I’m seeing this now on the Raspberry Pi - there is no GPU assist at all as
far as I can tell for SDL type graphics - so stuff that was fine on my
workstation/laptop is grinding a bit on the Pi and I’ve had to start using
SDL_UpdateRect myself for things like interactive text entry as when I was
doing a whole screen update on each keystroke, it was not able to keep up
with auto-repeat…

GordonOn Tue, 8 May 2012, Mohsen Jamali wrote:

SDL_UpdateRect() works much better but is still slow!
i have attached a picture that shows some blue lines and they turn around
the circle every 3seconds. in each degree i should clear the current
pixdels and draw another some new line. the coordination of pixels have
calculated before and have loaded by a header file. for using
SDL_UpdateRect() i divide the screen to 4 square and according to each
degree call SDL_UpdateRect().
sorry for reply too late!On Tue, May 8, 2012 at 3:27 PM, Brian Barrett <brian.ripoff at gmail.com>wrote:

Hi,

Video cards don’t really do pixels anymore. They are highly
asynchronous massively parallel machines. You generally want to send a
whole batch of information at a time, not individual pixels. What is
your high level goal? There might be other ways of achieving it.

Without knowing this goal, all I can ask is have you tried using
SDL_UpdateRect() rather than SDL_Flip()?

On 8 May 2012 10:38, Mohsen Jamali <@Mohsen_Jamali> wrote:

Same result, is there any way to write pixel colors to video memory
without
calling SDL_Flip() ?
i know that in DirectX you just set the colors of the pixels and there
is no
need to call any other function like SDL_Flip().


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: Selection_076.png
Type: image/png
Size: 15333 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20120514/ae6b9805/attachment.png

if didn’t get answer is should use fbdevOn Tue, May 8, 2012 at 5:10 PM, Patrick Baggett <baggett.patrick at gmail.com>wrote:

On Tue, May 8, 2012 at 4:38 AM, Mohsen Jamali <@Mohsen_Jamali>wrote:

Same result, is there any way to write pixel colors to video memory
without calling SDL_Flip() ?
i know that in DirectX you just set the colors of the pixels and there is
no need to call any other function like SDL_Flip().

Yes, DOS allows you to do that, as did 3dfx Glide back in 1997. DirectX
8/9 doesn’t allow this either – you call
IDirect3DDevice8/9::GetBackBuffer() and then
IDirect3DSurface8/9::LockRect()/UnlockRect(). If you’re running Windows
Vista or Windows 7 and using Aero, then your windows are composited –
you’re drawing to an offscreen surface and the then OS is drawing that on
the screen. The days of peek/poke are gone unless you’re running Linux with
fbdev.

Patrick


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

in a forum i saw a code:
if(SDL_GetVideoSurface()->flags & SDL_HWSURFACE )
printf(“hard\n”);
else
printf(“soft\n”);
it say that my video mode is soft. i have set my setting to this:
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT,
SCREEN_DEPTH,SDL_DOUBLEBUF);
but it seems that double buffer doesn’t work on my laptop.On Tue, May 8, 2012 at 7:42 PM, Gordon Henderson <gordon+sdl at drogon.net>wrote:

On Tue, 8 May 2012, Mohsen Jamali wrote:

Same result, is there any way to write pixel colors to video memory

without
calling SDL_Flip() ?
i know that in DirectX you just set the colors of the pixels and there is
no need to call any other function like SDL_Flip().

You need to call SDL_UpdateRect ()

And pass it the bounding rectangle of the pixels you’ve just changed.

What’s probably happening in your instance is that your writing to a
software copy of the framebuffer and the hardware can’t bouble buffer and
to the flip for you, so when flip is called it’s doing a big block-move
from the software copy to the real framebuffer - and this takes time if
it’s not accellerated. (and even if it is accellerated!)

I’m seeing this now on the Raspberry Pi - there is no GPU assist at all as
far as I can tell for SDL type graphics - so stuff that was fine on my
workstation/laptop is grinding a bit on the Pi and I’ve had to start using
SDL_UpdateRect myself for things like interactive text entry as when I was
doing a whole screen update on each keystroke, it was not able to keep up
with auto-repeat…

Gordon

_____________**
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/**listinfo.cgi/sdl-libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

it say that my video mode is soft. i have set my setting to this:
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT,
SCREEN_DEPTH,SDL_DOUBLEBUF);
but it seems that double buffer doesn’t work on my laptop.

in order to get a hardware surface you need to run in fullscreen mode.
I’m hoping you’ve already tried something like this ? (see below, all
of you desired options are bitwise ORed together using the pipe " | "
symbol )

screen = SDL_SetVideoMode(SCREEN_WIDTH,
SCREEN_HEIGHT,SCREEN_DEPTH,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);–
Jason White

of course, i have tried that but it is in software mode! :(On Mon, May 14, 2012 at 10:52 PM, Jason White < whitewaterssoftwareinfo at gmail.com> wrote:

it say that my video mode is soft. i have set my setting to this:
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT,
SCREEN_DEPTH,SDL_DOUBLEBUF);
but it seems that double buffer doesn’t work on my laptop.

in order to get a hardware surface you need to run in fullscreen mode.
I’m hoping you’ve already tried something like this ? (see below, all
of you desired options are bitwise ORed together using the pipe " | "
symbol )

screen = SDL_SetVideoMode(SCREEN_WIDTH,
SCREEN_HEIGHT,SCREEN_DEPTH,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);


Jason White


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org