src/render/opengl/SDL_render_gl.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 08 Feb 2011 10:38:12 -0800
changeset 5227 9c0c4d767ef6
parent 5226 710d00cb3a6a
child 5228 811beeb698f9
permissions -rw-r--r--
Reduce duplicated code in the texture update code paths
slouken@1918
     1
/*
slouken@1918
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 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@5226
    24
#if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED
slouken@1920
    25
slouken@1920
    26
#include "SDL_opengl.h"
slouken@5154
    27
#include "../SDL_sysrender.h"
slouken@1918
    28
slouken@2246
    29
#ifdef __MACOSX__
slouken@2246
    30
#include <OpenGL/OpenGL.h>
slouken@2246
    31
#endif
slouken@2246
    32
slouken@2778
    33
slouken@1918
    34
/* OpenGL renderer implementation */
slouken@1918
    35
slouken@2230
    36
/* Details on optimizing the texture path on Mac OS X:
slouken@5203
    37
   http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/opengl_texturedata.html
slouken@2230
    38
*/
slouken@2230
    39
slouken@5154
    40
/* Used to re-create the window with OpenGL capability */
slouken@5154
    41
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
icculus@2835
    42
slouken@1985
    43
static const float inv255f = 1.0f / 255.0f;
slouken@1985
    44
slouken@1918
    45
static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
slouken@5147
    46
static void GL_WindowEvent(SDL_Renderer * renderer,
slouken@5147
    47
                           const SDL_WindowEvent *event);
slouken@1918
    48
static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1918
    49
static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
    50
                            const SDL_Rect * rect, const void *pixels,
slouken@1918
    51
                            int pitch);
slouken@1918
    52
static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@5156
    53
                          const SDL_Rect * rect, void **pixels, int *pitch);
slouken@1918
    54
static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@5224
    55
static void GL_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect);
slouken@3596
    56
static int GL_RenderClear(SDL_Renderer * renderer);
slouken@3596
    57
static int GL_RenderDrawPoints(SDL_Renderer * renderer,
slouken@3596
    58
                               const SDL_Point * points, int count);
slouken@3596
    59
static int GL_RenderDrawLines(SDL_Renderer * renderer,
slouken@3596
    60
                              const SDL_Point * points, int count);
slouken@3596
    61
static int GL_RenderFillRects(SDL_Renderer * renderer,
slouken@3596
    62
                              const SDL_Rect ** rects, int count);
slouken@1918
    63
static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1985
    64
                         const SDL_Rect * srcrect, const SDL_Rect * dstrect);
slouken@3431
    65
static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@3435
    66
                               Uint32 pixel_format, void * pixels, int pitch);
slouken@1918
    67
static void GL_RenderPresent(SDL_Renderer * renderer);
slouken@1918
    68
static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1918
    69
static void GL_DestroyRenderer(SDL_Renderer * renderer);
slouken@1918
    70
slouken@1918
    71
slouken@1918
    72
SDL_RenderDriver GL_RenderDriver = {
slouken@1918
    73
    GL_CreateRenderer,
slouken@1918
    74
    {
slouken@1918
    75
     "opengl",
slouken@5203
    76
     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
slouken@5156
    77
     1,
slouken@5156
    78
     {SDL_PIXELFORMAT_ARGB8888},
slouken@1918
    79
     0,
slouken@1918
    80
     0}
slouken@1918
    81
};
slouken@1918
    82
slouken@1918
    83
typedef struct
slouken@1918
    84
{
slouken@1918
    85
    SDL_GLContext context;
slouken@2833
    86
    SDL_bool updateSize;
slouken@2233
    87
    SDL_bool GL_ARB_texture_rectangle_supported;
slouken@1927
    88
    int blendMode;
slouken@1927
    89
slouken@1927
    90
    /* OpenGL functions */
slouken@1927
    91
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
slouken@5204
    92
#include "SDL_glfuncs.h"
slouken@1927
    93
#undef SDL_PROC
slouken@1974
    94
slouken@2233
    95
    void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
slouken@2233
    96
                                 const GLvoid * pointer);
slouken@1918
    97
} GL_RenderData;
slouken@1918
    98
slouken@1918
    99
typedef struct
slouken@1918
   100
{
slouken@1918
   101
    GLuint texture;
slouken@1920
   102
    GLenum type;
slouken@1918
   103
    GLfloat texw;
slouken@1918
   104
    GLfloat texh;
slouken@1920
   105
    GLenum format;
slouken@1920
   106
    GLenum formattype;
slouken@1918
   107
    void *pixels;
slouken@1918
   108
    int pitch;
slouken@5227
   109
    SDL_Rect locked_rect;
slouken@1918
   110
} GL_TextureData;
slouken@1918
   111
slouken@1918
   112
slouken@1924
   113
static void
slouken@1924
   114
GL_SetError(const char *prefix, GLenum result)
slouken@1924
   115
{
slouken@1924
   116
    const char *error;
slouken@1924
   117
slouken@1924
   118
    switch (result) {
slouken@1924
   119
    case GL_NO_ERROR:
slouken@1924
   120
        error = "GL_NO_ERROR";
slouken@1924
   121
        break;
slouken@1924
   122
    case GL_INVALID_ENUM:
slouken@1924
   123
        error = "GL_INVALID_ENUM";
slouken@1924
   124
        break;
slouken@1924
   125
    case GL_INVALID_VALUE:
slouken@1924
   126
        error = "GL_INVALID_VALUE";
slouken@1924
   127
        break;
slouken@1924
   128
    case GL_INVALID_OPERATION:
slouken@1924
   129
        error = "GL_INVALID_OPERATION";
slouken@1924
   130
        break;
slouken@1924
   131
    case GL_STACK_OVERFLOW:
slouken@1924
   132
        error = "GL_STACK_OVERFLOW";
slouken@1924
   133
        break;
slouken@1924
   134
    case GL_STACK_UNDERFLOW:
slouken@1924
   135
        error = "GL_STACK_UNDERFLOW";
slouken@1924
   136
        break;
slouken@1924
   137
    case GL_OUT_OF_MEMORY:
slouken@1924
   138
        error = "GL_OUT_OF_MEMORY";
slouken@1924
   139
        break;
slouken@1924
   140
    case GL_TABLE_TOO_LARGE:
slouken@1924
   141
        error = "GL_TABLE_TOO_LARGE";
slouken@1924
   142
        break;
slouken@1924
   143
    default:
slouken@1924
   144
        error = "UNKNOWN";
slouken@1924
   145
        break;
slouken@1924
   146
    }
slouken@1924
   147
    SDL_SetError("%s: %s", prefix, error);
slouken@1924
   148
}
slouken@1924
   149
slouken@1927
   150
static int
slouken@1927
   151
GL_LoadFunctions(GL_RenderData * data)
slouken@1927
   152
{
slouken@1927
   153
#ifdef __SDL_NOGETPROCADDR__
slouken@1927
   154
#define SDL_PROC(ret,func,params) data->func=func;
slouken@1927
   155
#else
slouken@1927
   156
#define SDL_PROC(ret,func,params) \
slouken@1927
   157
    do { \
slouken@1927
   158
        data->func = SDL_GL_GetProcAddress(#func); \
slouken@1927
   159
        if ( ! data->func ) { \
slouken@1927
   160
            SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
slouken@1927
   161
            return -1; \
slouken@1927
   162
        } \
slouken@1927
   163
    } while ( 0 );
slouken@1927
   164
#endif /* __SDL_NOGETPROCADDR__ */
slouken@1927
   165
slouken@5204
   166
#include "SDL_glfuncs.h"
slouken@1927
   167
#undef SDL_PROC
slouken@1927
   168
    return 0;
slouken@1927
   169
}
slouken@1927
   170
slouken@1918
   171
SDL_Renderer *
slouken@1918
   172
GL_CreateRenderer(SDL_Window * window, Uint32 flags)
slouken@1918
   173
{
slouken@1918
   174
    SDL_Renderer *renderer;
slouken@1918
   175
    GL_RenderData *data;
slouken@1952
   176
    GLint value;
slouken@5154
   177
    Uint32 window_flags;
slouken@1918
   178
slouken@5154
   179
    window_flags = SDL_GetWindowFlags(window);
slouken@5154
   180
    if (!(window_flags & SDL_WINDOW_OPENGL)) {
slouken@5154
   181
        if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
slouken@1924
   182
            return NULL;
slouken@1924
   183
        }
slouken@1918
   184
    }
slouken@1918
   185
slouken@1920
   186
    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
slouken@1918
   187
    if (!renderer) {
slouken@1918
   188
        SDL_OutOfMemory();
slouken@1918
   189
        return NULL;
slouken@1918
   190
    }
slouken@1918
   191
slouken@1920
   192
    data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
slouken@1918
   193
    if (!data) {
slouken@1918
   194
        GL_DestroyRenderer(renderer);
slouken@1918
   195
        SDL_OutOfMemory();
slouken@1918
   196
        return NULL;
slouken@1918
   197
    }
slouken@1918
   198
slouken@5147
   199
    renderer->WindowEvent = GL_WindowEvent;
slouken@1918
   200
    renderer->CreateTexture = GL_CreateTexture;
slouken@1918
   201
    renderer->UpdateTexture = GL_UpdateTexture;
slouken@1918
   202
    renderer->LockTexture = GL_LockTexture;
slouken@1918
   203
    renderer->UnlockTexture = GL_UnlockTexture;
slouken@5224
   204
    renderer->SetClipRect = GL_SetClipRect;
slouken@3596
   205
    renderer->RenderClear = GL_RenderClear;
slouken@3596
   206
    renderer->RenderDrawPoints = GL_RenderDrawPoints;
slouken@3596
   207
    renderer->RenderDrawLines = GL_RenderDrawLines;
slouken@3596
   208
    renderer->RenderFillRects = GL_RenderFillRects;
slouken@1918
   209
    renderer->RenderCopy = GL_RenderCopy;
slouken@3431
   210
    renderer->RenderReadPixels = GL_RenderReadPixels;
slouken@1918
   211
    renderer->RenderPresent = GL_RenderPresent;
slouken@1918
   212
    renderer->DestroyTexture = GL_DestroyTexture;
slouken@1918
   213
    renderer->DestroyRenderer = GL_DestroyRenderer;
slouken@1918
   214
    renderer->info = GL_RenderDriver.info;
slouken@1918
   215
    renderer->driverdata = data;
slouken@1918
   216
slouken@5142
   217
    renderer->info.flags = SDL_RENDERER_ACCELERATED;
slouken@1918
   218
slouken@3685
   219
    data->context = SDL_GL_CreateContext(window);
slouken@1918
   220
    if (!data->context) {
slouken@1918
   221
        GL_DestroyRenderer(renderer);
slouken@1918
   222
        return NULL;
slouken@1918
   223
    }
slouken@3685
   224
    if (SDL_GL_MakeCurrent(window, data->context) < 0) {
slouken@1918
   225
        GL_DestroyRenderer(renderer);
slouken@1918
   226
        return NULL;
slouken@1918
   227
    }
slouken@5204
   228
slouken@5204
   229
    if (GL_LoadFunctions(data) < 0) {
slouken@5204
   230
        GL_DestroyRenderer(renderer);
slouken@5204
   231
        return NULL;
slouken@5204
   232
    }
slouken@5204
   233
slouken@2246
   234
#ifdef __MACOSX__
slouken@2246
   235
    /* Enable multi-threaded rendering */
slouken@2246
   236
    /* Disabled until Ryan finishes his VBO/PBO code...
bob@2295
   237
       CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine);
bob@2295
   238
     */
slouken@2246
   239
#endif
slouken@2246
   240
slouken@1965
   241
    if (flags & SDL_RENDERER_PRESENTVSYNC) {
slouken@1918
   242
        SDL_GL_SetSwapInterval(1);
slouken@1918
   243
    } else {
slouken@1918
   244
        SDL_GL_SetSwapInterval(0);
slouken@1918
   245
    }
slouken@1918
   246
    if (SDL_GL_GetSwapInterval() > 0) {
slouken@1965
   247
        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
slouken@1918
   248
    }
slouken@1918
   249
slouken@1952
   250
    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
slouken@1952
   251
    renderer->info.max_texture_width = value;
slouken@1952
   252
    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
slouken@1952
   253
    renderer->info.max_texture_height = value;
slouken@1920
   254
slouken@1926
   255
    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
slouken@1926
   256
        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
slouken@1926
   257
        data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
slouken@1926
   258
    }
slouken@2233
   259
    if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
slouken@2233
   260
        data->glTextureRangeAPPLE =
slouken@2233
   261
            (void (*)(GLenum, GLsizei, const GLvoid *))
slouken@2233
   262
            SDL_GL_GetProcAddress("glTextureRangeAPPLE");
slouken@2233
   263
    }
slouken@1920
   264
slouken@1918
   265
    /* Set up parameters for rendering */
slouken@1927
   266
    data->blendMode = -1;
slouken@1927
   267
    data->glDisable(GL_DEPTH_TEST);
slouken@1927
   268
    data->glDisable(GL_CULL_FACE);
slouken@3262
   269
    /* This ended up causing video discrepancies between OpenGL and Direct3D */
slouken@3262
   270
    /*data->glEnable(GL_LINE_SMOOTH);*/
slouken@1926
   271
    if (data->GL_ARB_texture_rectangle_supported) {
slouken@1927
   272
        data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
slouken@1926
   273
    } else {
slouken@1927
   274
        data->glEnable(GL_TEXTURE_2D);
slouken@1926
   275
    }
slouken@2833
   276
    data->updateSize = SDL_TRUE;
slouken@1918
   277
slouken@1918
   278
    return renderer;
slouken@1918
   279
}
slouken@1918
   280
slouken@5147
   281
static SDL_GLContext SDL_CurrentContext = NULL;
slouken@5147
   282
slouken@1923
   283
static int
slouken@1923
   284
GL_ActivateRenderer(SDL_Renderer * renderer)
slouken@1923
   285
{
slouken@1923
   286
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3685
   287
    SDL_Window *window = renderer->window;
slouken@1923
   288
slouken@5147
   289
    if (SDL_CurrentContext != data->context) {
slouken@5147
   290
        if (SDL_GL_MakeCurrent(window, data->context) < 0) {
slouken@5147
   291
            return -1;
slouken@5147
   292
        }
slouken@5147
   293
        SDL_CurrentContext = data->context;
slouken@1970
   294
    }
slouken@2833
   295
    if (data->updateSize) {
slouken@5154
   296
        int w, h;
slouken@5154
   297
slouken@5154
   298
        SDL_GetWindowSize(window, &w, &h);
slouken@2836
   299
        data->glMatrixMode(GL_PROJECTION);
slouken@2836
   300
        data->glLoadIdentity();
slouken@2836
   301
        data->glMatrixMode(GL_MODELVIEW);
slouken@2836
   302
        data->glLoadIdentity();
slouken@5154
   303
        data->glViewport(0, 0, w, h);
slouken@5154
   304
        data->glOrtho(0.0, (GLdouble) w, (GLdouble) h, 0.0, 0.0, 1.0);
slouken@2833
   305
        data->updateSize = SDL_FALSE;
slouken@2833
   306
    }
slouken@1970
   307
    return 0;
slouken@1970
   308
}
slouken@1970
   309
slouken@5147
   310
static void
slouken@5147
   311
GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
slouken@1970
   312
{
slouken@1970
   313
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1970
   314
slouken@5147
   315
    if (event->event == SDL_WINDOWEVENT_RESIZED) {
slouken@5147
   316
        /* Rebind the context to the window area and update matrices */
slouken@5147
   317
        SDL_CurrentContext = NULL;
slouken@5147
   318
        data->updateSize = SDL_TRUE;
slouken@5147
   319
    }
slouken@1923
   320
}
slouken@1923
   321
slouken@1922
   322
static __inline__ int
slouken@1922
   323
power_of_2(int input)
slouken@1922
   324
{
slouken@1922
   325
    int value = 1;
slouken@1922
   326
slouken@1922
   327
    while (value < input) {
slouken@1922
   328
        value <<= 1;
slouken@1922
   329
    }
slouken@1922
   330
    return value;
slouken@1922
   331
}
slouken@1922
   332
slouken@3433
   333
static __inline__ SDL_bool
slouken@3433
   334
convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
slouken@3433
   335
               GLint* internalFormat, GLenum* format, GLenum* type)
slouken@3433
   336
{
slouken@3433
   337
    switch (pixel_format) {
slouken@3433
   338
    case SDL_PIXELFORMAT_ARGB8888:
slouken@5156
   339
        *internalFormat = GL_RGBA8;
slouken@3433
   340
        *format = GL_BGRA;
slouken@3433
   341
        *type = GL_UNSIGNED_INT_8_8_8_8_REV;
slouken@3433
   342
        break;
slouken@3433
   343
    default:
slouken@3433
   344
        return SDL_FALSE;
slouken@3433
   345
    }
slouken@3433
   346
    return SDL_TRUE;
slouken@3433
   347
}
icculus@2835
   348
slouken@1918
   349
static int
slouken@1918
   350
GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
   351
{
slouken@1918
   352
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   353
    GL_TextureData *data;
slouken@1920
   354
    GLint internalFormat;
slouken@1920
   355
    GLenum format, type;
slouken@1922
   356
    int texture_w, texture_h;
slouken@1924
   357
    GLenum result;
slouken@1918
   358
slouken@5147
   359
    GL_ActivateRenderer(renderer);
slouken@5147
   360
slouken@3433
   361
    if (!convert_format(renderdata, texture->format, &internalFormat,
slouken@3433
   362
                        &format, &type)) {
slouken@4990
   363
        SDL_SetError("Texture format %s not supported by OpenGL",
slouken@4990
   364
                     SDL_GetPixelFormatName(texture->format));
slouken@1920
   365
        return -1;
slouken@1920
   366
    }
slouken@1920
   367
slouken@1920
   368
    data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
slouken@1918
   369
    if (!data) {
slouken@1918
   370
        SDL_OutOfMemory();
slouken@1918
   371
        return -1;
slouken@1918
   372
    }
slouken@1918
   373
slouken@2222
   374
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
slouken@5156
   375
        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
slouken@2222
   376
        data->pixels = SDL_malloc(texture->h * data->pitch);
slouken@2222
   377
        if (!data->pixels) {
slouken@2222
   378
            SDL_OutOfMemory();
slouken@2222
   379
            SDL_free(data);
slouken@2222
   380
            return -1;
slouken@2222
   381
        }
slouken@2222
   382
    }
slouken@2222
   383
slouken@1918
   384
    texture->driverdata = data;
slouken@1918
   385
slouken@1927
   386
    renderdata->glGetError();
slouken@1927
   387
    renderdata->glGenTextures(1, &data->texture);
slouken@1926
   388
    if (renderdata->GL_ARB_texture_rectangle_supported) {
slouken@1926
   389
        data->type = GL_TEXTURE_RECTANGLE_ARB;
slouken@1926
   390
        texture_w = texture->w;
slouken@1926
   391
        texture_h = texture->h;
icculus@2835
   392
        data->texw = (GLfloat) texture_w;
icculus@2835
   393
        data->texh = (GLfloat) texture_h;
slouken@1926
   394
    } else {
slouken@1926
   395
        data->type = GL_TEXTURE_2D;
slouken@1926
   396
        texture_w = power_of_2(texture->w);
slouken@1926
   397
        texture_h = power_of_2(texture->h);
icculus@2835
   398
        data->texw = (GLfloat) (texture->w) / texture_w;
slouken@1926
   399
        data->texh = (GLfloat) texture->h / texture_h;
slouken@1926
   400
    }
icculus@2835
   401
slouken@1920
   402
    data->format = format;
slouken@1920
   403
    data->formattype = type;
slouken@2884
   404
    renderdata->glEnable(data->type);
slouken@1927
   405
    renderdata->glBindTexture(data->type, data->texture);
slouken@2230
   406
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
slouken@5138
   407
                                GL_LINEAR);
slouken@2230
   408
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
slouken@5138
   409
                                GL_LINEAR);
slouken@2230
   410
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
slouken@2230
   411
                                GL_CLAMP_TO_EDGE);
slouken@2230
   412
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
slouken@2230
   413
                                GL_CLAMP_TO_EDGE);
slouken@2840
   414
#ifdef __MACOSX__
slouken@2230
   415
#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
slouken@2230
   416
#define GL_TEXTURE_STORAGE_HINT_APPLE       0x85BC
slouken@2230
   417
#endif
slouken@2230
   418
#ifndef STORAGE_CACHED_APPLE
slouken@2230
   419
#define STORAGE_CACHED_APPLE                0x85BE
slouken@2230
   420
#endif
slouken@2230
   421
#ifndef STORAGE_SHARED_APPLE
slouken@2230
   422
#define STORAGE_SHARED_APPLE                0x85BF
slouken@2230
   423
#endif
slouken@2230
   424
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
slouken@2230
   425
        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
slouken@2230
   426
                                    GL_STORAGE_SHARED_APPLE);
slouken@2230
   427
    } else {
slouken@2230
   428
        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
slouken@2230
   429
                                    GL_STORAGE_CACHED_APPLE);
slouken@2230
   430
    }
bob@2295
   431
    if (texture->access == SDL_TEXTUREACCESS_STREAMING
bob@2295
   432
        && texture->format == SDL_PIXELFORMAT_ARGB8888) {
slouken@2230
   433
        renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
slouken@2230
   434
        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
slouken@2230
   435
                                 texture_h, 0, format, type, data->pixels);
slouken@5156
   436
    }
slouken@5156
   437
    else
slouken@2809
   438
#endif
slouken@2230
   439
    {
slouken@2230
   440
        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
slouken@2230
   441
                                 texture_h, 0, format, type, NULL);
slouken@2230
   442
    }
slouken@3041
   443
    renderdata->glDisable(data->type);
slouken@1927
   444
    result = renderdata->glGetError();
slouken@1924
   445
    if (result != GL_NO_ERROR) {
slouken@1924
   446
        GL_SetError("glTexImage2D()", result);
slouken@1924
   447
        return -1;
slouken@1924
   448
    }
slouken@1918
   449
    return 0;
slouken@1918
   450
}
slouken@1918
   451
slouken@1918
   452
static int
slouken@1918
   453
GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
   454
                 const SDL_Rect * rect, const void *pixels, int pitch)
slouken@1918
   455
{
slouken@1927
   456
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   457
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1924
   458
    GLenum result;
slouken@1918
   459
slouken@5147
   460
    GL_ActivateRenderer(renderer);
slouken@5147
   461
slouken@1927
   462
    renderdata->glGetError();
slouken@5227
   463
    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
slouken@5227
   464
    renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
slouken@5227
   465
                              (pitch / SDL_BYTESPERPIXEL(texture->format)));
slouken@2884
   466
    renderdata->glEnable(data->type);
slouken@1927
   467
    renderdata->glBindTexture(data->type, data->texture);
slouken@1927
   468
    renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
slouken@1927
   469
                                rect->h, data->format, data->formattype,
slouken@1927
   470
                                pixels);
slouken@3041
   471
    renderdata->glDisable(data->type);
slouken@1927
   472
    result = renderdata->glGetError();
slouken@1924
   473
    if (result != GL_NO_ERROR) {
slouken@1924
   474
        GL_SetError("glTexSubImage2D()", result);
slouken@1924
   475
        return -1;
slouken@1924
   476
    }
slouken@1918
   477
    return 0;
slouken@1918
   478
}
slouken@1918
   479
slouken@1918
   480
static int
slouken@1918
   481
GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@5156
   482
               const SDL_Rect * rect, void **pixels, int *pitch)
slouken@1918
   483
{
slouken@1918
   484
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1918
   485
slouken@5227
   486
    data->locked_rect = *rect;
slouken@5227
   487
    *pixels = 
slouken@1920
   488
        (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
slouken@5156
   489
                  rect->x * SDL_BYTESPERPIXEL(texture->format));
slouken@1920
   490
    *pitch = data->pitch;
slouken@1918
   491
    return 0;
slouken@1918
   492
}
slouken@1918
   493
slouken@1918
   494
static void
slouken@1918
   495
GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
   496
{
slouken@5156
   497
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@5227
   498
    const SDL_Rect *rect;
slouken@5227
   499
    void *pixels;
slouken@1918
   500
slouken@5227
   501
    rect = &data->locked_rect;
slouken@5227
   502
    pixels = 
slouken@5227
   503
        (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
slouken@5227
   504
                  rect->x * SDL_BYTESPERPIXEL(texture->format));
slouken@5227
   505
    GL_UpdateTexture(renderer, texture, rect, pixels, data->pitch);
slouken@1918
   506
}
slouken@1918
   507
slouken@2936
   508
static void
slouken@5224
   509
GL_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
slouken@5224
   510
{
slouken@5224
   511
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@5224
   512
slouken@5224
   513
    GL_ActivateRenderer(renderer);
slouken@5224
   514
slouken@5224
   515
    if (rect) {
slouken@5224
   516
        int w, h;
slouken@5224
   517
slouken@5224
   518
        SDL_GetWindowSize(renderer->window, &w, &h);
slouken@5224
   519
        data->glScissor(rect->x, (h-(rect->y+rect->h)), rect->w, rect->h);
slouken@5224
   520
        data->glEnable(GL_SCISSOR_TEST);
slouken@5224
   521
    } else {
slouken@5224
   522
        data->glDisable(GL_SCISSOR_TEST);
slouken@5224
   523
    }
slouken@5224
   524
}
slouken@5224
   525
slouken@5224
   526
static void
slouken@5140
   527
GL_SetBlendMode(GL_RenderData * data, int blendMode)
slouken@2936
   528
{
slouken@2936
   529
    if (blendMode != data->blendMode) {
slouken@2936
   530
        switch (blendMode) {
slouken@2936
   531
        case SDL_BLENDMODE_NONE:
slouken@2936
   532
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
slouken@2936
   533
            data->glDisable(GL_BLEND);
slouken@2936
   534
            break;
slouken@2936
   535
        case SDL_BLENDMODE_BLEND:
slouken@2936
   536
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@2936
   537
            data->glEnable(GL_BLEND);
slouken@2936
   538
            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
slouken@2936
   539
            break;
slouken@2936
   540
        case SDL_BLENDMODE_ADD:
slouken@2936
   541
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@2936
   542
            data->glEnable(GL_BLEND);
slouken@2936
   543
            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
slouken@2936
   544
            break;
slouken@5184
   545
        case SDL_BLENDMODE_MOD:
slouken@5184
   546
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@5184
   547
            data->glEnable(GL_BLEND);
slouken@5184
   548
            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
slouken@5184
   549
            break;
slouken@2936
   550
        }
slouken@2936
   551
        data->blendMode = blendMode;
slouken@2936
   552
    }
slouken@2936
   553
}
slouken@2936
   554
slouken@1918
   555
static int
slouken@3596
   556
GL_RenderClear(SDL_Renderer * renderer)
slouken@3596
   557
{
slouken@3596
   558
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3596
   559
slouken@5147
   560
    GL_ActivateRenderer(renderer);
slouken@5147
   561
slouken@3596
   562
    data->glClearColor((GLfloat) renderer->r * inv255f,
slouken@3596
   563
                       (GLfloat) renderer->g * inv255f,
slouken@3596
   564
                       (GLfloat) renderer->b * inv255f,
slouken@3596
   565
                       (GLfloat) renderer->a * inv255f);
slouken@3596
   566
slouken@3596
   567
    data->glClear(GL_COLOR_BUFFER_BIT);
slouken@3596
   568
slouken@3596
   569
    return 0;
slouken@3596
   570
}
slouken@3596
   571
slouken@3596
   572
static int
slouken@3596
   573
GL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
slouken@3596
   574
                    int count)
slouken@2884
   575
{
slouken@2884
   576
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3536
   577
    int i;
slouken@2884
   578
slouken@5147
   579
    GL_ActivateRenderer(renderer);
slouken@5147
   580
slouken@5140
   581
    GL_SetBlendMode(data, renderer->blendMode);
slouken@2884
   582
slouken@2884
   583
    data->glColor4f((GLfloat) renderer->r * inv255f,
slouken@2884
   584
                    (GLfloat) renderer->g * inv255f,
slouken@2884
   585
                    (GLfloat) renderer->b * inv255f,
slouken@2884
   586
                    (GLfloat) renderer->a * inv255f);
slouken@2884
   587
slouken@2901
   588
    data->glBegin(GL_POINTS);
slouken@3536
   589
    for (i = 0; i < count; ++i) {
slouken@3536
   590
        data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
slouken@3536
   591
    }
slouken@2901
   592
    data->glEnd();
slouken@2901
   593
slouken@2901
   594
    return 0;
slouken@2901
   595
}
slouken@2901
   596
slouken@2901
   597
static int
slouken@3596
   598
GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
slouken@3596
   599
                   int count)
slouken@2901
   600
{
slouken@2901
   601
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3536
   602
    int i;
slouken@2901
   603
slouken@5147
   604
    GL_ActivateRenderer(renderer);
slouken@5147
   605
slouken@5140
   606
    GL_SetBlendMode(data, renderer->blendMode);
slouken@2901
   607
slouken@2901
   608
    data->glColor4f((GLfloat) renderer->r * inv255f,
slouken@2901
   609
                    (GLfloat) renderer->g * inv255f,
slouken@2901
   610
                    (GLfloat) renderer->b * inv255f,
slouken@2901
   611
                    (GLfloat) renderer->a * inv255f);
slouken@2901
   612
slouken@3536
   613
    if (count > 2 && 
slouken@3536
   614
        points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
slouken@3536
   615
        data->glBegin(GL_LINE_LOOP);
slouken@3536
   616
        /* GL_LINE_LOOP takes care of the final segment */
slouken@3536
   617
        --count;
slouken@3536
   618
        for (i = 0; i < count; ++i) {
slouken@3536
   619
            data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
slouken@3536
   620
        }
slouken@3536
   621
        data->glEnd();
slouken@3536
   622
    } else {
slouken@5086
   623
#if defined(__APPLE__) || defined(__WIN32__)
aschiffler@4910
   624
#else
slouken@4905
   625
        int x1, y1, x2, y2;
aschiffler@4910
   626
#endif
slouken@4905
   627
slouken@3536
   628
        data->glBegin(GL_LINE_STRIP);
slouken@3536
   629
        for (i = 0; i < count; ++i) {
slouken@3536
   630
            data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
slouken@3536
   631
        }
slouken@3536
   632
        data->glEnd();
slouken@3474
   633
slouken@3536
   634
        /* The line is half open, so we need one more point to complete it.
slouken@3536
   635
         * http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html
slouken@3536
   636
         * If we have to, we can use vertical line and horizontal line textures
slouken@3536
   637
         * for vertical and horizontal lines, and then create custom textures
slouken@3536
   638
         * for diagonal lines and software render those.  It's terrible, but at
slouken@3536
   639
         * least it would be pixel perfect.
slouken@3536
   640
         */
slouken@3536
   641
        data->glBegin(GL_POINTS);
slouken@5086
   642
#if defined(__APPLE__) || defined(__WIN32__)
slouken@3536
   643
        /* Mac OS X and Windows seem to always leave the second point open */
slouken@3536
   644
        data->glVertex2f(0.5f + points[count-1].x, 0.5f + points[count-1].y);
slouken@3474
   645
#else
slouken@3536
   646
        /* Linux seems to leave the right-most or bottom-most point open */
slouken@4905
   647
        x1 = points[0].x;
slouken@4905
   648
        y1 = points[0].y;
slouken@4905
   649
        x2 = points[count-1].x;
slouken@4905
   650
        y2 = points[count-1].y;
slouken@3536
   651
slouken@3536
   652
        if (x1 > x2) {
slouken@3536
   653
            data->glVertex2f(0.5f + x1, 0.5f + y1);
slouken@3536
   654
        } else if (x2 > x1) {
slouken@3536
   655
            data->glVertex2f(0.5f + x2, 0.5f + y2);
slouken@3536
   656
        } else if (y1 > y2) {
slouken@3536
   657
            data->glVertex2f(0.5f + x1, 0.5f + y1);
slouken@3536
   658
        } else if (y2 > y1) {
slouken@3536
   659
            data->glVertex2f(0.5f + x2, 0.5f + y2);
slouken@3536
   660
        }
slouken@3536
   661
#endif
slouken@3536
   662
        data->glEnd();
slouken@3474
   663
    }
slouken@3455
   664
slouken@1918
   665
    return 0;
slouken@1918
   666
}
slouken@1918
   667
slouken@1918
   668
static int
slouken@3596
   669
GL_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
slouken@2925
   670
{
slouken@2925
   671
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3536
   672
    int i;
slouken@2925
   673
slouken@5147
   674
    GL_ActivateRenderer(renderer);
slouken@5147
   675
slouken@5140
   676
    GL_SetBlendMode(data, renderer->blendMode);
slouken@2936
   677
slouken@2925
   678
    data->glColor4f((GLfloat) renderer->r * inv255f,
slouken@2925
   679
                    (GLfloat) renderer->g * inv255f,
slouken@2925
   680
                    (GLfloat) renderer->b * inv255f,
slouken@2925
   681
                    (GLfloat) renderer->a * inv255f);
slouken@2936
   682
slouken@3536
   683
    for (i = 0; i < count; ++i) {
slouken@3536
   684
        const SDL_Rect *rect = rects[i];
slouken@3536
   685
slouken@3536
   686
        data->glRecti(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
slouken@3536
   687
    }
slouken@2925
   688
slouken@2925
   689
    return 0;
slouken@2925
   690
}
slouken@2925
   691
slouken@2925
   692
static int
slouken@1918
   693
GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1985
   694
              const SDL_Rect * srcrect, const SDL_Rect * dstrect)
slouken@1918
   695
{
slouken@1918
   696
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1918
   697
    GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
slouken@1918
   698
    int minx, miny, maxx, maxy;
slouken@1918
   699
    GLfloat minu, maxu, minv, maxv;
slouken@1918
   700
slouken@5147
   701
    GL_ActivateRenderer(renderer);
slouken@5147
   702
slouken@1918
   703
    minx = dstrect->x;
slouken@1918
   704
    miny = dstrect->y;
slouken@1918
   705
    maxx = dstrect->x + dstrect->w;
slouken@1918
   706
    maxy = dstrect->y + dstrect->h;
slouken@1918
   707
slouken@1918
   708
    minu = (GLfloat) srcrect->x / texture->w;
slouken@1920
   709
    minu *= texturedata->texw;
slouken@1918
   710
    maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
slouken@1920
   711
    maxu *= texturedata->texw;
slouken@1918
   712
    minv = (GLfloat) srcrect->y / texture->h;
slouken@1920
   713
    minv *= texturedata->texh;
slouken@1918
   714
    maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
slouken@1920
   715
    maxv *= texturedata->texh;
slouken@1918
   716
slouken@2884
   717
    data->glEnable(texturedata->type);
slouken@1927
   718
    data->glBindTexture(texturedata->type, texturedata->texture);
slouken@1918
   719
slouken@1985
   720
    if (texture->modMode) {
slouken@1985
   721
        data->glColor4f((GLfloat) texture->r * inv255f,
slouken@1985
   722
                        (GLfloat) texture->g * inv255f,
slouken@1985
   723
                        (GLfloat) texture->b * inv255f,
slouken@1985
   724
                        (GLfloat) texture->a * inv255f);
slouken@1985
   725
    } else {
slouken@1985
   726
        data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
slouken@1985
   727
    }
slouken@1985
   728
slouken@5140
   729
    GL_SetBlendMode(data, texture->blendMode);
slouken@1918
   730
slouken@1927
   731
    data->glBegin(GL_TRIANGLE_STRIP);
slouken@1927
   732
    data->glTexCoord2f(minu, minv);
slouken@3472
   733
    data->glVertex2f((GLfloat) minx, (GLfloat) miny);
slouken@1927
   734
    data->glTexCoord2f(maxu, minv);
slouken@3472
   735
    data->glVertex2f((GLfloat) maxx, (GLfloat) miny);
slouken@1927
   736
    data->glTexCoord2f(minu, maxv);
slouken@3472
   737
    data->glVertex2f((GLfloat) minx, (GLfloat) maxy);
slouken@1927
   738
    data->glTexCoord2f(maxu, maxv);
slouken@3472
   739
    data->glVertex2f((GLfloat) maxx, (GLfloat) maxy);
slouken@1927
   740
    data->glEnd();
slouken@1918
   741
slouken@2884
   742
    data->glDisable(texturedata->type);
slouken@2884
   743
slouken@1918
   744
    return 0;
slouken@1918
   745
}
slouken@1918
   746
slouken@3431
   747
static int
slouken@3431
   748
GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@3435
   749
                    Uint32 pixel_format, void * pixels, int pitch)
slouken@3431
   750
{
slouken@3433
   751
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3685
   752
    SDL_Window *window = renderer->window;
slouken@3433
   753
    GLint internalFormat;
slouken@3433
   754
    GLenum format, type;
slouken@3435
   755
    Uint8 *src, *dst, *tmp;
slouken@5154
   756
    int w, h, length, rows;
slouken@3433
   757
slouken@5147
   758
    GL_ActivateRenderer(renderer);
slouken@5147
   759
slouken@3433
   760
    if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
slouken@3435
   761
        /* FIXME: Do a temp copy to a format that is supported */
slouken@3433
   762
        SDL_SetError("Unsupported pixel format");
slouken@3433
   763
        return -1;
slouken@3433
   764
    }
slouken@3433
   765
slouken@5154
   766
    SDL_GetWindowSize(window, &w, &h);
slouken@5154
   767
slouken@3446
   768
    data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
slouken@3446
   769
    data->glPixelStorei(GL_PACK_ROW_LENGTH,
slouken@5156
   770
                        (pitch / SDL_BYTESPERPIXEL(pixel_format)));
slouken@3433
   771
slouken@5154
   772
    data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
slouken@3435
   773
                       format, type, pixels);
slouken@3435
   774
slouken@3435
   775
    /* Flip the rows to be top-down */
slouken@5156
   776
    length = rect->w * SDL_BYTESPERPIXEL(pixel_format);
slouken@3435
   777
    src = (Uint8*)pixels + (rect->h-1)*pitch;
slouken@3435
   778
    dst = (Uint8*)pixels;
slouken@3435
   779
    tmp = SDL_stack_alloc(Uint8, length);
slouken@3435
   780
    rows = rect->h / 2;
slouken@3435
   781
    while (rows--) {
slouken@3435
   782
        SDL_memcpy(tmp, dst, length);
slouken@3435
   783
        SDL_memcpy(dst, src, length);
slouken@3435
   784
        SDL_memcpy(src, tmp, length);
slouken@3447
   785
        dst += pitch;
slouken@3447
   786
        src -= pitch;
slouken@3435
   787
    }
slouken@3435
   788
    SDL_stack_free(tmp);
slouken@3440
   789
slouken@3440
   790
    return 0;
slouken@3431
   791
}
slouken@3431
   792
slouken@1918
   793
static void
slouken@1918
   794
GL_RenderPresent(SDL_Renderer * renderer)
slouken@1918
   795
{
slouken@5147
   796
    GL_ActivateRenderer(renderer);
slouken@5147
   797
slouken@1918
   798
    SDL_GL_SwapWindow(renderer->window);
slouken@1918
   799
}
slouken@1918
   800
slouken@1918
   801
static void
slouken@1918
   802
GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
   803
{
slouken@1927
   804
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   805
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1918
   806
slouken@5147
   807
    GL_ActivateRenderer(renderer);
slouken@5147
   808
slouken@1918
   809
    if (!data) {
slouken@1918
   810
        return;
slouken@1918
   811
    }
slouken@1918
   812
    if (data->texture) {
slouken@1927
   813
        renderdata->glDeleteTextures(1, &data->texture);
slouken@1918
   814
    }
slouken@1920
   815
    if (data->pixels) {
slouken@1920
   816
        SDL_free(data->pixels);
slouken@1920
   817
    }
slouken@1918
   818
    SDL_free(data);
slouken@1918
   819
    texture->driverdata = NULL;
slouken@1918
   820
}
slouken@1918
   821
slouken@1975
   822
static void
slouken@1918
   823
GL_DestroyRenderer(SDL_Renderer * renderer)
slouken@1918
   824
{
slouken@1918
   825
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1918
   826
slouken@1918
   827
    if (data) {
slouken@1920
   828
        if (data->context) {
bob@2328
   829
            /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
slouken@1920
   830
            SDL_GL_DeleteContext(data->context);
slouken@1918
   831
        }
slouken@1918
   832
        SDL_free(data);
slouken@1918
   833
    }
slouken@1918
   834
    SDL_free(renderer);
slouken@1918
   835
}
slouken@1918
   836
slouken@5226
   837
#endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */
slouken@1918
   838
slouken@1918
   839
/* vi: set ts=4 sw=4 expandtab: */