Hey,
Thanks, for the answer,
I cannot use only the image loading process ! I am using Image loading, but
also, creating surface, combining images, drawing, calling external
libraries, rotating, zooming, etc.
So I tried the comparaison, and it almost worked ! I had to compare also
the flags of HWSURFACE.
To whom it may interest, here’s the function that tell if a Surface is
Display Optimised !
int sl_isSurfaceDisplayOptimised(SDL_Surface * surf)
{
SDL_Surface *screen = NULL;
screen = SDL_GetVideoSurface();
if (screen == NULL || screen->format == NULL)
{
return 0;
}
if (surf == NULL || surf->format == NULL)
{
return 0;
}
if (surf->format->BitsPerPixel == screen->format->BitsPerPixel
&& surf->format->Rmask == screen->format->Rmask
&& surf->format->Gmask == screen->format->Gmask
&& surf->format->Bmask == screen->format->Bmask)
{
if ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
{
if ((surf->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
{
return 1;
}
else
{
return 0;
}
}
return 1;
}
return 0;
}
Thanks,
SylvainOn Thu, Sep 27, 2012 at 2:46 PM, Jonathan Dearborn wrote:
The best way to do this is to rework the logic of your image loading so
that all images are optimized (once) right after they are created. This
can be simply done with an image loading wrapper like so:
SDL_Surface* loadImage(const char* filename)
{
SDL_Surface* temp = IMG_Load(filename);
if(!temp)
return NULL;
SDL_Surface* result = SDL_DisplayFormatAlpha(temp);
SDL_FreeSurface(temp);
return result;
}
Use something like this instead of IMG_Load() directly. This way there’s
no need to ever check whether an image is optimized. However, if your game
logic absolutely demands it, I would compare the
surface->format->BitsPerPixel, Rmask, Gmask, and Bmask of the display
surface and the surface in question.
Jonny D
On Thu, Sep 27, 2012 at 4:52 AM, Sylvain Becker <@Sylvain_Becker>wrote:
Hey,
I am using the SDL-1.2 for a tiny game that start to make many surface
convertions !
There is a function, called SDL_DisplayFormat, which convert any Surface
to the screen format, in order to optimise the speed of execution.
Sometimes, the surface optimisation is already done, and calling to many
times this function would create a slow-down ( I guess ?)
So, I am looking for a way to do a “smart” wrapper to this function, that
would avoid un-necessary call,
by checking if the initial input Surface is already optimised or not !
Is there a way to tell if the surface is already "DisplayFormat"
optimised ?
Thank you and best regards,
Sylvain
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org