src/video/SDL_renderer_gl.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 06 Dec 2008 18:22:28 +0000
changeset 2843 e919f2e3700d
parent 2840 53ca0d758b0a
child 2844 70b63882d2ef
permissions -rw-r--r--
Fixed the shader fragment problems using 2 byte YUV data in a 4 byte RGB
texture. This is a total hack though. Maybe we should be using a different
texture format?
slouken@1918
     1
/*
slouken@1918
     2
    SDL - Simple DirectMedia Layer
slouken@1918
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1918
     4
slouken@1918
     5
    This library is free software; you can redistribute it and/or
slouken@1918
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1918
     7
    License as published by the Free Software Foundation; either
slouken@1918
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1918
     9
slouken@1918
    10
    This library is distributed in the hope that it will be useful,
slouken@1918
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1918
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1918
    13
    Lesser General Public License for more details.
slouken@1918
    14
slouken@1918
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1918
    16
    License along with this library; if not, write to the Free Software
slouken@1918
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1918
    18
slouken@1918
    19
    Sam Lantinga
slouken@1918
    20
    slouken@libsdl.org
slouken@1918
    21
*/
slouken@1918
    22
#include "SDL_config.h"
slouken@1918
    23
slouken@1952
    24
#if SDL_VIDEO_RENDER_OGL
slouken@1920
    25
slouken@1920
    26
#include "SDL_video.h"
slouken@1920
    27
#include "SDL_opengl.h"
slouken@1920
    28
#include "SDL_sysvideo.h"
slouken@1920
    29
#include "SDL_pixels_c.h"
slouken@1920
    30
#include "SDL_rect_c.h"
slouken@1920
    31
#include "SDL_yuv_sw_c.h"
slouken@1918
    32
slouken@2246
    33
#ifdef __MACOSX__
slouken@2246
    34
#include <OpenGL/OpenGL.h>
slouken@2246
    35
#endif
slouken@2246
    36
slouken@2778
    37
slouken@1918
    38
/* OpenGL renderer implementation */
slouken@1918
    39
slouken@2230
    40
/* Details on optimizing the texture path on Mac OS X:
slouken@2230
    41
   http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_2.html
slouken@2230
    42
*/
slouken@2230
    43
icculus@2835
    44
/* !!! FIXME: this should go in a higher level than the GL renderer. */
icculus@2835
    45
static __inline__ int
icculus@2835
    46
bytes_per_pixel(const Uint32 format)
icculus@2835
    47
{
slouken@2839
    48
    if (!SDL_ISPIXELFORMAT_FOURCC(format)) {
slouken@2839
    49
        return SDL_BYTESPERPIXEL(format);
slouken@2839
    50
    }
slouken@2839
    51
slouken@2839
    52
    /* FOURCC format */
icculus@2835
    53
    switch (format) {
slouken@2839
    54
        case SDL_PIXELFORMAT_YV12:
slouken@2839
    55
        case SDL_PIXELFORMAT_IYUV:
slouken@2839
    56
        case SDL_PIXELFORMAT_YUY2:
icculus@2835
    57
        case SDL_PIXELFORMAT_UYVY:
slouken@2839
    58
        case SDL_PIXELFORMAT_YVYU:
icculus@2835
    59
            return 2;
icculus@2835
    60
        default:
slouken@2839
    61
            return 1;  /* shouldn't ever hit this. */
icculus@2835
    62
    }
icculus@2835
    63
}
icculus@2835
    64
icculus@2835
    65
slouken@1985
    66
static const float inv255f = 1.0f / 255.0f;
slouken@1985
    67
slouken@1918
    68
static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
slouken@1923
    69
static int GL_ActivateRenderer(SDL_Renderer * renderer);
slouken@1970
    70
static int GL_DisplayModeChanged(SDL_Renderer * renderer);
slouken@1918
    71
static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@2222
    72
static int GL_QueryTexturePixels(SDL_Renderer * renderer,
slouken@2222
    73
                                 SDL_Texture * texture, void **pixels,
slouken@2222
    74
                                 int *pitch);
slouken@1918
    75
static int GL_SetTexturePalette(SDL_Renderer * renderer,
slouken@1918
    76
                                SDL_Texture * texture,
slouken@1918
    77
                                const SDL_Color * colors, int firstcolor,
slouken@1918
    78
                                int ncolors);
slouken@1918
    79
static int GL_GetTexturePalette(SDL_Renderer * renderer,
slouken@1918
    80
                                SDL_Texture * texture, SDL_Color * colors,
slouken@1918
    81
                                int firstcolor, int ncolors);
slouken@1985
    82
static int GL_SetTextureColorMod(SDL_Renderer * renderer,
slouken@1985
    83
                                 SDL_Texture * texture);
slouken@1985
    84
static int GL_SetTextureAlphaMod(SDL_Renderer * renderer,
slouken@1985
    85
                                 SDL_Texture * texture);
slouken@1985
    86
static int GL_SetTextureBlendMode(SDL_Renderer * renderer,
slouken@1985
    87
                                  SDL_Texture * texture);
slouken@1985
    88
static int GL_SetTextureScaleMode(SDL_Renderer * renderer,
slouken@1985
    89
                                  SDL_Texture * texture);
slouken@1918
    90
static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
    91
                            const SDL_Rect * rect, const void *pixels,
slouken@1918
    92
                            int pitch);
slouken@1918
    93
static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1985
    94
                          const SDL_Rect * rect, int markDirty, void **pixels,
slouken@1985
    95
                          int *pitch);
slouken@1918
    96
static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1918
    97
static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
    98
                            int numrects, const SDL_Rect * rects);
slouken@1985
    99
static int GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
slouken@1985
   100
                         Uint8 a, const SDL_Rect * rect);
slouken@1918
   101
static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1985
   102
                         const SDL_Rect * srcrect, const SDL_Rect * dstrect);
slouken@1918
   103
static void GL_RenderPresent(SDL_Renderer * renderer);
slouken@1918
   104
static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1918
   105
static void GL_DestroyRenderer(SDL_Renderer * renderer);
slouken@1918
   106
slouken@1918
   107
slouken@1918
   108
SDL_RenderDriver GL_RenderDriver = {
slouken@1918
   109
    GL_CreateRenderer,
slouken@1918
   110
    {
slouken@1918
   111
     "opengl",
slouken@1974
   112
     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD |
slouken@1974
   113
      SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
slouken@1985
   114
     (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
slouken@1985
   115
      SDL_TEXTUREMODULATE_ALPHA),
slouken@1965
   116
     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
slouken@1965
   117
      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
slouken@1965
   118
      SDL_TEXTUREBLENDMODE_MOD),
slouken@1965
   119
     (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
slouken@1965
   120
      SDL_TEXTURESCALEMODE_SLOW),
slouken@2813
   121
     15,
slouken@1918
   122
     {
slouken@1965
   123
      SDL_PIXELFORMAT_INDEX1LSB,
slouken@1965
   124
      SDL_PIXELFORMAT_INDEX1MSB,
slouken@1965
   125
      SDL_PIXELFORMAT_INDEX8,
slouken@1965
   126
      SDL_PIXELFORMAT_RGB332,
slouken@1965
   127
      SDL_PIXELFORMAT_RGB444,
slouken@1965
   128
      SDL_PIXELFORMAT_RGB555,
slouken@1965
   129
      SDL_PIXELFORMAT_ARGB4444,
slouken@1965
   130
      SDL_PIXELFORMAT_ARGB1555,
slouken@1965
   131
      SDL_PIXELFORMAT_RGB565,
slouken@1965
   132
      SDL_PIXELFORMAT_RGB24,
slouken@1965
   133
      SDL_PIXELFORMAT_BGR24,
slouken@1965
   134
      SDL_PIXELFORMAT_RGB888,
slouken@1965
   135
      SDL_PIXELFORMAT_BGR888,
slouken@1965
   136
      SDL_PIXELFORMAT_ARGB8888,
slouken@1965
   137
      SDL_PIXELFORMAT_ABGR8888,
slouken@2813
   138
      SDL_PIXELFORMAT_ARGB2101010},
slouken@1918
   139
     0,
slouken@1918
   140
     0}
slouken@1918
   141
};
slouken@1918
   142
slouken@1918
   143
typedef struct
slouken@1918
   144
{
slouken@1918
   145
    SDL_GLContext context;
slouken@2833
   146
    SDL_bool updateSize;
slouken@2233
   147
    SDL_bool GL_ARB_texture_rectangle_supported;
slouken@1974
   148
    SDL_bool GL_EXT_paletted_texture_supported;
icculus@2835
   149
    SDL_bool GL_ARB_fragment_program_supported;
slouken@1927
   150
    int blendMode;
slouken@1927
   151
    int scaleMode;
slouken@1927
   152
slouken@1927
   153
    /* OpenGL functions */
slouken@1927
   154
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
slouken@1927
   155
#include "SDL_glfuncs.h"
slouken@1927
   156
#undef SDL_PROC
slouken@1974
   157
slouken@1974
   158
    PFNGLCOLORTABLEEXTPROC glColorTableEXT;
slouken@2233
   159
    void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
slouken@2233
   160
                                 const GLvoid * pointer);
icculus@2835
   161
icculus@2835
   162
    PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
icculus@2835
   163
    PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB;
icculus@2835
   164
    PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB;
icculus@2835
   165
    PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB;
icculus@2835
   166
    PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
icculus@2835
   167
    PFNGLBINDPROGRAMARBPROC glBindProgramARB;
icculus@2835
   168
    PFNGLPROGRAMSTRINGARBPROC glProgramStringARB;
icculus@2835
   169
icculus@2835
   170
    /* (optional) fragment programs */
icculus@2835
   171
    GLuint fragment_program_UYVY;
slouken@1918
   172
} GL_RenderData;
slouken@1918
   173
slouken@1918
   174
typedef struct
slouken@1918
   175
{
slouken@1918
   176
    GLuint texture;
icculus@2835
   177
    GLuint shader;
slouken@1920
   178
    GLenum type;
slouken@1918
   179
    GLfloat texw;
slouken@1918
   180
    GLfloat texh;
slouken@1920
   181
    GLenum format;
slouken@1920
   182
    GLenum formattype;
slouken@1974
   183
    Uint8 *palette;
slouken@1918
   184
    void *pixels;
slouken@1918
   185
    int pitch;
slouken@1920
   186
    SDL_DirtyRectList dirty;
slouken@2843
   187
int HACK_RYAN_FIXME;
slouken@1918
   188
} GL_TextureData;
slouken@1918
   189
slouken@1918
   190
slouken@1924
   191
static void
slouken@1924
   192
GL_SetError(const char *prefix, GLenum result)
slouken@1924
   193
{
slouken@1924
   194
    const char *error;
slouken@1924
   195
slouken@1924
   196
    switch (result) {
slouken@1924
   197
    case GL_NO_ERROR:
slouken@1924
   198
        error = "GL_NO_ERROR";
slouken@1924
   199
        break;
slouken@1924
   200
    case GL_INVALID_ENUM:
slouken@1924
   201
        error = "GL_INVALID_ENUM";
slouken@1924
   202
        break;
slouken@1924
   203
    case GL_INVALID_VALUE:
slouken@1924
   204
        error = "GL_INVALID_VALUE";
slouken@1924
   205
        break;
slouken@1924
   206
    case GL_INVALID_OPERATION:
slouken@1924
   207
        error = "GL_INVALID_OPERATION";
slouken@1924
   208
        break;
slouken@1924
   209
    case GL_STACK_OVERFLOW:
slouken@1924
   210
        error = "GL_STACK_OVERFLOW";
slouken@1924
   211
        break;
slouken@1924
   212
    case GL_STACK_UNDERFLOW:
slouken@1924
   213
        error = "GL_STACK_UNDERFLOW";
slouken@1924
   214
        break;
slouken@1924
   215
    case GL_OUT_OF_MEMORY:
slouken@1924
   216
        error = "GL_OUT_OF_MEMORY";
slouken@1924
   217
        break;
slouken@1924
   218
    case GL_TABLE_TOO_LARGE:
slouken@1924
   219
        error = "GL_TABLE_TOO_LARGE";
slouken@1924
   220
        break;
slouken@1924
   221
    default:
slouken@1924
   222
        error = "UNKNOWN";
slouken@1924
   223
        break;
slouken@1924
   224
    }
slouken@1924
   225
    SDL_SetError("%s: %s", prefix, error);
slouken@1924
   226
}
slouken@1924
   227
slouken@1927
   228
static int
slouken@1927
   229
GL_LoadFunctions(GL_RenderData * data)
slouken@1927
   230
{
slouken@1927
   231
#if defined(__QNXNTO__) && (_NTO_VERSION < 630)
slouken@1927
   232
#define __SDL_NOGETPROCADDR__
slouken@1927
   233
#elif defined(__MINT__)
slouken@1927
   234
#define __SDL_NOGETPROCADDR__
slouken@1927
   235
#endif
slouken@1927
   236
#ifdef __SDL_NOGETPROCADDR__
slouken@1927
   237
#define SDL_PROC(ret,func,params) data->func=func;
slouken@1927
   238
#else
slouken@1927
   239
#define SDL_PROC(ret,func,params) \
slouken@1927
   240
    do { \
slouken@1927
   241
        data->func = SDL_GL_GetProcAddress(#func); \
slouken@1927
   242
        if ( ! data->func ) { \
slouken@1927
   243
            SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
slouken@1927
   244
            return -1; \
slouken@1927
   245
        } \
slouken@1927
   246
    } while ( 0 );
slouken@1927
   247
#endif /* __SDL_NOGETPROCADDR__ */
slouken@1927
   248
slouken@1927
   249
#include "SDL_glfuncs.h"
slouken@1927
   250
#undef SDL_PROC
slouken@1927
   251
    return 0;
slouken@1927
   252
}
slouken@1927
   253
slouken@1918
   254
void
slouken@1918
   255
GL_AddRenderDriver(_THIS)
slouken@1918
   256
{
slouken@1920
   257
    if (_this->GL_CreateContext) {
slouken@1918
   258
        SDL_AddRenderDriver(0, &GL_RenderDriver);
slouken@1918
   259
    }
slouken@1918
   260
}
slouken@1918
   261
slouken@1918
   262
SDL_Renderer *
slouken@1918
   263
GL_CreateRenderer(SDL_Window * window, Uint32 flags)
slouken@1918
   264
{
slouken@1918
   265
    SDL_Renderer *renderer;
slouken@1918
   266
    GL_RenderData *data;
slouken@1952
   267
    GLint value;
slouken@1974
   268
    int doublebuffer;
slouken@1918
   269
slouken@1974
   270
    /* Render directly to the window, unless we're compositing */
slouken@1974
   271
#ifndef __MACOSX__
slouken@1974
   272
    if (flags & SDL_RENDERER_SINGLEBUFFER) {
slouken@1974
   273
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
slouken@1974
   274
    }
slouken@1974
   275
#endif
slouken@1918
   276
    if (!(window->flags & SDL_WINDOW_OPENGL)) {
slouken@1928
   277
        if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) {
slouken@1924
   278
            return NULL;
slouken@1924
   279
        }
slouken@1918
   280
    }
slouken@1918
   281
slouken@1920
   282
    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
slouken@1918
   283
    if (!renderer) {
slouken@1918
   284
        SDL_OutOfMemory();
slouken@1918
   285
        return NULL;
slouken@1918
   286
    }
slouken@1918
   287
slouken@1920
   288
    data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
slouken@1918
   289
    if (!data) {
slouken@1918
   290
        GL_DestroyRenderer(renderer);
slouken@1918
   291
        SDL_OutOfMemory();
slouken@1918
   292
        return NULL;
slouken@1918
   293
    }
slouken@1918
   294
slouken@1923
   295
    renderer->ActivateRenderer = GL_ActivateRenderer;
slouken@1970
   296
    renderer->DisplayModeChanged = GL_DisplayModeChanged;
slouken@1918
   297
    renderer->CreateTexture = GL_CreateTexture;
slouken@2222
   298
    renderer->QueryTexturePixels = GL_QueryTexturePixels;
slouken@1918
   299
    renderer->SetTexturePalette = GL_SetTexturePalette;
slouken@1918
   300
    renderer->GetTexturePalette = GL_GetTexturePalette;
slouken@1985
   301
    renderer->SetTextureColorMod = GL_SetTextureColorMod;
slouken@1985
   302
    renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod;
slouken@1985
   303
    renderer->SetTextureBlendMode = GL_SetTextureBlendMode;
slouken@1985
   304
    renderer->SetTextureScaleMode = GL_SetTextureScaleMode;
slouken@1918
   305
    renderer->UpdateTexture = GL_UpdateTexture;
slouken@1918
   306
    renderer->LockTexture = GL_LockTexture;
slouken@1918
   307
    renderer->UnlockTexture = GL_UnlockTexture;
slouken@1918
   308
    renderer->DirtyTexture = GL_DirtyTexture;
slouken@1918
   309
    renderer->RenderFill = GL_RenderFill;
slouken@1918
   310
    renderer->RenderCopy = GL_RenderCopy;
slouken@1918
   311
    renderer->RenderPresent = GL_RenderPresent;
slouken@1918
   312
    renderer->DestroyTexture = GL_DestroyTexture;
slouken@1918
   313
    renderer->DestroyRenderer = GL_DestroyRenderer;
slouken@1918
   314
    renderer->info = GL_RenderDriver.info;
slouken@1918
   315
    renderer->window = window->id;
slouken@1918
   316
    renderer->driverdata = data;
slouken@1918
   317
slouken@1918
   318
    renderer->info.flags =
slouken@1965
   319
        (SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED);
slouken@1918
   320
slouken@1927
   321
    if (GL_LoadFunctions(data) < 0) {
slouken@1927
   322
        GL_DestroyRenderer(renderer);
slouken@1927
   323
        return NULL;
slouken@1927
   324
    }
slouken@1927
   325
slouken@1918
   326
    data->context = SDL_GL_CreateContext(window->id);
slouken@1918
   327
    if (!data->context) {
slouken@1918
   328
        GL_DestroyRenderer(renderer);
slouken@1918
   329
        return NULL;
slouken@1918
   330
    }
slouken@1918
   331
    if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
slouken@1918
   332
        GL_DestroyRenderer(renderer);
slouken@1918
   333
        return NULL;
slouken@1918
   334
    }
slouken@2246
   335
#ifdef __MACOSX__
slouken@2246
   336
    /* Enable multi-threaded rendering */
slouken@2246
   337
    /* Disabled until Ryan finishes his VBO/PBO code...
bob@2295
   338
       CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine);
bob@2295
   339
     */
slouken@2246
   340
#endif
slouken@2246
   341
slouken@1965
   342
    if (flags & SDL_RENDERER_PRESENTVSYNC) {
slouken@1918
   343
        SDL_GL_SetSwapInterval(1);
slouken@1918
   344
    } else {
slouken@1918
   345
        SDL_GL_SetSwapInterval(0);
slouken@1918
   346
    }
slouken@1918
   347
    if (SDL_GL_GetSwapInterval() > 0) {
slouken@1965
   348
        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
slouken@1918
   349
    }
slouken@1918
   350
slouken@1974
   351
    if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer) == 0) {
slouken@1974
   352
        if (!doublebuffer) {
slouken@1974
   353
            renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
slouken@1974
   354
        }
slouken@1974
   355
    }
slouken@1974
   356
slouken@1952
   357
    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
slouken@1952
   358
    renderer->info.max_texture_width = value;
slouken@1952
   359
    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
slouken@1952
   360
    renderer->info.max_texture_height = value;
slouken@1920
   361
slouken@1926
   362
    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
slouken@1926
   363
        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
slouken@1926
   364
        data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
slouken@1926
   365
    }
slouken@1974
   366
    if (SDL_GL_ExtensionSupported("GL_EXT_paletted_texture")) {
slouken@1974
   367
        data->GL_EXT_paletted_texture_supported = SDL_TRUE;
slouken@1974
   368
        data->glColorTableEXT =
slouken@1974
   369
            (PFNGLCOLORTABLEEXTPROC) SDL_GL_GetProcAddress("glColorTableEXT");
slouken@1974
   370
    } else {
slouken@1974
   371
        /* Don't advertise support for 8-bit indexed texture format */
slouken@1974
   372
        Uint32 i, j;
slouken@1974
   373
        SDL_RendererInfo *info = &renderer->info;
slouken@1974
   374
        for (i = 0, j = 0; i < info->num_texture_formats; ++i) {
slouken@1974
   375
            if (info->texture_formats[i] != SDL_PIXELFORMAT_INDEX8) {
slouken@1974
   376
                info->texture_formats[j++] = info->texture_formats[i];
slouken@1974
   377
            }
slouken@1974
   378
        }
slouken@1974
   379
        --info->num_texture_formats;
slouken@1974
   380
    }
slouken@2233
   381
    if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
slouken@2233
   382
        data->glTextureRangeAPPLE =
slouken@2233
   383
            (void (*)(GLenum, GLsizei, const GLvoid *))
slouken@2233
   384
            SDL_GL_GetProcAddress("glTextureRangeAPPLE");
slouken@2233
   385
    }
slouken@1920
   386
icculus@2835
   387
    /* we might use fragment programs for YUV data, etc. */
icculus@2835
   388
    if (SDL_GL_ExtensionSupported("GL_ARB_fragment_program")) {
icculus@2835
   389
        /* !!! FIXME: this doesn't check for errors. */
icculus@2835
   390
        /* !!! FIXME: this should really reuse the glfuncs.h stuff. */
icculus@2835
   391
        data->glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC)
icculus@2835
   392
            SDL_GL_GetProcAddress("glGetProgramivARB");
icculus@2835
   393
        data->glGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC)
icculus@2835
   394
            SDL_GL_GetProcAddress("glGetProgramStringARB");
icculus@2835
   395
        data->glProgramLocalParameter4fvARB =
icculus@2835
   396
            (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)
icculus@2835
   397
            SDL_GL_GetProcAddress("glProgramLocalParameter4fvARB");
icculus@2835
   398
        data->glDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC)
icculus@2835
   399
            SDL_GL_GetProcAddress("glDeleteProgramsARB");
icculus@2835
   400
        data->glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)
icculus@2835
   401
            SDL_GL_GetProcAddress("glGenProgramsARB");
icculus@2835
   402
        data->glBindProgramARB = (PFNGLBINDPROGRAMARBPROC)
icculus@2835
   403
            SDL_GL_GetProcAddress("glBindProgramARB");
icculus@2835
   404
        data->glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)
icculus@2835
   405
            SDL_GL_GetProcAddress("glProgramStringARB");
icculus@2835
   406
        data->GL_ARB_fragment_program_supported = SDL_TRUE;
icculus@2835
   407
    }
icculus@2835
   408
slouken@1918
   409
    /* Set up parameters for rendering */
slouken@1927
   410
    data->blendMode = -1;
slouken@1927
   411
    data->scaleMode = -1;
slouken@1927
   412
    data->glDisable(GL_DEPTH_TEST);
slouken@1927
   413
    data->glDisable(GL_CULL_FACE);
slouken@1926
   414
    if (data->GL_ARB_texture_rectangle_supported) {
slouken@1927
   415
        data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
slouken@1926
   416
    } else {
slouken@1927
   417
        data->glEnable(GL_TEXTURE_2D);
slouken@1926
   418
    }
slouken@2833
   419
    data->updateSize = SDL_TRUE;
slouken@1918
   420
slouken@1918
   421
    return renderer;
slouken@1918
   422
}
slouken@1918
   423
slouken@1923
   424
static int
slouken@1923
   425
GL_ActivateRenderer(SDL_Renderer * renderer)
slouken@1923
   426
{
slouken@1923
   427
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1923
   428
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@1923
   429
slouken@1970
   430
    if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
slouken@1970
   431
        return -1;
slouken@1970
   432
    }
slouken@2833
   433
    if (data->updateSize) {
slouken@2836
   434
        data->glMatrixMode(GL_PROJECTION);
slouken@2836
   435
        data->glLoadIdentity();
slouken@2836
   436
        data->glMatrixMode(GL_MODELVIEW);
slouken@2836
   437
        data->glLoadIdentity();
slouken@2836
   438
        data->glViewport(0, 0, window->w, window->h);
slouken@2836
   439
        data->glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0,
slouken@2836
   440
                      0.0, 1.0);
slouken@2833
   441
        data->updateSize = SDL_FALSE;
slouken@2833
   442
    }
slouken@1970
   443
    return 0;
slouken@1970
   444
}
slouken@1970
   445
slouken@1970
   446
static int
slouken@1970
   447
GL_DisplayModeChanged(SDL_Renderer * renderer)
slouken@1970
   448
{
slouken@1970
   449
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1970
   450
slouken@2836
   451
    /* Rebind the context to the window area and update matrices */
slouken@2836
   452
    data->updateSize = SDL_TRUE;
slouken@2836
   453
    return GL_ActivateRenderer(renderer);
slouken@1923
   454
}
slouken@1923
   455
slouken@1922
   456
static __inline__ int
slouken@1922
   457
power_of_2(int input)
slouken@1922
   458
{
slouken@1922
   459
    int value = 1;
slouken@1922
   460
slouken@1922
   461
    while (value < input) {
slouken@1922
   462
        value <<= 1;
slouken@1922
   463
    }
slouken@1922
   464
    return value;
slouken@1922
   465
}
slouken@1922
   466
icculus@2835
   467
icculus@2835
   468
#define DEBUG_PROGRAM_COMPILE 1
icculus@2835
   469
icculus@2835
   470
static GLuint
icculus@2835
   471
compile_shader(GL_RenderData *data, GLenum shader_type, const char *source)
icculus@2835
   472
{
icculus@2835
   473
#if DEBUG_PROGRAM_COMPILE
icculus@2835
   474
    printf("compiling shader:\n%s\n\n", source);
icculus@2835
   475
#endif
icculus@2835
   476
icculus@2835
   477
    GLuint program = 0;
icculus@2835
   478
icculus@2835
   479
    data->glGetError();  /* flush any existing error state. */
icculus@2835
   480
    data->glGenProgramsARB(1, &program);
icculus@2835
   481
    data->glBindProgramARB(shader_type, program);
icculus@2835
   482
    data->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
icculus@2835
   483
                             SDL_strlen(source), source);
icculus@2835
   484
icculus@2835
   485
    if (data->glGetError() == GL_INVALID_OPERATION)
icculus@2835
   486
    { 
icculus@2835
   487
#if DEBUG_PROGRAM_COMPILE
icculus@2835
   488
        GLint pos = 0;
icculus@2835
   489
        const GLubyte *errstr;
icculus@2835
   490
        data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
icculus@2835
   491
        errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
icculus@2835
   492
        printf("program compile error at position %d: %s\n\n",
icculus@2835
   493
                  (int) pos, (const char *) errstr);
icculus@2835
   494
#endif
icculus@2835
   495
        data->glBindProgramARB(shader_type, 0);
icculus@2835
   496
        data->glDeleteProgramsARB(1, &program);
icculus@2835
   497
        return 0;
icculus@2835
   498
    } // if
icculus@2835
   499
icculus@2835
   500
    return program;
icculus@2835
   501
}
icculus@2835
   502
icculus@2835
   503
// UYVY to RGB equasion...
icculus@2835
   504
//  R = 1.164(Y-16) + 1.596(Cr-128)
icculus@2835
   505
//  G = 1.164(Y-16) - 0.813(Cr-128) - 0.391(Cb-128)
icculus@2835
   506
//  B = 1.164(Y-16) + 2.018(Cb-128)
icculus@2835
   507
// Byte layout is Cb, Y1, Cr, Y2.
icculus@2835
   508
// 4 bytes == 2 pixels: Y1/Cb/Cr, Y2/Cb/Cr
icculus@2835
   509
// !!! FIXME: this ignores blendmodes, etc.
icculus@2835
   510
// !!! FIXME: this could be more efficient...use a dot product for green, not convert to 255.0 range, etc.
icculus@2835
   511
static const char *fragment_program_UYVY_source_code =
icculus@2835
   512
    "!!ARBfp1.0\n"
icculus@2835
   513
icculus@2835
   514
    // outputs...
icculus@2835
   515
    "OUTPUT outcolor = result.color;\n"
icculus@2835
   516
icculus@2835
   517
    // scratch registers...
icculus@2835
   518
    "TEMP uyvy;\n"
icculus@2835
   519
    "TEMP luminance;\n"
icculus@2835
   520
    "TEMP work;\n"
icculus@2835
   521
icculus@2835
   522
    // We need 32 bits to store the data, but each pixel is 16 bits in itself.
icculus@2835
   523
    //  halve the coordinates to grab the correct 32 bits for the fragment.
icculus@2835
   524
    "MUL work, fragment.texcoord, { 0.5, 1.0, 1.0, 1.0 };\n"
icculus@2835
   525
icculus@2835
   526
    // Sample the YUV texture. Cb, Y1, Cr, Y2, are stored in r,g,b,a.
icculus@2835
   527
    // !!! FIXME: "RECT" needs to be "2D" if we're not using texture_rectangle extension.  :/
icculus@2835
   528
    "TEX uyvy, work, texture[0], RECT;\n"
icculus@2835
   529
icculus@2835
   530
    // Scale from 0.0/1.0 to 0.0/255.0 and do subtractions.  (!!! FIXME: optimize!)
icculus@2835
   531
    "MUL uyvy, uyvy, { 255.0, 255.0, 255.0, 255.0 };\n"
icculus@2835
   532
    "SUB uyvy, uyvy, { 128.0, 16.0, 128.0, 16.0 };\n"
icculus@2835
   533
icculus@2835
   534
    // Choose the luminance component by texcoord.
icculus@2835
   535
    // !!! FIXME: laziness wins out for now... just average Y1 and Y2.
icculus@2835
   536
    "ADD luminance, uyvy.yyyy, uyvy.wwww;\n"
icculus@2835
   537
    "MUL luminance, luminance, { 0.5, 0.5, 0.5, 0.5 };\n"
icculus@2835
   538
icculus@2835
   539
    // Multiply luminance by its magic value.
icculus@2835
   540
    "MUL luminance, luminance, { 1.164, 1.164, 1.164, 1.164 };\n"
icculus@2835
   541
icculus@2835
   542
    // uyvy.xyzw becomes Cr/Cr/Cb/Cb, with multiplications.
icculus@2835
   543
    "MUL uyvy, uyvy.zzxx, { 1.596, -0.813, 2.018, -0.391 };\n"
icculus@2835
   544
icculus@2835
   545
    // Add luminance Cr and Cb, store to RGB channels.
icculus@2835
   546
    "ADD work.rgb, luminance, uyvy;\n"
icculus@2835
   547
icculus@2835
   548
    // Do final addition for Green channel.  (!!! FIXME: this should be a DPH?)
icculus@2835
   549
    "ADD work.g, work.g, uyvy.w;\n"
icculus@2835
   550
icculus@2835
   551
    // Scale back to 0.0/1.0. (this number is 1.0/255.0).
icculus@2835
   552
    "MUL work, work, { 0.0039215686274509803, 0.0039215686274509803, 0.0039215686274509803, 0.0039215686274509803 };\n"
icculus@2835
   553
icculus@2835
   554
    // Make sure alpha channel is fully opaque.  (!!! FIXME: blend modes!)
icculus@2835
   555
    "MOV work.a, { 1.0 };\n"
icculus@2835
   556
icculus@2835
   557
    // Store out the final fragment color.
icculus@2835
   558
    "MOV outcolor, work;\n"
icculus@2835
   559
icculus@2835
   560
    // ...and we're done.
icculus@2835
   561
    "END\n";
icculus@2835
   562
icculus@2835
   563
slouken@1918
   564
static int
slouken@1918
   565
GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
   566
{
slouken@1918
   567
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   568
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@1918
   569
    GL_TextureData *data;
slouken@1920
   570
    GLint internalFormat;
slouken@1920
   571
    GLenum format, type;
slouken@1922
   572
    int texture_w, texture_h;
icculus@2835
   573
    GLuint shader = 0;
slouken@1924
   574
    GLenum result;
slouken@1918
   575
slouken@1920
   576
    switch (texture->format) {
slouken@1965
   577
    case SDL_PIXELFORMAT_INDEX1LSB:
slouken@1965
   578
    case SDL_PIXELFORMAT_INDEX1MSB:
slouken@1920
   579
        internalFormat = GL_RGB;
slouken@1920
   580
        format = GL_COLOR_INDEX;
slouken@1920
   581
        type = GL_BITMAP;
slouken@1920
   582
        break;
slouken@1965
   583
    case SDL_PIXELFORMAT_INDEX8:
slouken@1974
   584
        if (!renderdata->GL_EXT_paletted_texture_supported) {
slouken@1974
   585
            SDL_SetError("Unsupported texture format");
slouken@1974
   586
            return -1;
slouken@1974
   587
        }
slouken@1974
   588
        internalFormat = GL_COLOR_INDEX8_EXT;
slouken@1920
   589
        format = GL_COLOR_INDEX;
slouken@1920
   590
        type = GL_UNSIGNED_BYTE;
slouken@1920
   591
        break;
slouken@1965
   592
    case SDL_PIXELFORMAT_RGB332:
slouken@1920
   593
        internalFormat = GL_R3_G3_B2;
slouken@1920
   594
        format = GL_RGB;
slouken@1920
   595
        type = GL_UNSIGNED_BYTE_3_3_2;
slouken@1920
   596
        break;
slouken@1965
   597
    case SDL_PIXELFORMAT_RGB444:
slouken@1920
   598
        internalFormat = GL_RGB4;
slouken@1920
   599
        format = GL_RGB;
slouken@1920
   600
        type = GL_UNSIGNED_SHORT_4_4_4_4;
slouken@1920
   601
        break;
slouken@1965
   602
    case SDL_PIXELFORMAT_RGB555:
slouken@1920
   603
        internalFormat = GL_RGB5;
slouken@1920
   604
        format = GL_RGB;
slouken@1920
   605
        type = GL_UNSIGNED_SHORT_5_5_5_1;
slouken@1920
   606
        break;
slouken@1965
   607
    case SDL_PIXELFORMAT_ARGB4444:
slouken@1920
   608
        internalFormat = GL_RGBA4;
slouken@1920
   609
        format = GL_BGRA;
slouken@1920
   610
        type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
slouken@1920
   611
        break;
slouken@1965
   612
    case SDL_PIXELFORMAT_ARGB1555:
slouken@1920
   613
        internalFormat = GL_RGB5_A1;
slouken@1920
   614
        format = GL_BGRA;
slouken@1920
   615
        type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
slouken@1920
   616
        break;
slouken@1965
   617
    case SDL_PIXELFORMAT_RGB565:
slouken@1920
   618
        internalFormat = GL_RGB8;
slouken@1920
   619
        format = GL_RGB;
slouken@1920
   620
        type = GL_UNSIGNED_SHORT_5_6_5;
slouken@1920
   621
        break;
slouken@1965
   622
    case SDL_PIXELFORMAT_RGB24:
slouken@1920
   623
        internalFormat = GL_RGB8;
slouken@1920
   624
        format = GL_RGB;
slouken@1920
   625
        type = GL_UNSIGNED_BYTE;
slouken@1920
   626
        break;
slouken@1965
   627
    case SDL_PIXELFORMAT_RGB888:
slouken@1920
   628
        internalFormat = GL_RGB8;
slouken@1924
   629
        format = GL_BGRA;
slouken@1924
   630
        type = GL_UNSIGNED_BYTE;
slouken@1920
   631
        break;
slouken@1965
   632
    case SDL_PIXELFORMAT_BGR24:
slouken@1920
   633
        internalFormat = GL_RGB8;
slouken@1920
   634
        format = GL_BGR;
slouken@1920
   635
        type = GL_UNSIGNED_BYTE;
slouken@1920
   636
        break;
slouken@1965
   637
    case SDL_PIXELFORMAT_BGR888:
slouken@1920
   638
        internalFormat = GL_RGB8;
slouken@1924
   639
        format = GL_RGBA;
slouken@1924
   640
        type = GL_UNSIGNED_BYTE;
slouken@1920
   641
        break;
slouken@1965
   642
    case SDL_PIXELFORMAT_ARGB8888:
slouken@2230
   643
#ifdef __MACOSX__
slouken@2230
   644
        internalFormat = GL_RGBA;
slouken@2230
   645
        format = GL_BGRA;
slouken@2230
   646
        type = GL_UNSIGNED_INT_8_8_8_8_REV;
slouken@2230
   647
#else
slouken@1920
   648
        internalFormat = GL_RGBA8;
slouken@1920
   649
        format = GL_BGRA;
slouken@1924
   650
        type = GL_UNSIGNED_BYTE;
slouken@2230
   651
#endif
slouken@1920
   652
        break;
slouken@1965
   653
    case SDL_PIXELFORMAT_ABGR8888:
slouken@1920
   654
        internalFormat = GL_RGBA8;
slouken@1920
   655
        format = GL_RGBA;
slouken@1924
   656
        type = GL_UNSIGNED_BYTE;
slouken@1920
   657
        break;
slouken@1965
   658
    case SDL_PIXELFORMAT_ARGB2101010:
slouken@1920
   659
        internalFormat = GL_RGB10_A2;
slouken@1920
   660
        format = GL_BGRA;
slouken@1920
   661
        type = GL_UNSIGNED_INT_2_10_10_10_REV;
slouken@1920
   662
        break;
icculus@2835
   663
    case SDL_PIXELFORMAT_UYVY:
icculus@2835
   664
        if (renderdata->GL_ARB_fragment_program_supported) {
icculus@2835
   665
            if (renderdata->fragment_program_UYVY == 0) {
icculus@2835
   666
                renderdata->fragment_program_UYVY =
icculus@2835
   667
                    compile_shader(renderdata, GL_FRAGMENT_PROGRAM_ARB,
icculus@2835
   668
                                   fragment_program_UYVY_source_code);
icculus@2835
   669
                if (renderdata->fragment_program_UYVY == 0) {
icculus@2835
   670
                    SDL_SetError("Fragment program compile error");
icculus@2835
   671
                    return -1;
icculus@2835
   672
                }
icculus@2835
   673
            }
icculus@2835
   674
            shader = renderdata->fragment_program_UYVY;
icculus@2835
   675
            internalFormat = GL_RGBA;
icculus@2835
   676
            format = GL_RGBA;
icculus@2835
   677
            type = GL_UNSIGNED_BYTE;
icculus@2835
   678
        } else {
icculus@2835
   679
            SDL_SetError("Unsupported texture format");
icculus@2835
   680
            return -1;
icculus@2835
   681
        }
icculus@2835
   682
        break;
slouken@1920
   683
    default:
slouken@1920
   684
        SDL_SetError("Unsupported texture format");
slouken@1920
   685
        return -1;
slouken@1920
   686
    }
slouken@1920
   687
slouken@1920
   688
    data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
slouken@1918
   689
    if (!data) {
slouken@1918
   690
        SDL_OutOfMemory();
slouken@1918
   691
        return -1;
slouken@1918
   692
    }
slouken@1918
   693
icculus@2835
   694
    data->shader = shader;
icculus@2835
   695
slouken@1974
   696
    if (texture->format == SDL_PIXELFORMAT_INDEX8) {
slouken@1974
   697
        data->palette = (Uint8 *) SDL_malloc(3 * 256 * sizeof(Uint8));
slouken@1974
   698
        if (!data->palette) {
slouken@1974
   699
            SDL_OutOfMemory();
slouken@1974
   700
            SDL_free(data);
slouken@1974
   701
            return -1;
slouken@1974
   702
        }
slouken@1974
   703
        SDL_memset(data->palette, 0xFF, 3 * 256 * sizeof(Uint8));
slouken@1974
   704
    }
slouken@1974
   705
slouken@2222
   706
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
icculus@2835
   707
        data->pitch = texture->w * bytes_per_pixel(texture->format);
slouken@2222
   708
        data->pixels = SDL_malloc(texture->h * data->pitch);
slouken@2222
   709
        if (!data->pixels) {
slouken@2222
   710
            SDL_OutOfMemory();
slouken@2222
   711
            SDL_free(data);
slouken@2222
   712
            return -1;
slouken@2222
   713
        }
slouken@2222
   714
    }
slouken@2222
   715
slouken@1918
   716
    texture->driverdata = data;
slouken@1918
   717
slouken@1927
   718
    renderdata->glGetError();
slouken@1927
   719
    renderdata->glGenTextures(1, &data->texture);
slouken@1926
   720
    if (renderdata->GL_ARB_texture_rectangle_supported) {
slouken@1926
   721
        data->type = GL_TEXTURE_RECTANGLE_ARB;
slouken@1926
   722
        texture_w = texture->w;
slouken@1926
   723
        texture_h = texture->h;
icculus@2835
   724
        data->texw = (GLfloat) texture_w;
icculus@2835
   725
        data->texh = (GLfloat) texture_h;
slouken@1926
   726
    } else {
slouken@1926
   727
        data->type = GL_TEXTURE_2D;
slouken@1926
   728
        texture_w = power_of_2(texture->w);
slouken@1926
   729
        texture_h = power_of_2(texture->h);
icculus@2835
   730
        data->texw = (GLfloat) (texture->w) / texture_w;
slouken@1926
   731
        data->texh = (GLfloat) texture->h / texture_h;
slouken@1926
   732
    }
icculus@2835
   733
slouken@2839
   734
    /* YUV formats use RGBA but are really two bytes per pixel */
slouken@2839
   735
    if (internalFormat == GL_RGBA && bytes_per_pixel(texture->format) < 4) {
slouken@2843
   736
data->HACK_RYAN_FIXME = 2;
slouken@2843
   737
    } else {
slouken@2843
   738
data->HACK_RYAN_FIXME = 1;
slouken@2839
   739
    }
slouken@2843
   740
    texture_w /= data->HACK_RYAN_FIXME;
slouken@2839
   741
slouken@1920
   742
    data->format = format;
slouken@1920
   743
    data->formattype = type;
slouken@1927
   744
    renderdata->glBindTexture(data->type, data->texture);
slouken@2230
   745
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
slouken@2230
   746
                                GL_NEAREST);
slouken@2230
   747
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
slouken@2230
   748
                                GL_NEAREST);
slouken@2230
   749
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
slouken@2230
   750
                                GL_CLAMP_TO_EDGE);
slouken@2230
   751
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
slouken@2230
   752
                                GL_CLAMP_TO_EDGE);
slouken@2840
   753
#ifdef __MACOSX__
slouken@2230
   754
#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
slouken@2230
   755
#define GL_TEXTURE_STORAGE_HINT_APPLE       0x85BC
slouken@2230
   756
#endif
slouken@2230
   757
#ifndef STORAGE_CACHED_APPLE
slouken@2230
   758
#define STORAGE_CACHED_APPLE                0x85BE
slouken@2230
   759
#endif
slouken@2230
   760
#ifndef STORAGE_SHARED_APPLE
slouken@2230
   761
#define STORAGE_SHARED_APPLE                0x85BF
slouken@2230
   762
#endif
slouken@2230
   763
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
slouken@2230
   764
        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
slouken@2230
   765
                                    GL_STORAGE_SHARED_APPLE);
slouken@2230
   766
    } else {
slouken@2230
   767
        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
slouken@2230
   768
                                    GL_STORAGE_CACHED_APPLE);
slouken@2230
   769
    }
slouken@2809
   770
/* This causes a crash in testoverlay for some reason.  Apple bug? */
slouken@2809
   771
#if 0
bob@2295
   772
    if (texture->access == SDL_TEXTUREACCESS_STREAMING
bob@2295
   773
        && texture->format == SDL_PIXELFORMAT_ARGB8888) {
slouken@2237
   774
        /*
bob@2295
   775
           if (renderdata->glTextureRangeAPPLE) {
bob@2295
   776
           renderdata->glTextureRangeAPPLE(data->type,
bob@2295
   777
           texture->h * data->pitch,
bob@2295
   778
           data->pixels);
bob@2295
   779
           }
bob@2295
   780
         */
slouken@2230
   781
        renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
slouken@2230
   782
        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
slouken@2230
   783
                                 texture_h, 0, format, type, data->pixels);
slouken@2230
   784
    } else
slouken@2230
   785
#endif
slouken@2809
   786
#endif
slouken@2230
   787
    {
slouken@2840
   788
printf("teximage2d(%d,%d)\n", (int) texture_w, (int) texture_h);
slouken@2230
   789
        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
slouken@2230
   790
                                 texture_h, 0, format, type, NULL);
slouken@2230
   791
    }
slouken@1927
   792
    result = renderdata->glGetError();
slouken@1924
   793
    if (result != GL_NO_ERROR) {
slouken@1924
   794
        GL_SetError("glTexImage2D()", result);
slouken@1924
   795
        return -1;
slouken@1924
   796
    }
slouken@1918
   797
    return 0;
slouken@1918
   798
}
slouken@1918
   799
slouken@1918
   800
static int
slouken@2222
   801
GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@2222
   802
                      void **pixels, int *pitch)
slouken@2222
   803
{
slouken@2222
   804
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@2222
   805
slouken@2222
   806
    *pixels = data->pixels;
slouken@2222
   807
    *pitch = data->pitch;
slouken@2222
   808
    return 0;
slouken@2222
   809
}
slouken@2222
   810
slouken@2222
   811
static int
slouken@1918
   812
GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
   813
                     const SDL_Color * colors, int firstcolor, int ncolors)
slouken@1918
   814
{
slouken@1918
   815
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   816
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1974
   817
    Uint8 *palette;
slouken@1918
   818
slouken@1974
   819
    if (!data->palette) {
slouken@1974
   820
        SDL_SetError("Texture doesn't have a palette");
slouken@1974
   821
        return -1;
slouken@1974
   822
    }
slouken@1974
   823
    palette = data->palette + firstcolor * 3;
slouken@1974
   824
    while (ncolors--) {
slouken@1974
   825
        *palette++ = colors->r;
slouken@1974
   826
        *palette++ = colors->g;
slouken@1974
   827
        *palette++ = colors->b;
slouken@1974
   828
        ++colors;
slouken@1974
   829
    }
slouken@1974
   830
    renderdata->glBindTexture(data->type, data->texture);
slouken@1974
   831
    renderdata->glColorTableEXT(data->type, GL_RGB8, 256, GL_RGB,
slouken@1974
   832
                                GL_UNSIGNED_BYTE, data->palette);
slouken@1918
   833
    return 0;
slouken@1918
   834
}
slouken@1918
   835
slouken@1918
   836
static int
slouken@1918
   837
GL_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
   838
                     SDL_Color * colors, int firstcolor, int ncolors)
slouken@1918
   839
{
slouken@1974
   840
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   841
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1974
   842
    Uint8 *palette;
slouken@1918
   843
slouken@1974
   844
    if (!data->palette) {
slouken@1974
   845
        SDL_SetError("Texture doesn't have a palette");
slouken@1974
   846
        return -1;
slouken@1974
   847
    }
slouken@1974
   848
    palette = data->palette + firstcolor * 3;
slouken@1974
   849
    while (ncolors--) {
slouken@1974
   850
        colors->r = *palette++;
slouken@1974
   851
        colors->g = *palette++;
slouken@1974
   852
        colors->b = *palette++;
slouken@1974
   853
        colors->unused = SDL_ALPHA_OPAQUE;
slouken@1974
   854
        ++colors;
slouken@1974
   855
    }
slouken@1918
   856
    return 0;
slouken@1918
   857
}
slouken@1918
   858
slouken@1924
   859
static void
slouken@1927
   860
SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
slouken@1927
   861
                   int pitch)
slouken@1924
   862
{
slouken@1965
   863
    if (texture->format == SDL_PIXELFORMAT_INDEX1LSB) {
slouken@1927
   864
        renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
slouken@1965
   865
    } else if (texture->format == SDL_PIXELFORMAT_INDEX1MSB) {
slouken@1927
   866
        renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
slouken@1924
   867
    }
slouken@1927
   868
    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
slouken@2808
   869
    renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
slouken@2843
   870
                              (pitch / bytes_per_pixel(texture->format) / ((GL_TextureData *)texture->driverdata)->HACK_RYAN_FIXME));
slouken@1924
   871
}
slouken@1924
   872
slouken@1918
   873
static int
slouken@1985
   874
GL_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
   875
{
slouken@1986
   876
    return 0;
slouken@1985
   877
}
slouken@1985
   878
slouken@1985
   879
static int
slouken@1985
   880
GL_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
   881
{
slouken@1986
   882
    return 0;
slouken@1985
   883
}
slouken@1985
   884
slouken@1985
   885
static int
slouken@1985
   886
GL_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
   887
{
slouken@1985
   888
    switch (texture->blendMode) {
slouken@1985
   889
    case SDL_TEXTUREBLENDMODE_NONE:
slouken@1985
   890
    case SDL_TEXTUREBLENDMODE_MASK:
slouken@1985
   891
    case SDL_TEXTUREBLENDMODE_BLEND:
slouken@1985
   892
    case SDL_TEXTUREBLENDMODE_ADD:
slouken@1985
   893
    case SDL_TEXTUREBLENDMODE_MOD:
slouken@1985
   894
        return 0;
slouken@1985
   895
    default:
slouken@1985
   896
        SDL_Unsupported();
slouken@1985
   897
        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
slouken@1985
   898
        return -1;
slouken@1985
   899
    }
slouken@1985
   900
}
slouken@1985
   901
slouken@1985
   902
static int
slouken@1985
   903
GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
   904
{
slouken@1985
   905
    switch (texture->scaleMode) {
slouken@1985
   906
    case SDL_TEXTURESCALEMODE_NONE:
slouken@1985
   907
    case SDL_TEXTURESCALEMODE_FAST:
slouken@1985
   908
    case SDL_TEXTURESCALEMODE_SLOW:
slouken@1985
   909
        return 0;
slouken@1985
   910
    case SDL_TEXTURESCALEMODE_BEST:
slouken@1985
   911
        SDL_Unsupported();
slouken@1985
   912
        texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
slouken@1985
   913
        return -1;
slouken@1985
   914
    default:
slouken@1985
   915
        SDL_Unsupported();
slouken@1985
   916
        texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
slouken@1985
   917
        return -1;
slouken@1985
   918
    }
slouken@1985
   919
}
slouken@1985
   920
slouken@1985
   921
static int
slouken@1918
   922
GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
   923
                 const SDL_Rect * rect, const void *pixels, int pitch)
slouken@1918
   924
{
slouken@1927
   925
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   926
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1924
   927
    GLenum result;
slouken@1918
   928
slouken@1927
   929
    renderdata->glGetError();
slouken@1927
   930
    SetupTextureUpdate(renderdata, texture, pitch);
slouken@1927
   931
    renderdata->glBindTexture(data->type, data->texture);
icculus@2835
   932
printf("texsubimage2d(%d,%d,%d,%d)\n", (int) rect->x, (int) rect->y, (int) rect->w, (int) rect->h);
slouken@1927
   933
    renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
slouken@1927
   934
                                rect->h, data->format, data->formattype,
slouken@1927
   935
                                pixels);
slouken@1927
   936
    result = renderdata->glGetError();
slouken@1924
   937
    if (result != GL_NO_ERROR) {
slouken@1924
   938
        GL_SetError("glTexSubImage2D()", result);
slouken@1924
   939
        return -1;
slouken@1924
   940
    }
slouken@1918
   941
    return 0;
slouken@1918
   942
}
slouken@1918
   943
slouken@1918
   944
static int
slouken@1918
   945
GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
   946
               const SDL_Rect * rect, int markDirty, void **pixels,
slouken@1918
   947
               int *pitch)
slouken@1918
   948
{
slouken@1918
   949
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1918
   950
slouken@1920
   951
    if (markDirty) {
slouken@1920
   952
        SDL_AddDirtyRect(&data->dirty, rect);
slouken@1920
   953
    }
slouken@1918
   954
slouken@1920
   955
    *pixels =
slouken@1920
   956
        (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
icculus@2835
   957
                  rect->x * bytes_per_pixel(texture->format));
slouken@1920
   958
    *pitch = data->pitch;
slouken@1918
   959
    return 0;
slouken@1918
   960
}
slouken@1918
   961
slouken@1918
   962
static void
slouken@1918
   963
GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
   964
{
slouken@1918
   965
}
slouken@1918
   966
slouken@1918
   967
static void
slouken@1918
   968
GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
slouken@1918
   969
                const SDL_Rect * rects)
slouken@1918
   970
{
slouken@1918
   971
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1918
   972
    int i;
slouken@1918
   973
slouken@1918
   974
    for (i = 0; i < numrects; ++i) {
slouken@1920
   975
        SDL_AddDirtyRect(&data->dirty, &rects[i]);
slouken@1918
   976
    }
slouken@1918
   977
}
slouken@1918
   978
slouken@1918
   979
static int
slouken@1985
   980
GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
slouken@1985
   981
              const SDL_Rect * rect)
slouken@1918
   982
{
slouken@1918
   983
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1918
   984
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@1918
   985
slouken@1985
   986
    data->glClearColor((GLclampf) r * inv255f, (GLclampf) g * inv255f,
slouken@1985
   987
                       (GLclampf) b * inv255f, (GLclampf) a * inv255f);
slouken@1927
   988
    data->glViewport(rect->x, window->h - rect->y, rect->w, rect->h);
slouken@1927
   989
    data->glClear(GL_COLOR_BUFFER_BIT);
slouken@1927
   990
    data->glViewport(0, 0, window->w, window->h);
slouken@1918
   991
    return 0;
slouken@1918
   992
}
slouken@1918
   993
slouken@1918
   994
static int
slouken@1918
   995
GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1985
   996
              const SDL_Rect * srcrect, const SDL_Rect * dstrect)
slouken@1918
   997
{
slouken@1918
   998
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1918
   999
    GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
slouken@1918
  1000
    int minx, miny, maxx, maxy;
slouken@1918
  1001
    GLfloat minu, maxu, minv, maxv;
slouken@1918
  1002
slouken@2275
  1003
    if (texturedata->dirty.list) {
slouken@1920
  1004
        SDL_DirtyRect *dirty;
slouken@1920
  1005
        void *pixels;
icculus@2835
  1006
        int bpp = bytes_per_pixel(texture->format);
slouken@1920
  1007
        int pitch = texturedata->pitch;
slouken@1920
  1008
slouken@1927
  1009
        SetupTextureUpdate(data, texture, pitch);
slouken@1927
  1010
        data->glBindTexture(texturedata->type, texturedata->texture);
slouken@1920
  1011
        for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
slouken@1920
  1012
            SDL_Rect *rect = &dirty->rect;
slouken@1920
  1013
            pixels =
slouken@1920
  1014
                (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch +
slouken@1920
  1015
                          rect->x * bpp);
icculus@2835
  1016
printf("texsubimage2d(%d,%d,%d,%d)\n", (int) rect->x, (int) rect->y, (int) rect->w, (int) rect->h);
slouken@1927
  1017
            data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
slouken@2843
  1018
                                  rect->w / texturedata->HACK_RYAN_FIXME, rect->h, texturedata->format,
slouken@1927
  1019
                                  texturedata->formattype, pixels);
slouken@1920
  1020
        }
slouken@1920
  1021
        SDL_ClearDirtyRects(&texturedata->dirty);
slouken@1920
  1022
    }
slouken@1920
  1023
slouken@1918
  1024
    minx = dstrect->x;
slouken@1918
  1025
    miny = dstrect->y;
slouken@1918
  1026
    maxx = dstrect->x + dstrect->w;
slouken@1918
  1027
    maxy = dstrect->y + dstrect->h;
slouken@1918
  1028
slouken@1918
  1029
    minu = (GLfloat) srcrect->x / texture->w;
slouken@1920
  1030
    minu *= texturedata->texw;
slouken@1918
  1031
    maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
slouken@1920
  1032
    maxu *= texturedata->texw;
slouken@1918
  1033
    minv = (GLfloat) srcrect->y / texture->h;
slouken@1920
  1034
    minv *= texturedata->texh;
slouken@1918
  1035
    maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
slouken@1920
  1036
    maxv *= texturedata->texh;
slouken@1918
  1037
slouken@1927
  1038
    data->glBindTexture(texturedata->type, texturedata->texture);
slouken@1918
  1039
slouken@1985
  1040
    if (texture->modMode) {
slouken@1985
  1041
        data->glColor4f((GLfloat) texture->r * inv255f,
slouken@1985
  1042
                        (GLfloat) texture->g * inv255f,
slouken@1985
  1043
                        (GLfloat) texture->b * inv255f,
slouken@1985
  1044
                        (GLfloat) texture->a * inv255f);
slouken@1985
  1045
    } else {
slouken@1985
  1046
        data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
slouken@1985
  1047
    }
slouken@1985
  1048
slouken@1985
  1049
    if (texture->blendMode != data->blendMode) {
slouken@1985
  1050
        switch (texture->blendMode) {
slouken@1965
  1051
        case SDL_TEXTUREBLENDMODE_NONE:
slouken@1927
  1052
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
slouken@1927
  1053
            data->glDisable(GL_BLEND);
slouken@1927
  1054
            break;
slouken@1965
  1055
        case SDL_TEXTUREBLENDMODE_MASK:
slouken@1965
  1056
        case SDL_TEXTUREBLENDMODE_BLEND:
slouken@1927
  1057
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@1927
  1058
            data->glEnable(GL_BLEND);
slouken@1927
  1059
            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
slouken@1927
  1060
            break;
slouken@1965
  1061
        case SDL_TEXTUREBLENDMODE_ADD:
slouken@1927
  1062
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@1927
  1063
            data->glEnable(GL_BLEND);
slouken@1927
  1064
            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
slouken@1927
  1065
            break;
slouken@1965
  1066
        case SDL_TEXTUREBLENDMODE_MOD:
slouken@1927
  1067
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@1927
  1068
            data->glEnable(GL_BLEND);
slouken@1927
  1069
            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
slouken@1927
  1070
            break;
slouken@1927
  1071
        }
slouken@1985
  1072
        data->blendMode = texture->blendMode;
slouken@1918
  1073
    }
slouken@1918
  1074
slouken@1985
  1075
    if (texture->scaleMode != data->scaleMode) {
slouken@1985
  1076
        switch (texture->scaleMode) {
slouken@1965
  1077
        case SDL_TEXTURESCALEMODE_NONE:
slouken@1965
  1078
        case SDL_TEXTURESCALEMODE_FAST:
slouken@1927
  1079
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
slouken@1927
  1080
                                  GL_NEAREST);
slouken@1927
  1081
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
slouken@1927
  1082
                                  GL_NEAREST);
slouken@1927
  1083
            break;
slouken@1965
  1084
        case SDL_TEXTURESCALEMODE_SLOW:
slouken@1965
  1085
        case SDL_TEXTURESCALEMODE_BEST:
slouken@1927
  1086
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
slouken@1927
  1087
                                  GL_LINEAR);
slouken@1927
  1088
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
slouken@1927
  1089
                                  GL_LINEAR);
slouken@1927
  1090
            break;
slouken@1927
  1091
        }
slouken@1985
  1092
        data->scaleMode = texture->scaleMode;
slouken@1918
  1093
    }
slouken@1918
  1094
icculus@2835
  1095
    if (texturedata->shader != 0) {
icculus@2835
  1096
        data->glEnable(GL_FRAGMENT_PROGRAM_ARB);
icculus@2835
  1097
        data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, texturedata->shader);
icculus@2835
  1098
    }
icculus@2835
  1099
slouken@1927
  1100
    data->glBegin(GL_TRIANGLE_STRIP);
slouken@1927
  1101
    data->glTexCoord2f(minu, minv);
slouken@1927
  1102
    data->glVertex2i(minx, miny);
slouken@1927
  1103
    data->glTexCoord2f(maxu, minv);
slouken@1927
  1104
    data->glVertex2i(maxx, miny);
slouken@1927
  1105
    data->glTexCoord2f(minu, maxv);
slouken@1927
  1106
    data->glVertex2i(minx, maxy);
slouken@1927
  1107
    data->glTexCoord2f(maxu, maxv);
slouken@1927
  1108
    data->glVertex2i(maxx, maxy);
slouken@1927
  1109
    data->glEnd();
slouken@1918
  1110
icculus@2835
  1111
    if (texturedata->shader != 0) {
icculus@2835
  1112
        data->glDisable(GL_FRAGMENT_PROGRAM_ARB);
icculus@2835
  1113
    }
slouken@1918
  1114
    return 0;
slouken@1918
  1115
}
slouken@1918
  1116
slouken@1918
  1117
static void
slouken@1918
  1118
GL_RenderPresent(SDL_Renderer * renderer)
slouken@1918
  1119
{
slouken@1918
  1120
    SDL_GL_SwapWindow(renderer->window);
slouken@1918
  1121
}
slouken@1918
  1122
slouken@1918
  1123
static void
slouken@1918
  1124
GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
  1125
{
slouken@1927
  1126
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
  1127
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1918
  1128
slouken@1918
  1129
    if (!data) {
slouken@1918
  1130
        return;
slouken@1918
  1131
    }
slouken@1918
  1132
    if (data->texture) {
slouken@1927
  1133
        renderdata->glDeleteTextures(1, &data->texture);
slouken@1918
  1134
    }
slouken@1974
  1135
    if (data->palette) {
slouken@1974
  1136
        SDL_free(data->palette);
slouken@1974
  1137
    }
slouken@1920
  1138
    if (data->pixels) {
slouken@1920
  1139
        SDL_free(data->pixels);
slouken@1920
  1140
    }
slouken@1920
  1141
    SDL_FreeDirtyRects(&data->dirty);
slouken@1918
  1142
    SDL_free(data);
slouken@1918
  1143
    texture->driverdata = NULL;
slouken@1918
  1144
}
slouken@1918
  1145
slouken@1975
  1146
static void
slouken@1918
  1147
GL_DestroyRenderer(SDL_Renderer * renderer)
slouken@1918
  1148
{
slouken@1918
  1149
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1918
  1150
slouken@1918
  1151
    if (data) {
slouken@1920
  1152
        if (data->context) {
icculus@2835
  1153
            if (data->GL_ARB_fragment_program_supported) {
icculus@2835
  1154
                data->glDisable(GL_FRAGMENT_PROGRAM_ARB);
icculus@2835
  1155
                data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0);
icculus@2835
  1156
                if (data->fragment_program_UYVY != 0) {
icculus@2835
  1157
                    data->glDeleteProgramsARB(1, &data->fragment_program_UYVY);
icculus@2835
  1158
                }
icculus@2835
  1159
            }
icculus@2835
  1160
bob@2328
  1161
            /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
slouken@1920
  1162
            SDL_GL_DeleteContext(data->context);
slouken@1918
  1163
        }
slouken@1918
  1164
        SDL_free(data);
slouken@1918
  1165
    }
slouken@1918
  1166
    SDL_free(renderer);
slouken@1918
  1167
}
slouken@1918
  1168
slouken@1952
  1169
#endif /* SDL_VIDEO_RENDER_OGL */
slouken@1918
  1170
slouken@1918
  1171
/* vi: set ts=4 sw=4 expandtab: */