From: Holger Schemel Date: Tue, 9 Feb 2016 22:54:54 +0000 (+0100) Subject: fixed re-initialization of textures after change of renderer X-Git-Tag: 4.0.0.0-rc1~80 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=0a69f419ffadee5822bc103be9e85d378e0d0274;p=rocksndiamonds.git fixed re-initialization of textures after change of renderer --- diff --git a/src/init.c b/src/init.c index ca5d16b6..375bf6a3 100644 --- a/src/init.c +++ b/src/init.c @@ -230,6 +230,8 @@ void InitImageTextures() { int i, j, k; + FreeAllImageTextures(); + for (i = 0; i < NUM_GLOBAL_ANIMS; i++) { for (j = 0; j < NUM_GLOBAL_ANIM_PARTS_ALL; j++) @@ -241,8 +243,7 @@ void InitImageTextures() if (graphic == IMG_UNDEFINED) continue; - // (re)create textures from images for fast GPU blitting, if possible - ReCreateImageTextures(graphic); + CreateImageTextures(graphic); } } } diff --git a/src/libgame/image.c b/src/libgame/image.c index 16b4574d..76d9b183 100644 --- a/src/libgame/image.c +++ b/src/libgame/image.c @@ -351,11 +351,11 @@ void CreateImageWithSmallImages(int pos, int zoom_factor, int tile_size) setString(&img_info->leveldir, leveldir_current->identifier); } -static void CreateImageTexturesExt(int pos, boolean force) +void CreateImageTextures(int pos) { ImageInfo *img_info = getImageInfoEntryFromImageID(pos); - if (img_info == NULL || (img_info->contains_textures && !force)) + if (img_info == NULL || img_info->contains_textures) return; CreateBitmapTextures(img_info->bitmaps); @@ -363,14 +363,25 @@ static void CreateImageTexturesExt(int pos, boolean force) img_info->contains_textures = TRUE; } -void CreateImageTextures(int pos) +void FreeImageTextures(int pos) { - CreateImageTexturesExt(pos, FALSE); + ImageInfo *img_info = getImageInfoEntryFromImageID(pos); + + if (img_info == NULL || !img_info->contains_textures) + return; + + FreeBitmapTextures(img_info->bitmaps); + + img_info->contains_textures = FALSE; } -void ReCreateImageTextures(int pos) +void FreeAllImageTextures() { - CreateImageTexturesExt(pos, TRUE); + int num_images = getImageListSize(); + int i; + + for (i = 0; i < num_images; i++) + FreeImageTextures(i); } void ScaleImage(int pos, int zoom_factor) diff --git a/src/libgame/image.h b/src/libgame/image.h index 2d970823..76ff3509 100644 --- a/src/libgame/image.h +++ b/src/libgame/image.h @@ -68,7 +68,7 @@ void InitImageList(struct ConfigInfo *, int, struct ConfigTypeInfo *, void ReloadCustomImages(); void CreateImageWithSmallImages(int, int, int); void CreateImageTextures(int); -void ReCreateImageTextures(int); +void FreeAllImageTextures(); void ScaleImage(int, int); void FreeAllImages(); diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 7fbd38f7..d431aacf 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -349,6 +349,22 @@ void SDLCreateBitmapTextures(Bitmap *bitmap) #endif } +void SDLFreeBitmapTextures(Bitmap *bitmap) +{ +#if defined(TARGET_SDL2) + if (bitmap == NULL) + return; + + 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 SDLInitVideoDisplay(void) { #if !defined(TARGET_SDL2) diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 7cc3b459..121b15bf 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -435,6 +435,7 @@ struct MouseCursorInfo boolean SDLSetNativeSurface(SDL_Surface **); SDL_Surface *SDLGetNativeSurface(SDL_Surface *); void SDLCreateBitmapTextures(Bitmap *); +void SDLFreeBitmapTextures(Bitmap *); #if defined(TARGET_SDL2) SDL_Surface *SDL_DisplayFormat(SDL_Surface *); diff --git a/src/libgame/system.c b/src/libgame/system.c index 40b1aaa4..a52b4ec2 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -1190,6 +1190,11 @@ void CreateBitmapTextures(Bitmap **bitmaps) SDLCreateBitmapTextures(bitmaps[IMG_BITMAP_STANDARD]); } +void FreeBitmapTextures(Bitmap **bitmaps) +{ + SDLFreeBitmapTextures(bitmaps[IMG_BITMAP_STANDARD]); +} + void ScaleBitmap(Bitmap **bitmaps, int zoom_factor) { CreateScaledBitmaps(bitmaps, zoom_factor, 0, FALSE); diff --git a/src/libgame/system.h b/src/libgame/system.h index 875a6540..107d5ae0 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1377,6 +1377,7 @@ Bitmap *ZoomBitmap(Bitmap *, int, int); void ReCreateGameTileSizeBitmap(Bitmap **); void CreateBitmapWithSmallBitmaps(Bitmap **, int, int); void CreateBitmapTextures(Bitmap **); +void FreeBitmapTextures(Bitmap **); void ScaleBitmap(Bitmap **, int); void SetMouseCursor(int);