+void SDLLimitScreenUpdates(boolean enable)
+{
+ limit_screen_updates = enable;
+}
+
+static void UpdateScreen(SDL_Rect *rect)
+{
+ static unsigned int update_screen_delay = 0;
+ unsigned int update_screen_delay_value = 50; /* (milliseconds) */
+ SDL_Surface *screen = backbuffer->surface;
+
+ if (limit_screen_updates &&
+ !DelayReached(&update_screen_delay, update_screen_delay_value))
+ return;
+
+ LimitScreenUpdates(FALSE);
+
+#if 0
+ {
+ static int LastFrameCounter = 0;
+ boolean changed = (FrameCounter != LastFrameCounter);
+
+ printf("::: FrameCounter == %d [%s]\n", FrameCounter,
+ (changed ? "-" : "SAME FRAME UPDATED"));
+
+ LastFrameCounter = FrameCounter;
+
+ /*
+ if (FrameCounter % 2)
+ return;
+ */
+ }
+#endif
+
+#if USE_FINAL_SCREEN_BITMAP
+ if (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(REDRAW_ALL);
+
+ // 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);
+
+ screen = gfx.final_screen_bitmap->surface;
+
+ // force full window redraw
+ rect = NULL;
+ }
+#endif
+
+#if defined(TARGET_SDL2)
+#if USE_RENDERER
+ if (rect)
+ {
+ int bytes_x = screen->pitch / video.width;
+ int bytes_y = screen->pitch;
+
+ if (video.fullscreen_enabled)
+ bytes_x = screen->pitch / fullscreen_width;
+
+ SDL_UpdateTexture(sdl_texture, rect,
+ screen->pixels + rect->x * bytes_x + rect->y * bytes_y,
+ screen->pitch);
+ }
+ else
+ {
+ SDL_UpdateTexture(sdl_texture, NULL, screen->pixels, screen->pitch);
+ }
+
+ // clear render target buffer
+ SDL_RenderClear(sdl_renderer);
+
+ // copy backbuffer to render target buffer
+ SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL);
+
+#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);
+
+ // copy global masked border to render target buffer, if defined
+ if (gfx.draw_global_border_function != NULL)
+ gfx.draw_global_border_function(REDRAW_ALL);
+
+ // 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
+
+ // show render target buffer on screen
+ SDL_RenderPresent(sdl_renderer);
+
+#else
+
+ if (rect)
+ SDL_UpdateWindowSurfaceRects(sdl_window, rect, 1);
+ else
+ SDL_UpdateWindowSurface(sdl_window);
+#endif
+
+#else // TARGET_SDL
+ if (rect)
+ SDL_UpdateRects(screen, 1, rect);
+ else
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+#endif
+}
+