changed screen rendering mode from preprocessor to runtime configurable
authorHolger Schemel <info@artsoft.org>
Sun, 3 Apr 2016 11:16:48 +0000 (13:16 +0200)
committerHolger Schemel <info@artsoft.org>
Sun, 3 Apr 2016 11:17:30 +0000 (13:17 +0200)
src/files.c
src/libgame/sdl.c
src/libgame/sdl.h
src/libgame/system.c
src/libgame/system.h

index e5ca6168c5a3c5e4612d2460fad557ae3f0ce5a7..ebf045cb07aa52367ca0a579bb59051e3690f6e2 100644 (file)
@@ -7911,29 +7911,30 @@ void SaveScore(int nr)
 #define SETUP_TOKEN_FULLSCREEN                 17
 #define SETUP_TOKEN_WINDOW_SCALING_PERCENT     18
 #define SETUP_TOKEN_WINDOW_SCALING_QUALITY     19
-#define SETUP_TOKEN_ASK_ON_ESCAPE              20
-#define SETUP_TOKEN_ASK_ON_ESCAPE_EDITOR       21
-#define SETUP_TOKEN_QUICK_SWITCH               22
-#define SETUP_TOKEN_INPUT_ON_FOCUS             23
-#define SETUP_TOKEN_PREFER_AGA_GRAPHICS                24
-#define SETUP_TOKEN_GAME_FRAME_DELAY           25
-#define SETUP_TOKEN_SP_SHOW_BORDER_ELEMENTS    26
-#define SETUP_TOKEN_SMALL_GAME_GRAPHICS                27
-#define SETUP_TOKEN_SHOW_SNAPSHOT_BUTTONS      28
-#define SETUP_TOKEN_GRAPHICS_SET               29
-#define SETUP_TOKEN_SOUNDS_SET                 30
-#define SETUP_TOKEN_MUSIC_SET                  31
-#define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS    32
-#define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS      33
-#define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC       34
-#define SETUP_TOKEN_VOLUME_SIMPLE              35
-#define SETUP_TOKEN_VOLUME_LOOPS               36
-#define SETUP_TOKEN_VOLUME_MUSIC               37
-#define SETUP_TOKEN_TOUCH_CONTROL_TYPE         38
-#define SETUP_TOKEN_TOUCH_MOVE_DISTANCE                39
-#define SETUP_TOKEN_TOUCH_DROP_DISTANCE                40
-
-#define NUM_GLOBAL_SETUP_TOKENS                        41
+#define SETUP_TOKEN_SCREEN_RENDERING_MODE      20
+#define SETUP_TOKEN_ASK_ON_ESCAPE              21
+#define SETUP_TOKEN_ASK_ON_ESCAPE_EDITOR       22
+#define SETUP_TOKEN_QUICK_SWITCH               23
+#define SETUP_TOKEN_INPUT_ON_FOCUS             24
+#define SETUP_TOKEN_PREFER_AGA_GRAPHICS                25
+#define SETUP_TOKEN_GAME_FRAME_DELAY           26
+#define SETUP_TOKEN_SP_SHOW_BORDER_ELEMENTS    27
+#define SETUP_TOKEN_SMALL_GAME_GRAPHICS                28
+#define SETUP_TOKEN_SHOW_SNAPSHOT_BUTTONS      29
+#define SETUP_TOKEN_GRAPHICS_SET               30
+#define SETUP_TOKEN_SOUNDS_SET                 31
+#define SETUP_TOKEN_MUSIC_SET                  32
+#define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS    33
+#define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS      34
+#define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC       35
+#define SETUP_TOKEN_VOLUME_SIMPLE              36
+#define SETUP_TOKEN_VOLUME_LOOPS               37
+#define SETUP_TOKEN_VOLUME_MUSIC               38
+#define SETUP_TOKEN_TOUCH_CONTROL_TYPE         39
+#define SETUP_TOKEN_TOUCH_MOVE_DISTANCE                40
+#define SETUP_TOKEN_TOUCH_DROP_DISTANCE                41
+
+#define NUM_GLOBAL_SETUP_TOKENS                        42
 
 /* editor setup */
 #define SETUP_TOKEN_EDITOR_EL_BOULDERDASH      0
@@ -8085,6 +8086,7 @@ static struct TokenInfo global_setup_tokens[] =
   { TYPE_SWITCH, &si.fullscreen,              "fullscreen"             },
   { TYPE_INTEGER,&si.window_scaling_percent,  "window_scaling_percent" },
   { TYPE_STRING, &si.window_scaling_quality,  "window_scaling_quality" },
+  { TYPE_STRING, &si.screen_rendering_mode,   "screen_rendering_mode"  },
   { TYPE_SWITCH, &si.ask_on_escape,           "ask_on_escape"          },
   { TYPE_SWITCH, &si.ask_on_escape_editor,    "ask_on_escape_editor"   },
   { TYPE_SWITCH, &si.quick_switch,            "quick_player_switch"    },
@@ -8266,6 +8268,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->fullscreen = FALSE;
   si->window_scaling_percent = STD_WINDOW_SCALING_PERCENT;
   si->window_scaling_quality = getStringCopy(SCALING_QUALITY_DEFAULT);
+  si->screen_rendering_mode = getStringCopy(STR_SPECIAL_RENDERING_DEFAULT);
   si->ask_on_escape = TRUE;
   si->ask_on_escape_editor = TRUE;
   si->quick_switch = FALSE;
index 4d303910b57628c4ed7169b4839d0ffc341e30ba..d1bbe6efb28a1364ca4cde856b835c7553180f80 100644 (file)
 
 /* SDL internal variables */
 #if defined(TARGET_SDL2)
-#define USE_TARGET_TEXTURE             TRUE
-#define USE_TARGET_TEXTURE_ONLY                FALSE
-
 static SDL_Window *sdl_window = NULL;
 static SDL_Renderer *sdl_renderer = NULL;
-#if USE_TARGET_TEXTURE
 static SDL_Texture *sdl_texture_stream = NULL;
 static SDL_Texture *sdl_texture_target = NULL;
-#else
-static SDL_Texture *sdl_texture = NULL;
-#endif
 static boolean fullscreen_enabled = FALSE;
 #endif
 
@@ -93,10 +86,9 @@ static void UpdateScreen(SDL_Rect *rect)
   }
 #endif
 
-#if USE_FINAL_SCREEN_BITMAP
-  if (gfx.final_screen_bitmap != NULL) // may not be initialized yet
+  if (video.screen_rendering_mode == SPECIAL_RENDERING_BITMAP &&
+      gfx.final_screen_bitmap != NULL) // may not be initialized yet
   {
-    // !!! TEST !!!
     // draw global animations using bitmaps instead of using textures
     // to prevent texture scaling artefacts (this is potentially slower)
 
@@ -110,17 +102,13 @@ static void UpdateScreen(SDL_Rect *rect)
     // force full window redraw
     rect = NULL;
   }
-#endif
 
-#if USE_TARGET_TEXTURE
-#if USE_TARGET_TEXTURE_ONLY
-  SDL_Texture *sdl_texture = sdl_texture_target;
-#else
+#if defined(TARGET_SDL2)
   SDL_Texture *sdl_texture = sdl_texture_stream;
-#endif
-#endif
 
-#if defined(TARGET_SDL2)
+  if (video.screen_rendering_mode == SPECIAL_RENDERING_TARGET)
+    sdl_texture = sdl_texture_target;
+
   if (rect)
   {
     int bytes_x = screen->pitch / video.width;
@@ -138,25 +126,25 @@ static void UpdateScreen(SDL_Rect *rect)
   // clear render target buffer
   SDL_RenderClear(sdl_renderer);
 
-#if USE_TARGET_TEXTURE
-  SDL_SetRenderTarget(sdl_renderer, sdl_texture_target);
+  // set renderer to use target texture for rendering
+  if (video.screen_rendering_mode == SPECIAL_RENDERING_TARGET ||
+      video.screen_rendering_mode == SPECIAL_RENDERING_DOUBLE)
+    SDL_SetRenderTarget(sdl_renderer, sdl_texture_target);
 
-  // copy backbuffer to render target buffer
-  if (sdl_texture != sdl_texture_target)
-    SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL);
-#else
-  // copy backbuffer to render target buffer
-  SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL);
-#endif
+  // copy backbuffer texture to render target buffer
+  if (video.screen_rendering_mode != SPECIAL_RENDERING_TARGET)
+    SDL_RenderCopy(sdl_renderer, sdl_texture_stream, NULL, NULL);
 
-#if !USE_FINAL_SCREEN_BITMAP
-  FinalizeScreen();
-#endif
+  if (video.screen_rendering_mode != SPECIAL_RENDERING_BITMAP)
+    FinalizeScreen();
 
-#if USE_TARGET_TEXTURE
-  SDL_SetRenderTarget(sdl_renderer, NULL);
-  SDL_RenderCopy(sdl_renderer, sdl_texture_target, NULL, NULL);
-#endif
+  // when using target texture, copy it to screen buffer
+  if (video.screen_rendering_mode == SPECIAL_RENDERING_TARGET ||
+      video.screen_rendering_mode == SPECIAL_RENDERING_DOUBLE)
+  {
+    SDL_SetRenderTarget(sdl_renderer, NULL);
+    SDL_RenderCopy(sdl_renderer, sdl_texture_target, NULL, NULL);
+  }
 
   // show render target buffer on screen
   SDL_RenderPresent(sdl_renderer);
@@ -382,6 +370,13 @@ void SDLInitVideoBuffer(boolean fullscreen)
 {
   video.window_scaling_percent = setup.window_scaling_percent;
   video.window_scaling_quality = setup.window_scaling_quality;
+  video.screen_rendering_mode =
+    (strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_BITMAP) ?
+     SPECIAL_RENDERING_BITMAP :
+     strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_TARGET) ?
+     SPECIAL_RENDERING_TARGET:
+     strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_DOUBLE) ?
+     SPECIAL_RENDERING_DOUBLE : SPECIAL_RENDERING_OFF);
 
 #if defined(TARGET_SDL2)
   // SDL 2.0: support for (desktop) fullscreen mode available
@@ -454,7 +449,6 @@ static boolean SDLCreateScreen(boolean fullscreen)
   video.window_width  = window_scaling_factor * width;
   video.window_height = window_scaling_factor * height;
 
-#if USE_TARGET_TEXTURE
   if (sdl_texture_stream)
   {
     SDL_DestroyTexture(sdl_texture_stream);
@@ -466,13 +460,6 @@ static boolean SDLCreateScreen(boolean fullscreen)
     SDL_DestroyTexture(sdl_texture_target);
     sdl_texture_target = NULL;
   }
-#else
-  if (sdl_texture)
-  {
-    SDL_DestroyTexture(sdl_texture);
-    sdl_texture = NULL;
-  }
-#endif
 
   if (!(fullscreen && fullscreen_enabled))
   {
@@ -517,7 +504,6 @@ static boolean SDLCreateScreen(boolean fullscreen)
       // SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
       SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, setup.window_scaling_quality);
 
-#if USE_TARGET_TEXTURE
       sdl_texture_stream = SDL_CreateTexture(sdl_renderer,
                                             SDL_PIXELFORMAT_ARGB8888,
                                             SDL_TEXTUREACCESS_STREAMING,
@@ -527,19 +513,9 @@ static boolean SDLCreateScreen(boolean fullscreen)
                                             SDL_PIXELFORMAT_ARGB8888,
                                             SDL_TEXTUREACCESS_TARGET,
                                             width, height);
-#else
-      sdl_texture = SDL_CreateTexture(sdl_renderer,
-                                     SDL_PIXELFORMAT_ARGB8888,
-                                     SDL_TEXTUREACCESS_STREAMING,
-                                     width, height);
-#endif
 
-#if USE_TARGET_TEXTURE
       if (sdl_texture_stream != NULL &&
          sdl_texture_target != NULL)
-#else
-      if (sdl_texture != NULL)
-#endif
       {
        // use SDL default values for RGB masks and no alpha channel
        new_surface = SDL_CreateRGBSurface(0, width, height, 32, 0,0,0, 0);
@@ -649,6 +625,13 @@ boolean SDLSetVideoMode(boolean fullscreen)
       video.fullscreen_enabled = FALSE;
       video.window_scaling_percent = setup.window_scaling_percent;
       video.window_scaling_quality = setup.window_scaling_quality;
+      video.screen_rendering_mode =
+       (strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_BITMAP) ?
+        SPECIAL_RENDERING_BITMAP :
+        strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_TARGET) ?
+        SPECIAL_RENDERING_TARGET:
+        strEqual(setup.screen_rendering_mode, STR_SPECIAL_RENDERING_DOUBLE) ?
+        SPECIAL_RENDERING_DOUBLE : SPECIAL_RENDERING_OFF);
     }
   }
 
@@ -722,7 +705,6 @@ void SDLSetWindowScaling(int window_scaling_percent)
 
 void SDLSetWindowScalingQuality(char *window_scaling_quality)
 {
-#if USE_TARGET_TEXTURE
   SDL_Texture *new_texture;
 
   if (sdl_texture_stream == NULL ||
@@ -757,27 +739,6 @@ void SDLSetWindowScalingQuality(char *window_scaling_quality)
 
   SDLRedrawWindow();
 
-#else
-  if (sdl_texture == NULL)
-    return;
-
-  SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, window_scaling_quality);
-
-  SDL_Texture *new_texture = SDL_CreateTexture(sdl_renderer,
-                                              SDL_PIXELFORMAT_ARGB8888,
-                                              SDL_TEXTUREACCESS_STREAMING,
-                                              video.width, video.height);
-
-  if (new_texture != NULL)
-  {
-    SDL_DestroyTexture(sdl_texture);
-
-    sdl_texture = new_texture;
-
-    SDLRedrawWindow();
-  }
-#endif
-
   video.window_scaling_quality = window_scaling_quality;
 }
 
index 3b3266178c56aed9820ace30e8e7d0bc2b76b1d7..ae877957aed0d8261b2435a38e76afadf17cbeea 100644 (file)
 #define FULLSCREEN_STATUS      FULLSCREEN_AVAILABLE
 #endif
 
-#if defined(TARGET_SDL2)
-#define USE_FINAL_SCREEN_BITMAP        FALSE
-#else
-#define USE_FINAL_SCREEN_BITMAP        TRUE
-#endif
-
 #define CURSOR_MAX_WIDTH       32
 #define CURSOR_MAX_HEIGHT      32
 
index 3e49544cecc5f34918957491756ac27b5b194d7e..595daad7bd3fc148b43b0035fd8bc49b50d51f75 100644 (file)
@@ -209,9 +209,7 @@ void InitGfxWindowInfo(int win_xsize, int win_ysize)
   ReCreateBitmap(&gfx.background_bitmap, win_xsize, win_ysize, DEFAULT_DEPTH);
 
 #if defined(TARGET_SDL2)
-#if USE_FINAL_SCREEN_BITMAP
   ReCreateBitmap(&gfx.final_screen_bitmap, win_xsize, win_ysize, DEFAULT_DEPTH);
-#endif
 #endif
 
   ReCreateBitmap(&gfx.fade_bitmap_source, win_xsize, win_ysize, DEFAULT_DEPTH);
@@ -766,12 +764,11 @@ void BlitToScreen(Bitmap *bitmap,
   if (bitmap == NULL)
     return;
 
-#if USE_FINAL_SCREEN_BITMAP
-  BlitBitmap(bitmap, gfx.final_screen_bitmap, src_x, src_y,
-            width, height, dst_x, dst_y);
-#else
-  BlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y);
-#endif
+  if (video.screen_rendering_mode == SPECIAL_RENDERING_BITMAP)
+    BlitBitmap(bitmap, gfx.final_screen_bitmap, src_x, src_y,
+              width, height, dst_x, dst_y);
+  else
+    BlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y);
 }
 
 void BlitToScreenMasked(Bitmap *bitmap,
@@ -781,12 +778,11 @@ void BlitToScreenMasked(Bitmap *bitmap,
   if (bitmap == NULL)
     return;
 
-#if USE_FINAL_SCREEN_BITMAP
-  BlitBitmapMasked(bitmap, gfx.final_screen_bitmap, src_x, src_y,
-                  width, height, dst_x, dst_y);
-#else
-  BlitTextureMasked(bitmap, src_x, src_y, width, height, dst_x, dst_y);
-#endif
+  if (video.screen_rendering_mode == SPECIAL_RENDERING_BITMAP)
+    BlitBitmapMasked(bitmap, gfx.final_screen_bitmap, src_x, src_y,
+                    width, height, dst_x, dst_y);
+  else
+    BlitTextureMasked(bitmap, src_x, src_y, width, height, dst_x, dst_y);
 }
 
 void DrawSimpleBlackLine(Bitmap *bitmap, int from_x, int from_y,
index 593b245010806f0224515685d3cfd9ba135845f9..110e18c2392c3f462650f69e5ad0cf36bb246c29 100644 (file)
 
 #define SCALING_QUALITY_DEFAULT                SCALING_QUALITY_LINEAR
 
+/* values for screen rendering mode */
+#define STR_SPECIAL_RENDERING_OFF      "stream_texture_only"
+#define STR_SPECIAL_RENDERING_BITMAP   "bitmap_and_stream_texture"
+#define STR_SPECIAL_RENDERING_TARGET   "target_texture_only"
+#define STR_SPECIAL_RENDERING_DOUBLE   "stream_and_target_texture"
+
+#if defined(TARGET_SDL2)
+#define STR_SPECIAL_RENDERING_DEFAULT  STR_SPECIAL_RENDERING_DOUBLE
+#else
+#define STR_SPECIAL_RENDERING_DEFAULT  STR_SPECIAL_RENDERING_BITMAP
+#endif
+
+#define SPECIAL_RENDERING_OFF          0
+#define SPECIAL_RENDERING_BITMAP       1
+#define SPECIAL_RENDERING_TARGET       2
+#define SPECIAL_RENDERING_DOUBLE       3
+
+#if defined(TARGET_SDL2)
+#define SPECIAL_RENDERING_DEFAULT      SPECIAL_RENDERING_DOUBLE
+#else
+#define SPECIAL_RENDERING_DEFAULT      SPECIAL_RENDERING_BITMAP
+#endif
+
 /* values for touch control */
 #define TOUCH_CONTROL_VIRTUAL_BUTTONS  "virtual_buttons"
 #define TOUCH_CONTROL_WIPE_GESTURES    "wipe_gestures"
@@ -743,6 +766,7 @@ struct VideoSystemInfo
   boolean window_scaling_available;
   int window_scaling_percent;
   char *window_scaling_quality;
+  int screen_rendering_mode;
 
   boolean initialized;
 };
@@ -817,9 +841,7 @@ struct GfxInfo
   int fade_border_target_status;
   Bitmap *masked_border_bitmap_ptr;
 
-#if USE_FINAL_SCREEN_BITMAP
   Bitmap *final_screen_bitmap;
-#endif
 
   boolean clipping_enabled;
   int clip_x, clip_y;
@@ -1006,6 +1028,7 @@ struct SetupInfo
   boolean fullscreen;
   int window_scaling_percent;
   char *window_scaling_quality;
+  char *screen_rendering_mode;
   boolean ask_on_escape;
   boolean ask_on_escape_editor;
   boolean quick_switch;