X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsdl.c;h=71f6cf171ec796583b48dd40e09ddf05728cdc20;hb=d77d7ac6d22b63ff3e10608e54c7ac919915fae9;hp=3ab03783ba16a33a1da73c7c76362b368118368b;hpb=8bc9d8febda30d07142948f6b892365d3e11a940;p=rocksndiamonds.git diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 3ab03783..71f6cf17 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -286,6 +286,30 @@ SDL_Surface *SDLGetNativeSurface(SDL_Surface *surface) #endif +#if defined(TARGET_SDL2) +static SDL_Texture *SDLCreateTextureFromSurface(SDL_Surface *surface) +{ + SDL_Texture *texture = SDL_CreateTextureFromSurface(sdl_renderer, surface); + + if (texture == NULL) + Error(ERR_EXIT, "SDL_CreateTextureFromSurface() failed: %s", + SDL_GetError()); + + return texture; +} +#endif + +void SDLCreateBitmapTextures(Bitmap *bitmap) +{ +#if defined(TARGET_SDL2) + if (bitmap == NULL) + return; + + bitmap->texture = SDLCreateTextureFromSurface(bitmap->surface); + bitmap->texture_masked = SDLCreateTextureFromSurface(bitmap->surface_masked); +#endif +} + void SDLInitVideoDisplay(void) { #if !defined(TARGET_SDL2) @@ -871,8 +895,19 @@ void SDLFreeBitmapPointers(Bitmap *bitmap) SDL_FreeSurface(bitmap->surface); if (bitmap->surface_masked) SDL_FreeSurface(bitmap->surface_masked); + bitmap->surface = NULL; bitmap->surface_masked = NULL; + +#if defined(TARGET_SDL2) + if (bitmap->texture) + SDL_DestroyTexture(bitmap->texture); + if (bitmap->texture_masked) + SDL_DestroyTexture(bitmap->texture_masked); + + bitmap->texture = NULL; + bitmap->texture_masked = NULL; +#endif } void SDLCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap,