fixed re-initialization of textures after change of renderer
authorHolger Schemel <info@artsoft.org>
Tue, 9 Feb 2016 22:54:54 +0000 (23:54 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 9 Feb 2016 22:54:54 +0000 (23:54 +0100)
src/init.c
src/libgame/image.c
src/libgame/image.h
src/libgame/sdl.c
src/libgame/sdl.h
src/libgame/system.c
src/libgame/system.h

index ca5d16b6be699cbf992e0d0983b8297456ef53b4..375bf6a3174e2c25204b7c95a3ceabe41a615d28 100644 (file)
@@ -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);
       }
     }
   }
index 16b4574dab2022311cca9d25931efb07c16f56c5..76d9b183b730b1ef85511a101d869038b18aa8c9 100644 (file)
@@ -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)
index 2d970823451c9a5d4a587853f2739d4b3cff21bb..76ff3509fa583b24f60229d15f3644cb09387d74 100644 (file)
@@ -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();
index 7fbd38f7de3f072a809ee218f06ea9da7093d153..d431aacf29c96c34d73b2a4db489d075608a5640 100644 (file)
@@ -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)
index 7cc3b459612f15556249ca3544657b7537f63b08..121b15bf65769f6fad34e2fe02565ea2bfbe0145 100644 (file)
@@ -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 *);
index 40b1aaa47945aec040da5b9141441baf02a2abac..a52b4ec201da7e9f2403ed5e73bf0406442d9cde 100644 (file)
@@ -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);
index 875a65400c9c5dd4b6bed756834686abf8bb1a47..107d5ae08aed10897ac9abbc841d1976df36b4c9 100644 (file)
@@ -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);