Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added SDL_GetRenderer()

  • Loading branch information
slouken committed Apr 4, 2011
1 parent afb4098 commit c777f9b4eaa2ca32964f25c823d1e30da0f7659c
Showing with 27 additions and 0 deletions.
  1. +5 −0 include/SDL_render.h
  2. +22 −0 src/render/SDL_render.c
@@ -174,6 +174,11 @@ extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
*/
extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);

/**
* \brief Get the renderer associated with a window.
*/
extern DECLSPEC SDL_Renderer * SDLCALL SDL_GetRenderer(SDL_Window * window);

/**
* \brief Get information about a rendering context.
*/
@@ -30,6 +30,8 @@
#include "software/SDL_render_sw_c.h"


#define SDL_WINDOWRENDERDATA "_SDL_WindowRenderData"

#define CHECK_RENDERER_MAGIC(renderer, retval) \
if (!renderer || renderer->magic != &renderer_magic) { \
SDL_SetError("Invalid renderer"); \
@@ -123,6 +125,16 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
int n = SDL_GetNumRenderDrivers();
const char *hint;

if (!window) {
SDL_SetError("Invalid window");
return NULL;
}

if (SDL_GetRenderer(window)) {
SDL_SetError("Renderer already associated with window");
return NULL;
}

hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
if (hint) {
if (*hint == '0') {
@@ -178,6 +190,8 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
renderer->magic = &renderer_magic;
renderer->window = window;

SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);

SDL_RenderSetViewport(renderer, NULL);

SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
@@ -208,6 +222,12 @@ SDL_CreateSoftwareRenderer(SDL_Surface * surface)
#endif /* !SDL_RENDER_DISABLED */
}

SDL_Renderer *
SDL_GetRenderer(SDL_Window * window)
{
return (SDL_Renderer *)SDL_GetWindowData(window, SDL_WINDOWRENDERDATA);
}

int
SDL_GetRendererInfo(SDL_Renderer * renderer, SDL_RendererInfo * info)
{
@@ -1149,6 +1169,8 @@ SDL_DestroyRenderer(SDL_Renderer * renderer)
SDL_DestroyTexture(renderer->textures);
}

SDL_SetWindowData(renderer->window, SDL_WINDOWRENDERDATA, NULL);

/* It's no longer magical... */
renderer->magic = NULL;

0 comments on commit c777f9b

Please sign in to comment.