I’ve been playing around with SDL for a few days now (on a
PII 400 with a Matrox Millennium G200 video card and a
standard redhat 7.1 setup). I’ve just been trying to set
the value of each pixel to try and find the maximum
framerate I can get by writing each pixel for each frame.
I haven’t had any trouble getting it to work, but it just
seems really slow. At 640x480x32 I can only get about 8
fps. I tried writing directly to the hardware buffer as
well as writing to a buffer in system memory and then
blitting it, but the results were about the same.
Here’s what I’m doing to plot a screenful of pixels:
where pscreen is a pointer to the pixel data and sw_surface
is a pointer to an SDL_Surface.
Any suggestions?
first: always double-check that all surfaces have the same format,
and SDL_MapRGB() is not really designed to be used in realtime
you are calling a function in a dynamic library, the function itself is
pretty generic…
just build the color outside the loop:
where pscreen is a pointer to the pixel data and sw_surface
is a pointer to an SDL_Surface.
Any suggestions?
first: always double-check that all surfaces have the same format,
and SDL_MapRGB() is not really designed to be used in realtime
you are calling a function in a dynamic library, the function itself is
pretty generic…
just build the color outside the loop:
pscreen+=sw_buffer->pitch / 4 - x;
with
pscreen+=(sw_buffer->pitch>>2) - x;
since bit shifting is much faster than division/multiplication.
modern compilers will see divide-by-numeric-literal and replace it.
The gcc will do this even on -O0 (optimize level 0). To have this in
C source code is a myth, only assembler programmers might benefit
from replacing these things.
first: always double-check that all surfaces have the same format,
and SDL_MapRGB() is not really designed to be used in realtime
you are calling a function in a dynamic library, the function itself is
pretty generic…
just build the color outside the loop:
Thanks everybody for your help. Gautier’s suggestion ended
up more than doubling the frame rate. THe problem is, what
if I wanted to write pixel values as a function of x,y, and
time? Then I still have to call SDL_MapRGB in the inner
loop there or else build a huge 3D lookup table which
doesn’t sound very appealing. If I check the pixel format
beforehand, I suppose I could write my own My_MapRGB to
build up a color value depending on bpp and endianness of
the target machine. Does that sound like the best way to do
it?
If I check the pixel format
beforehand, I suppose I could write my own My_MapRGB to
build up a color value depending on bpp and endianness of
the target machine.
That’s how it’s usually done; you write code by hand for the most
important cases (your own hardware, and other formats in common use)
and provide a generic fallback solution for the rest. MapRGB/GetRGB are
mostly convenience functions; they aren’t really meant to be used in
an inner loop