src/render/SDL_render.c
changeset 5154 fb424691cfc7
child 5156 307ccc9c135e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/render/SDL_render.c	Wed Feb 02 14:34:54 2011 -0800
     1.3 @@ -0,0 +1,1113 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2010 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +/* The SDL 2D rendering system */
    1.28 +
    1.29 +#include "SDL_render.h"
    1.30 +#include "SDL_sysrender.h"
    1.31 +#include "../video/SDL_pixels_c.h"
    1.32 +
    1.33 +
    1.34 +#define CHECK_RENDERER_MAGIC(renderer, retval) \
    1.35 +    if (!renderer || renderer->magic != &renderer_magic) { \
    1.36 +        SDL_SetError("Invalid renderer"); \
    1.37 +        return retval; \
    1.38 +    }
    1.39 +
    1.40 +#define CHECK_TEXTURE_MAGIC(texture, retval) \
    1.41 +    if (!texture || texture->magic != &texture_magic) { \
    1.42 +        SDL_SetError("Invalid texture"); \
    1.43 +        return retval; \
    1.44 +    }
    1.45 +
    1.46 +
    1.47 +static const SDL_RenderDriver *render_drivers[] = {
    1.48 +#if SDL_VIDEO_RENDER_D3D
    1.49 +    &D3D_RenderDriver,
    1.50 +#endif
    1.51 +#if SDL_VIDEO_RENDER_OGL
    1.52 +    &GL_RenderDriver,
    1.53 +#endif
    1.54 +#if SDL_VIDEO_RENDER_OGL_ES
    1.55 +    &GL_ES_RenderDriver,
    1.56 +#endif
    1.57 +    &SW_RenderDriver
    1.58 +};
    1.59 +static char renderer_magic;
    1.60 +static char texture_magic;
    1.61 +
    1.62 +int
    1.63 +SDL_GetNumRenderDrivers(void)
    1.64 +{
    1.65 +    return SDL_arraysize(render_drivers);
    1.66 +}
    1.67 +
    1.68 +int
    1.69 +SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info)
    1.70 +{
    1.71 +    if (index < 0 || index >= SDL_GetNumRenderDrivers()) {
    1.72 +        SDL_SetError("index must be in the range of 0 - %d",
    1.73 +                     SDL_GetNumRenderDrivers() - 1);
    1.74 +        return -1;
    1.75 +    }
    1.76 +    *info = render_drivers[index]->info;
    1.77 +    return 0;
    1.78 +}
    1.79 +
    1.80 +static int
    1.81 +SDL_RendererEventWatch(void *userdata, SDL_Event *event)
    1.82 +{
    1.83 +    SDL_Renderer *renderer = (SDL_Renderer *)userdata;
    1.84 +
    1.85 +    if (event->type == SDL_WINDOWEVENT && renderer->WindowEvent) {
    1.86 +        SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
    1.87 +        if (window == renderer->window) {
    1.88 +            renderer->WindowEvent(renderer, &event->window);
    1.89 +        }
    1.90 +    }
    1.91 +    return 0;
    1.92 +}
    1.93 +
    1.94 +SDL_Renderer *
    1.95 +SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
    1.96 +{
    1.97 +    SDL_Renderer *renderer = NULL;
    1.98 +    int n = SDL_GetNumRenderDrivers();
    1.99 +
   1.100 +    if (index < 0) {
   1.101 +        char *override = SDL_getenv("SDL_VIDEO_RENDERER");
   1.102 +
   1.103 +        if (override) {
   1.104 +            for (index = 0; index < n; ++index) {
   1.105 +                const SDL_RenderDriver *driver = render_drivers[index];
   1.106 +
   1.107 +                if (SDL_strcasecmp(override, driver->info.name) == 0) {
   1.108 +                    /* Create a new renderer instance */
   1.109 +                    renderer = driver->CreateRenderer(window, flags);
   1.110 +                    break;
   1.111 +                }
   1.112 +            }
   1.113 +        } else {
   1.114 +            for (index = 0; index < n; ++index) {
   1.115 +                const SDL_RenderDriver *driver = render_drivers[index];
   1.116 +
   1.117 +                if ((driver->info.flags & flags) == flags) {
   1.118 +                    /* Create a new renderer instance */
   1.119 +                    renderer = driver->CreateRenderer(window, flags);
   1.120 +                    if (renderer) {
   1.121 +                        /* Yay, we got one! */
   1.122 +                        break;
   1.123 +                    }
   1.124 +                }
   1.125 +            }
   1.126 +        }
   1.127 +        if (index == n) {
   1.128 +            SDL_SetError("Couldn't find matching render driver");
   1.129 +            return NULL;
   1.130 +        }
   1.131 +    } else {
   1.132 +        if (index >= SDL_GetNumRenderDrivers()) {
   1.133 +            SDL_SetError("index must be -1 or in the range of 0 - %d",
   1.134 +                         SDL_GetNumRenderDrivers() - 1);
   1.135 +            return NULL;
   1.136 +        }
   1.137 +        /* Create a new renderer instance */
   1.138 +        renderer = render_drivers[index]->CreateRenderer(window, flags);
   1.139 +    }
   1.140 +
   1.141 +    if (renderer) {
   1.142 +        renderer->magic = &renderer_magic;
   1.143 +
   1.144 +        SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
   1.145 +    }
   1.146 +    return renderer;
   1.147 +}
   1.148 +
   1.149 +int
   1.150 +SDL_GetRendererInfo(SDL_Renderer * renderer, SDL_RendererInfo * info)
   1.151 +{
   1.152 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.153 +
   1.154 +    *info = renderer->info;
   1.155 +    return 0;
   1.156 +}
   1.157 +
   1.158 +SDL_Texture *
   1.159 +SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int h)
   1.160 +{
   1.161 +    SDL_Texture *texture;
   1.162 +
   1.163 +    CHECK_RENDERER_MAGIC(renderer, NULL);
   1.164 +
   1.165 +    if (w <= 0 || h <= 0) {
   1.166 +        SDL_SetError("Texture dimensions can't be 0");
   1.167 +        return 0;
   1.168 +    }
   1.169 +    texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
   1.170 +    if (!texture) {
   1.171 +        SDL_OutOfMemory();
   1.172 +        return 0;
   1.173 +    }
   1.174 +    texture->magic = &texture_magic;
   1.175 +    texture->format = format;
   1.176 +    texture->access = access;
   1.177 +    texture->w = w;
   1.178 +    texture->h = h;
   1.179 +    texture->r = 255;
   1.180 +    texture->g = 255;
   1.181 +    texture->b = 255;
   1.182 +    texture->a = 255;
   1.183 +    texture->renderer = renderer;
   1.184 +    texture->next = renderer->textures;
   1.185 +    if (renderer->textures) {
   1.186 +        renderer->textures->prev = texture;
   1.187 +    }
   1.188 +    renderer->textures = texture;
   1.189 +
   1.190 +    if (renderer->CreateTexture(renderer, texture) < 0) {
   1.191 +        SDL_DestroyTexture(texture);
   1.192 +        return 0;
   1.193 +    }
   1.194 +    return texture;
   1.195 +}
   1.196 +
   1.197 +SDL_Texture *
   1.198 +SDL_CreateTextureFromSurface(SDL_Renderer * renderer, Uint32 format, SDL_Surface * surface)
   1.199 +{
   1.200 +    SDL_Texture *texture;
   1.201 +    Uint32 requested_format = format;
   1.202 +    SDL_PixelFormat *fmt;
   1.203 +    int bpp;
   1.204 +    Uint32 Rmask, Gmask, Bmask, Amask;
   1.205 +
   1.206 +    CHECK_RENDERER_MAGIC(renderer, NULL);
   1.207 +
   1.208 +    if (!surface) {
   1.209 +        SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
   1.210 +        return NULL;
   1.211 +    }
   1.212 +    fmt = surface->format;
   1.213 +
   1.214 +    if (format) {
   1.215 +        if (!SDL_PixelFormatEnumToMasks
   1.216 +            (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   1.217 +            SDL_SetError("Unknown pixel format");
   1.218 +            return 0;
   1.219 +        }
   1.220 +    } else {
   1.221 +        SDL_bool hasColorkey;
   1.222 +        SDL_BlendMode blendMode;
   1.223 +        SDL_bool hasBlending;
   1.224 +
   1.225 +        hasColorkey = (SDL_GetColorKey(surface, NULL) == 0);
   1.226 +
   1.227 +        SDL_GetSurfaceBlendMode(surface, &blendMode);
   1.228 +        hasBlending = (blendMode == SDL_BLENDMODE_BLEND);
   1.229 +
   1.230 +        if (surface->format->Amask || (!hasColorkey && !hasBlending)) {
   1.231 +            Uint32 it;
   1.232 +            int pfmt;
   1.233 +
   1.234 +            /* Pixel formats, sorted by best first */
   1.235 +            static const Uint32 sdl_pformats[] = {
   1.236 +                SDL_PIXELFORMAT_ARGB8888,
   1.237 +                SDL_PIXELFORMAT_RGBA8888,
   1.238 +                SDL_PIXELFORMAT_ABGR8888,
   1.239 +                SDL_PIXELFORMAT_BGRA8888,
   1.240 +                SDL_PIXELFORMAT_RGB888,
   1.241 +                SDL_PIXELFORMAT_BGR888,
   1.242 +                SDL_PIXELFORMAT_RGB24,
   1.243 +                SDL_PIXELFORMAT_BGR24,
   1.244 +                SDL_PIXELFORMAT_RGB565,
   1.245 +                SDL_PIXELFORMAT_BGR565,
   1.246 +                SDL_PIXELFORMAT_ARGB1555,
   1.247 +                SDL_PIXELFORMAT_RGBA5551,
   1.248 +                SDL_PIXELFORMAT_ABGR1555,
   1.249 +                SDL_PIXELFORMAT_BGRA5551,
   1.250 +                SDL_PIXELFORMAT_RGB555,
   1.251 +                SDL_PIXELFORMAT_BGR555,
   1.252 +                SDL_PIXELFORMAT_ARGB4444,
   1.253 +                SDL_PIXELFORMAT_RGBA4444,
   1.254 +                SDL_PIXELFORMAT_ABGR4444,
   1.255 +                SDL_PIXELFORMAT_BGRA4444,
   1.256 +                SDL_PIXELFORMAT_RGB444,
   1.257 +                SDL_PIXELFORMAT_ARGB2101010,
   1.258 +                SDL_PIXELFORMAT_RGB332,
   1.259 +                SDL_PIXELFORMAT_UNKNOWN
   1.260 +            };
   1.261 +
   1.262 +            bpp = fmt->BitsPerPixel;
   1.263 +            Rmask = fmt->Rmask;
   1.264 +            Gmask = fmt->Gmask;
   1.265 +            Bmask = fmt->Bmask;
   1.266 +            Amask = fmt->Amask;
   1.267 +
   1.268 +            format =
   1.269 +                SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
   1.270 +            if (!format) {
   1.271 +                SDL_SetError("Unknown pixel format");
   1.272 +                return 0;
   1.273 +            }
   1.274 +
   1.275 +            /* Search requested format in the supported texture */
   1.276 +            /* formats by current renderer                      */
   1.277 +            for (it = 0; it < renderer->info.num_texture_formats; it++) {
   1.278 +                if (renderer->info.texture_formats[it] == format) {
   1.279 +                    break;
   1.280 +                }
   1.281 +            }
   1.282 +
   1.283 +            /* If requested format can't be found, search any best */
   1.284 +            /* format which renderer provides                      */
   1.285 +            if (it == renderer->info.num_texture_formats) {
   1.286 +                pfmt = 0;
   1.287 +                for (;;) {
   1.288 +                    if (sdl_pformats[pfmt] == SDL_PIXELFORMAT_UNKNOWN) {
   1.289 +                        break;
   1.290 +                    }
   1.291 +
   1.292 +                    for (it = 0; it < renderer->info.num_texture_formats;
   1.293 +                         it++) {
   1.294 +                        if (renderer->info.texture_formats[it] ==
   1.295 +                            sdl_pformats[pfmt]) {
   1.296 +                            break;
   1.297 +                        }
   1.298 +                    }
   1.299 +
   1.300 +                    if (it != renderer->info.num_texture_formats) {
   1.301 +                        /* The best format has been found */
   1.302 +                        break;
   1.303 +                    }
   1.304 +                    pfmt++;
   1.305 +                }
   1.306 +
   1.307 +                /* If any format can't be found, then return an error */
   1.308 +                if (it == renderer->info.num_texture_formats) {
   1.309 +                    SDL_SetError
   1.310 +                        ("Any of the supported pixel formats can't be found");
   1.311 +                    return 0;
   1.312 +                }
   1.313 +
   1.314 +                /* Convert found pixel format back to color masks */
   1.315 +                if (SDL_PixelFormatEnumToMasks
   1.316 +                    (renderer->info.texture_formats[it], &bpp, &Rmask, &Gmask,
   1.317 +                     &Bmask, &Amask) != SDL_TRUE) {
   1.318 +                    SDL_SetError("Unknown pixel format");
   1.319 +                    return 0;
   1.320 +                }
   1.321 +            }
   1.322 +        } else {
   1.323 +            /* Need a format with alpha */
   1.324 +            Uint32 it;
   1.325 +            int apfmt;
   1.326 +
   1.327 +            /* Pixel formats with alpha, sorted by best first */
   1.328 +            static const Uint32 sdl_alpha_pformats[] = {
   1.329 +                SDL_PIXELFORMAT_ARGB8888,
   1.330 +                SDL_PIXELFORMAT_RGBA8888,
   1.331 +                SDL_PIXELFORMAT_ABGR8888,
   1.332 +                SDL_PIXELFORMAT_BGRA8888,
   1.333 +                SDL_PIXELFORMAT_ARGB1555,
   1.334 +                SDL_PIXELFORMAT_RGBA5551,
   1.335 +                SDL_PIXELFORMAT_ABGR1555,
   1.336 +                SDL_PIXELFORMAT_BGRA5551,
   1.337 +                SDL_PIXELFORMAT_ARGB4444,
   1.338 +                SDL_PIXELFORMAT_RGBA4444,
   1.339 +                SDL_PIXELFORMAT_ABGR4444,
   1.340 +                SDL_PIXELFORMAT_BGRA4444,
   1.341 +                SDL_PIXELFORMAT_ARGB2101010,
   1.342 +                SDL_PIXELFORMAT_UNKNOWN
   1.343 +            };
   1.344 +
   1.345 +            if (surface->format->Amask) {
   1.346 +                /* If surface already has alpha, then try an original */
   1.347 +                /* surface format first                               */
   1.348 +                bpp = fmt->BitsPerPixel;
   1.349 +                Rmask = fmt->Rmask;
   1.350 +                Gmask = fmt->Gmask;
   1.351 +                Bmask = fmt->Bmask;
   1.352 +                Amask = fmt->Amask;
   1.353 +            } else {
   1.354 +                bpp = 32;
   1.355 +                Rmask = 0x00FF0000;
   1.356 +                Gmask = 0x0000FF00;
   1.357 +                Bmask = 0x000000FF;
   1.358 +                Amask = 0xFF000000;
   1.359 +            }
   1.360 +
   1.361 +            format =
   1.362 +                SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
   1.363 +            if (!format) {
   1.364 +                SDL_SetError("Unknown pixel format");
   1.365 +                return 0;
   1.366 +            }
   1.367 +
   1.368 +            /* Search this format in the supported texture formats */
   1.369 +            /* by current renderer                                 */
   1.370 +            for (it = 0; it < renderer->info.num_texture_formats; it++) {
   1.371 +                if (renderer->info.texture_formats[it] == format) {
   1.372 +                    break;
   1.373 +                }
   1.374 +            }
   1.375 +
   1.376 +            /* If this format can't be found, search any best       */
   1.377 +            /* compatible format with alpha which renderer provides */
   1.378 +            if (it == renderer->info.num_texture_formats) {
   1.379 +                apfmt = 0;
   1.380 +                for (;;) {
   1.381 +                    if (sdl_alpha_pformats[apfmt] == SDL_PIXELFORMAT_UNKNOWN) {
   1.382 +                        break;
   1.383 +                    }
   1.384 +
   1.385 +                    for (it = 0; it < renderer->info.num_texture_formats;
   1.386 +                         it++) {
   1.387 +                        if (renderer->info.texture_formats[it] ==
   1.388 +                            sdl_alpha_pformats[apfmt]) {
   1.389 +                            break;
   1.390 +                        }
   1.391 +                    }
   1.392 +
   1.393 +                    if (it != renderer->info.num_texture_formats) {
   1.394 +                        /* Compatible format has been found */
   1.395 +                        break;
   1.396 +                    }
   1.397 +                    apfmt++;
   1.398 +                }
   1.399 +
   1.400 +                /* If compatible format can't be found, then return an error */
   1.401 +                if (it == renderer->info.num_texture_formats) {
   1.402 +                    SDL_SetError("Compatible pixel format can't be found");
   1.403 +                    return 0;
   1.404 +                }
   1.405 +
   1.406 +                /* Convert found pixel format back to color masks */
   1.407 +                if (SDL_PixelFormatEnumToMasks
   1.408 +                    (renderer->info.texture_formats[it], &bpp, &Rmask, &Gmask,
   1.409 +                     &Bmask, &Amask) != SDL_TRUE) {
   1.410 +                    SDL_SetError("Unknown pixel format");
   1.411 +                    return 0;
   1.412 +                }
   1.413 +            }
   1.414 +        }
   1.415 +
   1.416 +        format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
   1.417 +        if (!format) {
   1.418 +            SDL_SetError("Unknown pixel format");
   1.419 +            return 0;
   1.420 +        }
   1.421 +    }
   1.422 +
   1.423 +    texture =
   1.424 +        SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
   1.425 +                          surface->w, surface->h);
   1.426 +    if (!texture && !requested_format) {
   1.427 +        SDL_DisplayMode desktop_mode;
   1.428 +        SDL_GetDesktopDisplayMode(&desktop_mode);
   1.429 +        format = desktop_mode.format;
   1.430 +        texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
   1.431 +                                    surface->w, surface->h);
   1.432 +    }
   1.433 +    if (!texture) {
   1.434 +        return 0;
   1.435 +    }
   1.436 +    if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask
   1.437 +        && Bmask == fmt->Bmask && Amask == fmt->Amask) {
   1.438 +        if (SDL_MUSTLOCK(surface)) {
   1.439 +            SDL_LockSurface(surface);
   1.440 +            SDL_UpdateTexture(texture, NULL, surface->pixels,
   1.441 +                              surface->pitch);
   1.442 +            SDL_UnlockSurface(surface);
   1.443 +        } else {
   1.444 +            SDL_UpdateTexture(texture, NULL, surface->pixels,
   1.445 +                              surface->pitch);
   1.446 +        }
   1.447 +    } else {
   1.448 +        SDL_PixelFormat dst_fmt;
   1.449 +        SDL_Surface *dst = NULL;
   1.450 +
   1.451 +        /* Set up a destination surface for the texture update */
   1.452 +        SDL_InitFormat(&dst_fmt, bpp, Rmask, Gmask, Bmask, Amask);
   1.453 +        dst = SDL_ConvertSurface(surface, &dst_fmt, 0);
   1.454 +        if (dst) {
   1.455 +            SDL_UpdateTexture(texture, NULL, dst->pixels, dst->pitch);
   1.456 +            SDL_FreeSurface(dst);
   1.457 +        }
   1.458 +        if (!dst) {
   1.459 +            SDL_DestroyTexture(texture);
   1.460 +            return 0;
   1.461 +        }
   1.462 +    }
   1.463 +
   1.464 +    {
   1.465 +        Uint8 r, g, b, a;
   1.466 +        SDL_BlendMode blendMode;
   1.467 +
   1.468 +        SDL_GetSurfaceColorMod(surface, &r, &g, &b);
   1.469 +        SDL_SetTextureColorMod(texture, r, g, b);
   1.470 +
   1.471 +        SDL_GetSurfaceAlphaMod(surface, &a);
   1.472 +        SDL_SetTextureAlphaMod(texture, a);
   1.473 +
   1.474 +        if (SDL_GetColorKey(surface, NULL) == 0) {
   1.475 +            /* We converted to a texture with alpha format */
   1.476 +            SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
   1.477 +        } else {
   1.478 +            SDL_GetSurfaceBlendMode(surface, &blendMode);
   1.479 +            SDL_SetTextureBlendMode(texture, blendMode);
   1.480 +        }
   1.481 +    }
   1.482 +    return texture;
   1.483 +}
   1.484 +
   1.485 +int
   1.486 +SDL_QueryTexture(SDL_Texture * texture, Uint32 * format, int *access,
   1.487 +                 int *w, int *h)
   1.488 +{
   1.489 +    CHECK_TEXTURE_MAGIC(texture, -1);
   1.490 +
   1.491 +    if (format) {
   1.492 +        *format = texture->format;
   1.493 +    }
   1.494 +    if (access) {
   1.495 +        *access = texture->access;
   1.496 +    }
   1.497 +    if (w) {
   1.498 +        *w = texture->w;
   1.499 +    }
   1.500 +    if (h) {
   1.501 +        *h = texture->h;
   1.502 +    }
   1.503 +    return 0;
   1.504 +}
   1.505 +
   1.506 +int
   1.507 +SDL_QueryTexturePixels(SDL_Texture * texture, void **pixels, int *pitch)
   1.508 +{
   1.509 +    SDL_Renderer *renderer;
   1.510 +
   1.511 +    CHECK_TEXTURE_MAGIC(texture, -1);
   1.512 +
   1.513 +    renderer = texture->renderer;
   1.514 +    if (!renderer->QueryTexturePixels) {
   1.515 +        SDL_Unsupported();
   1.516 +        return -1;
   1.517 +    }
   1.518 +    return renderer->QueryTexturePixels(renderer, texture, pixels, pitch);
   1.519 +}
   1.520 +
   1.521 +int
   1.522 +SDL_SetTextureColorMod(SDL_Texture * texture, Uint8 r, Uint8 g, Uint8 b)
   1.523 +{
   1.524 +    SDL_Renderer *renderer;
   1.525 +
   1.526 +    CHECK_TEXTURE_MAGIC(texture, -1);
   1.527 +
   1.528 +    renderer = texture->renderer;
   1.529 +    if (r < 255 || g < 255 || b < 255) {
   1.530 +        texture->modMode |= SDL_TEXTUREMODULATE_COLOR;
   1.531 +    } else {
   1.532 +        texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
   1.533 +    }
   1.534 +    texture->r = r;
   1.535 +    texture->g = g;
   1.536 +    texture->b = b;
   1.537 +    if (renderer->SetTextureColorMod) {
   1.538 +        return renderer->SetTextureColorMod(renderer, texture);
   1.539 +    } else {
   1.540 +        return 0;
   1.541 +    }
   1.542 +}
   1.543 +
   1.544 +int
   1.545 +SDL_GetTextureColorMod(SDL_Texture * texture, Uint8 * r, Uint8 * g,
   1.546 +                       Uint8 * b)
   1.547 +{
   1.548 +    SDL_Renderer *renderer;
   1.549 +
   1.550 +    CHECK_TEXTURE_MAGIC(texture, -1);
   1.551 +
   1.552 +    renderer = texture->renderer;
   1.553 +    if (r) {
   1.554 +        *r = texture->r;
   1.555 +    }
   1.556 +    if (g) {
   1.557 +        *g = texture->g;
   1.558 +    }
   1.559 +    if (b) {
   1.560 +        *b = texture->b;
   1.561 +    }
   1.562 +    return 0;
   1.563 +}
   1.564 +
   1.565 +int
   1.566 +SDL_SetTextureAlphaMod(SDL_Texture * texture, Uint8 alpha)
   1.567 +{
   1.568 +    SDL_Renderer *renderer;
   1.569 +
   1.570 +    CHECK_TEXTURE_MAGIC(texture, -1);
   1.571 +
   1.572 +    renderer = texture->renderer;
   1.573 +    if (alpha < 255) {
   1.574 +        texture->modMode |= SDL_TEXTUREMODULATE_ALPHA;
   1.575 +    } else {
   1.576 +        texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
   1.577 +    }
   1.578 +    texture->a = alpha;
   1.579 +    if (renderer->SetTextureAlphaMod) {
   1.580 +        return renderer->SetTextureAlphaMod(renderer, texture);
   1.581 +    } else {
   1.582 +        return 0;
   1.583 +    }
   1.584 +}
   1.585 +
   1.586 +int
   1.587 +SDL_GetTextureAlphaMod(SDL_Texture * texture, Uint8 * alpha)
   1.588 +{
   1.589 +    CHECK_TEXTURE_MAGIC(texture, -1);
   1.590 +
   1.591 +    if (alpha) {
   1.592 +        *alpha = texture->a;
   1.593 +    }
   1.594 +    return 0;
   1.595 +}
   1.596 +
   1.597 +int
   1.598 +SDL_SetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode blendMode)
   1.599 +{
   1.600 +    SDL_Renderer *renderer;
   1.601 +
   1.602 +    CHECK_TEXTURE_MAGIC(texture, -1);
   1.603 +
   1.604 +    renderer = texture->renderer;
   1.605 +    texture->blendMode = blendMode;
   1.606 +    if (renderer->SetTextureBlendMode) {
   1.607 +        return renderer->SetTextureBlendMode(renderer, texture);
   1.608 +    } else {
   1.609 +        return 0;
   1.610 +    }
   1.611 +}
   1.612 +
   1.613 +int
   1.614 +SDL_GetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode *blendMode)
   1.615 +{
   1.616 +    CHECK_TEXTURE_MAGIC(texture, -1);
   1.617 +
   1.618 +    if (blendMode) {
   1.619 +        *blendMode = texture->blendMode;
   1.620 +    }
   1.621 +    return 0;
   1.622 +}
   1.623 +
   1.624 +int
   1.625 +SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
   1.626 +                  const void *pixels, int pitch)
   1.627 +{
   1.628 +    SDL_Renderer *renderer;
   1.629 +    SDL_Rect full_rect;
   1.630 +
   1.631 +    CHECK_TEXTURE_MAGIC(texture, -1);
   1.632 +
   1.633 +    renderer = texture->renderer;
   1.634 +    if (!renderer->UpdateTexture) {
   1.635 +        SDL_Unsupported();
   1.636 +        return -1;
   1.637 +    }
   1.638 +    if (!rect) {
   1.639 +        full_rect.x = 0;
   1.640 +        full_rect.y = 0;
   1.641 +        full_rect.w = texture->w;
   1.642 +        full_rect.h = texture->h;
   1.643 +        rect = &full_rect;
   1.644 +    }
   1.645 +    return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
   1.646 +}
   1.647 +
   1.648 +int
   1.649 +SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect, int markDirty,
   1.650 +                void **pixels, int *pitch)
   1.651 +{
   1.652 +    SDL_Renderer *renderer;
   1.653 +    SDL_Rect full_rect;
   1.654 +
   1.655 +    CHECK_TEXTURE_MAGIC(texture, -1);
   1.656 +
   1.657 +    if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
   1.658 +        SDL_SetError("SDL_LockTexture(): texture must be streaming");
   1.659 +        return -1;
   1.660 +    }
   1.661 +    renderer = texture->renderer;
   1.662 +    if (!renderer->LockTexture) {
   1.663 +        SDL_Unsupported();
   1.664 +        return -1;
   1.665 +    }
   1.666 +    if (!rect) {
   1.667 +        full_rect.x = 0;
   1.668 +        full_rect.y = 0;
   1.669 +        full_rect.w = texture->w;
   1.670 +        full_rect.h = texture->h;
   1.671 +        rect = &full_rect;
   1.672 +    }
   1.673 +    return renderer->LockTexture(renderer, texture, rect, markDirty, pixels,
   1.674 +                                 pitch);
   1.675 +}
   1.676 +
   1.677 +void
   1.678 +SDL_UnlockTexture(SDL_Texture * texture)
   1.679 +{
   1.680 +    SDL_Renderer *renderer;
   1.681 +
   1.682 +    CHECK_TEXTURE_MAGIC(texture, );
   1.683 +
   1.684 +    if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
   1.685 +        return;
   1.686 +    }
   1.687 +    renderer = texture->renderer;
   1.688 +    if (!renderer->UnlockTexture) {
   1.689 +        return;
   1.690 +    }
   1.691 +    renderer->UnlockTexture(renderer, texture);
   1.692 +}
   1.693 +
   1.694 +void
   1.695 +SDL_DirtyTexture(SDL_Texture * texture, int numrects,
   1.696 +                 const SDL_Rect * rects)
   1.697 +{
   1.698 +    SDL_Renderer *renderer;
   1.699 +
   1.700 +    CHECK_TEXTURE_MAGIC(texture, );
   1.701 +
   1.702 +    if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
   1.703 +        return;
   1.704 +    }
   1.705 +    renderer = texture->renderer;
   1.706 +    if (!renderer->DirtyTexture) {
   1.707 +        return;
   1.708 +    }
   1.709 +    renderer->DirtyTexture(renderer, texture, numrects, rects);
   1.710 +}
   1.711 +
   1.712 +int
   1.713 +SDL_SetRenderDrawColor(SDL_Renderer * renderer,
   1.714 +                       Uint8 r, Uint8 g, Uint8 b, Uint8 a)
   1.715 +{
   1.716 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.717 +
   1.718 +    renderer->r = r;
   1.719 +    renderer->g = g;
   1.720 +    renderer->b = b;
   1.721 +    renderer->a = a;
   1.722 +    return 0;
   1.723 +}
   1.724 +
   1.725 +int
   1.726 +SDL_GetRenderDrawColor(SDL_Renderer * renderer,
   1.727 +                       Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
   1.728 +{
   1.729 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.730 +
   1.731 +    if (r) {
   1.732 +        *r = renderer->r;
   1.733 +    }
   1.734 +    if (g) {
   1.735 +        *g = renderer->g;
   1.736 +    }
   1.737 +    if (b) {
   1.738 +        *b = renderer->b;
   1.739 +    }
   1.740 +    if (a) {
   1.741 +        *a = renderer->a;
   1.742 +    }
   1.743 +    return 0;
   1.744 +}
   1.745 +
   1.746 +int
   1.747 +SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
   1.748 +{
   1.749 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.750 +
   1.751 +    renderer->blendMode = blendMode;
   1.752 +    return 0;
   1.753 +}
   1.754 +
   1.755 +int
   1.756 +SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer, SDL_BlendMode *blendMode)
   1.757 +{
   1.758 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.759 +
   1.760 +    *blendMode = renderer->blendMode;
   1.761 +    return 0;
   1.762 +}
   1.763 +
   1.764 +int
   1.765 +SDL_RenderClear(SDL_Renderer * renderer)
   1.766 +{
   1.767 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.768 +
   1.769 +    if (!renderer->RenderClear) {
   1.770 +        SDL_BlendMode blendMode = renderer->blendMode;
   1.771 +        int status;
   1.772 +
   1.773 +        if (blendMode >= SDL_BLENDMODE_BLEND) {
   1.774 +            SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
   1.775 +        }
   1.776 +
   1.777 +        status = SDL_RenderFillRect(renderer, NULL);
   1.778 +
   1.779 +        if (blendMode >= SDL_BLENDMODE_BLEND) {
   1.780 +            SDL_SetRenderDrawBlendMode(renderer, blendMode);
   1.781 +        }
   1.782 +        return status;
   1.783 +    }
   1.784 +    return renderer->RenderClear(renderer);
   1.785 +}
   1.786 +
   1.787 +int
   1.788 +SDL_RenderDrawPoint(SDL_Renderer * renderer, int x, int y)
   1.789 +{
   1.790 +    SDL_Point point;
   1.791 +
   1.792 +    point.x = x;
   1.793 +    point.y = y;
   1.794 +    return SDL_RenderDrawPoints(renderer, &point, 1);
   1.795 +}
   1.796 +
   1.797 +int
   1.798 +SDL_RenderDrawPoints(SDL_Renderer * renderer,
   1.799 +                     const SDL_Point * points, int count)
   1.800 +{
   1.801 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.802 +
   1.803 +    if (!points) {
   1.804 +        SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points");
   1.805 +        return -1;
   1.806 +    }
   1.807 +    if (count < 1) {
   1.808 +        return 0;
   1.809 +    }
   1.810 +    return renderer->RenderDrawPoints(renderer, points, count);
   1.811 +}
   1.812 +
   1.813 +int
   1.814 +SDL_RenderDrawLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
   1.815 +{
   1.816 +    SDL_Point points[2];
   1.817 +
   1.818 +    points[0].x = x1;
   1.819 +    points[0].y = y1;
   1.820 +    points[1].x = x2;
   1.821 +    points[1].y = y2;
   1.822 +    return SDL_RenderDrawLines(renderer, points, 2);
   1.823 +}
   1.824 +
   1.825 +int
   1.826 +SDL_RenderDrawLines(SDL_Renderer * renderer,
   1.827 +                    const SDL_Point * points, int count)
   1.828 +{
   1.829 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.830 +
   1.831 +    if (!points) {
   1.832 +        SDL_SetError("SDL_RenderDrawLines(): Passed NULL points");
   1.833 +        return -1;
   1.834 +    }
   1.835 +    if (count < 2) {
   1.836 +        return 0;
   1.837 +    }
   1.838 +    return renderer->RenderDrawLines(renderer, points, count);
   1.839 +}
   1.840 +
   1.841 +int
   1.842 +SDL_RenderDrawRect(SDL_Renderer * renderer, const SDL_Rect * rect)
   1.843 +{
   1.844 +    SDL_Rect full_rect;
   1.845 +    SDL_Point points[5];
   1.846 +
   1.847 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.848 +
   1.849 +    /* If 'rect' == NULL, then outline the whole surface */
   1.850 +    if (!rect) {
   1.851 +        SDL_Window *window = renderer->window;
   1.852 +
   1.853 +        full_rect.x = 0;
   1.854 +        full_rect.y = 0;
   1.855 +        SDL_GetWindowSize(window, &full_rect.w, &full_rect.h);
   1.856 +        rect = &full_rect;
   1.857 +    }
   1.858 +
   1.859 +    points[0].x = rect->x;
   1.860 +    points[0].y = rect->y;
   1.861 +    points[1].x = rect->x+rect->w-1;
   1.862 +    points[1].y = rect->y;
   1.863 +    points[2].x = rect->x+rect->w-1;
   1.864 +    points[2].y = rect->y+rect->h-1;
   1.865 +    points[3].x = rect->x;
   1.866 +    points[3].y = rect->y+rect->h-1;
   1.867 +    points[4].x = rect->x;
   1.868 +    points[4].y = rect->y;
   1.869 +    return SDL_RenderDrawLines(renderer, points, 5);
   1.870 +}
   1.871 +
   1.872 +int
   1.873 +SDL_RenderDrawRects(SDL_Renderer * renderer,
   1.874 +                    const SDL_Rect ** rects, int count)
   1.875 +{
   1.876 +    int i;
   1.877 +
   1.878 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.879 +
   1.880 +    if (!rects) {
   1.881 +        SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects");
   1.882 +        return -1;
   1.883 +    }
   1.884 +    if (count < 1) {
   1.885 +        return 0;
   1.886 +    }
   1.887 +
   1.888 +    /* Check for NULL rect, which means fill entire window */
   1.889 +    for (i = 0; i < count; ++i) {
   1.890 +        if (SDL_RenderDrawRect(renderer, rects[i]) < 0) {
   1.891 +            return -1;
   1.892 +        }
   1.893 +    }
   1.894 +    return 0;
   1.895 +}
   1.896 +
   1.897 +int
   1.898 +SDL_RenderFillRect(SDL_Renderer * renderer, const SDL_Rect * rect)
   1.899 +{
   1.900 +    return SDL_RenderFillRects(renderer, &rect, 1);
   1.901 +}
   1.902 +
   1.903 +int
   1.904 +SDL_RenderFillRects(SDL_Renderer * renderer,
   1.905 +                    const SDL_Rect ** rects, int count)
   1.906 +{
   1.907 +    int i;
   1.908 +
   1.909 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.910 +
   1.911 +    if (!rects) {
   1.912 +        SDL_SetError("SDL_RenderFillRects(): Passed NULL rects");
   1.913 +        return -1;
   1.914 +    }
   1.915 +    if (count < 1) {
   1.916 +        return 0;
   1.917 +    }
   1.918 +
   1.919 +    /* Check for NULL rect, which means fill entire window */
   1.920 +    for (i = 0; i < count; ++i) {
   1.921 +        if (rects[i] == NULL) {
   1.922 +            SDL_Window *window = renderer->window;
   1.923 +            SDL_Rect full_rect;
   1.924 +            const SDL_Rect *rect;
   1.925 +
   1.926 +            full_rect.x = 0;
   1.927 +            full_rect.y = 0;
   1.928 +            SDL_GetWindowSize(window, &full_rect.w, &full_rect.h);
   1.929 +            rect = &full_rect;
   1.930 +            return renderer->RenderFillRects(renderer, &rect, 1);
   1.931 +        }
   1.932 +    }
   1.933 +    return renderer->RenderFillRects(renderer, rects, count);
   1.934 +}
   1.935 +
   1.936 +int
   1.937 +SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   1.938 +               const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   1.939 +{
   1.940 +    SDL_Window *window;
   1.941 +    SDL_Rect real_srcrect;
   1.942 +    SDL_Rect real_dstrect;
   1.943 +
   1.944 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.945 +    CHECK_TEXTURE_MAGIC(texture, -1);
   1.946 +
   1.947 +    if (renderer != texture->renderer) {
   1.948 +        SDL_SetError("Texture was not created with this renderer");
   1.949 +        return -1;
   1.950 +    }
   1.951 +    window = renderer->window;
   1.952 +
   1.953 +    real_srcrect.x = 0;
   1.954 +    real_srcrect.y = 0;
   1.955 +    real_srcrect.w = texture->w;
   1.956 +    real_srcrect.h = texture->h;
   1.957 +    if (srcrect) {
   1.958 +        if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
   1.959 +            return 0;
   1.960 +        }
   1.961 +    }
   1.962 +
   1.963 +    real_dstrect.x = 0;
   1.964 +    real_dstrect.y = 0;
   1.965 +    SDL_GetWindowSize(window, &real_dstrect.w, &real_dstrect.h);
   1.966 +    if (dstrect) {
   1.967 +        if (!SDL_IntersectRect(dstrect, &real_dstrect, &real_dstrect)) {
   1.968 +            return 0;
   1.969 +        }
   1.970 +        /* Clip srcrect by the same amount as dstrect was clipped */
   1.971 +        if (dstrect->w != real_dstrect.w) {
   1.972 +            int deltax = (real_dstrect.x - dstrect->x);
   1.973 +            int deltaw = (real_dstrect.w - dstrect->w);
   1.974 +            real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
   1.975 +            real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;
   1.976 +        }
   1.977 +        if (dstrect->h != real_dstrect.h) {
   1.978 +            int deltay = (real_dstrect.y - dstrect->y);
   1.979 +            int deltah = (real_dstrect.h - dstrect->h);
   1.980 +            real_srcrect.y += (deltay * real_srcrect.h) / dstrect->h;
   1.981 +            real_srcrect.h += (deltah * real_srcrect.h) / dstrect->h;
   1.982 +        }
   1.983 +    }
   1.984 +
   1.985 +    return renderer->RenderCopy(renderer, texture, &real_srcrect,
   1.986 +                                &real_dstrect);
   1.987 +}
   1.988 +
   1.989 +int
   1.990 +SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   1.991 +                     Uint32 format, void * pixels, int pitch)
   1.992 +{
   1.993 +    SDL_Window *window;
   1.994 +    SDL_Rect real_rect;
   1.995 +
   1.996 +    CHECK_RENDERER_MAGIC(renderer, -1);
   1.997 +
   1.998 +    if (!renderer->RenderReadPixels) {
   1.999 +        SDL_Unsupported();
  1.1000 +        return -1;
  1.1001 +    }
  1.1002 +    window = renderer->window;
  1.1003 +
  1.1004 +    if (!format) {
  1.1005 +        format = SDL_GetWindowPixelFormat(window);
  1.1006 +    }
  1.1007 +
  1.1008 +    real_rect.x = 0;
  1.1009 +    real_rect.y = 0;
  1.1010 +    SDL_GetWindowSize(window, &real_rect.w, &real_rect.h);
  1.1011 +    if (rect) {
  1.1012 +        if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
  1.1013 +            return 0;
  1.1014 +        }
  1.1015 +        if (real_rect.y > rect->y) {
  1.1016 +            pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
  1.1017 +        }
  1.1018 +        if (real_rect.x > rect->x) {
  1.1019 +            int bpp = SDL_BYTESPERPIXEL(SDL_GetWindowPixelFormat(window));
  1.1020 +            pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
  1.1021 +        }
  1.1022 +    }
  1.1023 +
  1.1024 +    return renderer->RenderReadPixels(renderer, &real_rect,
  1.1025 +                                      format, pixels, pitch);
  1.1026 +}
  1.1027 +
  1.1028 +int
  1.1029 +SDL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
  1.1030 +                      Uint32 format, const void * pixels, int pitch)
  1.1031 +{
  1.1032 +    SDL_Window *window;
  1.1033 +    SDL_Rect real_rect;
  1.1034 +
  1.1035 +    CHECK_RENDERER_MAGIC(renderer, -1);
  1.1036 +
  1.1037 +    if (!renderer->RenderWritePixels) {
  1.1038 +        SDL_Unsupported();
  1.1039 +        return -1;
  1.1040 +    }
  1.1041 +    window = renderer->window;
  1.1042 +
  1.1043 +    if (!format) {
  1.1044 +        format = SDL_GetWindowPixelFormat(window);
  1.1045 +    }
  1.1046 +
  1.1047 +    real_rect.x = 0;
  1.1048 +    real_rect.y = 0;
  1.1049 +    SDL_GetWindowSize(window, &real_rect.w, &real_rect.h);
  1.1050 +    if (rect) {
  1.1051 +        if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
  1.1052 +            return 0;
  1.1053 +        }
  1.1054 +        if (real_rect.y > rect->y) {
  1.1055 +            pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y);
  1.1056 +        }
  1.1057 +        if (real_rect.x > rect->x) {
  1.1058 +            int bpp = SDL_BYTESPERPIXEL(SDL_GetWindowPixelFormat(window));
  1.1059 +            pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x);
  1.1060 +        }
  1.1061 +    }
  1.1062 +
  1.1063 +    return renderer->RenderWritePixels(renderer, &real_rect,
  1.1064 +                                       format, pixels, pitch);
  1.1065 +}
  1.1066 +
  1.1067 +void
  1.1068 +SDL_RenderPresent(SDL_Renderer * renderer)
  1.1069 +{
  1.1070 +    CHECK_RENDERER_MAGIC(renderer, );
  1.1071 +
  1.1072 +    renderer->RenderPresent(renderer);
  1.1073 +}
  1.1074 +
  1.1075 +void
  1.1076 +SDL_DestroyTexture(SDL_Texture * texture)
  1.1077 +{
  1.1078 +    SDL_Renderer *renderer;
  1.1079 +
  1.1080 +    CHECK_TEXTURE_MAGIC(texture, );
  1.1081 +    texture->magic = NULL;
  1.1082 +
  1.1083 +    renderer = texture->renderer;
  1.1084 +    if (texture->next) {
  1.1085 +        texture->next->prev = texture->prev;
  1.1086 +    }
  1.1087 +    if (texture->prev) {
  1.1088 +        texture->prev->next = texture->next;
  1.1089 +    } else {
  1.1090 +        renderer->textures = texture->next;
  1.1091 +    }
  1.1092 +
  1.1093 +    renderer->DestroyTexture(renderer, texture);
  1.1094 +    SDL_free(texture);
  1.1095 +}
  1.1096 +
  1.1097 +void
  1.1098 +SDL_DestroyRenderer(SDL_Renderer * renderer)
  1.1099 +{
  1.1100 +    CHECK_RENDERER_MAGIC(renderer, );
  1.1101 +
  1.1102 +    SDL_DelEventWatch(SDL_RendererEventWatch, renderer);
  1.1103 +
  1.1104 +    /* Free existing textures for this renderer */
  1.1105 +    while (renderer->textures) {
  1.1106 +        SDL_DestroyTexture(renderer->textures);
  1.1107 +    }
  1.1108 +
  1.1109 +    /* It's no longer magical... */
  1.1110 +    renderer->magic = NULL;
  1.1111 +
  1.1112 +    /* Free the renderer instance */
  1.1113 +    renderer->DestroyRenderer(renderer);
  1.1114 +}
  1.1115 +
  1.1116 +/* vi: set ts=4 sw=4 expandtab: */