src/video/SDL_renderer_gl.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 12 Jan 2011 19:33:04 -0800
changeset 4990 397e748d901a
parent 4929 aa8888658021
child 5062 e8916fe9cfc8
permissions -rw-r--r--
Improved error message for unsupported texture format
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@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@2884
    54
    case SDL_PIXELFORMAT_YV12:
slouken@2884
    55
    case SDL_PIXELFORMAT_IYUV:
slouken@2884
    56
    case SDL_PIXELFORMAT_YUY2:
slouken@2884
    57
    case SDL_PIXELFORMAT_UYVY:
slouken@2884
    58
    case SDL_PIXELFORMAT_YVYU:
slouken@2884
    59
        return 2;
slouken@2884
    60
    default:
slouken@2884
    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@3596
    99
static int GL_RenderClear(SDL_Renderer * renderer);
slouken@3596
   100
static int GL_RenderDrawPoints(SDL_Renderer * renderer,
slouken@3596
   101
                               const SDL_Point * points, int count);
slouken@3596
   102
static int GL_RenderDrawLines(SDL_Renderer * renderer,
slouken@3596
   103
                              const SDL_Point * points, int count);
slouken@3596
   104
static int GL_RenderDrawRects(SDL_Renderer * renderer,
slouken@3596
   105
                              const SDL_Rect ** rects, int count);
slouken@3596
   106
static int GL_RenderFillRects(SDL_Renderer * renderer,
slouken@3596
   107
                              const SDL_Rect ** rects, int count);
slouken@1918
   108
static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1985
   109
                         const SDL_Rect * srcrect, const SDL_Rect * dstrect);
slouken@3431
   110
static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@3435
   111
                               Uint32 pixel_format, void * pixels, int pitch);
slouken@3431
   112
static int GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@3435
   113
                                Uint32 pixel_format, const void * pixels, int pitch);
slouken@1918
   114
static void GL_RenderPresent(SDL_Renderer * renderer);
slouken@1918
   115
static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1918
   116
static void GL_DestroyRenderer(SDL_Renderer * renderer);
slouken@1918
   117
slouken@1918
   118
slouken@1918
   119
SDL_RenderDriver GL_RenderDriver = {
slouken@1918
   120
    GL_CreateRenderer,
slouken@1918
   121
    {
slouken@1918
   122
     "opengl",
slouken@1974
   123
     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD |
slouken@1974
   124
      SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
slouken@1985
   125
     (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
slouken@1985
   126
      SDL_TEXTUREMODULATE_ALPHA),
slouken@2884
   127
     (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
slouken@2884
   128
      SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
slouken@4929
   129
     (SDL_SCALEMODE_NONE | SDL_SCALEMODE_FAST | SDL_SCALEMODE_SLOW),
slouken@2813
   130
     15,
slouken@1918
   131
     {
slouken@1965
   132
      SDL_PIXELFORMAT_INDEX1LSB,
slouken@1965
   133
      SDL_PIXELFORMAT_INDEX1MSB,
slouken@1965
   134
      SDL_PIXELFORMAT_INDEX8,
slouken@1965
   135
      SDL_PIXELFORMAT_RGB332,
slouken@1965
   136
      SDL_PIXELFORMAT_RGB444,
slouken@1965
   137
      SDL_PIXELFORMAT_RGB555,
slouken@1965
   138
      SDL_PIXELFORMAT_ARGB4444,
slouken@1965
   139
      SDL_PIXELFORMAT_ARGB1555,
slouken@1965
   140
      SDL_PIXELFORMAT_RGB565,
slouken@1965
   141
      SDL_PIXELFORMAT_RGB24,
slouken@1965
   142
      SDL_PIXELFORMAT_BGR24,
slouken@1965
   143
      SDL_PIXELFORMAT_RGB888,
slouken@1965
   144
      SDL_PIXELFORMAT_BGR888,
slouken@1965
   145
      SDL_PIXELFORMAT_ARGB8888,
slouken@1965
   146
      SDL_PIXELFORMAT_ABGR8888,
slouken@2813
   147
      SDL_PIXELFORMAT_ARGB2101010},
slouken@1918
   148
     0,
slouken@1918
   149
     0}
slouken@1918
   150
};
slouken@1918
   151
slouken@1918
   152
typedef struct
slouken@1918
   153
{
slouken@1918
   154
    SDL_GLContext context;
slouken@2833
   155
    SDL_bool updateSize;
slouken@2233
   156
    SDL_bool GL_ARB_texture_rectangle_supported;
slouken@1974
   157
    SDL_bool GL_EXT_paletted_texture_supported;
slouken@2845
   158
    SDL_bool GL_APPLE_ycbcr_422_supported;
slouken@2845
   159
    SDL_bool GL_MESA_ycbcr_texture_supported;
icculus@2835
   160
    SDL_bool GL_ARB_fragment_program_supported;
slouken@1927
   161
    int blendMode;
slouken@1927
   162
    int scaleMode;
slouken@1927
   163
slouken@1927
   164
    /* OpenGL functions */
slouken@1927
   165
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
slouken@1927
   166
#include "SDL_glfuncs.h"
slouken@1927
   167
#undef SDL_PROC
slouken@1974
   168
slouken@1974
   169
    PFNGLCOLORTABLEEXTPROC glColorTableEXT;
slouken@2233
   170
    void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
slouken@2233
   171
                                 const GLvoid * pointer);
icculus@2835
   172
icculus@2835
   173
    PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
icculus@2835
   174
    PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB;
icculus@2835
   175
    PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB;
icculus@2835
   176
    PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB;
icculus@2835
   177
    PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
icculus@2835
   178
    PFNGLBINDPROGRAMARBPROC glBindProgramARB;
icculus@2835
   179
    PFNGLPROGRAMSTRINGARBPROC glProgramStringARB;
icculus@2835
   180
icculus@2835
   181
    /* (optional) fragment programs */
slouken@3468
   182
    GLuint fragment_program_mask;
icculus@2835
   183
    GLuint fragment_program_UYVY;
slouken@1918
   184
} GL_RenderData;
slouken@1918
   185
slouken@1918
   186
typedef struct
slouken@1918
   187
{
slouken@1918
   188
    GLuint texture;
icculus@2835
   189
    GLuint shader;
slouken@1920
   190
    GLenum type;
slouken@1918
   191
    GLfloat texw;
slouken@1918
   192
    GLfloat texh;
slouken@1920
   193
    GLenum format;
slouken@1920
   194
    GLenum formattype;
slouken@1974
   195
    Uint8 *palette;
slouken@1918
   196
    void *pixels;
slouken@1918
   197
    int pitch;
slouken@1920
   198
    SDL_DirtyRectList dirty;
slouken@2884
   199
    int HACK_RYAN_FIXME;
slouken@1918
   200
} GL_TextureData;
slouken@1918
   201
slouken@1918
   202
slouken@1924
   203
static void
slouken@1924
   204
GL_SetError(const char *prefix, GLenum result)
slouken@1924
   205
{
slouken@1924
   206
    const char *error;
slouken@1924
   207
slouken@1924
   208
    switch (result) {
slouken@1924
   209
    case GL_NO_ERROR:
slouken@1924
   210
        error = "GL_NO_ERROR";
slouken@1924
   211
        break;
slouken@1924
   212
    case GL_INVALID_ENUM:
slouken@1924
   213
        error = "GL_INVALID_ENUM";
slouken@1924
   214
        break;
slouken@1924
   215
    case GL_INVALID_VALUE:
slouken@1924
   216
        error = "GL_INVALID_VALUE";
slouken@1924
   217
        break;
slouken@1924
   218
    case GL_INVALID_OPERATION:
slouken@1924
   219
        error = "GL_INVALID_OPERATION";
slouken@1924
   220
        break;
slouken@1924
   221
    case GL_STACK_OVERFLOW:
slouken@1924
   222
        error = "GL_STACK_OVERFLOW";
slouken@1924
   223
        break;
slouken@1924
   224
    case GL_STACK_UNDERFLOW:
slouken@1924
   225
        error = "GL_STACK_UNDERFLOW";
slouken@1924
   226
        break;
slouken@1924
   227
    case GL_OUT_OF_MEMORY:
slouken@1924
   228
        error = "GL_OUT_OF_MEMORY";
slouken@1924
   229
        break;
slouken@1924
   230
    case GL_TABLE_TOO_LARGE:
slouken@1924
   231
        error = "GL_TABLE_TOO_LARGE";
slouken@1924
   232
        break;
slouken@1924
   233
    default:
slouken@1924
   234
        error = "UNKNOWN";
slouken@1924
   235
        break;
slouken@1924
   236
    }
slouken@1924
   237
    SDL_SetError("%s: %s", prefix, error);
slouken@1924
   238
}
slouken@1924
   239
slouken@1927
   240
static int
slouken@1927
   241
GL_LoadFunctions(GL_RenderData * data)
slouken@1927
   242
{
slouken@1927
   243
#if defined(__QNXNTO__) && (_NTO_VERSION < 630)
slouken@1927
   244
#define __SDL_NOGETPROCADDR__
slouken@1927
   245
#endif
slouken@1927
   246
#ifdef __SDL_NOGETPROCADDR__
slouken@1927
   247
#define SDL_PROC(ret,func,params) data->func=func;
slouken@1927
   248
#else
slouken@1927
   249
#define SDL_PROC(ret,func,params) \
slouken@1927
   250
    do { \
slouken@1927
   251
        data->func = SDL_GL_GetProcAddress(#func); \
slouken@1927
   252
        if ( ! data->func ) { \
slouken@1927
   253
            SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
slouken@1927
   254
            return -1; \
slouken@1927
   255
        } \
slouken@1927
   256
    } while ( 0 );
slouken@1927
   257
#endif /* __SDL_NOGETPROCADDR__ */
slouken@1927
   258
slouken@1927
   259
#include "SDL_glfuncs.h"
slouken@1927
   260
#undef SDL_PROC
slouken@1927
   261
    return 0;
slouken@1927
   262
}
slouken@1927
   263
slouken@1918
   264
SDL_Renderer *
slouken@1918
   265
GL_CreateRenderer(SDL_Window * window, Uint32 flags)
slouken@1918
   266
{
slouken@1918
   267
    SDL_Renderer *renderer;
slouken@1918
   268
    GL_RenderData *data;
slouken@1952
   269
    GLint value;
slouken@1974
   270
    int doublebuffer;
slouken@1918
   271
slouken@1974
   272
    /* Render directly to the window, unless we're compositing */
slouken@1974
   273
#ifndef __MACOSX__
slouken@1974
   274
    if (flags & SDL_RENDERER_SINGLEBUFFER) {
slouken@1974
   275
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
slouken@1974
   276
    }
slouken@1974
   277
#endif
slouken@1918
   278
    if (!(window->flags & SDL_WINDOW_OPENGL)) {
slouken@1928
   279
        if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) {
slouken@1924
   280
            return NULL;
slouken@1924
   281
        }
slouken@1918
   282
    }
slouken@1918
   283
slouken@1920
   284
    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
slouken@1918
   285
    if (!renderer) {
slouken@1918
   286
        SDL_OutOfMemory();
slouken@1918
   287
        return NULL;
slouken@1918
   288
    }
slouken@1918
   289
slouken@1920
   290
    data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
slouken@1918
   291
    if (!data) {
slouken@1918
   292
        GL_DestroyRenderer(renderer);
slouken@1918
   293
        SDL_OutOfMemory();
slouken@1918
   294
        return NULL;
slouken@1918
   295
    }
slouken@1918
   296
slouken@1923
   297
    renderer->ActivateRenderer = GL_ActivateRenderer;
slouken@1970
   298
    renderer->DisplayModeChanged = GL_DisplayModeChanged;
slouken@1918
   299
    renderer->CreateTexture = GL_CreateTexture;
slouken@2222
   300
    renderer->QueryTexturePixels = GL_QueryTexturePixels;
slouken@1918
   301
    renderer->SetTexturePalette = GL_SetTexturePalette;
slouken@1918
   302
    renderer->GetTexturePalette = GL_GetTexturePalette;
slouken@1985
   303
    renderer->SetTextureColorMod = GL_SetTextureColorMod;
slouken@1985
   304
    renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod;
slouken@1985
   305
    renderer->SetTextureBlendMode = GL_SetTextureBlendMode;
slouken@1985
   306
    renderer->SetTextureScaleMode = GL_SetTextureScaleMode;
slouken@1918
   307
    renderer->UpdateTexture = GL_UpdateTexture;
slouken@1918
   308
    renderer->LockTexture = GL_LockTexture;
slouken@1918
   309
    renderer->UnlockTexture = GL_UnlockTexture;
slouken@1918
   310
    renderer->DirtyTexture = GL_DirtyTexture;
slouken@3596
   311
    renderer->RenderClear = GL_RenderClear;
slouken@3596
   312
    renderer->RenderDrawPoints = GL_RenderDrawPoints;
slouken@3596
   313
    renderer->RenderDrawLines = GL_RenderDrawLines;
slouken@3596
   314
    renderer->RenderDrawRects = GL_RenderDrawRects;
slouken@3596
   315
    renderer->RenderFillRects = GL_RenderFillRects;
slouken@1918
   316
    renderer->RenderCopy = GL_RenderCopy;
slouken@3431
   317
    renderer->RenderReadPixels = GL_RenderReadPixels;
slouken@3431
   318
    renderer->RenderWritePixels = GL_RenderWritePixels;
slouken@1918
   319
    renderer->RenderPresent = GL_RenderPresent;
slouken@1918
   320
    renderer->DestroyTexture = GL_DestroyTexture;
slouken@1918
   321
    renderer->DestroyRenderer = GL_DestroyRenderer;
slouken@1918
   322
    renderer->info = GL_RenderDriver.info;
slouken@3685
   323
    renderer->window = window;
slouken@1918
   324
    renderer->driverdata = data;
slouken@1918
   325
slouken@1918
   326
    renderer->info.flags =
slouken@1965
   327
        (SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED);
slouken@1918
   328
slouken@1927
   329
    if (GL_LoadFunctions(data) < 0) {
slouken@1927
   330
        GL_DestroyRenderer(renderer);
slouken@1927
   331
        return NULL;
slouken@1927
   332
    }
slouken@1927
   333
slouken@3685
   334
    data->context = SDL_GL_CreateContext(window);
slouken@1918
   335
    if (!data->context) {
slouken@1918
   336
        GL_DestroyRenderer(renderer);
slouken@1918
   337
        return NULL;
slouken@1918
   338
    }
slouken@3685
   339
    if (SDL_GL_MakeCurrent(window, data->context) < 0) {
slouken@1918
   340
        GL_DestroyRenderer(renderer);
slouken@1918
   341
        return NULL;
slouken@1918
   342
    }
slouken@2246
   343
#ifdef __MACOSX__
slouken@2246
   344
    /* Enable multi-threaded rendering */
slouken@2246
   345
    /* Disabled until Ryan finishes his VBO/PBO code...
bob@2295
   346
       CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine);
bob@2295
   347
     */
slouken@2246
   348
#endif
slouken@2246
   349
slouken@1965
   350
    if (flags & SDL_RENDERER_PRESENTVSYNC) {
slouken@1918
   351
        SDL_GL_SetSwapInterval(1);
slouken@1918
   352
    } else {
slouken@1918
   353
        SDL_GL_SetSwapInterval(0);
slouken@1918
   354
    }
slouken@1918
   355
    if (SDL_GL_GetSwapInterval() > 0) {
slouken@1965
   356
        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
slouken@1918
   357
    }
slouken@1918
   358
slouken@1974
   359
    if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer) == 0) {
slouken@1974
   360
        if (!doublebuffer) {
slouken@1974
   361
            renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
slouken@1974
   362
        }
slouken@1974
   363
    }
slouken@1974
   364
slouken@1952
   365
    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
slouken@1952
   366
    renderer->info.max_texture_width = value;
slouken@1952
   367
    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
slouken@1952
   368
    renderer->info.max_texture_height = value;
slouken@1920
   369
slouken@1926
   370
    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
slouken@1926
   371
        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
slouken@1926
   372
        data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
slouken@1926
   373
    }
slouken@1974
   374
    if (SDL_GL_ExtensionSupported("GL_EXT_paletted_texture")) {
slouken@1974
   375
        data->GL_EXT_paletted_texture_supported = SDL_TRUE;
slouken@1974
   376
        data->glColorTableEXT =
slouken@1974
   377
            (PFNGLCOLORTABLEEXTPROC) SDL_GL_GetProcAddress("glColorTableEXT");
slouken@1974
   378
    } else {
slouken@1974
   379
        /* Don't advertise support for 8-bit indexed texture format */
slouken@1974
   380
        Uint32 i, j;
slouken@1974
   381
        SDL_RendererInfo *info = &renderer->info;
slouken@1974
   382
        for (i = 0, j = 0; i < info->num_texture_formats; ++i) {
slouken@1974
   383
            if (info->texture_formats[i] != SDL_PIXELFORMAT_INDEX8) {
slouken@1974
   384
                info->texture_formats[j++] = info->texture_formats[i];
slouken@1974
   385
            }
slouken@1974
   386
        }
slouken@1974
   387
        --info->num_texture_formats;
slouken@1974
   388
    }
slouken@2845
   389
    if (SDL_GL_ExtensionSupported("GL_APPLE_ycbcr_422")) {
slouken@2845
   390
        data->GL_APPLE_ycbcr_422_supported = SDL_TRUE;
slouken@2845
   391
    }
slouken@2845
   392
    if (SDL_GL_ExtensionSupported("GL_MESA_ycbcr_texture")) {
slouken@2845
   393
        data->GL_MESA_ycbcr_texture_supported = SDL_TRUE;
slouken@2845
   394
    }
slouken@2233
   395
    if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
slouken@2233
   396
        data->glTextureRangeAPPLE =
slouken@2233
   397
            (void (*)(GLenum, GLsizei, const GLvoid *))
slouken@2233
   398
            SDL_GL_GetProcAddress("glTextureRangeAPPLE");
slouken@2233
   399
    }
slouken@1920
   400
icculus@2835
   401
    /* we might use fragment programs for YUV data, etc. */
icculus@2835
   402
    if (SDL_GL_ExtensionSupported("GL_ARB_fragment_program")) {
icculus@2835
   403
        /* !!! FIXME: this doesn't check for errors. */
icculus@2835
   404
        /* !!! FIXME: this should really reuse the glfuncs.h stuff. */
icculus@2835
   405
        data->glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC)
icculus@2835
   406
            SDL_GL_GetProcAddress("glGetProgramivARB");
icculus@2835
   407
        data->glGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC)
icculus@2835
   408
            SDL_GL_GetProcAddress("glGetProgramStringARB");
icculus@2835
   409
        data->glProgramLocalParameter4fvARB =
icculus@2835
   410
            (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)
icculus@2835
   411
            SDL_GL_GetProcAddress("glProgramLocalParameter4fvARB");
icculus@2835
   412
        data->glDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC)
icculus@2835
   413
            SDL_GL_GetProcAddress("glDeleteProgramsARB");
icculus@2835
   414
        data->glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)
icculus@2835
   415
            SDL_GL_GetProcAddress("glGenProgramsARB");
icculus@2835
   416
        data->glBindProgramARB = (PFNGLBINDPROGRAMARBPROC)
icculus@2835
   417
            SDL_GL_GetProcAddress("glBindProgramARB");
icculus@2835
   418
        data->glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)
icculus@2835
   419
            SDL_GL_GetProcAddress("glProgramStringARB");
icculus@2835
   420
        data->GL_ARB_fragment_program_supported = SDL_TRUE;
icculus@2835
   421
    }
icculus@2835
   422
slouken@1918
   423
    /* Set up parameters for rendering */
slouken@1927
   424
    data->blendMode = -1;
slouken@1927
   425
    data->scaleMode = -1;
slouken@1927
   426
    data->glDisable(GL_DEPTH_TEST);
slouken@1927
   427
    data->glDisable(GL_CULL_FACE);
slouken@3262
   428
    /* This ended up causing video discrepancies between OpenGL and Direct3D */
slouken@3262
   429
    /*data->glEnable(GL_LINE_SMOOTH);*/
slouken@1926
   430
    if (data->GL_ARB_texture_rectangle_supported) {
slouken@1927
   431
        data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
slouken@1926
   432
    } else {
slouken@1927
   433
        data->glEnable(GL_TEXTURE_2D);
slouken@1926
   434
    }
slouken@2833
   435
    data->updateSize = SDL_TRUE;
slouken@1918
   436
slouken@1918
   437
    return renderer;
slouken@1918
   438
}
slouken@1918
   439
slouken@1923
   440
static int
slouken@1923
   441
GL_ActivateRenderer(SDL_Renderer * renderer)
slouken@1923
   442
{
slouken@1923
   443
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3685
   444
    SDL_Window *window = renderer->window;
slouken@1923
   445
slouken@3685
   446
    if (SDL_GL_MakeCurrent(window, data->context) < 0) {
slouken@1970
   447
        return -1;
slouken@1970
   448
    }
slouken@2833
   449
    if (data->updateSize) {
slouken@2836
   450
        data->glMatrixMode(GL_PROJECTION);
slouken@2836
   451
        data->glLoadIdentity();
slouken@2836
   452
        data->glMatrixMode(GL_MODELVIEW);
slouken@2836
   453
        data->glLoadIdentity();
slouken@2836
   454
        data->glViewport(0, 0, window->w, window->h);
slouken@3324
   455
        data->glOrtho(0.0, (GLdouble) window->w,
slouken@3324
   456
                      (GLdouble) window->h, 0.0, 0.0, 1.0);
slouken@2833
   457
        data->updateSize = SDL_FALSE;
slouken@2833
   458
    }
slouken@1970
   459
    return 0;
slouken@1970
   460
}
slouken@1970
   461
slouken@1970
   462
static int
slouken@1970
   463
GL_DisplayModeChanged(SDL_Renderer * renderer)
slouken@1970
   464
{
slouken@1970
   465
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1970
   466
slouken@2836
   467
    /* Rebind the context to the window area and update matrices */
slouken@2836
   468
    data->updateSize = SDL_TRUE;
slouken@2836
   469
    return GL_ActivateRenderer(renderer);
slouken@1923
   470
}
slouken@1923
   471
slouken@1922
   472
static __inline__ int
slouken@1922
   473
power_of_2(int input)
slouken@1922
   474
{
slouken@1922
   475
    int value = 1;
slouken@1922
   476
slouken@1922
   477
    while (value < input) {
slouken@1922
   478
        value <<= 1;
slouken@1922
   479
    }
slouken@1922
   480
    return value;
slouken@1922
   481
}
slouken@1922
   482
icculus@2835
   483
slouken@2858
   484
//#define DEBUG_PROGRAM_COMPILE 1
icculus@2835
   485
slouken@3468
   486
static void
slouken@3468
   487
set_shader_error(GL_RenderData * data, const char *prefix)
slouken@3468
   488
{
slouken@3468
   489
    GLint pos = 0;
slouken@3468
   490
    const GLubyte *errstr;
slouken@3468
   491
    data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
slouken@3468
   492
    errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
slouken@3479
   493
    SDL_SetError("%s: shader compile error at position %d: %s",
slouken@3468
   494
           prefix, (int) pos, (const char *) errstr);
slouken@3468
   495
}
slouken@3468
   496
icculus@2835
   497
static GLuint
slouken@2884
   498
compile_shader(GL_RenderData * data, GLenum shader_type, const char *_code)
icculus@2835
   499
{
icculus@2847
   500
    const int have_texture_rects = data->GL_ARB_texture_rectangle_supported;
icculus@2847
   501
    const char *replacement = have_texture_rects ? "RECT" : "2D";
slouken@2918
   502
    const size_t replacementlen = SDL_strlen(replacement);
icculus@2847
   503
    const char *token = "%TEXTURETARGET%";
slouken@2918
   504
    const size_t tokenlen = SDL_strlen(token);
icculus@2847
   505
    char *code = NULL;
icculus@2847
   506
    char *ptr = NULL;
icculus@2847
   507
    GLuint program = 0;
icculus@2847
   508
icculus@2847
   509
    /*
icculus@2847
   510
     * The TEX instruction needs a different target depending on what we use.
icculus@2847
   511
     *  To handle this, we use "%TEXTURETARGET%" and replace the string before
icculus@2847
   512
     *  compiling the shader.
icculus@2847
   513
     */
icculus@2847
   514
    code = SDL_strdup(_code);
icculus@2847
   515
    if (code == NULL)
icculus@2847
   516
        return 0;
icculus@2847
   517
slouken@2884
   518
    for (ptr = SDL_strstr(code, token); ptr; ptr = SDL_strstr(ptr + 1, token)) {
slouken@2918
   519
        SDL_memcpy(ptr, replacement, replacementlen);
slouken@2918
   520
        SDL_memmove(ptr + replacementlen, ptr + tokenlen,
slouken@2918
   521
                    SDL_strlen(ptr + tokenlen) + 1);
icculus@2847
   522
    }
icculus@2847
   523
icculus@2835
   524
#if DEBUG_PROGRAM_COMPILE
icculus@2847
   525
    printf("compiling shader:\n%s\n\n", code);
icculus@2835
   526
#endif
icculus@2835
   527
slouken@2884
   528
    data->glGetError();         /* flush any existing error state. */
icculus@2835
   529
    data->glGenProgramsARB(1, &program);
icculus@2835
   530
    data->glBindProgramARB(shader_type, program);
icculus@2835
   531
    data->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
slouken@3253
   532
                             (GLsizei)SDL_strlen(code), code);
icculus@2847
   533
icculus@2847
   534
    SDL_free(code);
icculus@2835
   535
slouken@2884
   536
    if (data->glGetError() == GL_INVALID_OPERATION) {
icculus@2835
   537
#if DEBUG_PROGRAM_COMPILE
icculus@2835
   538
        GLint pos = 0;
icculus@2835
   539
        const GLubyte *errstr;
icculus@2835
   540
        data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
icculus@2835
   541
        errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
icculus@2835
   542
        printf("program compile error at position %d: %s\n\n",
slouken@2884
   543
               (int) pos, (const char *) errstr);
icculus@2835
   544
#endif
icculus@2835
   545
        data->glBindProgramARB(shader_type, 0);
icculus@2835
   546
        data->glDeleteProgramsARB(1, &program);
icculus@2835
   547
        return 0;
icculus@2848
   548
    }
icculus@2835
   549
icculus@2835
   550
    return program;
icculus@2835
   551
}
icculus@2835
   552
icculus@2848
   553
icculus@2848
   554
/*
slouken@3468
   555
 * Fragment program that implements mask semantics
slouken@3468
   556
 */
slouken@3468
   557
static const char *fragment_program_mask_source_code = "!!ARBfp1.0\n"
slouken@3468
   558
"OUTPUT output = result.color;\n"
slouken@3468
   559
"TEMP value;\n"
slouken@3468
   560
"TEX value, fragment.texcoord[0], texture[0], %TEXTURETARGET%;\n"
slouken@3468
   561
"MUL value, fragment.color, value;\n"
slouken@3468
   562
"SGE value.a, value.a, 0.001;\n"
slouken@3468
   563
"MOV output, value;\n"
slouken@3468
   564
"END";
slouken@3468
   565
slouken@3468
   566
/*
icculus@2848
   567
 * Fragment program that renders from UYVY textures.
icculus@2848
   568
 * The UYVY to RGB equasion is:
icculus@2848
   569
 *   R = 1.164(Y-16) + 1.596(Cr-128)
icculus@2848
   570
 *   G = 1.164(Y-16) - 0.813(Cr-128) - 0.391(Cb-128)
icculus@2848
   571
 *   B = 1.164(Y-16) + 2.018(Cb-128)
icculus@2848
   572
 * Byte layout is Cb, Y1, Cr, Y2, stored in the R, G, B, A channels.
icculus@2848
   573
 * 4 bytes == 2 pixels: Y1/Cb/Cr, Y2/Cb/Cr
icculus@2848
   574
 *
icculus@2848
   575
 * !!! FIXME: this ignores blendmodes, etc.
icculus@2848
   576
 * !!! FIXME: this could be more efficient...use a dot product for green, etc.
icculus@2848
   577
 */
slouken@2884
   578
static const char *fragment_program_UYVY_source_code = "!!ARBfp1.0\n"
icculus@2848
   579
    /* outputs... */
icculus@2835
   580
    "OUTPUT outcolor = result.color;\n"
icculus@2848
   581
    /* scratch registers... */
slouken@2884
   582
    "TEMP uyvy;\n" "TEMP luminance;\n" "TEMP work;\n"
icculus@2848
   583
    /* Halve the coordinates to grab the correct 32 bits for the fragment. */
icculus@2835
   584
    "MUL work, fragment.texcoord, { 0.5, 1.0, 1.0, 1.0 };\n"
icculus@2848
   585
    /* Sample the YUV texture. Cb, Y1, Cr, Y2, are stored in x, y, z, w. */
icculus@2847
   586
    "TEX uyvy, work, texture[0], %TEXTURETARGET%;\n"
icculus@2848
   587
    /* Do subtractions (128/255, 16/255, 128/255, 16/255) */
slouken@2846
   588
    "SUB uyvy, uyvy, { 0.501960784313726, 0.06274509803922, 0.501960784313726, 0.06274509803922 };\n"
icculus@2848
   589
    /* Choose the luminance component by texcoord. */
icculus@2848
   590
    /* !!! FIXME: laziness wins out for now... just average Y1 and Y2. */
icculus@2835
   591
    "ADD luminance, uyvy.yyyy, uyvy.wwww;\n"
icculus@2835
   592
    "MUL luminance, luminance, { 0.5, 0.5, 0.5, 0.5 };\n"
icculus@2848
   593
    /* Multiply luminance by its magic value. */
icculus@2835
   594
    "MUL luminance, luminance, { 1.164, 1.164, 1.164, 1.164 };\n"
icculus@2848
   595
    /* uyvy.xyzw becomes Cr/Cr/Cb/Cb, with multiplications. */
icculus@2835
   596
    "MUL uyvy, uyvy.zzxx, { 1.596, -0.813, 2.018, -0.391 };\n"
icculus@2848
   597
    /* Add luminance to Cr and Cb, store to RGB channels. */
icculus@2835
   598
    "ADD work.rgb, luminance, uyvy;\n"
icculus@2848
   599
    /* Do final addition for Green channel.  (!!! FIXME: this should be a DPH?) */
icculus@2835
   600
    "ADD work.g, work.g, uyvy.w;\n"
icculus@2848
   601
    /* Make sure alpha channel is fully opaque.  (!!! FIXME: blend modes!) */
icculus@2835
   602
    "MOV work.a, { 1.0 };\n"
icculus@2848
   603
    /* Store out the final fragment color... */
icculus@2835
   604
    "MOV outcolor, work;\n"
icculus@2848
   605
    /* ...and we're done! */
icculus@2835
   606
    "END\n";
icculus@2835
   607
slouken@3433
   608
static __inline__ SDL_bool
slouken@3433
   609
convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
slouken@3433
   610
               GLint* internalFormat, GLenum* format, GLenum* type)
slouken@3433
   611
{
slouken@3433
   612
    switch (pixel_format) {
slouken@3433
   613
    case SDL_PIXELFORMAT_INDEX1LSB:
slouken@3433
   614
    case SDL_PIXELFORMAT_INDEX1MSB:
slouken@3433
   615
        *internalFormat = GL_RGB;
slouken@3433
   616
        *format = GL_COLOR_INDEX;
slouken@3433
   617
        *type = GL_BITMAP;
slouken@3433
   618
        break;
slouken@3433
   619
    case SDL_PIXELFORMAT_INDEX8:
slouken@3433
   620
        if (!renderdata->GL_EXT_paletted_texture_supported) {
slouken@3433
   621
            return SDL_FALSE;
slouken@3433
   622
        }
slouken@3433
   623
        *internalFormat = GL_COLOR_INDEX8_EXT;
slouken@3433
   624
        *format = GL_COLOR_INDEX;
slouken@3433
   625
        *type = GL_UNSIGNED_BYTE;
slouken@3433
   626
        break;
slouken@3433
   627
    case SDL_PIXELFORMAT_RGB332:
slouken@3433
   628
        *internalFormat = GL_R3_G3_B2;
slouken@3433
   629
        *format = GL_RGB;
slouken@3433
   630
        *type = GL_UNSIGNED_BYTE_3_3_2;
slouken@3433
   631
        break;
slouken@3433
   632
    case SDL_PIXELFORMAT_RGB444:
slouken@3433
   633
        *internalFormat = GL_RGB4;
slouken@3433
   634
        *format = GL_RGB;
slouken@3433
   635
        *type = GL_UNSIGNED_SHORT_4_4_4_4;
slouken@3433
   636
        break;
slouken@3433
   637
    case SDL_PIXELFORMAT_RGB555:
slouken@3433
   638
        *internalFormat = GL_RGB5;
slouken@3433
   639
        *format = GL_RGB;
slouken@3433
   640
        *type = GL_UNSIGNED_SHORT_5_5_5_1;
slouken@3433
   641
        break;
slouken@3433
   642
    case SDL_PIXELFORMAT_ARGB4444:
slouken@3433
   643
        *internalFormat = GL_RGBA4;
slouken@3433
   644
        *format = GL_BGRA;
slouken@3433
   645
        *type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
slouken@3433
   646
        break;
slouken@3433
   647
    case SDL_PIXELFORMAT_ARGB1555:
slouken@3433
   648
        *internalFormat = GL_RGB5_A1;
slouken@3433
   649
        *format = GL_BGRA;
slouken@3433
   650
        *type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
slouken@3433
   651
        break;
slouken@3433
   652
    case SDL_PIXELFORMAT_RGB565:
slouken@3433
   653
        *internalFormat = GL_RGB8;
slouken@3433
   654
        *format = GL_RGB;
slouken@3433
   655
        *type = GL_UNSIGNED_SHORT_5_6_5;
slouken@3433
   656
        break;
slouken@3433
   657
    case SDL_PIXELFORMAT_RGB24:
slouken@3433
   658
        *internalFormat = GL_RGB8;
slouken@3433
   659
        *format = GL_RGB;
slouken@3433
   660
        *type = GL_UNSIGNED_BYTE;
slouken@3433
   661
        break;
slouken@3433
   662
    case SDL_PIXELFORMAT_RGB888:
slouken@3433
   663
        *internalFormat = GL_RGB8;
slouken@3433
   664
        *format = GL_BGRA;
slouken@3433
   665
        *type = GL_UNSIGNED_BYTE;
slouken@3433
   666
        break;
slouken@3433
   667
    case SDL_PIXELFORMAT_BGR24:
slouken@3433
   668
        *internalFormat = GL_RGB8;
slouken@3433
   669
        *format = GL_BGR;
slouken@3433
   670
        *type = GL_UNSIGNED_BYTE;
slouken@3433
   671
        break;
slouken@3433
   672
    case SDL_PIXELFORMAT_BGR888:
slouken@3433
   673
        *internalFormat = GL_RGB8;
slouken@3433
   674
        *format = GL_RGBA;
slouken@3433
   675
        *type = GL_UNSIGNED_BYTE;
slouken@3433
   676
        break;
slouken@3433
   677
    case SDL_PIXELFORMAT_ARGB8888:
slouken@3433
   678
#ifdef __MACOSX__
slouken@3433
   679
        *internalFormat = GL_RGBA;
slouken@3433
   680
        *format = GL_BGRA;
slouken@3433
   681
        *type = GL_UNSIGNED_INT_8_8_8_8_REV;
slouken@3433
   682
#else
slouken@3433
   683
        *internalFormat = GL_RGBA8;
slouken@3433
   684
        *format = GL_BGRA;
slouken@3433
   685
        *type = GL_UNSIGNED_BYTE;
slouken@3433
   686
#endif
slouken@3433
   687
        break;
slouken@3433
   688
    case SDL_PIXELFORMAT_ABGR8888:
slouken@3433
   689
        *internalFormat = GL_RGBA8;
slouken@3433
   690
        *format = GL_RGBA;
slouken@3433
   691
        *type = GL_UNSIGNED_BYTE;
slouken@3433
   692
        break;
slouken@3433
   693
    case SDL_PIXELFORMAT_ARGB2101010:
slouken@3433
   694
        *internalFormat = GL_RGB10_A2;
slouken@3433
   695
        *format = GL_BGRA;
slouken@3433
   696
        *type = GL_UNSIGNED_INT_2_10_10_10_REV;
slouken@3433
   697
        break;
slouken@3433
   698
    case SDL_PIXELFORMAT_UYVY:
slouken@3433
   699
        if (renderdata->GL_APPLE_ycbcr_422_supported) {
slouken@3433
   700
            *internalFormat = GL_RGB;
slouken@3433
   701
            *format = GL_YCBCR_422_APPLE;
slouken@3433
   702
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@3433
   703
            *type = GL_UNSIGNED_SHORT_8_8_APPLE;
slouken@3433
   704
#else
slouken@3433
   705
            *type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
slouken@3433
   706
#endif
slouken@3433
   707
        } else if (renderdata->GL_MESA_ycbcr_texture_supported) {
slouken@3494
   708
            *internalFormat = GL_YCBCR_MESA;
slouken@3433
   709
            *format = GL_YCBCR_MESA;
slouken@3433
   710
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@3433
   711
            *type = GL_UNSIGNED_SHORT_8_8_MESA;
slouken@3433
   712
#else
slouken@3433
   713
            *type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
slouken@3433
   714
#endif
slouken@3433
   715
        } else if (renderdata->GL_ARB_fragment_program_supported) {
slouken@3433
   716
            *internalFormat = GL_RGBA;
slouken@3433
   717
            *format = GL_RGBA;
slouken@3433
   718
            *type = GL_UNSIGNED_BYTE;
slouken@3433
   719
        } else {
slouken@3433
   720
            return SDL_FALSE;
slouken@3433
   721
        }
slouken@3433
   722
        break;
slouken@3433
   723
    case SDL_PIXELFORMAT_YUY2:
slouken@3433
   724
        if (renderdata->GL_APPLE_ycbcr_422_supported) {
slouken@3433
   725
            *internalFormat = GL_RGB;
slouken@3433
   726
            *format = GL_YCBCR_422_APPLE;
slouken@3433
   727
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@3433
   728
            *type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
slouken@3433
   729
#else
slouken@3433
   730
            *type = GL_UNSIGNED_SHORT_8_8_APPLE;
slouken@3433
   731
#endif
slouken@3433
   732
        } else if (renderdata->GL_MESA_ycbcr_texture_supported) {
slouken@3494
   733
            *internalFormat = GL_YCBCR_MESA;
slouken@3433
   734
            *format = GL_YCBCR_MESA;
slouken@3433
   735
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@3433
   736
            *type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
slouken@3433
   737
#else
slouken@3433
   738
            *type = GL_UNSIGNED_SHORT_8_8_MESA;
slouken@3433
   739
#endif
slouken@3433
   740
        } else {
slouken@3433
   741
            return SDL_FALSE;
slouken@3433
   742
        }
slouken@3433
   743
        break;
slouken@3433
   744
    default:
slouken@3433
   745
        return SDL_FALSE;
slouken@3433
   746
    }
slouken@3433
   747
    return SDL_TRUE;
slouken@3433
   748
}
icculus@2835
   749
slouken@1918
   750
static int
slouken@1918
   751
GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
   752
{
slouken@1918
   753
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   754
    GL_TextureData *data;
slouken@1920
   755
    GLint internalFormat;
slouken@1920
   756
    GLenum format, type;
slouken@1922
   757
    int texture_w, texture_h;
icculus@2835
   758
    GLuint shader = 0;
slouken@1924
   759
    GLenum result;
slouken@1918
   760
slouken@3433
   761
    if (!convert_format(renderdata, texture->format, &internalFormat,
slouken@3433
   762
                        &format, &type)) {
slouken@4990
   763
        SDL_SetError("Texture format %s not supported by OpenGL",
slouken@4990
   764
                     SDL_GetPixelFormatName(texture->format));
slouken@1920
   765
        return -1;
slouken@1920
   766
    }
slouken@3433
   767
    if (texture->format == SDL_PIXELFORMAT_UYVY &&
slouken@3433
   768
        !renderdata->GL_APPLE_ycbcr_422_supported &&
slouken@3433
   769
        !renderdata->GL_MESA_ycbcr_texture_supported &&
slouken@3433
   770
        renderdata->GL_ARB_fragment_program_supported) {
slouken@3433
   771
        if (renderdata->fragment_program_UYVY == 0) {
slouken@3433
   772
            renderdata->fragment_program_UYVY =
slouken@3433
   773
                compile_shader(renderdata, GL_FRAGMENT_PROGRAM_ARB,
slouken@3433
   774
                               fragment_program_UYVY_source_code);
slouken@3433
   775
            if (renderdata->fragment_program_UYVY == 0) {
slouken@3468
   776
                set_shader_error(renderdata, "UYVY");
slouken@3433
   777
                return -1;
slouken@3433
   778
            }
slouken@3433
   779
        }
slouken@3433
   780
        shader = renderdata->fragment_program_UYVY;
slouken@3433
   781
    }
slouken@1920
   782
slouken@1920
   783
    data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
slouken@1918
   784
    if (!data) {
slouken@1918
   785
        SDL_OutOfMemory();
slouken@1918
   786
        return -1;
slouken@1918
   787
    }
slouken@1918
   788
icculus@2835
   789
    data->shader = shader;
icculus@2835
   790
slouken@1974
   791
    if (texture->format == SDL_PIXELFORMAT_INDEX8) {
slouken@1974
   792
        data->palette = (Uint8 *) SDL_malloc(3 * 256 * sizeof(Uint8));
slouken@1974
   793
        if (!data->palette) {
slouken@1974
   794
            SDL_OutOfMemory();
slouken@1974
   795
            SDL_free(data);
slouken@1974
   796
            return -1;
slouken@1974
   797
        }
slouken@1974
   798
        SDL_memset(data->palette, 0xFF, 3 * 256 * sizeof(Uint8));
slouken@1974
   799
    }
slouken@1974
   800
slouken@2222
   801
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
icculus@2835
   802
        data->pitch = texture->w * bytes_per_pixel(texture->format);
slouken@2222
   803
        data->pixels = SDL_malloc(texture->h * data->pitch);
slouken@2222
   804
        if (!data->pixels) {
slouken@2222
   805
            SDL_OutOfMemory();
slouken@2222
   806
            SDL_free(data);
slouken@2222
   807
            return -1;
slouken@2222
   808
        }
slouken@2222
   809
    }
slouken@2222
   810
slouken@1918
   811
    texture->driverdata = data;
slouken@1918
   812
slouken@1927
   813
    renderdata->glGetError();
slouken@1927
   814
    renderdata->glGenTextures(1, &data->texture);
slouken@1926
   815
    if (renderdata->GL_ARB_texture_rectangle_supported) {
slouken@1926
   816
        data->type = GL_TEXTURE_RECTANGLE_ARB;
slouken@1926
   817
        texture_w = texture->w;
slouken@1926
   818
        texture_h = texture->h;
icculus@2835
   819
        data->texw = (GLfloat) texture_w;
icculus@2835
   820
        data->texh = (GLfloat) texture_h;
slouken@1926
   821
    } else {
slouken@1926
   822
        data->type = GL_TEXTURE_2D;
slouken@1926
   823
        texture_w = power_of_2(texture->w);
slouken@1926
   824
        texture_h = power_of_2(texture->h);
icculus@2835
   825
        data->texw = (GLfloat) (texture->w) / texture_w;
slouken@1926
   826
        data->texh = (GLfloat) texture->h / texture_h;
slouken@1926
   827
    }
icculus@2835
   828
slouken@2839
   829
    /* YUV formats use RGBA but are really two bytes per pixel */
slouken@2839
   830
    if (internalFormat == GL_RGBA && bytes_per_pixel(texture->format) < 4) {
slouken@3707
   831
        texture_w /= 2;
slouken@3707
   832
        if (data->type == GL_TEXTURE_2D) {
slouken@3707
   833
            data->texw *= 2.0f;
slouken@3707
   834
        }
slouken@2884
   835
        data->HACK_RYAN_FIXME = 2;
slouken@2843
   836
    } else {
slouken@2884
   837
        data->HACK_RYAN_FIXME = 1;
slouken@2839
   838
    }
slouken@2839
   839
slouken@1920
   840
    data->format = format;
slouken@1920
   841
    data->formattype = type;
slouken@2884
   842
    renderdata->glEnable(data->type);
slouken@1927
   843
    renderdata->glBindTexture(data->type, data->texture);
slouken@2230
   844
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
slouken@2230
   845
                                GL_NEAREST);
slouken@2230
   846
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
slouken@2230
   847
                                GL_NEAREST);
slouken@2230
   848
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
slouken@2230
   849
                                GL_CLAMP_TO_EDGE);
slouken@2230
   850
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
slouken@2230
   851
                                GL_CLAMP_TO_EDGE);
slouken@2840
   852
#ifdef __MACOSX__
slouken@2230
   853
#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
slouken@2230
   854
#define GL_TEXTURE_STORAGE_HINT_APPLE       0x85BC
slouken@2230
   855
#endif
slouken@2230
   856
#ifndef STORAGE_CACHED_APPLE
slouken@2230
   857
#define STORAGE_CACHED_APPLE                0x85BE
slouken@2230
   858
#endif
slouken@2230
   859
#ifndef STORAGE_SHARED_APPLE
slouken@2230
   860
#define STORAGE_SHARED_APPLE                0x85BF
slouken@2230
   861
#endif
slouken@2230
   862
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
slouken@2230
   863
        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
slouken@2230
   864
                                    GL_STORAGE_SHARED_APPLE);
slouken@2230
   865
    } else {
slouken@2230
   866
        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
slouken@2230
   867
                                    GL_STORAGE_CACHED_APPLE);
slouken@2230
   868
    }
slouken@2809
   869
/* This causes a crash in testoverlay for some reason.  Apple bug? */
slouken@2809
   870
#if 0
bob@2295
   871
    if (texture->access == SDL_TEXTUREACCESS_STREAMING
bob@2295
   872
        && texture->format == SDL_PIXELFORMAT_ARGB8888) {
slouken@2237
   873
        /*
bob@2295
   874
           if (renderdata->glTextureRangeAPPLE) {
bob@2295
   875
           renderdata->glTextureRangeAPPLE(data->type,
bob@2295
   876
           texture->h * data->pitch,
bob@2295
   877
           data->pixels);
bob@2295
   878
           }
bob@2295
   879
         */
slouken@2230
   880
        renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
slouken@2230
   881
        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
slouken@2230
   882
                                 texture_h, 0, format, type, data->pixels);
slouken@2230
   883
    } else
slouken@2230
   884
#endif
slouken@2809
   885
#endif
slouken@2230
   886
    {
slouken@2230
   887
        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
slouken@2230
   888
                                 texture_h, 0, format, type, NULL);
slouken@2230
   889
    }
slouken@3041
   890
    renderdata->glDisable(data->type);
slouken@1927
   891
    result = renderdata->glGetError();
slouken@1924
   892
    if (result != GL_NO_ERROR) {
slouken@1924
   893
        GL_SetError("glTexImage2D()", result);
slouken@1924
   894
        return -1;
slouken@1924
   895
    }
slouken@1918
   896
    return 0;
slouken@1918
   897
}
slouken@1918
   898
slouken@1918
   899
static int
slouken@2222
   900
GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@2222
   901
                      void **pixels, int *pitch)
slouken@2222
   902
{
slouken@2222
   903
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@2222
   904
slouken@2222
   905
    *pixels = data->pixels;
slouken@2222
   906
    *pitch = data->pitch;
slouken@2222
   907
    return 0;
slouken@2222
   908
}
slouken@2222
   909
slouken@2222
   910
static int
slouken@1918
   911
GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
   912
                     const SDL_Color * colors, int firstcolor, int ncolors)
slouken@1918
   913
{
slouken@1918
   914
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   915
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1974
   916
    Uint8 *palette;
slouken@1918
   917
slouken@1974
   918
    if (!data->palette) {
slouken@1974
   919
        SDL_SetError("Texture doesn't have a palette");
slouken@1974
   920
        return -1;
slouken@1974
   921
    }
slouken@1974
   922
    palette = data->palette + firstcolor * 3;
slouken@1974
   923
    while (ncolors--) {
slouken@1974
   924
        *palette++ = colors->r;
slouken@1974
   925
        *palette++ = colors->g;
slouken@1974
   926
        *palette++ = colors->b;
slouken@1974
   927
        ++colors;
slouken@1974
   928
    }
slouken@2884
   929
    renderdata->glEnable(data->type);
slouken@1974
   930
    renderdata->glBindTexture(data->type, data->texture);
slouken@1974
   931
    renderdata->glColorTableEXT(data->type, GL_RGB8, 256, GL_RGB,
slouken@1974
   932
                                GL_UNSIGNED_BYTE, data->palette);
slouken@1918
   933
    return 0;
slouken@1918
   934
}
slouken@1918
   935
slouken@1918
   936
static int
slouken@1918
   937
GL_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
   938
                     SDL_Color * colors, int firstcolor, int ncolors)
slouken@1918
   939
{
slouken@1918
   940
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1974
   941
    Uint8 *palette;
slouken@1918
   942
slouken@1974
   943
    if (!data->palette) {
slouken@1974
   944
        SDL_SetError("Texture doesn't have a palette");
slouken@1974
   945
        return -1;
slouken@1974
   946
    }
slouken@1974
   947
    palette = data->palette + firstcolor * 3;
slouken@1974
   948
    while (ncolors--) {
slouken@1974
   949
        colors->r = *palette++;
slouken@1974
   950
        colors->g = *palette++;
slouken@1974
   951
        colors->b = *palette++;
slouken@1974
   952
        colors->unused = SDL_ALPHA_OPAQUE;
slouken@1974
   953
        ++colors;
slouken@1974
   954
    }
slouken@1918
   955
    return 0;
slouken@1918
   956
}
slouken@1918
   957
slouken@1924
   958
static void
slouken@1927
   959
SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
slouken@1927
   960
                   int pitch)
slouken@1924
   961
{
slouken@1965
   962
    if (texture->format == SDL_PIXELFORMAT_INDEX1LSB) {
slouken@1927
   963
        renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
slouken@1965
   964
    } else if (texture->format == SDL_PIXELFORMAT_INDEX1MSB) {
slouken@1927
   965
        renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
slouken@1924
   966
    }
slouken@1927
   967
    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
slouken@2808
   968
    renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
slouken@2884
   969
                              (pitch / bytes_per_pixel(texture->format)) /
slouken@3013
   970
                              ((GL_TextureData *) texture->driverdata)->
slouken@3013
   971
                              HACK_RYAN_FIXME);
slouken@1924
   972
}
slouken@1924
   973
slouken@1918
   974
static int
slouken@1985
   975
GL_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
   976
{
slouken@1986
   977
    return 0;
slouken@1985
   978
}
slouken@1985
   979
slouken@1985
   980
static int
slouken@1985
   981
GL_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
   982
{
slouken@1986
   983
    return 0;
slouken@1985
   984
}
slouken@1985
   985
slouken@1985
   986
static int
slouken@1985
   987
GL_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
   988
{
slouken@1985
   989
    switch (texture->blendMode) {
slouken@2884
   990
    case SDL_BLENDMODE_NONE:
slouken@2884
   991
    case SDL_BLENDMODE_MASK:
slouken@2884
   992
    case SDL_BLENDMODE_BLEND:
slouken@2884
   993
    case SDL_BLENDMODE_ADD:
slouken@2884
   994
    case SDL_BLENDMODE_MOD:
slouken@1985
   995
        return 0;
slouken@1985
   996
    default:
slouken@1985
   997
        SDL_Unsupported();
slouken@2884
   998
        texture->blendMode = SDL_BLENDMODE_NONE;
slouken@1985
   999
        return -1;
slouken@1985
  1000
    }
slouken@1985
  1001
}
slouken@1985
  1002
slouken@1985
  1003
static int
slouken@1985
  1004
GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
  1005
{
slouken@1985
  1006
    switch (texture->scaleMode) {
slouken@4929
  1007
    case SDL_SCALEMODE_NONE:
slouken@4929
  1008
    case SDL_SCALEMODE_FAST:
slouken@4929
  1009
    case SDL_SCALEMODE_SLOW:
slouken@1985
  1010
        return 0;
slouken@4929
  1011
    case SDL_SCALEMODE_BEST:
slouken@1985
  1012
        SDL_Unsupported();
slouken@4929
  1013
        texture->scaleMode = SDL_SCALEMODE_SLOW;
slouken@1985
  1014
        return -1;
slouken@1985
  1015
    default:
slouken@1985
  1016
        SDL_Unsupported();
slouken@4929
  1017
        texture->scaleMode = SDL_SCALEMODE_NONE;
slouken@1985
  1018
        return -1;
slouken@1985
  1019
    }
slouken@1985
  1020
}
slouken@1985
  1021
slouken@1985
  1022
static int
slouken@1918
  1023
GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
  1024
                 const SDL_Rect * rect, const void *pixels, int pitch)
slouken@1918
  1025
{
slouken@1927
  1026
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
  1027
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1924
  1028
    GLenum result;
slouken@1918
  1029
slouken@1927
  1030
    renderdata->glGetError();
slouken@1927
  1031
    SetupTextureUpdate(renderdata, texture, pitch);
slouken@2884
  1032
    renderdata->glEnable(data->type);
slouken@1927
  1033
    renderdata->glBindTexture(data->type, data->texture);
slouken@1927
  1034
    renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
slouken@1927
  1035
                                rect->h, data->format, data->formattype,
slouken@1927
  1036
                                pixels);
slouken@3041
  1037
    renderdata->glDisable(data->type);
slouken@1927
  1038
    result = renderdata->glGetError();
slouken@1924
  1039
    if (result != GL_NO_ERROR) {
slouken@1924
  1040
        GL_SetError("glTexSubImage2D()", result);
slouken@1924
  1041
        return -1;
slouken@1924
  1042
    }
slouken@1918
  1043
    return 0;
slouken@1918
  1044
}
slouken@1918
  1045
slouken@1918
  1046
static int
slouken@1918
  1047
GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
  1048
               const SDL_Rect * rect, int markDirty, void **pixels,
slouken@1918
  1049
               int *pitch)
slouken@1918
  1050
{
slouken@1918
  1051
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1918
  1052
slouken@1920
  1053
    if (markDirty) {
slouken@1920
  1054
        SDL_AddDirtyRect(&data->dirty, rect);
slouken@1920
  1055
    }
slouken@1918
  1056
slouken@1920
  1057
    *pixels =
slouken@1920
  1058
        (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
icculus@2835
  1059
                  rect->x * bytes_per_pixel(texture->format));
slouken@1920
  1060
    *pitch = data->pitch;
slouken@1918
  1061
    return 0;
slouken@1918
  1062
}
slouken@1918
  1063
slouken@1918
  1064
static void
slouken@1918
  1065
GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
  1066
{
slouken@1918
  1067
}
slouken@1918
  1068
slouken@1918
  1069
static void
slouken@1918
  1070
GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
slouken@1918
  1071
                const SDL_Rect * rects)
slouken@1918
  1072
{
slouken@1918
  1073
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1918
  1074
    int i;
slouken@1918
  1075
slouken@1918
  1076
    for (i = 0; i < numrects; ++i) {
slouken@1920
  1077
        SDL_AddDirtyRect(&data->dirty, &rects[i]);
slouken@1918
  1078
    }
slouken@1918
  1079
}
slouken@1918
  1080
slouken@2936
  1081
static void
slouken@3458
  1082
GL_SetBlendMode(GL_RenderData * data, int blendMode, int isprimitive)
slouken@2936
  1083
{
slouken@2936
  1084
    if (blendMode != data->blendMode) {
slouken@2936
  1085
        switch (blendMode) {
slouken@2936
  1086
        case SDL_BLENDMODE_NONE:
slouken@2936
  1087
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
slouken@2936
  1088
            data->glDisable(GL_BLEND);
slouken@2936
  1089
            break;
slouken@2936
  1090
        case SDL_BLENDMODE_MASK:
slouken@3458
  1091
            if (isprimitive) {
slouken@3458
  1092
                /* The same as SDL_BLENDMODE_NONE */
slouken@3458
  1093
                blendMode = SDL_BLENDMODE_NONE;
slouken@3458
  1094
                data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
slouken@3458
  1095
                data->glDisable(GL_BLEND);
slouken@3458
  1096
            } else {
slouken@3458
  1097
                data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
slouken@3458
  1098
                data->glEnable(GL_BLEND);
slouken@3458
  1099
                data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
slouken@3458
  1100
            }
slouken@3457
  1101
            break;
slouken@2936
  1102
        case SDL_BLENDMODE_BLEND:
slouken@2936
  1103
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@2936
  1104
            data->glEnable(GL_BLEND);
slouken@2936
  1105
            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
slouken@2936
  1106
            break;
slouken@2936
  1107
        case SDL_BLENDMODE_ADD:
slouken@2936
  1108
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@2936
  1109
            data->glEnable(GL_BLEND);
slouken@2936
  1110
            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
slouken@2936
  1111
            break;
slouken@2936
  1112
        case SDL_BLENDMODE_MOD:
slouken@2936
  1113
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@2936
  1114
            data->glEnable(GL_BLEND);
slouken@2936
  1115
            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
slouken@2936
  1116
            break;
slouken@2936
  1117
        }
slouken@2936
  1118
        data->blendMode = blendMode;
slouken@2936
  1119
    }
slouken@2936
  1120
}
slouken@2936
  1121
slouken@1918
  1122
static int
slouken@3596
  1123
GL_RenderClear(SDL_Renderer * renderer)
slouken@3596
  1124
{
slouken@3596
  1125
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3596
  1126
slouken@3596
  1127
    data->glClearColor((GLfloat) renderer->r * inv255f,
slouken@3596
  1128
                       (GLfloat) renderer->g * inv255f,
slouken@3596
  1129
                       (GLfloat) renderer->b * inv255f,
slouken@3596
  1130
                       (GLfloat) renderer->a * inv255f);
slouken@3596
  1131
slouken@3596
  1132
    data->glClear(GL_COLOR_BUFFER_BIT);
slouken@3596
  1133
slouken@3596
  1134
    return 0;
slouken@3596
  1135
}
slouken@3596
  1136
slouken@3596
  1137
static int
slouken@3596
  1138
GL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
slouken@3596
  1139
                    int count)
slouken@2884
  1140
{
slouken@2884
  1141
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3536
  1142
    int i;
slouken@2884
  1143
slouken@3458
  1144
    GL_SetBlendMode(data, renderer->blendMode, 1);
slouken@2884
  1145
slouken@2884
  1146
    data->glColor4f((GLfloat) renderer->r * inv255f,
slouken@2884
  1147
                    (GLfloat) renderer->g * inv255f,
slouken@2884
  1148
                    (GLfloat) renderer->b * inv255f,
slouken@2884
  1149
                    (GLfloat) renderer->a * inv255f);
slouken@2884
  1150
slouken@2901
  1151
    data->glBegin(GL_POINTS);
slouken@3536
  1152
    for (i = 0; i < count; ++i) {
slouken@3536
  1153
        data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
slouken@3536
  1154
    }
slouken@2901
  1155
    data->glEnd();
slouken@2901
  1156
slouken@2901
  1157
    return 0;
slouken@2901
  1158
}
slouken@2901
  1159
slouken@2901
  1160
static int
slouken@3596
  1161
GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
slouken@3596
  1162
                   int count)
slouken@2901
  1163
{
slouken@2901
  1164
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3536
  1165
    int i;
slouken@2901
  1166
slouken@3458
  1167
    GL_SetBlendMode(data, renderer->blendMode, 1);
slouken@2901
  1168
slouken@2901
  1169
    data->glColor4f((GLfloat) renderer->r * inv255f,
slouken@2901
  1170
                    (GLfloat) renderer->g * inv255f,
slouken@2901
  1171
                    (GLfloat) renderer->b * inv255f,
slouken@2901
  1172
                    (GLfloat) renderer->a * inv255f);
slouken@2901
  1173
slouken@3536
  1174
    if (count > 2 && 
slouken@3536
  1175
        points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
slouken@3536
  1176
        data->glBegin(GL_LINE_LOOP);
slouken@3536
  1177
        /* GL_LINE_LOOP takes care of the final segment */
slouken@3536
  1178
        --count;
slouken@3536
  1179
        for (i = 0; i < count; ++i) {
slouken@3536
  1180
            data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
slouken@3536
  1181
        }
slouken@3536
  1182
        data->glEnd();
slouken@3536
  1183
    } else {
aschiffler@4910
  1184
#if defined(__APPLE__) || defined(__WIN32__)
aschiffler@4910
  1185
#else
slouken@4905
  1186
        int x1, y1, x2, y2;
aschiffler@4910
  1187
#endif
slouken@4905
  1188
slouken@3536
  1189
        data->glBegin(GL_LINE_STRIP);
slouken@3536
  1190
        for (i = 0; i < count; ++i) {
slouken@3536
  1191
            data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
slouken@3536
  1192
        }
slouken@3536
  1193
        data->glEnd();
slouken@3474
  1194
slouken@3536
  1195
        /* The line is half open, so we need one more point to complete it.
slouken@3536
  1196
         * http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html
slouken@3536
  1197
         * If we have to, we can use vertical line and horizontal line textures
slouken@3536
  1198
         * for vertical and horizontal lines, and then create custom textures
slouken@3536
  1199
         * for diagonal lines and software render those.  It's terrible, but at
slouken@3536
  1200
         * least it would be pixel perfect.
slouken@3536
  1201
         */
slouken@3536
  1202
        data->glBegin(GL_POINTS);
slouken@3533
  1203
#if defined(__APPLE__) || defined(__WIN32__)
slouken@3536
  1204
        /* Mac OS X and Windows seem to always leave the second point open */
slouken@3536
  1205
        data->glVertex2f(0.5f + points[count-1].x, 0.5f + points[count-1].y);
slouken@3474
  1206
#else
slouken@3536
  1207
        /* Linux seems to leave the right-most or bottom-most point open */
slouken@4905
  1208
        x1 = points[0].x;
slouken@4905
  1209
        y1 = points[0].y;
slouken@4905
  1210
        x2 = points[count-1].x;
slouken@4905
  1211
        y2 = points[count-1].y;
slouken@3536
  1212
slouken@3536
  1213
        if (x1 > x2) {
slouken@3536
  1214
            data->glVertex2f(0.5f + x1, 0.5f + y1);
slouken@3536
  1215
        } else if (x2 > x1) {
slouken@3536
  1216
            data->glVertex2f(0.5f + x2, 0.5f + y2);
slouken@3536
  1217
        } else if (y1 > y2) {
slouken@3536
  1218
            data->glVertex2f(0.5f + x1, 0.5f + y1);
slouken@3536
  1219
        } else if (y2 > y1) {
slouken@3536
  1220
            data->glVertex2f(0.5f + x2, 0.5f + y2);
slouken@3536
  1221
        }
slouken@3536
  1222
#endif
slouken@3536
  1223
        data->glEnd();
slouken@3474
  1224
    }
slouken@3455
  1225
slouken@1918
  1226
    return 0;
slouken@1918
  1227
}
slouken@1918
  1228
slouken@1918
  1229
static int
slouken@3596
  1230
GL_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
slouken@3596
  1231
{
slouken@3596
  1232
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3596
  1233
    int i, x, y;
slouken@3596
  1234
slouken@3596
  1235
    GL_SetBlendMode(data, renderer->blendMode, 1);
slouken@3596
  1236
slouken@3596
  1237
    data->glColor4f((GLfloat) renderer->r * inv255f,
slouken@3596
  1238
                    (GLfloat) renderer->g * inv255f,
slouken@3596
  1239
                    (GLfloat) renderer->b * inv255f,
slouken@3596
  1240
                    (GLfloat) renderer->a * inv255f);
slouken@3596
  1241
slouken@3596
  1242
    data->glBegin(GL_LINE_LOOP);
slouken@3596
  1243
    for (i = 0; i < count; ++i) {
slouken@3596
  1244
        const SDL_Rect *rect = rects[i];
slouken@3596
  1245
slouken@3596
  1246
        x = rect->x;
slouken@3596
  1247
        y = rect->y;
slouken@3596
  1248
        data->glVertex2f(0.5f + x, 0.5f + y);
slouken@3596
  1249
slouken@3596
  1250
        x = rect->x+rect->w-1;
slouken@3596
  1251
        y = rect->y;
slouken@3596
  1252
        data->glVertex2f(0.5f + x, 0.5f + y);
slouken@3596
  1253
slouken@3596
  1254
        x = rect->x+rect->w-1;
slouken@3596
  1255
        y = rect->y+rect->h-1;
slouken@3596
  1256
        data->glVertex2f(0.5f + x, 0.5f + y);
slouken@3596
  1257
slouken@3596
  1258
        x = rect->x;
slouken@3596
  1259
        y = rect->y+rect->h-1;
slouken@3596
  1260
        data->glVertex2f(0.5f + x, 0.5f + y);
slouken@3596
  1261
    }
slouken@3596
  1262
    data->glEnd();
slouken@3596
  1263
slouken@3596
  1264
    return 0;
slouken@3596
  1265
}
slouken@3596
  1266
slouken@3596
  1267
static int
slouken@3596
  1268
GL_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
slouken@2925
  1269
{
slouken@2925
  1270
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3536
  1271
    int i;
slouken@2925
  1272
slouken@3458
  1273
    GL_SetBlendMode(data, renderer->blendMode, 1);
slouken@2936
  1274
slouken@2925
  1275
    data->glColor4f((GLfloat) renderer->r * inv255f,
slouken@2925
  1276
                    (GLfloat) renderer->g * inv255f,
slouken@2925
  1277
                    (GLfloat) renderer->b * inv255f,
slouken@2925
  1278
                    (GLfloat) renderer->a * inv255f);
slouken@2936
  1279
slouken@3536
  1280
    for (i = 0; i < count; ++i) {
slouken@3536
  1281
        const SDL_Rect *rect = rects[i];
slouken@3536
  1282
slouken@3536
  1283
        data->glRecti(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
slouken@3536
  1284
    }
slouken@2925
  1285
slouken@2925
  1286
    return 0;
slouken@2925
  1287
}
slouken@2925
  1288
slouken@2925
  1289
static int
slouken@1918
  1290
GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1985
  1291
              const SDL_Rect * srcrect, const SDL_Rect * dstrect)
slouken@1918
  1292
{
slouken@1918
  1293
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1918
  1294
    GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
slouken@3468
  1295
    GLuint shader = 0;
slouken@1918
  1296
    int minx, miny, maxx, maxy;
slouken@1918
  1297
    GLfloat minu, maxu, minv, maxv;
slouken@1918
  1298
slouken@2275
  1299
    if (texturedata->dirty.list) {
slouken@1920
  1300
        SDL_DirtyRect *dirty;
slouken@1920
  1301
        void *pixels;
icculus@2835
  1302
        int bpp = bytes_per_pixel(texture->format);
slouken@1920
  1303
        int pitch = texturedata->pitch;
slouken@1920
  1304
slouken@1927
  1305
        SetupTextureUpdate(data, texture, pitch);
slouken@2884
  1306
        data->glEnable(texturedata->type);
slouken@1927
  1307
        data->glBindTexture(texturedata->type, texturedata->texture);
slouken@1920
  1308
        for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
slouken@1920
  1309
            SDL_Rect *rect = &dirty->rect;
slouken@1920
  1310
            pixels =
slouken@1920
  1311
                (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch +
slouken@1920
  1312
                          rect->x * bpp);
slouken@1927
  1313
            data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
slouken@2884
  1314
                                  rect->w / texturedata->HACK_RYAN_FIXME,
slouken@2884
  1315
                                  rect->h, texturedata->format,
slouken@1927
  1316
                                  texturedata->formattype, pixels);
slouken@1920
  1317
        }
slouken@1920
  1318
        SDL_ClearDirtyRects(&texturedata->dirty);
slouken@1920
  1319
    }
slouken@1920
  1320
slouken@1918
  1321
    minx = dstrect->x;
slouken@1918
  1322
    miny = dstrect->y;
slouken@1918
  1323
    maxx = dstrect->x + dstrect->w;
slouken@1918
  1324
    maxy = dstrect->y + dstrect->h;
slouken@1918
  1325
slouken@1918
  1326
    minu = (GLfloat) srcrect->x / texture->w;
slouken@1920
  1327
    minu *= texturedata->texw;
slouken@1918
  1328
    maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
slouken@1920
  1329
    maxu *= texturedata->texw;
slouken@1918
  1330
    minv = (GLfloat) srcrect->y / texture->h;
slouken@1920
  1331
    minv *= texturedata->texh;
slouken@1918
  1332
    maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
slouken@1920
  1333
    maxv *= texturedata->texh;
slouken@1918
  1334
slouken@2884
  1335
    data->glEnable(texturedata->type);
slouken@1927
  1336
    data->glBindTexture(texturedata->type, texturedata->texture);
slouken@1918
  1337
slouken@1985
  1338
    if (texture->modMode) {
slouken@1985
  1339
        data->glColor4f((GLfloat) texture->r * inv255f,
slouken@1985
  1340
                        (GLfloat) texture->g * inv255f,
slouken@1985
  1341
                        (GLfloat) texture->b * inv255f,
slouken@1985
  1342
                        (GLfloat) texture->a * inv255f);
slouken@1985
  1343
    } else {
slouken@1985
  1344
        data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
slouken@1985
  1345
    }
slouken@1985
  1346
slouken@3458
  1347
    GL_SetBlendMode(data, texture->blendMode, 0);
slouken@1918
  1348
slouken@3468
  1349
    /* Set up the shader for the copy, we have a special one for MASK */
slouken@3468
  1350
    shader = texturedata->shader;
slouken@3468
  1351
    if (texture->blendMode == SDL_BLENDMODE_MASK && !shader) {
slouken@3468
  1352
        if (data->fragment_program_mask == 0) {
slouken@3468
  1353
            data->fragment_program_mask =
slouken@3468
  1354
                compile_shader(data, GL_FRAGMENT_PROGRAM_ARB,
slouken@3468
  1355
                               fragment_program_mask_source_code);
slouken@3468
  1356
            if (data->fragment_program_mask == 0) {
slouken@3468
  1357
                /* That's okay, we'll just miss some of the blend semantics */
slouken@3468
  1358
                data->fragment_program_mask = ~0;
slouken@3468
  1359
            }
slouken@3468
  1360
        }
slouken@3468
  1361
        if (data->fragment_program_mask != ~0) {
slouken@3468
  1362
            shader = data->fragment_program_mask;
slouken@3468
  1363
        }
slouken@3468
  1364
    }
slouken@3468
  1365
slouken@1985
  1366
    if (texture->scaleMode != data->scaleMode) {
slouken@1985
  1367
        switch (texture->scaleMode) {
slouken@4929
  1368
        case SDL_SCALEMODE_NONE:
slouken@4929
  1369
        case SDL_SCALEMODE_FAST:
slouken@1927
  1370
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
slouken@1927
  1371
                                  GL_NEAREST);
slouken@1927
  1372
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
slouken@1927
  1373
                                  GL_NEAREST);
slouken@1927
  1374
            break;
slouken@4929
  1375
        case SDL_SCALEMODE_SLOW:
slouken@4929
  1376
        case SDL_SCALEMODE_BEST:
slouken@1927
  1377
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
slouken@1927
  1378
                                  GL_LINEAR);
slouken@1927
  1379
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
slouken@1927
  1380
                                  GL_LINEAR);
slouken@1927
  1381
            break;
slouken@1927
  1382
        }
slouken@1985
  1383
        data->scaleMode = texture->scaleMode;
slouken@1918
  1384
    }
slouken@1918
  1385
slouken@3468
  1386
    if (shader) {
icculus@2835
  1387
        data->glEnable(GL_FRAGMENT_PROGRAM_ARB);
slouken@3468
  1388
        data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader);
icculus@2835
  1389
    }
icculus@2835
  1390
slouken@1927
  1391
    data->glBegin(GL_TRIANGLE_STRIP);
slouken@1927
  1392
    data->glTexCoord2f(minu, minv);
slouken@3472
  1393
    data->glVertex2f((GLfloat) minx, (GLfloat) miny);
slouken@1927
  1394
    data->glTexCoord2f(maxu, minv);
slouken@3472
  1395
    data->glVertex2f((GLfloat) maxx, (GLfloat) miny);
slouken@1927
  1396
    data->glTexCoord2f(minu, maxv);
slouken@3472
  1397
    data->glVertex2f((GLfloat) minx, (GLfloat) maxy);
slouken@1927
  1398
    data->glTexCoord2f(maxu, maxv);
slouken@3472
  1399
    data->glVertex2f((GLfloat) maxx, (GLfloat) maxy);
slouken@1927
  1400
    data->glEnd();
slouken@1918
  1401
slouken@3468
  1402
    if (shader) {
icculus@2835
  1403
        data->glDisable(GL_FRAGMENT_PROGRAM_ARB);
icculus@2835
  1404
    }
slouken@2884
  1405
slouken@2884
  1406
    data->glDisable(texturedata->type);
slouken@2884
  1407
slouken@1918
  1408
    return 0;
slouken@1918
  1409
}
slouken@1918
  1410
slouken@3431
  1411
static int
slouken@3431
  1412
GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@3435
  1413
                    Uint32 pixel_format, void * pixels, int pitch)
slouken@3431
  1414
{
slouken@3433
  1415
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3685
  1416
    SDL_Window *window = renderer->window;
slouken@3433
  1417
    GLint internalFormat;
slouken@3433
  1418
    GLenum format, type;
slouken@3435
  1419
    Uint8 *src, *dst, *tmp;
slouken@3435
  1420
    int length, rows;
slouken@3433
  1421
slouken@3433
  1422
    if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
slouken@3435
  1423
        /* FIXME: Do a temp copy to a format that is supported */
slouken@3433
  1424
        SDL_SetError("Unsupported pixel format");
slouken@3433
  1425
        return -1;
slouken@3433
  1426
    }
slouken@3433
  1427
slouken@3433
  1428
    if (pixel_format == SDL_PIXELFORMAT_INDEX1LSB) {
slouken@3433
  1429
        data->glPixelStorei(GL_PACK_LSB_FIRST, 1);
slouken@3433
  1430
    } else if (pixel_format == SDL_PIXELFORMAT_INDEX1MSB) {
slouken@3433
  1431
        data->glPixelStorei(GL_PACK_LSB_FIRST, 0);
slouken@3433
  1432
    }
slouken@3446
  1433
    data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
slouken@3446
  1434
    data->glPixelStorei(GL_PACK_ROW_LENGTH,
slouken@3446
  1435
                        (pitch / bytes_per_pixel(pixel_format)));
slouken@3433
  1436
slouken@3447
  1437
    data->glReadPixels(rect->x, (window->h-rect->y)-rect->h, rect->w, rect->h,
slouken@3435
  1438
                       format, type, pixels);
slouken@3435
  1439
slouken@3435
  1440
    /* Flip the rows to be top-down */
slouken@3435
  1441
    length = rect->w * bytes_per_pixel(pixel_format);
slouken@3435
  1442
    src = (Uint8*)pixels + (rect->h-1)*pitch;
slouken@3435
  1443
    dst = (Uint8*)pixels;
slouken@3435
  1444
    tmp = SDL_stack_alloc(Uint8, length);
slouken@3435
  1445
    rows = rect->h / 2;
slouken@3435
  1446
    while (rows--) {
slouken@3435
  1447
        SDL_memcpy(tmp, dst, length);
slouken@3435
  1448
        SDL_memcpy(dst, src, length);
slouken@3435
  1449
        SDL_memcpy(src, tmp, length);
slouken@3447
  1450
        dst += pitch;
slouken@3447
  1451
        src -= pitch;
slouken@3435
  1452
    }
slouken@3435
  1453
    SDL_stack_free(tmp);
slouken@3440
  1454
slouken@3440
  1455
    return 0;
slouken@3431
  1456
}
slouken@3431
  1457
slouken@3431
  1458
static int
slouken@3431
  1459
GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@3435
  1460
                     Uint32 pixel_format, const void * pixels, int pitch)
slouken@3431
  1461
{
slouken@3435
  1462
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@3685
  1463
    SDL_Window *window = renderer->window;
slouken@3435
  1464
    GLint internalFormat;
slouken@3435
  1465
    GLenum format, type;
slouken@3607
  1466
    Uint8 *src, *dst, *tmp;
slouken@3607
  1467
    int length, rows;
slouken@3435
  1468
slouken@3435
  1469
    if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
slouken@3435
  1470
        /* FIXME: Do a temp copy to a format that is supported */
slouken@3435
  1471
        SDL_SetError("Unsupported pixel format");
slouken@3435
  1472
        return -1;
slouken@3435
  1473
    }
slouken@3435
  1474
slouken@3435
  1475
    if (pixel_format == SDL_PIXELFORMAT_INDEX1LSB) {
slouken@3435
  1476
        data->glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
slouken@3435
  1477
    } else if (pixel_format == SDL_PIXELFORMAT_INDEX1MSB) {
slouken@3435
  1478
        data->glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
slouken@3435
  1479
    }
slouken@3435
  1480
    data->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
slouken@3435
  1481
    data->glPixelStorei(GL_UNPACK_ROW_LENGTH,
slouken@3435
  1482
                        (pitch / bytes_per_pixel(pixel_format)));
slouken@3435
  1483
slouken@3607
  1484
    /* Flip the rows to be bottom-up */
slouken@3607
  1485
    length = rect->h * rect->w * pitch;
slouken@3607
  1486
    tmp = SDL_stack_alloc(Uint8, length);
slouken@3607
  1487
    src = (Uint8*)pixels + (rect->h-1)*pitch;
slouken@3607
  1488
    dst = (Uint8*)tmp;
slouken@3607
  1489
    rows = rect->h;
slouken@3607
  1490
    while (rows--) {
slouken@3607
  1491
        SDL_memcpy(dst, src, pitch);
slouken@3607
  1492
        dst += pitch;
slouken@3607
  1493
        src -= pitch;
slouken@3607
  1494
    }
slouken@3607
  1495
slouken@3607
  1496
    data->glRasterPos2i(rect->x, (window->h-rect->y));
slouken@3607
  1497
    data->glDrawPixels(rect->w, rect->h, format, type, tmp);
slouken@3607
  1498
    SDL_stack_free(tmp);
slouken@3440
  1499
slouken@3440
  1500
    return 0;
slouken@3431
  1501
}
slouken@3431
  1502
slouken@1918
  1503
static void
slouken@1918
  1504
GL_RenderPresent(SDL_Renderer * renderer)
slouken@1918
  1505
{
slouken@1918
  1506
    SDL_GL_SwapWindow(renderer->window);
slouken@1918
  1507
}
slouken@1918
  1508
slouken@1918
  1509
static void
slouken@1918
  1510
GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
  1511
{
slouken@1927
  1512
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
  1513
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1918
  1514
slouken@1918
  1515
    if (!data) {
slouken@1918
  1516
        return;
slouken@1918
  1517
    }
slouken@1918
  1518
    if (data->texture) {
slouken@1927
  1519
        renderdata->glDeleteTextures(1, &data->texture);
slouken@1918
  1520
    }
slouken@1974
  1521
    if (data->palette) {
slouken@1974
  1522
        SDL_free(data->palette);
slouken@1974
  1523
    }
slouken@1920
  1524
    if (data->pixels) {
slouken@1920
  1525
        SDL_free(data->pixels);
slouken@1920
  1526
    }
slouken@1920
  1527
    SDL_FreeDirtyRects(&data->dirty);
slouken@1918
  1528
    SDL_free(data);
slouken@1918
  1529
    texture->driverdata = NULL;
slouken@1918
  1530
}
slouken@1918
  1531
slouken@1975
  1532
static void
slouken@1918
  1533
GL_DestroyRenderer(SDL_Renderer * renderer)
slouken@1918
  1534
{
slouken@1918
  1535
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1918
  1536
slouken@1918
  1537
    if (data) {
slouken@1920
  1538
        if (data->context) {
icculus@2835
  1539
            if (data->GL_ARB_fragment_program_supported) {
icculus@2835
  1540
                data->glDisable(GL_FRAGMENT_PROGRAM_ARB);
icculus@2835
  1541
                data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0);
slouken@3468
  1542
                if (data->fragment_program_mask &&
slouken@3468
  1543
                    data->fragment_program_mask != ~0) {
slouken@3468
  1544
                    data->glDeleteProgramsARB(1,
slouken@3468
  1545
                                              &data->fragment_program_mask);
slouken@3468
  1546
                }
slouken@3468
  1547
                if (data->fragment_program_UYVY &&
slouken@3468
  1548
                    data->fragment_program_UYVY != ~0) {
slouken@2884
  1549
                    data->glDeleteProgramsARB(1,
slouken@2884
  1550
                                              &data->fragment_program_UYVY);
icculus@2835
  1551
                }
icculus@2835
  1552
            }
icculus@2835
  1553
bob@2328
  1554
            /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
slouken@1920
  1555
            SDL_GL_DeleteContext(data->context);
slouken@1918
  1556
        }
slouken@1918
  1557
        SDL_free(data);
slouken@1918
  1558
    }
slouken@1918
  1559
    SDL_free(renderer);
slouken@1918
  1560
}
slouken@1918
  1561
slouken@1952
  1562
#endif /* SDL_VIDEO_RENDER_OGL */
slouken@1918
  1563
slouken@1918
  1564
/* vi: set ts=4 sw=4 expandtab: */