Added SDL_GetRenderer()
authorSam Lantinga <slouken@libsdl.org>
Mon, 04 Apr 2011 09:29:13 -0700
changeset 552815c9c03a80cc
parent 5527 9a03d2300486
child 5529 8c0d15077360
Added SDL_GetRenderer()
include/SDL_render.h
src/render/SDL_render.c
     1.1 --- a/include/SDL_render.h	Sun Apr 03 18:33:32 2011 -0500
     1.2 +++ b/include/SDL_render.h	Mon Apr 04 09:29:13 2011 -0700
     1.3 @@ -175,6 +175,11 @@
     1.4  extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);
     1.5  
     1.6  /**
     1.7 + *  \brief Get the renderer associated with a window.
     1.8 + */
     1.9 +extern DECLSPEC SDL_Renderer * SDLCALL SDL_GetRenderer(SDL_Window * window);
    1.10 +
    1.11 +/**
    1.12   *  \brief Get information about a rendering context.
    1.13   */
    1.14  extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
     2.1 --- a/src/render/SDL_render.c	Sun Apr 03 18:33:32 2011 -0500
     2.2 +++ b/src/render/SDL_render.c	Mon Apr 04 09:29:13 2011 -0700
     2.3 @@ -30,6 +30,8 @@
     2.4  #include "software/SDL_render_sw_c.h"
     2.5  
     2.6  
     2.7 +#define SDL_WINDOWRENDERDATA    "_SDL_WindowRenderData"
     2.8 +
     2.9  #define CHECK_RENDERER_MAGIC(renderer, retval) \
    2.10      if (!renderer || renderer->magic != &renderer_magic) { \
    2.11          SDL_SetError("Invalid renderer"); \
    2.12 @@ -123,6 +125,16 @@
    2.13      int n = SDL_GetNumRenderDrivers();
    2.14      const char *hint;
    2.15  
    2.16 +    if (!window) {
    2.17 +        SDL_SetError("Invalid window");
    2.18 +        return NULL;
    2.19 +    }
    2.20 +
    2.21 +    if (SDL_GetRenderer(window)) {
    2.22 +        SDL_SetError("Renderer already associated with window");
    2.23 +        return NULL;
    2.24 +    }
    2.25 +
    2.26      hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
    2.27      if (hint) {
    2.28          if (*hint == '0') {
    2.29 @@ -178,6 +190,8 @@
    2.30          renderer->magic = &renderer_magic;
    2.31          renderer->window = window;
    2.32  
    2.33 +        SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
    2.34 +
    2.35          SDL_RenderSetViewport(renderer, NULL);
    2.36  
    2.37          SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
    2.38 @@ -208,6 +222,12 @@
    2.39  #endif /* !SDL_RENDER_DISABLED */
    2.40  }
    2.41  
    2.42 +SDL_Renderer *
    2.43 +SDL_GetRenderer(SDL_Window * window)
    2.44 +{
    2.45 +    return (SDL_Renderer *)SDL_GetWindowData(window, SDL_WINDOWRENDERDATA);
    2.46 +}
    2.47 +
    2.48  int
    2.49  SDL_GetRendererInfo(SDL_Renderer * renderer, SDL_RendererInfo * info)
    2.50  {
    2.51 @@ -1149,6 +1169,8 @@
    2.52          SDL_DestroyTexture(renderer->textures);
    2.53      }
    2.54  
    2.55 +    SDL_SetWindowData(renderer->window, SDL_WINDOWRENDERDATA, NULL);
    2.56 +
    2.57      /* It's no longer magical... */
    2.58      renderer->magic = NULL;
    2.59