(none) gsoc2008_iphone
authorHolmes Futrell <hfutrell@umail.ucsb.edu>
Fri, 11 Jul 2008 00:22:16 +0000
branchgsoc2008_iphone
changeset 233569dd5af09ff1
parent 2334 80ceefc00ada
child 2336 932bd1cb2b03
(none)
src/video/SDL_renderer_gl.c
src/video/glrenderer/SDL_renderer_gl.c
     1.1 --- a/src/video/SDL_renderer_gl.c	Fri Jul 11 00:21:45 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,960 +0,0 @@
     1.4 -/*
     1.5 -    SDL - Simple DirectMedia Layer
     1.6 -    Copyright (C) 1997-2006 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 -#if SDL_VIDEO_RENDER_OGL
    1.28 -
    1.29 -#include "SDL_video.h"
    1.30 -#include "SDL_opengl.h"
    1.31 -#include "SDL_sysvideo.h"
    1.32 -#include "SDL_pixels_c.h"
    1.33 -#include "SDL_rect_c.h"
    1.34 -#include "SDL_yuv_sw_c.h"
    1.35 -
    1.36 -#ifdef __MACOSX__
    1.37 -#include <OpenGL/OpenGL.h>
    1.38 -#endif
    1.39 -
    1.40 -/* OpenGL renderer implementation */
    1.41 -
    1.42 -/* Details on optimizing the texture path on Mac OS X:
    1.43 -   http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_2.html
    1.44 -*/
    1.45 -
    1.46 -static const float inv255f = 1.0f / 255.0f;
    1.47 -
    1.48 -static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
    1.49 -static int GL_ActivateRenderer(SDL_Renderer * renderer);
    1.50 -static int GL_DisplayModeChanged(SDL_Renderer * renderer);
    1.51 -static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    1.52 -static int GL_QueryTexturePixels(SDL_Renderer * renderer,
    1.53 -                                 SDL_Texture * texture, void **pixels,
    1.54 -                                 int *pitch);
    1.55 -static int GL_SetTexturePalette(SDL_Renderer * renderer,
    1.56 -                                SDL_Texture * texture,
    1.57 -                                const SDL_Color * colors, int firstcolor,
    1.58 -                                int ncolors);
    1.59 -static int GL_GetTexturePalette(SDL_Renderer * renderer,
    1.60 -                                SDL_Texture * texture, SDL_Color * colors,
    1.61 -                                int firstcolor, int ncolors);
    1.62 -static int GL_SetTextureColorMod(SDL_Renderer * renderer,
    1.63 -                                 SDL_Texture * texture);
    1.64 -static int GL_SetTextureAlphaMod(SDL_Renderer * renderer,
    1.65 -                                 SDL_Texture * texture);
    1.66 -static int GL_SetTextureBlendMode(SDL_Renderer * renderer,
    1.67 -                                  SDL_Texture * texture);
    1.68 -static int GL_SetTextureScaleMode(SDL_Renderer * renderer,
    1.69 -                                  SDL_Texture * texture);
    1.70 -static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    1.71 -                            const SDL_Rect * rect, const void *pixels,
    1.72 -                            int pitch);
    1.73 -static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    1.74 -                          const SDL_Rect * rect, int markDirty, void **pixels,
    1.75 -                          int *pitch);
    1.76 -static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    1.77 -static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    1.78 -                            int numrects, const SDL_Rect * rects);
    1.79 -static int GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
    1.80 -                         Uint8 a, const SDL_Rect * rect);
    1.81 -static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    1.82 -                         const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    1.83 -static void GL_RenderPresent(SDL_Renderer * renderer);
    1.84 -static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    1.85 -static void GL_DestroyRenderer(SDL_Renderer * renderer);
    1.86 -
    1.87 -
    1.88 -SDL_RenderDriver GL_RenderDriver = {
    1.89 -    GL_CreateRenderer,
    1.90 -    {
    1.91 -     "opengl",
    1.92 -     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD |
    1.93 -      SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
    1.94 -     (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
    1.95 -      SDL_TEXTUREMODULATE_ALPHA),
    1.96 -     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
    1.97 -      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
    1.98 -      SDL_TEXTUREBLENDMODE_MOD),
    1.99 -     (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
   1.100 -      SDL_TEXTURESCALEMODE_SLOW),
   1.101 -     16,
   1.102 -     {
   1.103 -      SDL_PIXELFORMAT_INDEX1LSB,
   1.104 -      SDL_PIXELFORMAT_INDEX1MSB,
   1.105 -      SDL_PIXELFORMAT_INDEX8,
   1.106 -      SDL_PIXELFORMAT_RGB332,
   1.107 -      SDL_PIXELFORMAT_RGB444,
   1.108 -      SDL_PIXELFORMAT_RGB555,
   1.109 -      SDL_PIXELFORMAT_ARGB4444,
   1.110 -      SDL_PIXELFORMAT_ARGB1555,
   1.111 -      SDL_PIXELFORMAT_RGB565,
   1.112 -      SDL_PIXELFORMAT_RGB24,
   1.113 -      SDL_PIXELFORMAT_BGR24,
   1.114 -      SDL_PIXELFORMAT_RGB888,
   1.115 -      SDL_PIXELFORMAT_BGR888,
   1.116 -      SDL_PIXELFORMAT_ARGB8888,
   1.117 -      SDL_PIXELFORMAT_ABGR8888,
   1.118 -      SDL_PIXELFORMAT_ARGB2101010},
   1.119 -     0,
   1.120 -     0}
   1.121 -};
   1.122 -
   1.123 -typedef struct
   1.124 -{
   1.125 -    SDL_GLContext context;
   1.126 -    SDL_bool updateSize;
   1.127 -    SDL_bool GL_ARB_texture_rectangle_supported;
   1.128 -    SDL_bool GL_EXT_paletted_texture_supported;
   1.129 -    int blendMode;
   1.130 -    int scaleMode;
   1.131 -
   1.132 -    /* OpenGL functions */
   1.133 -#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
   1.134 -#include "SDL_glfuncs.h"
   1.135 -#undef SDL_PROC
   1.136 -
   1.137 -    PFNGLCOLORTABLEEXTPROC glColorTableEXT;
   1.138 -    void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
   1.139 -                                 const GLvoid * pointer);
   1.140 -} GL_RenderData;
   1.141 -
   1.142 -typedef struct
   1.143 -{
   1.144 -    GLuint texture;
   1.145 -    GLenum type;
   1.146 -    GLfloat texw;
   1.147 -    GLfloat texh;
   1.148 -    GLenum format;
   1.149 -    GLenum formattype;
   1.150 -    Uint8 *palette;
   1.151 -    void *pixels;
   1.152 -    int pitch;
   1.153 -    SDL_DirtyRectList dirty;
   1.154 -} GL_TextureData;
   1.155 -
   1.156 -
   1.157 -static void
   1.158 -GL_SetError(const char *prefix, GLenum result)
   1.159 -{
   1.160 -    const char *error;
   1.161 -
   1.162 -    switch (result) {
   1.163 -    case GL_NO_ERROR:
   1.164 -        error = "GL_NO_ERROR";
   1.165 -        break;
   1.166 -    case GL_INVALID_ENUM:
   1.167 -        error = "GL_INVALID_ENUM";
   1.168 -        break;
   1.169 -    case GL_INVALID_VALUE:
   1.170 -        error = "GL_INVALID_VALUE";
   1.171 -        break;
   1.172 -    case GL_INVALID_OPERATION:
   1.173 -        error = "GL_INVALID_OPERATION";
   1.174 -        break;
   1.175 -    case GL_STACK_OVERFLOW:
   1.176 -        error = "GL_STACK_OVERFLOW";
   1.177 -        break;
   1.178 -    case GL_STACK_UNDERFLOW:
   1.179 -        error = "GL_STACK_UNDERFLOW";
   1.180 -        break;
   1.181 -    case GL_OUT_OF_MEMORY:
   1.182 -        error = "GL_OUT_OF_MEMORY";
   1.183 -        break;
   1.184 -    case GL_TABLE_TOO_LARGE:
   1.185 -        error = "GL_TABLE_TOO_LARGE";
   1.186 -        break;
   1.187 -    default:
   1.188 -        error = "UNKNOWN";
   1.189 -        break;
   1.190 -    }
   1.191 -    SDL_SetError("%s: %s", prefix, error);
   1.192 -}
   1.193 -
   1.194 -static int
   1.195 -GL_LoadFunctions(GL_RenderData * data)
   1.196 -{
   1.197 -#if defined(__QNXNTO__) && (_NTO_VERSION < 630)
   1.198 -#define __SDL_NOGETPROCADDR__
   1.199 -#elif defined(__MINT__)
   1.200 -#define __SDL_NOGETPROCADDR__
   1.201 -#endif
   1.202 -#ifdef __SDL_NOGETPROCADDR__
   1.203 -#define SDL_PROC(ret,func,params) data->func=func;
   1.204 -#else
   1.205 -#define SDL_PROC(ret,func,params) \
   1.206 -    do { \
   1.207 -        data->func = SDL_GL_GetProcAddress(#func); \
   1.208 -        if ( ! data->func ) { \
   1.209 -            SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
   1.210 -            return -1; \
   1.211 -        } \
   1.212 -    } while ( 0 );
   1.213 -#endif /* __SDL_NOGETPROCADDR__ */
   1.214 -
   1.215 -#include "SDL_glfuncs.h"
   1.216 -#undef SDL_PROC
   1.217 -    return 0;
   1.218 -}
   1.219 -
   1.220 -void
   1.221 -GL_AddRenderDriver(_THIS)
   1.222 -{
   1.223 -    if (_this->GL_CreateContext) {
   1.224 -        SDL_AddRenderDriver(0, &GL_RenderDriver);
   1.225 -    }
   1.226 -}
   1.227 -
   1.228 -SDL_Renderer *
   1.229 -GL_CreateRenderer(SDL_Window * window, Uint32 flags)
   1.230 -{
   1.231 -    SDL_Renderer *renderer;
   1.232 -    GL_RenderData *data;
   1.233 -    GLint value;
   1.234 -    int doublebuffer;
   1.235 -
   1.236 -    /* Render directly to the window, unless we're compositing */
   1.237 -#ifndef __MACOSX__
   1.238 -    if (flags & SDL_RENDERER_SINGLEBUFFER) {
   1.239 -        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
   1.240 -    }
   1.241 -#endif
   1.242 -    if (!(window->flags & SDL_WINDOW_OPENGL)) {
   1.243 -        if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) {
   1.244 -            return NULL;
   1.245 -        }
   1.246 -    }
   1.247 -
   1.248 -    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   1.249 -    if (!renderer) {
   1.250 -        SDL_OutOfMemory();
   1.251 -        return NULL;
   1.252 -    }
   1.253 -
   1.254 -    data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
   1.255 -    if (!data) {
   1.256 -        GL_DestroyRenderer(renderer);
   1.257 -        SDL_OutOfMemory();
   1.258 -        return NULL;
   1.259 -    }
   1.260 -
   1.261 -    renderer->ActivateRenderer = GL_ActivateRenderer;
   1.262 -    renderer->DisplayModeChanged = GL_DisplayModeChanged;
   1.263 -    renderer->CreateTexture = GL_CreateTexture;
   1.264 -    renderer->QueryTexturePixels = GL_QueryTexturePixels;
   1.265 -    renderer->SetTexturePalette = GL_SetTexturePalette;
   1.266 -    renderer->GetTexturePalette = GL_GetTexturePalette;
   1.267 -    renderer->SetTextureColorMod = GL_SetTextureColorMod;
   1.268 -    renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod;
   1.269 -    renderer->SetTextureBlendMode = GL_SetTextureBlendMode;
   1.270 -    renderer->SetTextureScaleMode = GL_SetTextureScaleMode;
   1.271 -    renderer->UpdateTexture = GL_UpdateTexture;
   1.272 -    renderer->LockTexture = GL_LockTexture;
   1.273 -    renderer->UnlockTexture = GL_UnlockTexture;
   1.274 -    renderer->DirtyTexture = GL_DirtyTexture;
   1.275 -    renderer->RenderFill = GL_RenderFill;
   1.276 -    renderer->RenderCopy = GL_RenderCopy;
   1.277 -    renderer->RenderPresent = GL_RenderPresent;
   1.278 -    renderer->DestroyTexture = GL_DestroyTexture;
   1.279 -    renderer->DestroyRenderer = GL_DestroyRenderer;
   1.280 -    renderer->info = GL_RenderDriver.info;
   1.281 -    renderer->window = window->id;
   1.282 -    renderer->driverdata = data;
   1.283 -
   1.284 -    renderer->info.flags =
   1.285 -        (SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED);
   1.286 -
   1.287 -    if (GL_LoadFunctions(data) < 0) {
   1.288 -        GL_DestroyRenderer(renderer);
   1.289 -        return NULL;
   1.290 -    }
   1.291 -
   1.292 -    data->context = SDL_GL_CreateContext(window->id);
   1.293 -    if (!data->context) {
   1.294 -        GL_DestroyRenderer(renderer);
   1.295 -        return NULL;
   1.296 -    }
   1.297 -    if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
   1.298 -        GL_DestroyRenderer(renderer);
   1.299 -        return NULL;
   1.300 -    }
   1.301 -#ifdef __MACOSX__
   1.302 -    /* Enable multi-threaded rendering */
   1.303 -    /* Disabled until Ryan finishes his VBO/PBO code...
   1.304 -       CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine);
   1.305 -     */
   1.306 -#endif
   1.307 -
   1.308 -    if (flags & SDL_RENDERER_PRESENTVSYNC) {
   1.309 -        SDL_GL_SetSwapInterval(1);
   1.310 -    } else {
   1.311 -        SDL_GL_SetSwapInterval(0);
   1.312 -    }
   1.313 -    if (SDL_GL_GetSwapInterval() > 0) {
   1.314 -        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
   1.315 -    }
   1.316 -
   1.317 -    if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer) == 0) {
   1.318 -        if (!doublebuffer) {
   1.319 -            renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
   1.320 -        }
   1.321 -    }
   1.322 -
   1.323 -    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
   1.324 -    renderer->info.max_texture_width = value;
   1.325 -    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
   1.326 -    renderer->info.max_texture_height = value;
   1.327 -
   1.328 -    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
   1.329 -        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
   1.330 -        data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
   1.331 -    }
   1.332 -    if (SDL_GL_ExtensionSupported("GL_EXT_paletted_texture")) {
   1.333 -        data->GL_EXT_paletted_texture_supported = SDL_TRUE;
   1.334 -        data->glColorTableEXT =
   1.335 -            (PFNGLCOLORTABLEEXTPROC) SDL_GL_GetProcAddress("glColorTableEXT");
   1.336 -    } else {
   1.337 -        /* Don't advertise support for 8-bit indexed texture format */
   1.338 -        Uint32 i, j;
   1.339 -        SDL_RendererInfo *info = &renderer->info;
   1.340 -        for (i = 0, j = 0; i < info->num_texture_formats; ++i) {
   1.341 -            if (info->texture_formats[i] != SDL_PIXELFORMAT_INDEX8) {
   1.342 -                info->texture_formats[j++] = info->texture_formats[i];
   1.343 -            }
   1.344 -        }
   1.345 -        --info->num_texture_formats;
   1.346 -    }
   1.347 -    if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
   1.348 -        data->glTextureRangeAPPLE =
   1.349 -            (void (*)(GLenum, GLsizei, const GLvoid *))
   1.350 -            SDL_GL_GetProcAddress("glTextureRangeAPPLE");
   1.351 -    }
   1.352 -
   1.353 -    /* Set up parameters for rendering */
   1.354 -    data->blendMode = -1;
   1.355 -    data->scaleMode = -1;
   1.356 -    data->glDisable(GL_DEPTH_TEST);
   1.357 -    data->glDisable(GL_CULL_FACE);
   1.358 -    if (data->GL_ARB_texture_rectangle_supported) {
   1.359 -        data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
   1.360 -    } else {
   1.361 -        data->glEnable(GL_TEXTURE_2D);
   1.362 -    }
   1.363 -    data->updateSize = SDL_TRUE;
   1.364 -
   1.365 -    return renderer;
   1.366 -}
   1.367 -
   1.368 -static int
   1.369 -GL_ActivateRenderer(SDL_Renderer * renderer)
   1.370 -{
   1.371 -    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   1.372 -    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.373 -
   1.374 -    if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
   1.375 -        return -1;
   1.376 -    }
   1.377 -    if (data->updateSize) {
   1.378 -        data->glMatrixMode(GL_PROJECTION);
   1.379 -        data->glLoadIdentity();
   1.380 -        data->glMatrixMode(GL_MODELVIEW);
   1.381 -        data->glLoadIdentity();
   1.382 -        data->glViewport(0, 0, window->w, window->h);
   1.383 -        data->glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0,
   1.384 -                      0.0, 1.0);
   1.385 -        data->updateSize = SDL_FALSE;
   1.386 -    }
   1.387 -    return 0;
   1.388 -}
   1.389 -
   1.390 -static int
   1.391 -GL_DisplayModeChanged(SDL_Renderer * renderer)
   1.392 -{
   1.393 -    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   1.394 -
   1.395 -    data->updateSize = SDL_TRUE;
   1.396 -    return 0;
   1.397 -}
   1.398 -
   1.399 -static __inline__ int
   1.400 -power_of_2(int input)
   1.401 -{
   1.402 -    int value = 1;
   1.403 -
   1.404 -    while (value < input) {
   1.405 -        value <<= 1;
   1.406 -    }
   1.407 -    return value;
   1.408 -}
   1.409 -
   1.410 -static int
   1.411 -GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   1.412 -{
   1.413 -    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   1.414 -    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.415 -    GL_TextureData *data;
   1.416 -    GLint internalFormat;
   1.417 -    GLenum format, type;
   1.418 -    int texture_w, texture_h;
   1.419 -    GLenum result;
   1.420 -
   1.421 -    switch (texture->format) {
   1.422 -    case SDL_PIXELFORMAT_INDEX1LSB:
   1.423 -    case SDL_PIXELFORMAT_INDEX1MSB:
   1.424 -        internalFormat = GL_RGB;
   1.425 -        format = GL_COLOR_INDEX;
   1.426 -        type = GL_BITMAP;
   1.427 -        break;
   1.428 -    case SDL_PIXELFORMAT_INDEX8:
   1.429 -        if (!renderdata->GL_EXT_paletted_texture_supported) {
   1.430 -            SDL_SetError("Unsupported texture format");
   1.431 -            return -1;
   1.432 -        }
   1.433 -        internalFormat = GL_COLOR_INDEX8_EXT;
   1.434 -        format = GL_COLOR_INDEX;
   1.435 -        type = GL_UNSIGNED_BYTE;
   1.436 -        break;
   1.437 -    case SDL_PIXELFORMAT_RGB332:
   1.438 -        internalFormat = GL_R3_G3_B2;
   1.439 -        format = GL_RGB;
   1.440 -        type = GL_UNSIGNED_BYTE_3_3_2;
   1.441 -        break;
   1.442 -    case SDL_PIXELFORMAT_RGB444:
   1.443 -        internalFormat = GL_RGB4;
   1.444 -        format = GL_RGB;
   1.445 -        type = GL_UNSIGNED_SHORT_4_4_4_4;
   1.446 -        break;
   1.447 -    case SDL_PIXELFORMAT_RGB555:
   1.448 -        internalFormat = GL_RGB5;
   1.449 -        format = GL_RGB;
   1.450 -        type = GL_UNSIGNED_SHORT_5_5_5_1;
   1.451 -        break;
   1.452 -    case SDL_PIXELFORMAT_ARGB4444:
   1.453 -        internalFormat = GL_RGBA4;
   1.454 -        format = GL_BGRA;
   1.455 -        type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
   1.456 -        break;
   1.457 -    case SDL_PIXELFORMAT_ARGB1555:
   1.458 -        internalFormat = GL_RGB5_A1;
   1.459 -        format = GL_BGRA;
   1.460 -        type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
   1.461 -        break;
   1.462 -    case SDL_PIXELFORMAT_RGB565:
   1.463 -        internalFormat = GL_RGB8;
   1.464 -        format = GL_RGB;
   1.465 -        type = GL_UNSIGNED_SHORT_5_6_5;
   1.466 -        break;
   1.467 -    case SDL_PIXELFORMAT_RGB24:
   1.468 -        internalFormat = GL_RGB8;
   1.469 -        format = GL_RGB;
   1.470 -        type = GL_UNSIGNED_BYTE;
   1.471 -        break;
   1.472 -    case SDL_PIXELFORMAT_RGB888:
   1.473 -        internalFormat = GL_RGB8;
   1.474 -        format = GL_BGRA;
   1.475 -        type = GL_UNSIGNED_BYTE;
   1.476 -        break;
   1.477 -    case SDL_PIXELFORMAT_BGR24:
   1.478 -        internalFormat = GL_RGB8;
   1.479 -        format = GL_BGR;
   1.480 -        type = GL_UNSIGNED_BYTE;
   1.481 -        break;
   1.482 -    case SDL_PIXELFORMAT_BGR888:
   1.483 -        internalFormat = GL_RGB8;
   1.484 -        format = GL_RGBA;
   1.485 -        type = GL_UNSIGNED_BYTE;
   1.486 -        break;
   1.487 -    case SDL_PIXELFORMAT_ARGB8888:
   1.488 -#ifdef __MACOSX__
   1.489 -        internalFormat = GL_RGBA;
   1.490 -        format = GL_BGRA;
   1.491 -        type = GL_UNSIGNED_INT_8_8_8_8_REV;
   1.492 -#else
   1.493 -        internalFormat = GL_RGBA8;
   1.494 -        format = GL_BGRA;
   1.495 -        type = GL_UNSIGNED_BYTE;
   1.496 -#endif
   1.497 -        break;
   1.498 -    case SDL_PIXELFORMAT_ABGR8888:
   1.499 -        internalFormat = GL_RGBA8;
   1.500 -        format = GL_RGBA;
   1.501 -        type = GL_UNSIGNED_BYTE;
   1.502 -        break;
   1.503 -    case SDL_PIXELFORMAT_ARGB2101010:
   1.504 -        internalFormat = GL_RGB10_A2;
   1.505 -        format = GL_BGRA;
   1.506 -        type = GL_UNSIGNED_INT_2_10_10_10_REV;
   1.507 -        break;
   1.508 -    default:
   1.509 -        SDL_SetError("Unsupported texture format");
   1.510 -        return -1;
   1.511 -    }
   1.512 -
   1.513 -    data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
   1.514 -    if (!data) {
   1.515 -        SDL_OutOfMemory();
   1.516 -        return -1;
   1.517 -    }
   1.518 -
   1.519 -    if (texture->format == SDL_PIXELFORMAT_INDEX8) {
   1.520 -        data->palette = (Uint8 *) SDL_malloc(3 * 256 * sizeof(Uint8));
   1.521 -        if (!data->palette) {
   1.522 -            SDL_OutOfMemory();
   1.523 -            SDL_free(data);
   1.524 -            return -1;
   1.525 -        }
   1.526 -        SDL_memset(data->palette, 0xFF, 3 * 256 * sizeof(Uint8));
   1.527 -    }
   1.528 -
   1.529 -    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
   1.530 -        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
   1.531 -        data->pixels = SDL_malloc(texture->h * data->pitch);
   1.532 -        if (!data->pixels) {
   1.533 -            SDL_OutOfMemory();
   1.534 -            SDL_free(data);
   1.535 -            return -1;
   1.536 -        }
   1.537 -    }
   1.538 -
   1.539 -    texture->driverdata = data;
   1.540 -
   1.541 -    renderdata->glGetError();
   1.542 -    renderdata->glGenTextures(1, &data->texture);
   1.543 -    if (renderdata->GL_ARB_texture_rectangle_supported) {
   1.544 -        data->type = GL_TEXTURE_RECTANGLE_ARB;
   1.545 -        texture_w = texture->w;
   1.546 -        texture_h = texture->h;
   1.547 -        data->texw = (GLfloat) texture->w;
   1.548 -        data->texh = (GLfloat) texture->h;
   1.549 -    } else {
   1.550 -        data->type = GL_TEXTURE_2D;
   1.551 -        texture_w = power_of_2(texture->w);
   1.552 -        texture_h = power_of_2(texture->h);
   1.553 -        data->texw = (GLfloat) texture->w / texture_w;
   1.554 -        data->texh = (GLfloat) texture->h / texture_h;
   1.555 -    }
   1.556 -    data->format = format;
   1.557 -    data->formattype = type;
   1.558 -    renderdata->glBindTexture(data->type, data->texture);
   1.559 -    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
   1.560 -                                GL_NEAREST);
   1.561 -    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
   1.562 -                                GL_NEAREST);
   1.563 -    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
   1.564 -                                GL_CLAMP_TO_EDGE);
   1.565 -    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
   1.566 -                                GL_CLAMP_TO_EDGE);
   1.567 -#ifdef __MACOSX__
   1.568 -#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
   1.569 -#define GL_TEXTURE_STORAGE_HINT_APPLE       0x85BC
   1.570 -#endif
   1.571 -#ifndef STORAGE_CACHED_APPLE
   1.572 -#define STORAGE_CACHED_APPLE                0x85BE
   1.573 -#endif
   1.574 -#ifndef STORAGE_SHARED_APPLE
   1.575 -#define STORAGE_SHARED_APPLE                0x85BF
   1.576 -#endif
   1.577 -    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
   1.578 -        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
   1.579 -                                    GL_STORAGE_SHARED_APPLE);
   1.580 -    } else {
   1.581 -        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
   1.582 -                                    GL_STORAGE_CACHED_APPLE);
   1.583 -    }
   1.584 -    if (texture->access == SDL_TEXTUREACCESS_STREAMING
   1.585 -        && texture->format == SDL_PIXELFORMAT_ARGB8888) {
   1.586 -        /*
   1.587 -           if (renderdata->glTextureRangeAPPLE) {
   1.588 -           renderdata->glTextureRangeAPPLE(data->type,
   1.589 -           texture->h * data->pitch,
   1.590 -           data->pixels);
   1.591 -           }
   1.592 -         */
   1.593 -        renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
   1.594 -        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
   1.595 -                                 texture_h, 0, format, type, data->pixels);
   1.596 -    } else
   1.597 -#endif
   1.598 -    {
   1.599 -        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
   1.600 -                                 texture_h, 0, format, type, NULL);
   1.601 -    }
   1.602 -    result = renderdata->glGetError();
   1.603 -    if (result != GL_NO_ERROR) {
   1.604 -        GL_SetError("glTexImage2D()", result);
   1.605 -        return -1;
   1.606 -    }
   1.607 -    return 0;
   1.608 -}
   1.609 -
   1.610 -static int
   1.611 -GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   1.612 -                      void **pixels, int *pitch)
   1.613 -{
   1.614 -    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   1.615 -
   1.616 -    *pixels = data->pixels;
   1.617 -    *pitch = data->pitch;
   1.618 -    return 0;
   1.619 -}
   1.620 -
   1.621 -static int
   1.622 -GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   1.623 -                     const SDL_Color * colors, int firstcolor, int ncolors)
   1.624 -{
   1.625 -    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   1.626 -    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   1.627 -    Uint8 *palette;
   1.628 -
   1.629 -    if (!data->palette) {
   1.630 -        SDL_SetError("Texture doesn't have a palette");
   1.631 -        return -1;
   1.632 -    }
   1.633 -    palette = data->palette + firstcolor * 3;
   1.634 -    while (ncolors--) {
   1.635 -        *palette++ = colors->r;
   1.636 -        *palette++ = colors->g;
   1.637 -        *palette++ = colors->b;
   1.638 -        ++colors;
   1.639 -    }
   1.640 -    renderdata->glBindTexture(data->type, data->texture);
   1.641 -    renderdata->glColorTableEXT(data->type, GL_RGB8, 256, GL_RGB,
   1.642 -                                GL_UNSIGNED_BYTE, data->palette);
   1.643 -    return 0;
   1.644 -}
   1.645 -
   1.646 -static int
   1.647 -GL_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   1.648 -                     SDL_Color * colors, int firstcolor, int ncolors)
   1.649 -{
   1.650 -    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   1.651 -    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   1.652 -    Uint8 *palette;
   1.653 -
   1.654 -    if (!data->palette) {
   1.655 -        SDL_SetError("Texture doesn't have a palette");
   1.656 -        return -1;
   1.657 -    }
   1.658 -    palette = data->palette + firstcolor * 3;
   1.659 -    while (ncolors--) {
   1.660 -        colors->r = *palette++;
   1.661 -        colors->g = *palette++;
   1.662 -        colors->b = *palette++;
   1.663 -        colors->unused = SDL_ALPHA_OPAQUE;
   1.664 -        ++colors;
   1.665 -    }
   1.666 -    return 0;
   1.667 -}
   1.668 -
   1.669 -static void
   1.670 -SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
   1.671 -                   int pitch)
   1.672 -{
   1.673 -    if (texture->format == SDL_PIXELFORMAT_INDEX1LSB) {
   1.674 -        renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
   1.675 -    } else if (texture->format == SDL_PIXELFORMAT_INDEX1MSB) {
   1.676 -        renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
   1.677 -    }
   1.678 -    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   1.679 -    renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
   1.680 -                              pitch / SDL_BYTESPERPIXEL(texture->format));
   1.681 -}
   1.682 -
   1.683 -static int
   1.684 -GL_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
   1.685 -{
   1.686 -    return 0;
   1.687 -}
   1.688 -
   1.689 -static int
   1.690 -GL_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
   1.691 -{
   1.692 -    return 0;
   1.693 -}
   1.694 -
   1.695 -static int
   1.696 -GL_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
   1.697 -{
   1.698 -    switch (texture->blendMode) {
   1.699 -    case SDL_TEXTUREBLENDMODE_NONE:
   1.700 -    case SDL_TEXTUREBLENDMODE_MASK:
   1.701 -    case SDL_TEXTUREBLENDMODE_BLEND:
   1.702 -    case SDL_TEXTUREBLENDMODE_ADD:
   1.703 -    case SDL_TEXTUREBLENDMODE_MOD:
   1.704 -        return 0;
   1.705 -    default:
   1.706 -        SDL_Unsupported();
   1.707 -        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
   1.708 -        return -1;
   1.709 -    }
   1.710 -}
   1.711 -
   1.712 -static int
   1.713 -GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
   1.714 -{
   1.715 -    switch (texture->scaleMode) {
   1.716 -    case SDL_TEXTURESCALEMODE_NONE:
   1.717 -    case SDL_TEXTURESCALEMODE_FAST:
   1.718 -    case SDL_TEXTURESCALEMODE_SLOW:
   1.719 -        return 0;
   1.720 -    case SDL_TEXTURESCALEMODE_BEST:
   1.721 -        SDL_Unsupported();
   1.722 -        texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
   1.723 -        return -1;
   1.724 -    default:
   1.725 -        SDL_Unsupported();
   1.726 -        texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
   1.727 -        return -1;
   1.728 -    }
   1.729 -}
   1.730 -
   1.731 -static int
   1.732 -GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   1.733 -                 const SDL_Rect * rect, const void *pixels, int pitch)
   1.734 -{
   1.735 -    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   1.736 -    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   1.737 -    GLenum result;
   1.738 -
   1.739 -    renderdata->glGetError();
   1.740 -    SetupTextureUpdate(renderdata, texture, pitch);
   1.741 -    renderdata->glBindTexture(data->type, data->texture);
   1.742 -    renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
   1.743 -                                rect->h, data->format, data->formattype,
   1.744 -                                pixels);
   1.745 -    result = renderdata->glGetError();
   1.746 -    if (result != GL_NO_ERROR) {
   1.747 -        GL_SetError("glTexSubImage2D()", result);
   1.748 -        return -1;
   1.749 -    }
   1.750 -    return 0;
   1.751 -}
   1.752 -
   1.753 -static int
   1.754 -GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   1.755 -               const SDL_Rect * rect, int markDirty, void **pixels,
   1.756 -               int *pitch)
   1.757 -{
   1.758 -    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   1.759 -
   1.760 -    if (markDirty) {
   1.761 -        SDL_AddDirtyRect(&data->dirty, rect);
   1.762 -    }
   1.763 -
   1.764 -    *pixels =
   1.765 -        (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
   1.766 -                  rect->x * SDL_BYTESPERPIXEL(texture->format));
   1.767 -    *pitch = data->pitch;
   1.768 -    return 0;
   1.769 -}
   1.770 -
   1.771 -static void
   1.772 -GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   1.773 -{
   1.774 -}
   1.775 -
   1.776 -static void
   1.777 -GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
   1.778 -                const SDL_Rect * rects)
   1.779 -{
   1.780 -    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   1.781 -    int i;
   1.782 -
   1.783 -    for (i = 0; i < numrects; ++i) {
   1.784 -        SDL_AddDirtyRect(&data->dirty, &rects[i]);
   1.785 -    }
   1.786 -}
   1.787 -
   1.788 -static int
   1.789 -GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
   1.790 -              const SDL_Rect * rect)
   1.791 -{
   1.792 -    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   1.793 -    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.794 -
   1.795 -    data->glClearColor((GLclampf) r * inv255f, (GLclampf) g * inv255f,
   1.796 -                       (GLclampf) b * inv255f, (GLclampf) a * inv255f);
   1.797 -    data->glViewport(rect->x, window->h - rect->y, rect->w, rect->h);
   1.798 -    data->glClear(GL_COLOR_BUFFER_BIT);
   1.799 -    data->glViewport(0, 0, window->w, window->h);
   1.800 -    return 0;
   1.801 -}
   1.802 -
   1.803 -static int
   1.804 -GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   1.805 -              const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   1.806 -{
   1.807 -    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   1.808 -    GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
   1.809 -    int minx, miny, maxx, maxy;
   1.810 -    GLfloat minu, maxu, minv, maxv;
   1.811 -
   1.812 -    if (texturedata->dirty.list) {
   1.813 -        SDL_DirtyRect *dirty;
   1.814 -        void *pixels;
   1.815 -        int bpp = SDL_BYTESPERPIXEL(texture->format);
   1.816 -        int pitch = texturedata->pitch;
   1.817 -
   1.818 -        SetupTextureUpdate(data, texture, pitch);
   1.819 -        data->glBindTexture(texturedata->type, texturedata->texture);
   1.820 -        for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
   1.821 -            SDL_Rect *rect = &dirty->rect;
   1.822 -            pixels =
   1.823 -                (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch +
   1.824 -                          rect->x * bpp);
   1.825 -            data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
   1.826 -                                  rect->w, rect->h, texturedata->format,
   1.827 -                                  texturedata->formattype, pixels);
   1.828 -        }
   1.829 -        SDL_ClearDirtyRects(&texturedata->dirty);
   1.830 -    }
   1.831 -
   1.832 -    minx = dstrect->x;
   1.833 -    miny = dstrect->y;
   1.834 -    maxx = dstrect->x + dstrect->w;
   1.835 -    maxy = dstrect->y + dstrect->h;
   1.836 -
   1.837 -    minu = (GLfloat) srcrect->x / texture->w;
   1.838 -    minu *= texturedata->texw;
   1.839 -    maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
   1.840 -    maxu *= texturedata->texw;
   1.841 -    minv = (GLfloat) srcrect->y / texture->h;
   1.842 -    minv *= texturedata->texh;
   1.843 -    maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
   1.844 -    maxv *= texturedata->texh;
   1.845 -
   1.846 -    data->glBindTexture(texturedata->type, texturedata->texture);
   1.847 -
   1.848 -    if (texture->modMode) {
   1.849 -        data->glColor4f((GLfloat) texture->r * inv255f,
   1.850 -                        (GLfloat) texture->g * inv255f,
   1.851 -                        (GLfloat) texture->b * inv255f,
   1.852 -                        (GLfloat) texture->a * inv255f);
   1.853 -    } else {
   1.854 -        data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
   1.855 -    }
   1.856 -
   1.857 -    if (texture->blendMode != data->blendMode) {
   1.858 -        switch (texture->blendMode) {
   1.859 -        case SDL_TEXTUREBLENDMODE_NONE:
   1.860 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
   1.861 -            data->glDisable(GL_BLEND);
   1.862 -            break;
   1.863 -        case SDL_TEXTUREBLENDMODE_MASK:
   1.864 -        case SDL_TEXTUREBLENDMODE_BLEND:
   1.865 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   1.866 -            data->glEnable(GL_BLEND);
   1.867 -            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   1.868 -            break;
   1.869 -        case SDL_TEXTUREBLENDMODE_ADD:
   1.870 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   1.871 -            data->glEnable(GL_BLEND);
   1.872 -            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
   1.873 -            break;
   1.874 -        case SDL_TEXTUREBLENDMODE_MOD:
   1.875 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   1.876 -            data->glEnable(GL_BLEND);
   1.877 -            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
   1.878 -            break;
   1.879 -        }
   1.880 -        data->blendMode = texture->blendMode;
   1.881 -    }
   1.882 -
   1.883 -    if (texture->scaleMode != data->scaleMode) {
   1.884 -        switch (texture->scaleMode) {
   1.885 -        case SDL_TEXTURESCALEMODE_NONE:
   1.886 -        case SDL_TEXTURESCALEMODE_FAST:
   1.887 -            data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
   1.888 -                                  GL_NEAREST);
   1.889 -            data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
   1.890 -                                  GL_NEAREST);
   1.891 -            break;
   1.892 -        case SDL_TEXTURESCALEMODE_SLOW:
   1.893 -        case SDL_TEXTURESCALEMODE_BEST:
   1.894 -            data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
   1.895 -                                  GL_LINEAR);
   1.896 -            data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
   1.897 -                                  GL_LINEAR);
   1.898 -            break;
   1.899 -        }
   1.900 -        data->scaleMode = texture->scaleMode;
   1.901 -    }
   1.902 -
   1.903 -    data->glBegin(GL_TRIANGLE_STRIP);
   1.904 -    data->glTexCoord2f(minu, minv);
   1.905 -    data->glVertex2i(minx, miny);
   1.906 -    data->glTexCoord2f(maxu, minv);
   1.907 -    data->glVertex2i(maxx, miny);
   1.908 -    data->glTexCoord2f(minu, maxv);
   1.909 -    data->glVertex2i(minx, maxy);
   1.910 -    data->glTexCoord2f(maxu, maxv);
   1.911 -    data->glVertex2i(maxx, maxy);
   1.912 -    data->glEnd();
   1.913 -
   1.914 -    return 0;
   1.915 -}
   1.916 -
   1.917 -static void
   1.918 -GL_RenderPresent(SDL_Renderer * renderer)
   1.919 -{
   1.920 -    SDL_GL_SwapWindow(renderer->window);
   1.921 -}
   1.922 -
   1.923 -static void
   1.924 -GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   1.925 -{
   1.926 -    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   1.927 -    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   1.928 -
   1.929 -    if (!data) {
   1.930 -        return;
   1.931 -    }
   1.932 -    if (data->texture) {
   1.933 -        renderdata->glDeleteTextures(1, &data->texture);
   1.934 -    }
   1.935 -    if (data->palette) {
   1.936 -        SDL_free(data->palette);
   1.937 -    }
   1.938 -    if (data->pixels) {
   1.939 -        SDL_free(data->pixels);
   1.940 -    }
   1.941 -    SDL_FreeDirtyRects(&data->dirty);
   1.942 -    SDL_free(data);
   1.943 -    texture->driverdata = NULL;
   1.944 -}
   1.945 -
   1.946 -static void
   1.947 -GL_DestroyRenderer(SDL_Renderer * renderer)
   1.948 -{
   1.949 -    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   1.950 -
   1.951 -    if (data) {
   1.952 -        if (data->context) {
   1.953 -            /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
   1.954 -            SDL_GL_DeleteContext(data->context);
   1.955 -        }
   1.956 -        SDL_free(data);
   1.957 -    }
   1.958 -    SDL_free(renderer);
   1.959 -}
   1.960 -
   1.961 -#endif /* SDL_VIDEO_RENDER_OGL */
   1.962 -
   1.963 -/* vi: set ts=4 sw=4 expandtab: */
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/video/glrenderer/SDL_renderer_gl.c	Fri Jul 11 00:22:16 2008 +0000
     2.3 @@ -0,0 +1,960 @@
     2.4 +/*
     2.5 +    SDL - Simple DirectMedia Layer
     2.6 +    Copyright (C) 1997-2006 Sam Lantinga
     2.7 +
     2.8 +    This library is free software; you can redistribute it and/or
     2.9 +    modify it under the terms of the GNU Lesser General Public
    2.10 +    License as published by the Free Software Foundation; either
    2.11 +    version 2.1 of the License, or (at your option) any later version.
    2.12 +
    2.13 +    This library is distributed in the hope that it will be useful,
    2.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 +    Lesser General Public License for more details.
    2.17 +
    2.18 +    You should have received a copy of the GNU Lesser General Public
    2.19 +    License along with this library; if not, write to the Free Software
    2.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.21 +
    2.22 +    Sam Lantinga
    2.23 +    slouken@libsdl.org
    2.24 +*/
    2.25 +#include "SDL_config.h"
    2.26 +
    2.27 +#if SDL_VIDEO_RENDER_OGL
    2.28 +
    2.29 +#include "SDL_video.h"
    2.30 +#include "SDL_opengl.h"
    2.31 +#include "SDL_sysvideo.h"
    2.32 +#include "SDL_pixels_c.h"
    2.33 +#include "SDL_rect_c.h"
    2.34 +#include "SDL_yuv_sw_c.h"
    2.35 +
    2.36 +#ifdef __MACOSX__
    2.37 +#include <OpenGL/OpenGL.h>
    2.38 +#endif
    2.39 +
    2.40 +/* OpenGL renderer implementation */
    2.41 +
    2.42 +/* Details on optimizing the texture path on Mac OS X:
    2.43 +   http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_2.html
    2.44 +*/
    2.45 +
    2.46 +static const float inv255f = 1.0f / 255.0f;
    2.47 +
    2.48 +static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
    2.49 +static int GL_ActivateRenderer(SDL_Renderer * renderer);
    2.50 +static int GL_DisplayModeChanged(SDL_Renderer * renderer);
    2.51 +static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    2.52 +static int GL_QueryTexturePixels(SDL_Renderer * renderer,
    2.53 +                                 SDL_Texture * texture, void **pixels,
    2.54 +                                 int *pitch);
    2.55 +static int GL_SetTexturePalette(SDL_Renderer * renderer,
    2.56 +                                SDL_Texture * texture,
    2.57 +                                const SDL_Color * colors, int firstcolor,
    2.58 +                                int ncolors);
    2.59 +static int GL_GetTexturePalette(SDL_Renderer * renderer,
    2.60 +                                SDL_Texture * texture, SDL_Color * colors,
    2.61 +                                int firstcolor, int ncolors);
    2.62 +static int GL_SetTextureColorMod(SDL_Renderer * renderer,
    2.63 +                                 SDL_Texture * texture);
    2.64 +static int GL_SetTextureAlphaMod(SDL_Renderer * renderer,
    2.65 +                                 SDL_Texture * texture);
    2.66 +static int GL_SetTextureBlendMode(SDL_Renderer * renderer,
    2.67 +                                  SDL_Texture * texture);
    2.68 +static int GL_SetTextureScaleMode(SDL_Renderer * renderer,
    2.69 +                                  SDL_Texture * texture);
    2.70 +static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    2.71 +                            const SDL_Rect * rect, const void *pixels,
    2.72 +                            int pitch);
    2.73 +static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    2.74 +                          const SDL_Rect * rect, int markDirty, void **pixels,
    2.75 +                          int *pitch);
    2.76 +static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    2.77 +static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    2.78 +                            int numrects, const SDL_Rect * rects);
    2.79 +static int GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
    2.80 +                         Uint8 a, const SDL_Rect * rect);
    2.81 +static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    2.82 +                         const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    2.83 +static void GL_RenderPresent(SDL_Renderer * renderer);
    2.84 +static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    2.85 +static void GL_DestroyRenderer(SDL_Renderer * renderer);
    2.86 +
    2.87 +
    2.88 +SDL_RenderDriver GL_RenderDriver = {
    2.89 +    GL_CreateRenderer,
    2.90 +    {
    2.91 +     "opengl",
    2.92 +     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD |
    2.93 +      SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
    2.94 +     (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
    2.95 +      SDL_TEXTUREMODULATE_ALPHA),
    2.96 +     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
    2.97 +      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
    2.98 +      SDL_TEXTUREBLENDMODE_MOD),
    2.99 +     (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
   2.100 +      SDL_TEXTURESCALEMODE_SLOW),
   2.101 +     16,
   2.102 +     {
   2.103 +      SDL_PIXELFORMAT_INDEX1LSB,
   2.104 +      SDL_PIXELFORMAT_INDEX1MSB,
   2.105 +      SDL_PIXELFORMAT_INDEX8,
   2.106 +      SDL_PIXELFORMAT_RGB332,
   2.107 +      SDL_PIXELFORMAT_RGB444,
   2.108 +      SDL_PIXELFORMAT_RGB555,
   2.109 +      SDL_PIXELFORMAT_ARGB4444,
   2.110 +      SDL_PIXELFORMAT_ARGB1555,
   2.111 +      SDL_PIXELFORMAT_RGB565,
   2.112 +      SDL_PIXELFORMAT_RGB24,
   2.113 +      SDL_PIXELFORMAT_BGR24,
   2.114 +      SDL_PIXELFORMAT_RGB888,
   2.115 +      SDL_PIXELFORMAT_BGR888,
   2.116 +      SDL_PIXELFORMAT_ARGB8888,
   2.117 +      SDL_PIXELFORMAT_ABGR8888,
   2.118 +      SDL_PIXELFORMAT_ARGB2101010},
   2.119 +     0,
   2.120 +     0}
   2.121 +};
   2.122 +
   2.123 +typedef struct
   2.124 +{
   2.125 +    SDL_GLContext context;
   2.126 +    SDL_bool updateSize;
   2.127 +    SDL_bool GL_ARB_texture_rectangle_supported;
   2.128 +    SDL_bool GL_EXT_paletted_texture_supported;
   2.129 +    int blendMode;
   2.130 +    int scaleMode;
   2.131 +
   2.132 +    /* OpenGL functions */
   2.133 +#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
   2.134 +#include "SDL_glfuncs.h"
   2.135 +#undef SDL_PROC
   2.136 +
   2.137 +    PFNGLCOLORTABLEEXTPROC glColorTableEXT;
   2.138 +    void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
   2.139 +                                 const GLvoid * pointer);
   2.140 +} GL_RenderData;
   2.141 +
   2.142 +typedef struct
   2.143 +{
   2.144 +    GLuint texture;
   2.145 +    GLenum type;
   2.146 +    GLfloat texw;
   2.147 +    GLfloat texh;
   2.148 +    GLenum format;
   2.149 +    GLenum formattype;
   2.150 +    Uint8 *palette;
   2.151 +    void *pixels;
   2.152 +    int pitch;
   2.153 +    SDL_DirtyRectList dirty;
   2.154 +} GL_TextureData;
   2.155 +
   2.156 +
   2.157 +static void
   2.158 +GL_SetError(const char *prefix, GLenum result)
   2.159 +{
   2.160 +    const char *error;
   2.161 +
   2.162 +    switch (result) {
   2.163 +    case GL_NO_ERROR:
   2.164 +        error = "GL_NO_ERROR";
   2.165 +        break;
   2.166 +    case GL_INVALID_ENUM:
   2.167 +        error = "GL_INVALID_ENUM";
   2.168 +        break;
   2.169 +    case GL_INVALID_VALUE:
   2.170 +        error = "GL_INVALID_VALUE";
   2.171 +        break;
   2.172 +    case GL_INVALID_OPERATION:
   2.173 +        error = "GL_INVALID_OPERATION";
   2.174 +        break;
   2.175 +    case GL_STACK_OVERFLOW:
   2.176 +        error = "GL_STACK_OVERFLOW";
   2.177 +        break;
   2.178 +    case GL_STACK_UNDERFLOW:
   2.179 +        error = "GL_STACK_UNDERFLOW";
   2.180 +        break;
   2.181 +    case GL_OUT_OF_MEMORY:
   2.182 +        error = "GL_OUT_OF_MEMORY";
   2.183 +        break;
   2.184 +    case GL_TABLE_TOO_LARGE:
   2.185 +        error = "GL_TABLE_TOO_LARGE";
   2.186 +        break;
   2.187 +    default:
   2.188 +        error = "UNKNOWN";
   2.189 +        break;
   2.190 +    }
   2.191 +    SDL_SetError("%s: %s", prefix, error);
   2.192 +}
   2.193 +
   2.194 +static int
   2.195 +GL_LoadFunctions(GL_RenderData * data)
   2.196 +{
   2.197 +#if defined(__QNXNTO__) && (_NTO_VERSION < 630)
   2.198 +#define __SDL_NOGETPROCADDR__
   2.199 +#elif defined(__MINT__)
   2.200 +#define __SDL_NOGETPROCADDR__
   2.201 +#endif
   2.202 +#ifdef __SDL_NOGETPROCADDR__
   2.203 +#define SDL_PROC(ret,func,params) data->func=func;
   2.204 +#else
   2.205 +#define SDL_PROC(ret,func,params) \
   2.206 +    do { \
   2.207 +        data->func = SDL_GL_GetProcAddress(#func); \
   2.208 +        if ( ! data->func ) { \
   2.209 +            SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
   2.210 +            return -1; \
   2.211 +        } \
   2.212 +    } while ( 0 );
   2.213 +#endif /* __SDL_NOGETPROCADDR__ */
   2.214 +
   2.215 +#include "SDL_glfuncs.h"
   2.216 +#undef SDL_PROC
   2.217 +    return 0;
   2.218 +}
   2.219 +
   2.220 +void
   2.221 +GL_AddRenderDriver(_THIS)
   2.222 +{
   2.223 +    if (_this->GL_CreateContext) {
   2.224 +        SDL_AddRenderDriver(0, &GL_RenderDriver);
   2.225 +    }
   2.226 +}
   2.227 +
   2.228 +SDL_Renderer *
   2.229 +GL_CreateRenderer(SDL_Window * window, Uint32 flags)
   2.230 +{
   2.231 +    SDL_Renderer *renderer;
   2.232 +    GL_RenderData *data;
   2.233 +    GLint value;
   2.234 +    int doublebuffer;
   2.235 +
   2.236 +    /* Render directly to the window, unless we're compositing */
   2.237 +#ifndef __MACOSX__
   2.238 +    if (flags & SDL_RENDERER_SINGLEBUFFER) {
   2.239 +        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
   2.240 +    }
   2.241 +#endif
   2.242 +    if (!(window->flags & SDL_WINDOW_OPENGL)) {
   2.243 +        if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) {
   2.244 +            return NULL;
   2.245 +        }
   2.246 +    }
   2.247 +
   2.248 +    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   2.249 +    if (!renderer) {
   2.250 +        SDL_OutOfMemory();
   2.251 +        return NULL;
   2.252 +    }
   2.253 +
   2.254 +    data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
   2.255 +    if (!data) {
   2.256 +        GL_DestroyRenderer(renderer);
   2.257 +        SDL_OutOfMemory();
   2.258 +        return NULL;
   2.259 +    }
   2.260 +
   2.261 +    renderer->ActivateRenderer = GL_ActivateRenderer;
   2.262 +    renderer->DisplayModeChanged = GL_DisplayModeChanged;
   2.263 +    renderer->CreateTexture = GL_CreateTexture;
   2.264 +    renderer->QueryTexturePixels = GL_QueryTexturePixels;
   2.265 +    renderer->SetTexturePalette = GL_SetTexturePalette;
   2.266 +    renderer->GetTexturePalette = GL_GetTexturePalette;
   2.267 +    renderer->SetTextureColorMod = GL_SetTextureColorMod;
   2.268 +    renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod;
   2.269 +    renderer->SetTextureBlendMode = GL_SetTextureBlendMode;
   2.270 +    renderer->SetTextureScaleMode = GL_SetTextureScaleMode;
   2.271 +    renderer->UpdateTexture = GL_UpdateTexture;
   2.272 +    renderer->LockTexture = GL_LockTexture;
   2.273 +    renderer->UnlockTexture = GL_UnlockTexture;
   2.274 +    renderer->DirtyTexture = GL_DirtyTexture;
   2.275 +    renderer->RenderFill = GL_RenderFill;
   2.276 +    renderer->RenderCopy = GL_RenderCopy;
   2.277 +    renderer->RenderPresent = GL_RenderPresent;
   2.278 +    renderer->DestroyTexture = GL_DestroyTexture;
   2.279 +    renderer->DestroyRenderer = GL_DestroyRenderer;
   2.280 +    renderer->info = GL_RenderDriver.info;
   2.281 +    renderer->window = window->id;
   2.282 +    renderer->driverdata = data;
   2.283 +
   2.284 +    renderer->info.flags =
   2.285 +        (SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED);
   2.286 +
   2.287 +    if (GL_LoadFunctions(data) < 0) {
   2.288 +        GL_DestroyRenderer(renderer);
   2.289 +        return NULL;
   2.290 +    }
   2.291 +
   2.292 +    data->context = SDL_GL_CreateContext(window->id);
   2.293 +    if (!data->context) {
   2.294 +        GL_DestroyRenderer(renderer);
   2.295 +        return NULL;
   2.296 +    }
   2.297 +    if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
   2.298 +        GL_DestroyRenderer(renderer);
   2.299 +        return NULL;
   2.300 +    }
   2.301 +#ifdef __MACOSX__
   2.302 +    /* Enable multi-threaded rendering */
   2.303 +    /* Disabled until Ryan finishes his VBO/PBO code...
   2.304 +       CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine);
   2.305 +     */
   2.306 +#endif
   2.307 +
   2.308 +    if (flags & SDL_RENDERER_PRESENTVSYNC) {
   2.309 +        SDL_GL_SetSwapInterval(1);
   2.310 +    } else {
   2.311 +        SDL_GL_SetSwapInterval(0);
   2.312 +    }
   2.313 +    if (SDL_GL_GetSwapInterval() > 0) {
   2.314 +        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
   2.315 +    }
   2.316 +
   2.317 +    if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer) == 0) {
   2.318 +        if (!doublebuffer) {
   2.319 +            renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
   2.320 +        }
   2.321 +    }
   2.322 +
   2.323 +    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
   2.324 +    renderer->info.max_texture_width = value;
   2.325 +    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
   2.326 +    renderer->info.max_texture_height = value;
   2.327 +
   2.328 +    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
   2.329 +        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
   2.330 +        data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
   2.331 +    }
   2.332 +    if (SDL_GL_ExtensionSupported("GL_EXT_paletted_texture")) {
   2.333 +        data->GL_EXT_paletted_texture_supported = SDL_TRUE;
   2.334 +        data->glColorTableEXT =
   2.335 +            (PFNGLCOLORTABLEEXTPROC) SDL_GL_GetProcAddress("glColorTableEXT");
   2.336 +    } else {
   2.337 +        /* Don't advertise support for 8-bit indexed texture format */
   2.338 +        Uint32 i, j;
   2.339 +        SDL_RendererInfo *info = &renderer->info;
   2.340 +        for (i = 0, j = 0; i < info->num_texture_formats; ++i) {
   2.341 +            if (info->texture_formats[i] != SDL_PIXELFORMAT_INDEX8) {
   2.342 +                info->texture_formats[j++] = info->texture_formats[i];
   2.343 +            }
   2.344 +        }
   2.345 +        --info->num_texture_formats;
   2.346 +    }
   2.347 +    if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
   2.348 +        data->glTextureRangeAPPLE =
   2.349 +            (void (*)(GLenum, GLsizei, const GLvoid *))
   2.350 +            SDL_GL_GetProcAddress("glTextureRangeAPPLE");
   2.351 +    }
   2.352 +
   2.353 +    /* Set up parameters for rendering */
   2.354 +    data->blendMode = -1;
   2.355 +    data->scaleMode = -1;
   2.356 +    data->glDisable(GL_DEPTH_TEST);
   2.357 +    data->glDisable(GL_CULL_FACE);
   2.358 +    if (data->GL_ARB_texture_rectangle_supported) {
   2.359 +        data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
   2.360 +    } else {
   2.361 +        data->glEnable(GL_TEXTURE_2D);
   2.362 +    }
   2.363 +    data->updateSize = SDL_TRUE;
   2.364 +
   2.365 +    return renderer;
   2.366 +}
   2.367 +
   2.368 +static int
   2.369 +GL_ActivateRenderer(SDL_Renderer * renderer)
   2.370 +{
   2.371 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   2.372 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   2.373 +
   2.374 +    if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
   2.375 +        return -1;
   2.376 +    }
   2.377 +    if (data->updateSize) {
   2.378 +        data->glMatrixMode(GL_PROJECTION);
   2.379 +        data->glLoadIdentity();
   2.380 +        data->glMatrixMode(GL_MODELVIEW);
   2.381 +        data->glLoadIdentity();
   2.382 +        data->glViewport(0, 0, window->w, window->h);
   2.383 +        data->glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0,
   2.384 +                      0.0, 1.0);
   2.385 +        data->updateSize = SDL_FALSE;
   2.386 +    }
   2.387 +    return 0;
   2.388 +}
   2.389 +
   2.390 +static int
   2.391 +GL_DisplayModeChanged(SDL_Renderer * renderer)
   2.392 +{
   2.393 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   2.394 +
   2.395 +    data->updateSize = SDL_TRUE;
   2.396 +    return 0;
   2.397 +}
   2.398 +
   2.399 +static __inline__ int
   2.400 +power_of_2(int input)
   2.401 +{
   2.402 +    int value = 1;
   2.403 +
   2.404 +    while (value < input) {
   2.405 +        value <<= 1;
   2.406 +    }
   2.407 +    return value;
   2.408 +}
   2.409 +
   2.410 +static int
   2.411 +GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   2.412 +{
   2.413 +    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   2.414 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   2.415 +    GL_TextureData *data;
   2.416 +    GLint internalFormat;
   2.417 +    GLenum format, type;
   2.418 +    int texture_w, texture_h;
   2.419 +    GLenum result;
   2.420 +
   2.421 +    switch (texture->format) {
   2.422 +    case SDL_PIXELFORMAT_INDEX1LSB:
   2.423 +    case SDL_PIXELFORMAT_INDEX1MSB:
   2.424 +        internalFormat = GL_RGB;
   2.425 +        format = GL_COLOR_INDEX;
   2.426 +        type = GL_BITMAP;
   2.427 +        break;
   2.428 +    case SDL_PIXELFORMAT_INDEX8:
   2.429 +        if (!renderdata->GL_EXT_paletted_texture_supported) {
   2.430 +            SDL_SetError("Unsupported texture format");
   2.431 +            return -1;
   2.432 +        }
   2.433 +        internalFormat = GL_COLOR_INDEX8_EXT;
   2.434 +        format = GL_COLOR_INDEX;
   2.435 +        type = GL_UNSIGNED_BYTE;
   2.436 +        break;
   2.437 +    case SDL_PIXELFORMAT_RGB332:
   2.438 +        internalFormat = GL_R3_G3_B2;
   2.439 +        format = GL_RGB;
   2.440 +        type = GL_UNSIGNED_BYTE_3_3_2;
   2.441 +        break;
   2.442 +    case SDL_PIXELFORMAT_RGB444:
   2.443 +        internalFormat = GL_RGB4;
   2.444 +        format = GL_RGB;
   2.445 +        type = GL_UNSIGNED_SHORT_4_4_4_4;
   2.446 +        break;
   2.447 +    case SDL_PIXELFORMAT_RGB555:
   2.448 +        internalFormat = GL_RGB5;
   2.449 +        format = GL_RGB;
   2.450 +        type = GL_UNSIGNED_SHORT_5_5_5_1;
   2.451 +        break;
   2.452 +    case SDL_PIXELFORMAT_ARGB4444:
   2.453 +        internalFormat = GL_RGBA4;
   2.454 +        format = GL_BGRA;
   2.455 +        type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
   2.456 +        break;
   2.457 +    case SDL_PIXELFORMAT_ARGB1555:
   2.458 +        internalFormat = GL_RGB5_A1;
   2.459 +        format = GL_BGRA;
   2.460 +        type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
   2.461 +        break;
   2.462 +    case SDL_PIXELFORMAT_RGB565:
   2.463 +        internalFormat = GL_RGB8;
   2.464 +        format = GL_RGB;
   2.465 +        type = GL_UNSIGNED_SHORT_5_6_5;
   2.466 +        break;
   2.467 +    case SDL_PIXELFORMAT_RGB24:
   2.468 +        internalFormat = GL_RGB8;
   2.469 +        format = GL_RGB;
   2.470 +        type = GL_UNSIGNED_BYTE;
   2.471 +        break;
   2.472 +    case SDL_PIXELFORMAT_RGB888:
   2.473 +        internalFormat = GL_RGB8;
   2.474 +        format = GL_BGRA;
   2.475 +        type = GL_UNSIGNED_BYTE;
   2.476 +        break;
   2.477 +    case SDL_PIXELFORMAT_BGR24:
   2.478 +        internalFormat = GL_RGB8;
   2.479 +        format = GL_BGR;
   2.480 +        type = GL_UNSIGNED_BYTE;
   2.481 +        break;
   2.482 +    case SDL_PIXELFORMAT_BGR888:
   2.483 +        internalFormat = GL_RGB8;
   2.484 +        format = GL_RGBA;
   2.485 +        type = GL_UNSIGNED_BYTE;
   2.486 +        break;
   2.487 +    case SDL_PIXELFORMAT_ARGB8888:
   2.488 +#ifdef __MACOSX__
   2.489 +        internalFormat = GL_RGBA;
   2.490 +        format = GL_BGRA;
   2.491 +        type = GL_UNSIGNED_INT_8_8_8_8_REV;
   2.492 +#else
   2.493 +        internalFormat = GL_RGBA8;
   2.494 +        format = GL_BGRA;
   2.495 +        type = GL_UNSIGNED_BYTE;
   2.496 +#endif
   2.497 +        break;
   2.498 +    case SDL_PIXELFORMAT_ABGR8888:
   2.499 +        internalFormat = GL_RGBA8;
   2.500 +        format = GL_RGBA;
   2.501 +        type = GL_UNSIGNED_BYTE;
   2.502 +        break;
   2.503 +    case SDL_PIXELFORMAT_ARGB2101010:
   2.504 +        internalFormat = GL_RGB10_A2;
   2.505 +        format = GL_BGRA;
   2.506 +        type = GL_UNSIGNED_INT_2_10_10_10_REV;
   2.507 +        break;
   2.508 +    default:
   2.509 +        SDL_SetError("Unsupported texture format");
   2.510 +        return -1;
   2.511 +    }
   2.512 +
   2.513 +    data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
   2.514 +    if (!data) {
   2.515 +        SDL_OutOfMemory();
   2.516 +        return -1;
   2.517 +    }
   2.518 +
   2.519 +    if (texture->format == SDL_PIXELFORMAT_INDEX8) {
   2.520 +        data->palette = (Uint8 *) SDL_malloc(3 * 256 * sizeof(Uint8));
   2.521 +        if (!data->palette) {
   2.522 +            SDL_OutOfMemory();
   2.523 +            SDL_free(data);
   2.524 +            return -1;
   2.525 +        }
   2.526 +        SDL_memset(data->palette, 0xFF, 3 * 256 * sizeof(Uint8));
   2.527 +    }
   2.528 +
   2.529 +    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
   2.530 +        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
   2.531 +        data->pixels = SDL_malloc(texture->h * data->pitch);
   2.532 +        if (!data->pixels) {
   2.533 +            SDL_OutOfMemory();
   2.534 +            SDL_free(data);
   2.535 +            return -1;
   2.536 +        }
   2.537 +    }
   2.538 +
   2.539 +    texture->driverdata = data;
   2.540 +
   2.541 +    renderdata->glGetError();
   2.542 +    renderdata->glGenTextures(1, &data->texture);
   2.543 +    if (renderdata->GL_ARB_texture_rectangle_supported) {
   2.544 +        data->type = GL_TEXTURE_RECTANGLE_ARB;
   2.545 +        texture_w = texture->w;
   2.546 +        texture_h = texture->h;
   2.547 +        data->texw = (GLfloat) texture->w;
   2.548 +        data->texh = (GLfloat) texture->h;
   2.549 +    } else {
   2.550 +        data->type = GL_TEXTURE_2D;
   2.551 +        texture_w = power_of_2(texture->w);
   2.552 +        texture_h = power_of_2(texture->h);
   2.553 +        data->texw = (GLfloat) texture->w / texture_w;
   2.554 +        data->texh = (GLfloat) texture->h / texture_h;
   2.555 +    }
   2.556 +    data->format = format;
   2.557 +    data->formattype = type;
   2.558 +    renderdata->glBindTexture(data->type, data->texture);
   2.559 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
   2.560 +                                GL_NEAREST);
   2.561 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
   2.562 +                                GL_NEAREST);
   2.563 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
   2.564 +                                GL_CLAMP_TO_EDGE);
   2.565 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
   2.566 +                                GL_CLAMP_TO_EDGE);
   2.567 +#ifdef __MACOSX__
   2.568 +#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
   2.569 +#define GL_TEXTURE_STORAGE_HINT_APPLE       0x85BC
   2.570 +#endif
   2.571 +#ifndef STORAGE_CACHED_APPLE
   2.572 +#define STORAGE_CACHED_APPLE                0x85BE
   2.573 +#endif
   2.574 +#ifndef STORAGE_SHARED_APPLE
   2.575 +#define STORAGE_SHARED_APPLE                0x85BF
   2.576 +#endif
   2.577 +    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
   2.578 +        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
   2.579 +                                    GL_STORAGE_SHARED_APPLE);
   2.580 +    } else {
   2.581 +        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
   2.582 +                                    GL_STORAGE_CACHED_APPLE);
   2.583 +    }
   2.584 +    if (texture->access == SDL_TEXTUREACCESS_STREAMING
   2.585 +        && texture->format == SDL_PIXELFORMAT_ARGB8888) {
   2.586 +        /*
   2.587 +           if (renderdata->glTextureRangeAPPLE) {
   2.588 +           renderdata->glTextureRangeAPPLE(data->type,
   2.589 +           texture->h * data->pitch,
   2.590 +           data->pixels);
   2.591 +           }
   2.592 +         */
   2.593 +        renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
   2.594 +        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
   2.595 +                                 texture_h, 0, format, type, data->pixels);
   2.596 +    } else
   2.597 +#endif
   2.598 +    {
   2.599 +        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
   2.600 +                                 texture_h, 0, format, type, NULL);
   2.601 +    }
   2.602 +    result = renderdata->glGetError();
   2.603 +    if (result != GL_NO_ERROR) {
   2.604 +        GL_SetError("glTexImage2D()", result);
   2.605 +        return -1;
   2.606 +    }
   2.607 +    return 0;
   2.608 +}
   2.609 +
   2.610 +static int
   2.611 +GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   2.612 +                      void **pixels, int *pitch)
   2.613 +{
   2.614 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   2.615 +
   2.616 +    *pixels = data->pixels;
   2.617 +    *pitch = data->pitch;
   2.618 +    return 0;
   2.619 +}
   2.620 +
   2.621 +static int
   2.622 +GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   2.623 +                     const SDL_Color * colors, int firstcolor, int ncolors)
   2.624 +{
   2.625 +    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   2.626 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   2.627 +    Uint8 *palette;
   2.628 +
   2.629 +    if (!data->palette) {
   2.630 +        SDL_SetError("Texture doesn't have a palette");
   2.631 +        return -1;
   2.632 +    }
   2.633 +    palette = data->palette + firstcolor * 3;
   2.634 +    while (ncolors--) {
   2.635 +        *palette++ = colors->r;
   2.636 +        *palette++ = colors->g;
   2.637 +        *palette++ = colors->b;
   2.638 +        ++colors;
   2.639 +    }
   2.640 +    renderdata->glBindTexture(data->type, data->texture);
   2.641 +    renderdata->glColorTableEXT(data->type, GL_RGB8, 256, GL_RGB,
   2.642 +                                GL_UNSIGNED_BYTE, data->palette);
   2.643 +    return 0;
   2.644 +}
   2.645 +
   2.646 +static int
   2.647 +GL_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   2.648 +                     SDL_Color * colors, int firstcolor, int ncolors)
   2.649 +{
   2.650 +    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   2.651 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   2.652 +    Uint8 *palette;
   2.653 +
   2.654 +    if (!data->palette) {
   2.655 +        SDL_SetError("Texture doesn't have a palette");
   2.656 +        return -1;
   2.657 +    }
   2.658 +    palette = data->palette + firstcolor * 3;
   2.659 +    while (ncolors--) {
   2.660 +        colors->r = *palette++;
   2.661 +        colors->g = *palette++;
   2.662 +        colors->b = *palette++;
   2.663 +        colors->unused = SDL_ALPHA_OPAQUE;
   2.664 +        ++colors;
   2.665 +    }
   2.666 +    return 0;
   2.667 +}
   2.668 +
   2.669 +static void
   2.670 +SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
   2.671 +                   int pitch)
   2.672 +{
   2.673 +    if (texture->format == SDL_PIXELFORMAT_INDEX1LSB) {
   2.674 +        renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
   2.675 +    } else if (texture->format == SDL_PIXELFORMAT_INDEX1MSB) {
   2.676 +        renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
   2.677 +    }
   2.678 +    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   2.679 +    renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
   2.680 +                              pitch / SDL_BYTESPERPIXEL(texture->format));
   2.681 +}
   2.682 +
   2.683 +static int
   2.684 +GL_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
   2.685 +{
   2.686 +    return 0;
   2.687 +}
   2.688 +
   2.689 +static int
   2.690 +GL_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
   2.691 +{
   2.692 +    return 0;
   2.693 +}
   2.694 +
   2.695 +static int
   2.696 +GL_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
   2.697 +{
   2.698 +    switch (texture->blendMode) {
   2.699 +    case SDL_TEXTUREBLENDMODE_NONE:
   2.700 +    case SDL_TEXTUREBLENDMODE_MASK:
   2.701 +    case SDL_TEXTUREBLENDMODE_BLEND:
   2.702 +    case SDL_TEXTUREBLENDMODE_ADD:
   2.703 +    case SDL_TEXTUREBLENDMODE_MOD:
   2.704 +        return 0;
   2.705 +    default:
   2.706 +        SDL_Unsupported();
   2.707 +        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
   2.708 +        return -1;
   2.709 +    }
   2.710 +}
   2.711 +
   2.712 +static int
   2.713 +GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
   2.714 +{
   2.715 +    switch (texture->scaleMode) {
   2.716 +    case SDL_TEXTURESCALEMODE_NONE:
   2.717 +    case SDL_TEXTURESCALEMODE_FAST:
   2.718 +    case SDL_TEXTURESCALEMODE_SLOW:
   2.719 +        return 0;
   2.720 +    case SDL_TEXTURESCALEMODE_BEST:
   2.721 +        SDL_Unsupported();
   2.722 +        texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
   2.723 +        return -1;
   2.724 +    default:
   2.725 +        SDL_Unsupported();
   2.726 +        texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
   2.727 +        return -1;
   2.728 +    }
   2.729 +}
   2.730 +
   2.731 +static int
   2.732 +GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   2.733 +                 const SDL_Rect * rect, const void *pixels, int pitch)
   2.734 +{
   2.735 +    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   2.736 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   2.737 +    GLenum result;
   2.738 +
   2.739 +    renderdata->glGetError();
   2.740 +    SetupTextureUpdate(renderdata, texture, pitch);
   2.741 +    renderdata->glBindTexture(data->type, data->texture);
   2.742 +    renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
   2.743 +                                rect->h, data->format, data->formattype,
   2.744 +                                pixels);
   2.745 +    result = renderdata->glGetError();
   2.746 +    if (result != GL_NO_ERROR) {
   2.747 +        GL_SetError("glTexSubImage2D()", result);
   2.748 +        return -1;
   2.749 +    }
   2.750 +    return 0;
   2.751 +}
   2.752 +
   2.753 +static int
   2.754 +GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   2.755 +               const SDL_Rect * rect, int markDirty, void **pixels,
   2.756 +               int *pitch)
   2.757 +{
   2.758 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   2.759 +
   2.760 +    if (markDirty) {
   2.761 +        SDL_AddDirtyRect(&data->dirty, rect);
   2.762 +    }
   2.763 +
   2.764 +    *pixels =
   2.765 +        (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
   2.766 +                  rect->x * SDL_BYTESPERPIXEL(texture->format));
   2.767 +    *pitch = data->pitch;
   2.768 +    return 0;
   2.769 +}
   2.770 +
   2.771 +static void
   2.772 +GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   2.773 +{
   2.774 +}
   2.775 +
   2.776 +static void
   2.777 +GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
   2.778 +                const SDL_Rect * rects)
   2.779 +{
   2.780 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   2.781 +    int i;
   2.782 +
   2.783 +    for (i = 0; i < numrects; ++i) {
   2.784 +        SDL_AddDirtyRect(&data->dirty, &rects[i]);
   2.785 +    }
   2.786 +}
   2.787 +
   2.788 +static int
   2.789 +GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
   2.790 +              const SDL_Rect * rect)
   2.791 +{
   2.792 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   2.793 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   2.794 +
   2.795 +    data->glClearColor((GLclampf) r * inv255f, (GLclampf) g * inv255f,
   2.796 +                       (GLclampf) b * inv255f, (GLclampf) a * inv255f);
   2.797 +    data->glViewport(rect->x, window->h - rect->y, rect->w, rect->h);
   2.798 +    data->glClear(GL_COLOR_BUFFER_BIT);
   2.799 +    data->glViewport(0, 0, window->w, window->h);
   2.800 +    return 0;
   2.801 +}
   2.802 +
   2.803 +static int
   2.804 +GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   2.805 +              const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   2.806 +{
   2.807 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   2.808 +    GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
   2.809 +    int minx, miny, maxx, maxy;
   2.810 +    GLfloat minu, maxu, minv, maxv;
   2.811 +
   2.812 +    if (texturedata->dirty.list) {
   2.813 +        SDL_DirtyRect *dirty;
   2.814 +        void *pixels;
   2.815 +        int bpp = SDL_BYTESPERPIXEL(texture->format);
   2.816 +        int pitch = texturedata->pitch;
   2.817 +
   2.818 +        SetupTextureUpdate(data, texture, pitch);
   2.819 +        data->glBindTexture(texturedata->type, texturedata->texture);
   2.820 +        for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
   2.821 +            SDL_Rect *rect = &dirty->rect;
   2.822 +            pixels =
   2.823 +                (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch +
   2.824 +                          rect->x * bpp);
   2.825 +            data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
   2.826 +                                  rect->w, rect->h, texturedata->format,
   2.827 +                                  texturedata->formattype, pixels);
   2.828 +        }
   2.829 +        SDL_ClearDirtyRects(&texturedata->dirty);
   2.830 +    }
   2.831 +
   2.832 +    minx = dstrect->x;
   2.833 +    miny = dstrect->y;
   2.834 +    maxx = dstrect->x + dstrect->w;
   2.835 +    maxy = dstrect->y + dstrect->h;
   2.836 +
   2.837 +    minu = (GLfloat) srcrect->x / texture->w;
   2.838 +    minu *= texturedata->texw;
   2.839 +    maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
   2.840 +    maxu *= texturedata->texw;
   2.841 +    minv = (GLfloat) srcrect->y / texture->h;
   2.842 +    minv *= texturedata->texh;
   2.843 +    maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
   2.844 +    maxv *= texturedata->texh;
   2.845 +
   2.846 +    data->glBindTexture(texturedata->type, texturedata->texture);
   2.847 +
   2.848 +    if (texture->modMode) {
   2.849 +        data->glColor4f((GLfloat) texture->r * inv255f,
   2.850 +                        (GLfloat) texture->g * inv255f,
   2.851 +                        (GLfloat) texture->b * inv255f,
   2.852 +                        (GLfloat) texture->a * inv255f);
   2.853 +    } else {
   2.854 +        data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
   2.855 +    }
   2.856 +
   2.857 +    if (texture->blendMode != data->blendMode) {
   2.858 +        switch (texture->blendMode) {
   2.859 +        case SDL_TEXTUREBLENDMODE_NONE:
   2.860 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
   2.861 +            data->glDisable(GL_BLEND);
   2.862 +            break;
   2.863 +        case SDL_TEXTUREBLENDMODE_MASK:
   2.864 +        case SDL_TEXTUREBLENDMODE_BLEND:
   2.865 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   2.866 +            data->glEnable(GL_BLEND);
   2.867 +            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   2.868 +            break;
   2.869 +        case SDL_TEXTUREBLENDMODE_ADD:
   2.870 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   2.871 +            data->glEnable(GL_BLEND);
   2.872 +            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
   2.873 +            break;
   2.874 +        case SDL_TEXTUREBLENDMODE_MOD:
   2.875 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   2.876 +            data->glEnable(GL_BLEND);
   2.877 +            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
   2.878 +            break;
   2.879 +        }
   2.880 +        data->blendMode = texture->blendMode;
   2.881 +    }
   2.882 +
   2.883 +    if (texture->scaleMode != data->scaleMode) {
   2.884 +        switch (texture->scaleMode) {
   2.885 +        case SDL_TEXTURESCALEMODE_NONE:
   2.886 +        case SDL_TEXTURESCALEMODE_FAST:
   2.887 +            data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
   2.888 +                                  GL_NEAREST);
   2.889 +            data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
   2.890 +                                  GL_NEAREST);
   2.891 +            break;
   2.892 +        case SDL_TEXTURESCALEMODE_SLOW:
   2.893 +        case SDL_TEXTURESCALEMODE_BEST:
   2.894 +            data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
   2.895 +                                  GL_LINEAR);
   2.896 +            data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
   2.897 +                                  GL_LINEAR);
   2.898 +            break;
   2.899 +        }
   2.900 +        data->scaleMode = texture->scaleMode;
   2.901 +    }
   2.902 +
   2.903 +    data->glBegin(GL_TRIANGLE_STRIP);
   2.904 +    data->glTexCoord2f(minu, minv);
   2.905 +    data->glVertex2i(minx, miny);
   2.906 +    data->glTexCoord2f(maxu, minv);
   2.907 +    data->glVertex2i(maxx, miny);
   2.908 +    data->glTexCoord2f(minu, maxv);
   2.909 +    data->glVertex2i(minx, maxy);
   2.910 +    data->glTexCoord2f(maxu, maxv);
   2.911 +    data->glVertex2i(maxx, maxy);
   2.912 +    data->glEnd();
   2.913 +
   2.914 +    return 0;
   2.915 +}
   2.916 +
   2.917 +static void
   2.918 +GL_RenderPresent(SDL_Renderer * renderer)
   2.919 +{
   2.920 +    SDL_GL_SwapWindow(renderer->window);
   2.921 +}
   2.922 +
   2.923 +static void
   2.924 +GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   2.925 +{
   2.926 +    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   2.927 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   2.928 +
   2.929 +    if (!data) {
   2.930 +        return;
   2.931 +    }
   2.932 +    if (data->texture) {
   2.933 +        renderdata->glDeleteTextures(1, &data->texture);
   2.934 +    }
   2.935 +    if (data->palette) {
   2.936 +        SDL_free(data->palette);
   2.937 +    }
   2.938 +    if (data->pixels) {
   2.939 +        SDL_free(data->pixels);
   2.940 +    }
   2.941 +    SDL_FreeDirtyRects(&data->dirty);
   2.942 +    SDL_free(data);
   2.943 +    texture->driverdata = NULL;
   2.944 +}
   2.945 +
   2.946 +static void
   2.947 +GL_DestroyRenderer(SDL_Renderer * renderer)
   2.948 +{
   2.949 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   2.950 +
   2.951 +    if (data) {
   2.952 +        if (data->context) {
   2.953 +            /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
   2.954 +            SDL_GL_DeleteContext(data->context);
   2.955 +        }
   2.956 +        SDL_free(data);
   2.957 +    }
   2.958 +    SDL_free(renderer);
   2.959 +}
   2.960 +
   2.961 +#endif /* SDL_VIDEO_RENDER_OGL */
   2.962 +
   2.963 +/* vi: set ts=4 sw=4 expandtab: */