/* 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
limit_screen_updates = enable;
}
+static void FinalizeScreen()
+{
+ // copy global animations to render target buffer, if defined (below border)
+ if (gfx.draw_global_anim_function != NULL)
+ gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_1);
+
+ // copy global masked border to render target buffer, if defined
+ if (gfx.draw_global_border_function != NULL)
+ gfx.draw_global_border_function(DRAW_BORDER_TO_SCREEN);
+
+ // copy global animations to render target buffer, if defined (above border)
+ if (gfx.draw_global_anim_function != NULL)
+ gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_2);
+}
+
static void UpdateScreen(SDL_Rect *rect)
{
static unsigned int update_screen_delay = 0;
}
#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)
BlitBitmap(backbuffer, gfx.final_screen_bitmap, 0, 0,
gfx.win_xsize, gfx.win_ysize, 0, 0);
- // copy global animations to render target buffer, if defined (below border)
- if (gfx.draw_global_anim_function != NULL)
- gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_1);
-
- // copy global masked border to render target buffer, if defined
- if (gfx.draw_global_border_function != NULL)
- gfx.draw_global_border_function(DRAW_BORDER_TO_SCREEN);
-
- // copy global animations to render target buffer, if defined (above border)
- if (gfx.draw_global_anim_function != NULL)
- gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_2);
+ FinalizeScreen();
screen = gfx.final_screen_bitmap->surface;
// 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;
// clear render target buffer
SDL_RenderClear(sdl_renderer);
-#if USE_TARGET_TEXTURE
- 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
-
-#if !USE_FINAL_SCREEN_BITMAP
- // copy global animations to render target buffer, if defined (below border)
- if (gfx.draw_global_anim_function != NULL)
- gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_1);
+ // 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 global masked border to render target buffer, if defined
- if (gfx.draw_global_border_function != NULL)
- gfx.draw_global_border_function(DRAW_BORDER_TO_SCREEN);
+ // copy backbuffer texture to render target buffer
+ if (video.screen_rendering_mode != SPECIAL_RENDERING_TARGET)
+ SDL_RenderCopy(sdl_renderer, sdl_texture_stream, NULL, NULL);
- // copy global animations to render target buffer, if defined (above border)
- if (gfx.draw_global_anim_function != NULL)
- gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_2);
-#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);
#endif
}
-void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
- boolean fullscreen)
+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
#endif
/* open SDL video output device (window or fullscreen mode) */
- if (!SDLSetVideoMode(backbuffer, fullscreen))
+ if (!SDLSetVideoMode(fullscreen))
Error(ERR_EXIT, "setting video mode failed");
/* !!! SDL2 can only set the window icon if the window already exists !!! */
should never be drawn to directly, it would do no harm nevertheless. */
/* create additional (symbolic) buffer for double-buffering */
- ReCreateBitmap(window, video.width, video.height, video.depth);
+ ReCreateBitmap(&window, video.width, video.height, video.depth);
}
-static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
- boolean fullscreen)
+static boolean SDLCreateScreen(boolean fullscreen)
{
SDL_Surface *new_surface = NULL;
video.window_width = window_scaling_factor * width;
video.window_height = window_scaling_factor * height;
- if ((*backbuffer)->surface)
- {
- SDL_FreeSurface((*backbuffer)->surface);
- (*backbuffer)->surface = NULL;
- }
-
-#if USE_TARGET_TEXTURE
if (sdl_texture_stream)
{
SDL_DestroyTexture(sdl_texture_stream);
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))
{
// 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,
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);
#else // TARGET_SDL
- if ((*backbuffer)->surface)
- {
- SDL_FreeSurface((*backbuffer)->surface);
- (*backbuffer)->surface = NULL;
- }
-
if (gfx.final_screen_bitmap == NULL)
gfx.final_screen_bitmap = CreateBitmapStruct();
fullscreen_enabled = fullscreen;
#endif
- return new_surface;
+ if (backbuffer == NULL)
+ backbuffer = CreateBitmapStruct();
+
+ backbuffer->width = video.width;
+ backbuffer->height = video.height;
+
+ if (backbuffer->surface)
+ SDL_FreeSurface(backbuffer->surface);
+
+ backbuffer->surface = new_surface;
+
+ return (new_surface != NULL);
}
-boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
+boolean SDLSetVideoMode(boolean fullscreen)
{
- boolean success = TRUE;
- SDL_Surface *new_surface = NULL;
+ boolean success = FALSE;
SetWindowTitle();
- if (*backbuffer == NULL)
- *backbuffer = CreateBitmapStruct();
-
- /* (real bitmap might be larger in fullscreen mode with video offsets) */
- (*backbuffer)->width = video.width;
- (*backbuffer)->height = video.height;
-
if (fullscreen && !video.fullscreen_enabled && video.fullscreen_available)
{
/* switch display to fullscreen mode, if available */
- new_surface = SDLCreateScreen(backbuffer, TRUE);
+ success = SDLCreateScreen(TRUE);
- if (new_surface == NULL)
+ if (!success)
{
/* switching display to fullscreen mode failed -- do not try it again */
video.fullscreen_available = FALSE;
-
- success = FALSE;
}
else
{
- (*backbuffer)->surface = new_surface;
-
video.fullscreen_enabled = TRUE;
-
- success = TRUE;
}
}
- if ((!fullscreen && video.fullscreen_enabled) || new_surface == NULL)
+ if ((!fullscreen && video.fullscreen_enabled) || !success)
{
/* switch display to window mode */
- new_surface = SDLCreateScreen(backbuffer, FALSE);
+ success = SDLCreateScreen(FALSE);
- if (new_surface == NULL)
+ if (!success)
{
/* switching display to window mode failed -- should not happen */
-
- success = FALSE;
}
else
{
- (*backbuffer)->surface = new_surface;
-
video.fullscreen_enabled = FALSE;
video.window_scaling_percent = setup.window_scaling_percent;
video.window_scaling_quality = setup.window_scaling_quality;
-
- success = TRUE;
+ 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);
}
}
void SDLSetWindowScalingQuality(char *window_scaling_quality)
{
-#if USE_TARGET_TEXTURE
SDL_Texture *new_texture;
if (sdl_texture_stream == NULL ||
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;
}
+void SDLSetScreenRenderingMode(char *screen_rendering_mode)
+{
+ video.screen_rendering_mode =
+ (strEqual(screen_rendering_mode, STR_SPECIAL_RENDERING_BITMAP) ?
+ SPECIAL_RENDERING_BITMAP :
+ strEqual(screen_rendering_mode, STR_SPECIAL_RENDERING_TARGET) ?
+ SPECIAL_RENDERING_TARGET:
+ strEqual(screen_rendering_mode, STR_SPECIAL_RENDERING_DOUBLE) ?
+ SPECIAL_RENDERING_DOUBLE : SPECIAL_RENDERING_OFF);
+}
+
void SDLSetWindowFullscreen(boolean fullscreen)
{
if (sdl_window == NULL)
SDL_FillRect(real_dst_bitmap->surface, &rect, color);
-#if defined(TARGET_SDL2)
- if (dst_bitmap == window)
- {
- // SDL_UpdateWindowSurface(sdl_window);
- // SDL_UpdateWindowSurfaceRects(sdl_window, &rect, 1);
- UpdateScreen(&rect);
- }
-#else
if (dst_bitmap == window)
- {
- // SDL_UpdateRect(backbuffer->surface, x, y, width, height);
UpdateScreen(&rect);
- }
-#endif
}
void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,