Commit 1ecf4dfc5f95b584160c2dae7dddb51b7808ebcb

Ryan C. Gordon 2018-10-04T16:34:44

render: Added SDL_RenderFlush().

diff --git a/include/SDL_render.h b/include/SDL_render.h
index d336192..850e908 100644
--- a/include/SDL_render.h
+++ b/include/SDL_render.h
@@ -876,6 +876,31 @@ extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
  */
 extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
 
+/**
+ *  \brief Force the rendering context to flush any pending commands to the
+ *         underlying rendering API.
+ *
+ *  You do not need to (and in fact, shouldn't) call this function unless
+ *  you are planning to call into OpenGL/Direct3D/Metal/whatever directly
+ *  in addition to using an SDL_Renderer.
+ *
+ *  This is for a very-specific case: if you are using SDL's render API,
+ *  you asked for a specific renderer backend (OpenGL, Direct3D, etc),
+ *  you set SDL_HINT_RENDER_BATCHING to "1", and you plan to make
+ *  OpenGL/D3D/whatever calls in addition to SDL render API calls. If all of
+ *  this applies, you should call SDL_RenderFlush() between calls to SDL's
+ *  render API and the low-level API you're using in cooperation.
+ *
+ *  In all other cases, you can ignore this function. This is only here to
+ *  get maximum performance out of a specific situation. In all other cases,
+ *  SDL will do the right thing, perhaps at a performance loss.
+ *
+ *  This function is first available in SDL 2.0.10, and is not needed in
+ *  2.0.9 and earlier, as earlier versions did not queue rendering commands
+ *  at all, instead flushing them to the OS immediately.
+ */
+extern DECLSPEC int SDLCALL SDL_RenderFlush(SDL_Renderer * renderer);
+
 
 /**
  *  \brief Bind the texture to the current OpenGL/ES/ES2 context for use with
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index b1f029f..0006041 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -696,3 +696,4 @@
 #define SDL_SensorUpdate SDL_SensorUpdate_REAL
 #define SDL_IsTablet SDL_IsTablet_REAL
 #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL
+#define SDL_RenderFlush SDL_RenderFlush_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 6619f88..4461d55 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -738,3 +738,4 @@ SDL_DYNAPI_PROC(void,SDL_SensorClose,(SDL_Sensor *a),(a),)
 SDL_DYNAPI_PROC(void,SDL_SensorUpdate,(void),(),)
 SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return)
 SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetDisplayOrientation,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_RenderFlush,(SDL_Renderer *a),(a),return)
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 5c7e36d..5bbcd79 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -254,6 +254,12 @@ FlushRenderCommandsIfNotBatching(SDL_Renderer *renderer)
     return renderer->batching ? 0 : FlushRenderCommands(renderer);
 }
 
+int
+SDL_RenderFlush(SDL_Renderer * renderer)
+{
+    return FlushRenderCommands(renderer);
+}
+
 static SDL_AllocVertGap *
 AllocateVertexGap(SDL_Renderer *renderer)
 {