added re-initialization of textures after change of renderer
authorHolger Schemel <info@artsoft.org>
Sun, 7 Feb 2016 22:52:03 +0000 (23:52 +0100)
committerHolger Schemel <info@artsoft.org>
Sun, 7 Feb 2016 22:52:03 +0000 (23:52 +0100)
src/init.c
src/init.h
src/libgame/image.c
src/libgame/image.h
src/libgame/sdl.c
src/tools.c

index e33a5adb8e7037d22a2fef9be46d92db6f3760ce..ca5d16b6be699cbf992e0d0983b8297456ef53b4 100644 (file)
@@ -226,7 +226,7 @@ void InitBitmapPointers()
       graphic_info[i].bitmap = graphic_info[i].bitmaps[IMG_BITMAP_STANDARD];
 }
 
-static void InitGlobalAnimImages()
+void InitImageTextures()
 {
   int i, j, k;
 
@@ -241,8 +241,8 @@ static void InitGlobalAnimImages()
        if (graphic == IMG_UNDEFINED)
          continue;
 
-       // create textures from images for fast GPU blitting, if possible
-       CreateImageTextures(graphic);
+       // (re)create textures from images for fast GPU blitting, if possible
+       ReCreateImageTextures(graphic);
       }
     }
   }
@@ -2026,8 +2026,9 @@ static void ReinitializeGraphics()
   print_timestamp_time("InitFontGraphicInfo");
   InitGlobalAnimGraphicInfo();         /* initialize global animation config */
   print_timestamp_time("InitGlobalAnimGraphicInfo");
-  InitGlobalAnimImages();              /* initialize global animation images */
-  print_timestamp_time("InitGlobalAnimImages");
+
+  InitImageTextures();                 /* create textures for certain images */
+  print_timestamp_time("InitImageTextures");
 
   InitGraphicInfo_EM();                        /* graphic mapping for EM engine */
   print_timestamp_time("InitGraphicInfo_EM");
index 9c6185f7bdda42b5239fd2490336fdf95384a876..ab14b75de2e7e623d67396172e24f8ab7e3e1405 100644 (file)
@@ -43,6 +43,7 @@ void KeyboardAutoRepeatOffUnlessAutoplay();
 
 void InitGfxBuffers();
 void InitGadgets();
+void InitImageTextures();
 
 void DisplayExitMessage(char *, va_list);
 
index 2275bc73544b657313149d1cc9652c4a40484b0f..16b4574dab2022311cca9d25931efb07c16f56c5 100644 (file)
@@ -351,11 +351,11 @@ void CreateImageWithSmallImages(int pos, int zoom_factor, int tile_size)
   setString(&img_info->leveldir, leveldir_current->identifier);
 }
 
-void CreateImageTextures(int pos)
+static void CreateImageTexturesExt(int pos, boolean force)
 {
   ImageInfo *img_info = getImageInfoEntryFromImageID(pos);
 
-  if (img_info == NULL || img_info->contains_textures)
+  if (img_info == NULL || (img_info->contains_textures && !force))
     return;
 
   CreateBitmapTextures(img_info->bitmaps);
@@ -363,6 +363,16 @@ void CreateImageTextures(int pos)
   img_info->contains_textures = TRUE;
 }
 
+void CreateImageTextures(int pos)
+{
+  CreateImageTexturesExt(pos, FALSE);
+}
+
+void ReCreateImageTextures(int pos)
+{
+  CreateImageTexturesExt(pos, TRUE);
+}
+
 void ScaleImage(int pos, int zoom_factor)
 {
   ImageInfo *img_info = getImageInfoEntryFromImageID(pos);
index 627694c04a38c0a288a1e2c9a9027f58aacfbba6..2d970823451c9a5d4a587853f2739d4b3cff21bb 100644 (file)
@@ -68,6 +68,7 @@ void InitImageList(struct ConfigInfo *, int, struct ConfigTypeInfo *,
 void ReloadCustomImages();
 void CreateImageWithSmallImages(int, int, int);
 void CreateImageTextures(int);
+void ReCreateImageTextures(int);
 void ScaleImage(int, int);
 
 void FreeAllImages();
index 0b2e1c1663064c7886a5cfe46e36f52db794deee..0759b549fe643dc5ace17a427b8b38f77b6dbd0c 100644 (file)
@@ -317,6 +317,11 @@ void SDLCreateBitmapTextures(Bitmap *bitmap)
   if (bitmap == NULL)
     return;
 
+  if (bitmap->texture)
+    SDL_DestroyTexture(bitmap->texture);
+  if (bitmap->texture_masked)
+    SDL_DestroyTexture(bitmap->texture_masked);
+
   bitmap->texture        = SDLCreateTextureFromSurface(bitmap->surface);
   bitmap->texture_masked = SDLCreateTextureFromSurface(bitmap->surface_masked);
 #endif
index e2352d185703d22585a66931c5e3a5ab07b199ac..dbeba50c151b71240f4558ffc780909718ec1f46 100644 (file)
@@ -8330,6 +8330,7 @@ void ChangeViewportPropertiesIfNeeded()
     // printf("::: init_video_buffer\n");
 
     InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
+    InitImageTextures();
   }
 
   if (init_gadgets_and_toons)