Yes. Where did you find that? in SDL_draw.c, I see[1]
68 void (*Draw_Pixel)(SDL_Surface *super,
69 Sint16 x, Sint16 y, Uint32 color) = Draw_Pixel_Init;
So calling “Draw_Pixel” the first time actually
* dereferences the Draw_Pixel pointer
* calls Draw_Pixel_Init()
* calls Draw_Init
* re-assigns the Draw_Pixel pointer to a
function specific to your bit-depth, e.g.
Draw_Pixel_4
* re-calls Draw_Pixel (involves a dereference)
* re-calls Draw_Pixel (involves a dereference)
This seems to be a way of avoiding the user of the library (I.e. you)
having to call an initialisation function before using the methods.
It’s also buggy, if I’ve read this correctly, drawing the first pixel
you specify twice.
It also means that each call to Draw_Pixel has an extra bit of
indirection involved over a normal function call. I did some tests a
while ago to see which is faster: the function-pointer based approach to
specifying a colourdepth-specific draw function or the switch-based that
is in the SDL docs. I was suprised to find that for small-medium numbers
of calls, the switch-based tended to be faster in my environment, with
the function-pointer method pulling ahead only once you are calling the
putpixel method millions of times in succession, certainly, many times
more than there were pixels in my surface (which I imagine no real-world
app will do)
[1]
http://sdl-draw.cvs.sourceforge.net/sdl-draw/sdl-draw/src/SDL_draw.c?view=markupOn Tue, Oct 09, 2007 at 10:55:36PM +0800, cocobear wrote:
I am reading the source code of SDL_draw library,here is the prototype
of Draw_Pixel function:
void Draw_Pixel(SDL_Surface *super,
Sint16 x, Sint16 y,
Uint32 color);
But I can’t find the implement of this function.
I can only find a function pointer of Draw_Pixel :
extern DECLSPEC
void (*Draw_Pixel)(SDL_Surface *super,
Sint16 x, Sint16 y, Uint32 color);
this is just a definition of Draw_Pixel(variable) ,isn’t it?
–
Jon Dowland