Added SDL_GetRenderTarget() API function
authorSam Lantinga <slouken@libsdl.org>
Fri, 12 Oct 2012 02:20:10 -0700
changeset 6578 77d70ec131bc
parent 6577 d38491853506
child 6579 2390a7403b77
Added SDL_GetRenderTarget() API function Also fixed a bug with setting logical size for a render target.
include/SDL_render.h
src/render/SDL_render.c
--- a/include/SDL_render.h	Thu Oct 11 15:05:00 2012 -0700
+++ b/include/SDL_render.h	Fri Oct 12 02:20:10 2012 -0700
@@ -413,11 +413,22 @@
  * \param texture The targeted texture, which must be created with the SDL_TEXTUREACCESS_TARGET flag, or NULL for the default render target
  *
  * \return 0 on success, or -1 on error
+ *
+ *  \sa SDL_GetRenderTarget()
  */
 extern DECLSPEC int SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer,
                                                 SDL_Texture *texture);
 
 /**
+ * \brief Get the current render target or NULL for the default render target.
+ *
+ * \return The current render target
+ *
+ *  \sa SDL_SetRenderTarget()
+ */
+extern DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *renderer);
+
+/**
  *  \brief Set device independent resolution for rendering
  *
  *  \param w      The width of the logical resolution
--- a/src/render/SDL_render.c	Thu Oct 11 15:05:00 2012 -0700
+++ b/src/render/SDL_render.c	Fri Oct 12 02:20:10 2012 -0700
@@ -952,6 +952,12 @@
     return 0;
 }
 
+SDL_Texture *
+SDL_GetRenderTarget(SDL_Renderer *renderer)
+{
+    return renderer->target;
+}
+
 static int
 UpdateLogicalSize(SDL_Renderer *renderer)
 {
@@ -961,7 +967,9 @@
     float scale;
     SDL_Rect viewport;
 
-    if (renderer->window) {
+    if (renderer->target) {
+        SDL_QueryTexture(renderer->target, NULL, NULL, &w, &h);
+    } else if (renderer->window) {
         SDL_GetWindowSize(renderer->window, &w, &h);
     } else {
         /* FIXME */