src/video/SDL_renderer_gl.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 28 Aug 2006 03:17:39 +0000
changeset 1985 8055185ae4ed
parent 1975 ccef0d0c40c6
child 1986 f4c65e3bfaed
permissions -rw-r--r--
Added source color and alpha modulation support.
Added perl script to generate optimized render copy functions.
slouken@1918
     1
/*
slouken@1918
     2
    SDL - Simple DirectMedia Layer
slouken@1918
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1918
     4
slouken@1918
     5
    This library is free software; you can redistribute it and/or
slouken@1918
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1918
     7
    License as published by the Free Software Foundation; either
slouken@1918
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1918
     9
slouken@1918
    10
    This library is distributed in the hope that it will be useful,
slouken@1918
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1918
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1918
    13
    Lesser General Public License for more details.
slouken@1918
    14
slouken@1918
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1918
    16
    License along with this library; if not, write to the Free Software
slouken@1918
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1918
    18
slouken@1918
    19
    Sam Lantinga
slouken@1918
    20
    slouken@libsdl.org
slouken@1918
    21
*/
slouken@1918
    22
#include "SDL_config.h"
slouken@1918
    23
slouken@1952
    24
#if SDL_VIDEO_RENDER_OGL
slouken@1920
    25
slouken@1920
    26
#include "SDL_video.h"
slouken@1920
    27
#include "SDL_opengl.h"
slouken@1920
    28
#include "SDL_sysvideo.h"
slouken@1920
    29
#include "SDL_pixels_c.h"
slouken@1920
    30
#include "SDL_rect_c.h"
slouken@1920
    31
#include "SDL_yuv_sw_c.h"
slouken@1918
    32
slouken@1918
    33
/* OpenGL renderer implementation */
slouken@1918
    34
slouken@1985
    35
static const float inv255f = 1.0f / 255.0f;
slouken@1985
    36
slouken@1918
    37
static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
slouken@1923
    38
static int GL_ActivateRenderer(SDL_Renderer * renderer);
slouken@1970
    39
static int GL_DisplayModeChanged(SDL_Renderer * renderer);
slouken@1918
    40
static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1918
    41
static int GL_SetTexturePalette(SDL_Renderer * renderer,
slouken@1918
    42
                                SDL_Texture * texture,
slouken@1918
    43
                                const SDL_Color * colors, int firstcolor,
slouken@1918
    44
                                int ncolors);
slouken@1918
    45
static int GL_GetTexturePalette(SDL_Renderer * renderer,
slouken@1918
    46
                                SDL_Texture * texture, SDL_Color * colors,
slouken@1918
    47
                                int firstcolor, int ncolors);
slouken@1985
    48
static int GL_SetTextureColorMod(SDL_Renderer * renderer,
slouken@1985
    49
                                 SDL_Texture * texture);
slouken@1985
    50
static int GL_SetTextureAlphaMod(SDL_Renderer * renderer,
slouken@1985
    51
                                 SDL_Texture * texture);
slouken@1985
    52
static int GL_SetTextureBlendMode(SDL_Renderer * renderer,
slouken@1985
    53
                                  SDL_Texture * texture);
slouken@1985
    54
static int GL_SetTextureScaleMode(SDL_Renderer * renderer,
slouken@1985
    55
                                  SDL_Texture * texture);
slouken@1918
    56
static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
    57
                            const SDL_Rect * rect, const void *pixels,
slouken@1918
    58
                            int pitch);
slouken@1918
    59
static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1985
    60
                          const SDL_Rect * rect, int markDirty, void **pixels,
slouken@1985
    61
                          int *pitch);
slouken@1918
    62
static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1918
    63
static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
    64
                            int numrects, const SDL_Rect * rects);
slouken@1985
    65
static int GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
slouken@1985
    66
                         Uint8 a, const SDL_Rect * rect);
slouken@1918
    67
static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1985
    68
                         const SDL_Rect * srcrect, const SDL_Rect * dstrect);
slouken@1918
    69
static void GL_RenderPresent(SDL_Renderer * renderer);
slouken@1918
    70
static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1918
    71
static void GL_DestroyRenderer(SDL_Renderer * renderer);
slouken@1918
    72
slouken@1918
    73
slouken@1918
    74
SDL_RenderDriver GL_RenderDriver = {
slouken@1918
    75
    GL_CreateRenderer,
slouken@1918
    76
    {
slouken@1918
    77
     "opengl",
slouken@1974
    78
     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD |
slouken@1974
    79
      SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
slouken@1985
    80
     (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
slouken@1985
    81
      SDL_TEXTUREMODULATE_ALPHA),
slouken@1965
    82
     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
slouken@1965
    83
      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
slouken@1965
    84
      SDL_TEXTUREBLENDMODE_MOD),
slouken@1965
    85
     (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
slouken@1965
    86
      SDL_TEXTURESCALEMODE_SLOW),
slouken@1924
    87
     16,
slouken@1918
    88
     {
slouken@1965
    89
      SDL_PIXELFORMAT_INDEX1LSB,
slouken@1965
    90
      SDL_PIXELFORMAT_INDEX1MSB,
slouken@1965
    91
      SDL_PIXELFORMAT_INDEX8,
slouken@1965
    92
      SDL_PIXELFORMAT_RGB332,
slouken@1965
    93
      SDL_PIXELFORMAT_RGB444,
slouken@1965
    94
      SDL_PIXELFORMAT_RGB555,
slouken@1965
    95
      SDL_PIXELFORMAT_ARGB4444,
slouken@1965
    96
      SDL_PIXELFORMAT_ARGB1555,
slouken@1965
    97
      SDL_PIXELFORMAT_RGB565,
slouken@1965
    98
      SDL_PIXELFORMAT_RGB24,
slouken@1965
    99
      SDL_PIXELFORMAT_BGR24,
slouken@1965
   100
      SDL_PIXELFORMAT_RGB888,
slouken@1965
   101
      SDL_PIXELFORMAT_BGR888,
slouken@1965
   102
      SDL_PIXELFORMAT_ARGB8888,
slouken@1965
   103
      SDL_PIXELFORMAT_ABGR8888,
slouken@1965
   104
      SDL_PIXELFORMAT_ARGB2101010},
slouken@1918
   105
     0,
slouken@1918
   106
     0}
slouken@1918
   107
};
slouken@1918
   108
slouken@1918
   109
typedef struct
slouken@1918
   110
{
slouken@1918
   111
    SDL_GLContext context;
slouken@1970
   112
    SDL_bool updateSize;
slouken@1974
   113
    SDL_bool GL_EXT_paletted_texture_supported;
slouken@1926
   114
    SDL_bool GL_ARB_texture_rectangle_supported;
slouken@1927
   115
    int blendMode;
slouken@1927
   116
    int scaleMode;
slouken@1927
   117
slouken@1927
   118
    /* OpenGL functions */
slouken@1927
   119
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
slouken@1927
   120
#include "SDL_glfuncs.h"
slouken@1927
   121
#undef SDL_PROC
slouken@1974
   122
slouken@1974
   123
    PFNGLCOLORTABLEEXTPROC glColorTableEXT;
slouken@1918
   124
} GL_RenderData;
slouken@1918
   125
slouken@1918
   126
typedef struct
slouken@1918
   127
{
slouken@1918
   128
    GLuint texture;
slouken@1920
   129
    GLenum type;
slouken@1918
   130
    GLfloat texw;
slouken@1918
   131
    GLfloat texh;
slouken@1920
   132
    GLenum format;
slouken@1920
   133
    GLenum formattype;
slouken@1974
   134
    Uint8 *palette;
slouken@1918
   135
    void *pixels;
slouken@1918
   136
    int pitch;
slouken@1920
   137
    SDL_DirtyRectList dirty;
slouken@1918
   138
} GL_TextureData;
slouken@1918
   139
slouken@1918
   140
slouken@1924
   141
static void
slouken@1924
   142
GL_SetError(const char *prefix, GLenum result)
slouken@1924
   143
{
slouken@1924
   144
    const char *error;
slouken@1924
   145
slouken@1924
   146
    switch (result) {
slouken@1924
   147
    case GL_NO_ERROR:
slouken@1924
   148
        error = "GL_NO_ERROR";
slouken@1924
   149
        break;
slouken@1924
   150
    case GL_INVALID_ENUM:
slouken@1924
   151
        error = "GL_INVALID_ENUM";
slouken@1924
   152
        break;
slouken@1924
   153
    case GL_INVALID_VALUE:
slouken@1924
   154
        error = "GL_INVALID_VALUE";
slouken@1924
   155
        break;
slouken@1924
   156
    case GL_INVALID_OPERATION:
slouken@1924
   157
        error = "GL_INVALID_OPERATION";
slouken@1924
   158
        break;
slouken@1924
   159
    case GL_STACK_OVERFLOW:
slouken@1924
   160
        error = "GL_STACK_OVERFLOW";
slouken@1924
   161
        break;
slouken@1924
   162
    case GL_STACK_UNDERFLOW:
slouken@1924
   163
        error = "GL_STACK_UNDERFLOW";
slouken@1924
   164
        break;
slouken@1924
   165
    case GL_OUT_OF_MEMORY:
slouken@1924
   166
        error = "GL_OUT_OF_MEMORY";
slouken@1924
   167
        break;
slouken@1924
   168
    case GL_TABLE_TOO_LARGE:
slouken@1924
   169
        error = "GL_TABLE_TOO_LARGE";
slouken@1924
   170
        break;
slouken@1924
   171
    default:
slouken@1924
   172
        error = "UNKNOWN";
slouken@1924
   173
        break;
slouken@1924
   174
    }
slouken@1924
   175
    SDL_SetError("%s: %s", prefix, error);
slouken@1924
   176
}
slouken@1924
   177
slouken@1927
   178
static int
slouken@1927
   179
GL_LoadFunctions(GL_RenderData * data)
slouken@1927
   180
{
slouken@1927
   181
#if defined(__QNXNTO__) && (_NTO_VERSION < 630)
slouken@1927
   182
#define __SDL_NOGETPROCADDR__
slouken@1927
   183
#elif defined(__MINT__)
slouken@1927
   184
#define __SDL_NOGETPROCADDR__
slouken@1927
   185
#endif
slouken@1927
   186
#ifdef __SDL_NOGETPROCADDR__
slouken@1927
   187
#define SDL_PROC(ret,func,params) data->func=func;
slouken@1927
   188
#else
slouken@1927
   189
#define SDL_PROC(ret,func,params) \
slouken@1927
   190
    do { \
slouken@1927
   191
        data->func = SDL_GL_GetProcAddress(#func); \
slouken@1927
   192
        if ( ! data->func ) { \
slouken@1927
   193
            SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
slouken@1927
   194
            return -1; \
slouken@1927
   195
        } \
slouken@1927
   196
    } while ( 0 );
slouken@1927
   197
#endif /* __SDL_NOGETPROCADDR__ */
slouken@1927
   198
slouken@1927
   199
#include "SDL_glfuncs.h"
slouken@1927
   200
#undef SDL_PROC
slouken@1927
   201
    return 0;
slouken@1927
   202
}
slouken@1927
   203
slouken@1918
   204
void
slouken@1918
   205
GL_AddRenderDriver(_THIS)
slouken@1918
   206
{
slouken@1920
   207
    if (_this->GL_CreateContext) {
slouken@1918
   208
        SDL_AddRenderDriver(0, &GL_RenderDriver);
slouken@1918
   209
    }
slouken@1918
   210
}
slouken@1918
   211
slouken@1918
   212
SDL_Renderer *
slouken@1918
   213
GL_CreateRenderer(SDL_Window * window, Uint32 flags)
slouken@1918
   214
{
slouken@1918
   215
    SDL_Renderer *renderer;
slouken@1918
   216
    GL_RenderData *data;
slouken@1952
   217
    GLint value;
slouken@1974
   218
    int doublebuffer;
slouken@1918
   219
slouken@1974
   220
    /* Render directly to the window, unless we're compositing */
slouken@1974
   221
#ifndef __MACOSX__
slouken@1974
   222
    if (flags & SDL_RENDERER_SINGLEBUFFER) {
slouken@1974
   223
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
slouken@1974
   224
    }
slouken@1974
   225
#endif
slouken@1918
   226
    if (!(window->flags & SDL_WINDOW_OPENGL)) {
slouken@1928
   227
        if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) {
slouken@1924
   228
            return NULL;
slouken@1924
   229
        }
slouken@1918
   230
    }
slouken@1918
   231
slouken@1920
   232
    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
slouken@1918
   233
    if (!renderer) {
slouken@1918
   234
        SDL_OutOfMemory();
slouken@1918
   235
        return NULL;
slouken@1918
   236
    }
slouken@1918
   237
slouken@1920
   238
    data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
slouken@1918
   239
    if (!data) {
slouken@1918
   240
        GL_DestroyRenderer(renderer);
slouken@1918
   241
        SDL_OutOfMemory();
slouken@1918
   242
        return NULL;
slouken@1918
   243
    }
slouken@1918
   244
slouken@1923
   245
    renderer->ActivateRenderer = GL_ActivateRenderer;
slouken@1970
   246
    renderer->DisplayModeChanged = GL_DisplayModeChanged;
slouken@1918
   247
    renderer->CreateTexture = GL_CreateTexture;
slouken@1918
   248
    renderer->SetTexturePalette = GL_SetTexturePalette;
slouken@1918
   249
    renderer->GetTexturePalette = GL_GetTexturePalette;
slouken@1985
   250
    renderer->SetTextureColorMod = GL_SetTextureColorMod;
slouken@1985
   251
    renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod;
slouken@1985
   252
    renderer->SetTextureBlendMode = GL_SetTextureBlendMode;
slouken@1985
   253
    renderer->SetTextureScaleMode = GL_SetTextureScaleMode;
slouken@1918
   254
    renderer->UpdateTexture = GL_UpdateTexture;
slouken@1918
   255
    renderer->LockTexture = GL_LockTexture;
slouken@1918
   256
    renderer->UnlockTexture = GL_UnlockTexture;
slouken@1918
   257
    renderer->DirtyTexture = GL_DirtyTexture;
slouken@1918
   258
    renderer->RenderFill = GL_RenderFill;
slouken@1918
   259
    renderer->RenderCopy = GL_RenderCopy;
slouken@1918
   260
    renderer->RenderPresent = GL_RenderPresent;
slouken@1918
   261
    renderer->DestroyTexture = GL_DestroyTexture;
slouken@1918
   262
    renderer->DestroyRenderer = GL_DestroyRenderer;
slouken@1918
   263
    renderer->info = GL_RenderDriver.info;
slouken@1918
   264
    renderer->window = window->id;
slouken@1918
   265
    renderer->driverdata = data;
slouken@1918
   266
slouken@1918
   267
    renderer->info.flags =
slouken@1965
   268
        (SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED);
slouken@1918
   269
slouken@1927
   270
    if (GL_LoadFunctions(data) < 0) {
slouken@1927
   271
        GL_DestroyRenderer(renderer);
slouken@1927
   272
        return NULL;
slouken@1927
   273
    }
slouken@1927
   274
slouken@1918
   275
    data->context = SDL_GL_CreateContext(window->id);
slouken@1918
   276
    if (!data->context) {
slouken@1918
   277
        GL_DestroyRenderer(renderer);
slouken@1918
   278
        return NULL;
slouken@1918
   279
    }
slouken@1918
   280
    if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
slouken@1918
   281
        GL_DestroyRenderer(renderer);
slouken@1918
   282
        return NULL;
slouken@1918
   283
    }
slouken@1918
   284
slouken@1965
   285
    if (flags & SDL_RENDERER_PRESENTVSYNC) {
slouken@1918
   286
        SDL_GL_SetSwapInterval(1);
slouken@1918
   287
    } else {
slouken@1918
   288
        SDL_GL_SetSwapInterval(0);
slouken@1918
   289
    }
slouken@1918
   290
    if (SDL_GL_GetSwapInterval() > 0) {
slouken@1965
   291
        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
slouken@1918
   292
    }
slouken@1918
   293
slouken@1974
   294
    if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer) == 0) {
slouken@1974
   295
        if (!doublebuffer) {
slouken@1974
   296
            renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
slouken@1974
   297
        }
slouken@1974
   298
    }
slouken@1974
   299
slouken@1952
   300
    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
slouken@1952
   301
    renderer->info.max_texture_width = value;
slouken@1952
   302
    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
slouken@1952
   303
    renderer->info.max_texture_height = value;
slouken@1920
   304
slouken@1926
   305
    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
slouken@1926
   306
        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
slouken@1926
   307
        data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
slouken@1926
   308
    }
slouken@1974
   309
    if (SDL_GL_ExtensionSupported("GL_EXT_paletted_texture")) {
slouken@1974
   310
        data->GL_EXT_paletted_texture_supported = SDL_TRUE;
slouken@1974
   311
        data->glColorTableEXT =
slouken@1974
   312
            (PFNGLCOLORTABLEEXTPROC) SDL_GL_GetProcAddress("glColorTableEXT");
slouken@1974
   313
    } else {
slouken@1974
   314
        /* Don't advertise support for 8-bit indexed texture format */
slouken@1974
   315
        Uint32 i, j;
slouken@1974
   316
        SDL_RendererInfo *info = &renderer->info;
slouken@1974
   317
        for (i = 0, j = 0; i < info->num_texture_formats; ++i) {
slouken@1974
   318
            if (info->texture_formats[i] != SDL_PIXELFORMAT_INDEX8) {
slouken@1974
   319
                info->texture_formats[j++] = info->texture_formats[i];
slouken@1974
   320
            }
slouken@1974
   321
        }
slouken@1974
   322
        --info->num_texture_formats;
slouken@1974
   323
    }
slouken@1920
   324
slouken@1918
   325
    /* Set up parameters for rendering */
slouken@1927
   326
    data->blendMode = -1;
slouken@1927
   327
    data->scaleMode = -1;
slouken@1927
   328
    data->glDisable(GL_DEPTH_TEST);
slouken@1927
   329
    data->glDisable(GL_CULL_FACE);
slouken@1926
   330
    if (data->GL_ARB_texture_rectangle_supported) {
slouken@1927
   331
        data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
slouken@1926
   332
    } else {
slouken@1927
   333
        data->glEnable(GL_TEXTURE_2D);
slouken@1926
   334
    }
slouken@1970
   335
    data->updateSize = SDL_TRUE;
slouken@1918
   336
slouken@1918
   337
    return renderer;
slouken@1918
   338
}
slouken@1918
   339
slouken@1923
   340
static int
slouken@1923
   341
GL_ActivateRenderer(SDL_Renderer * renderer)
slouken@1923
   342
{
slouken@1923
   343
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1923
   344
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@1923
   345
slouken@1970
   346
    if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
slouken@1970
   347
        return -1;
slouken@1970
   348
    }
slouken@1970
   349
    if (data->updateSize) {
slouken@1970
   350
        data->glMatrixMode(GL_PROJECTION);
slouken@1970
   351
        data->glLoadIdentity();
slouken@1970
   352
        data->glMatrixMode(GL_MODELVIEW);
slouken@1970
   353
        data->glLoadIdentity();
slouken@1970
   354
        data->glViewport(0, 0, window->w, window->h);
slouken@1970
   355
        data->glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0,
slouken@1970
   356
                      0.0, 1.0);
slouken@1970
   357
        data->updateSize = SDL_FALSE;
slouken@1970
   358
    }
slouken@1970
   359
    return 0;
slouken@1970
   360
}
slouken@1970
   361
slouken@1970
   362
static int
slouken@1970
   363
GL_DisplayModeChanged(SDL_Renderer * renderer)
slouken@1970
   364
{
slouken@1970
   365
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1970
   366
slouken@1970
   367
    data->updateSize = SDL_TRUE;
slouken@1970
   368
    return 0;
slouken@1923
   369
}
slouken@1923
   370
slouken@1922
   371
static __inline__ int
slouken@1922
   372
power_of_2(int input)
slouken@1922
   373
{
slouken@1922
   374
    int value = 1;
slouken@1922
   375
slouken@1922
   376
    while (value < input) {
slouken@1922
   377
        value <<= 1;
slouken@1922
   378
    }
slouken@1922
   379
    return value;
slouken@1922
   380
}
slouken@1922
   381
slouken@1918
   382
static int
slouken@1918
   383
GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
   384
{
slouken@1918
   385
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   386
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@1918
   387
    GL_TextureData *data;
slouken@1920
   388
    GLint internalFormat;
slouken@1920
   389
    GLenum format, type;
slouken@1922
   390
    int texture_w, texture_h;
slouken@1924
   391
    GLenum result;
slouken@1918
   392
slouken@1920
   393
    switch (texture->format) {
slouken@1965
   394
    case SDL_PIXELFORMAT_INDEX1LSB:
slouken@1965
   395
    case SDL_PIXELFORMAT_INDEX1MSB:
slouken@1920
   396
        internalFormat = GL_RGB;
slouken@1920
   397
        format = GL_COLOR_INDEX;
slouken@1920
   398
        type = GL_BITMAP;
slouken@1920
   399
        break;
slouken@1965
   400
    case SDL_PIXELFORMAT_INDEX8:
slouken@1974
   401
        if (!renderdata->GL_EXT_paletted_texture_supported) {
slouken@1974
   402
            SDL_SetError("Unsupported texture format");
slouken@1974
   403
            return -1;
slouken@1974
   404
        }
slouken@1974
   405
        internalFormat = GL_COLOR_INDEX8_EXT;
slouken@1920
   406
        format = GL_COLOR_INDEX;
slouken@1920
   407
        type = GL_UNSIGNED_BYTE;
slouken@1920
   408
        break;
slouken@1965
   409
    case SDL_PIXELFORMAT_RGB332:
slouken@1920
   410
        internalFormat = GL_R3_G3_B2;
slouken@1920
   411
        format = GL_RGB;
slouken@1920
   412
        type = GL_UNSIGNED_BYTE_3_3_2;
slouken@1920
   413
        break;
slouken@1965
   414
    case SDL_PIXELFORMAT_RGB444:
slouken@1920
   415
        internalFormat = GL_RGB4;
slouken@1920
   416
        format = GL_RGB;
slouken@1920
   417
        type = GL_UNSIGNED_SHORT_4_4_4_4;
slouken@1920
   418
        break;
slouken@1965
   419
    case SDL_PIXELFORMAT_RGB555:
slouken@1920
   420
        internalFormat = GL_RGB5;
slouken@1920
   421
        format = GL_RGB;
slouken@1920
   422
        type = GL_UNSIGNED_SHORT_5_5_5_1;
slouken@1920
   423
        break;
slouken@1965
   424
    case SDL_PIXELFORMAT_ARGB4444:
slouken@1920
   425
        internalFormat = GL_RGBA4;
slouken@1920
   426
        format = GL_BGRA;
slouken@1920
   427
        type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
slouken@1920
   428
        break;
slouken@1965
   429
    case SDL_PIXELFORMAT_ARGB1555:
slouken@1920
   430
        internalFormat = GL_RGB5_A1;
slouken@1920
   431
        format = GL_BGRA;
slouken@1920
   432
        type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
slouken@1920
   433
        break;
slouken@1965
   434
    case SDL_PIXELFORMAT_RGB565:
slouken@1920
   435
        internalFormat = GL_RGB8;
slouken@1920
   436
        format = GL_RGB;
slouken@1920
   437
        type = GL_UNSIGNED_SHORT_5_6_5;
slouken@1920
   438
        break;
slouken@1965
   439
    case SDL_PIXELFORMAT_RGB24:
slouken@1920
   440
        internalFormat = GL_RGB8;
slouken@1920
   441
        format = GL_RGB;
slouken@1920
   442
        type = GL_UNSIGNED_BYTE;
slouken@1920
   443
        break;
slouken@1965
   444
    case SDL_PIXELFORMAT_RGB888:
slouken@1920
   445
        internalFormat = GL_RGB8;
slouken@1924
   446
        format = GL_BGRA;
slouken@1924
   447
        type = GL_UNSIGNED_BYTE;
slouken@1920
   448
        break;
slouken@1965
   449
    case SDL_PIXELFORMAT_BGR24:
slouken@1920
   450
        internalFormat = GL_RGB8;
slouken@1920
   451
        format = GL_BGR;
slouken@1920
   452
        type = GL_UNSIGNED_BYTE;
slouken@1920
   453
        break;
slouken@1965
   454
    case SDL_PIXELFORMAT_BGR888:
slouken@1920
   455
        internalFormat = GL_RGB8;
slouken@1924
   456
        format = GL_RGBA;
slouken@1924
   457
        type = GL_UNSIGNED_BYTE;
slouken@1920
   458
        break;
slouken@1965
   459
    case SDL_PIXELFORMAT_ARGB8888:
slouken@1920
   460
        internalFormat = GL_RGBA8;
slouken@1920
   461
        format = GL_BGRA;
slouken@1924
   462
        type = GL_UNSIGNED_BYTE;
slouken@1920
   463
        break;
slouken@1965
   464
    case SDL_PIXELFORMAT_ABGR8888:
slouken@1920
   465
        internalFormat = GL_RGBA8;
slouken@1920
   466
        format = GL_RGBA;
slouken@1924
   467
        type = GL_UNSIGNED_BYTE;
slouken@1920
   468
        break;
slouken@1965
   469
    case SDL_PIXELFORMAT_ARGB2101010:
slouken@1920
   470
        internalFormat = GL_RGB10_A2;
slouken@1920
   471
        format = GL_BGRA;
slouken@1920
   472
        type = GL_UNSIGNED_INT_2_10_10_10_REV;
slouken@1920
   473
        break;
slouken@1920
   474
    default:
slouken@1920
   475
        SDL_SetError("Unsupported texture format");
slouken@1920
   476
        return -1;
slouken@1920
   477
    }
slouken@1920
   478
slouken@1920
   479
    data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
slouken@1918
   480
    if (!data) {
slouken@1918
   481
        SDL_OutOfMemory();
slouken@1918
   482
        return -1;
slouken@1918
   483
    }
slouken@1918
   484
slouken@1974
   485
    if (texture->format == SDL_PIXELFORMAT_INDEX8) {
slouken@1974
   486
        data->palette = (Uint8 *) SDL_malloc(3 * 256 * sizeof(Uint8));
slouken@1974
   487
        if (!data->palette) {
slouken@1974
   488
            SDL_OutOfMemory();
slouken@1974
   489
            SDL_free(data);
slouken@1974
   490
            return -1;
slouken@1974
   491
        }
slouken@1974
   492
        SDL_memset(data->palette, 0xFF, 3 * 256 * sizeof(Uint8));
slouken@1974
   493
    }
slouken@1974
   494
slouken@1918
   495
    texture->driverdata = data;
slouken@1918
   496
slouken@1927
   497
    renderdata->glGetError();
slouken@1927
   498
    renderdata->glGenTextures(1, &data->texture);
slouken@1926
   499
    if (renderdata->GL_ARB_texture_rectangle_supported) {
slouken@1926
   500
        data->type = GL_TEXTURE_RECTANGLE_ARB;
slouken@1926
   501
        texture_w = texture->w;
slouken@1926
   502
        texture_h = texture->h;
slouken@1926
   503
        data->texw = (GLfloat) texture->w;
slouken@1926
   504
        data->texh = (GLfloat) texture->h;
slouken@1926
   505
    } else {
slouken@1926
   506
        data->type = GL_TEXTURE_2D;
slouken@1926
   507
        texture_w = power_of_2(texture->w);
slouken@1926
   508
        texture_h = power_of_2(texture->h);
slouken@1926
   509
        data->texw = (GLfloat) texture->w / texture_w;
slouken@1926
   510
        data->texh = (GLfloat) texture->h / texture_h;
slouken@1926
   511
    }
slouken@1920
   512
    data->format = format;
slouken@1920
   513
    data->formattype = type;
slouken@1927
   514
    renderdata->glBindTexture(data->type, data->texture);
slouken@1927
   515
    renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
slouken@1927
   516
                             texture_h, 0, format, type, NULL);
slouken@1927
   517
    result = renderdata->glGetError();
slouken@1924
   518
    if (result != GL_NO_ERROR) {
slouken@1924
   519
        GL_SetError("glTexImage2D()", result);
slouken@1924
   520
        return -1;
slouken@1924
   521
    }
slouken@1918
   522
    return 0;
slouken@1918
   523
}
slouken@1918
   524
slouken@1918
   525
static int
slouken@1918
   526
GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
   527
                     const SDL_Color * colors, int firstcolor, int ncolors)
slouken@1918
   528
{
slouken@1918
   529
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   530
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1974
   531
    Uint8 *palette;
slouken@1918
   532
slouken@1974
   533
    if (!data->palette) {
slouken@1974
   534
        SDL_SetError("Texture doesn't have a palette");
slouken@1974
   535
        return -1;
slouken@1974
   536
    }
slouken@1974
   537
    palette = data->palette + firstcolor * 3;
slouken@1974
   538
    while (ncolors--) {
slouken@1974
   539
        *palette++ = colors->r;
slouken@1974
   540
        *palette++ = colors->g;
slouken@1974
   541
        *palette++ = colors->b;
slouken@1974
   542
        ++colors;
slouken@1974
   543
    }
slouken@1974
   544
    renderdata->glBindTexture(data->type, data->texture);
slouken@1974
   545
    renderdata->glColorTableEXT(data->type, GL_RGB8, 256, GL_RGB,
slouken@1974
   546
                                GL_UNSIGNED_BYTE, data->palette);
slouken@1918
   547
    return 0;
slouken@1918
   548
}
slouken@1918
   549
slouken@1918
   550
static int
slouken@1918
   551
GL_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
   552
                     SDL_Color * colors, int firstcolor, int ncolors)
slouken@1918
   553
{
slouken@1974
   554
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   555
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1974
   556
    Uint8 *palette;
slouken@1918
   557
slouken@1974
   558
    if (!data->palette) {
slouken@1974
   559
        SDL_SetError("Texture doesn't have a palette");
slouken@1974
   560
        return -1;
slouken@1974
   561
    }
slouken@1974
   562
    palette = data->palette + firstcolor * 3;
slouken@1974
   563
    while (ncolors--) {
slouken@1974
   564
        colors->r = *palette++;
slouken@1974
   565
        colors->g = *palette++;
slouken@1974
   566
        colors->b = *palette++;
slouken@1974
   567
        colors->unused = SDL_ALPHA_OPAQUE;
slouken@1974
   568
        ++colors;
slouken@1974
   569
    }
slouken@1918
   570
    return 0;
slouken@1918
   571
}
slouken@1918
   572
slouken@1924
   573
static void
slouken@1927
   574
SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
slouken@1927
   575
                   int pitch)
slouken@1924
   576
{
slouken@1965
   577
    if (texture->format == SDL_PIXELFORMAT_INDEX1LSB) {
slouken@1927
   578
        renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
slouken@1965
   579
    } else if (texture->format == SDL_PIXELFORMAT_INDEX1MSB) {
slouken@1927
   580
        renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
slouken@1924
   581
    }
slouken@1927
   582
    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
slouken@1927
   583
    renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
slouken@1927
   584
                              pitch / SDL_BYTESPERPIXEL(texture->format));
slouken@1924
   585
}
slouken@1924
   586
slouken@1918
   587
static int
slouken@1985
   588
GL_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
   589
{
slouken@1985
   590
    return -1;
slouken@1985
   591
}
slouken@1985
   592
slouken@1985
   593
static int
slouken@1985
   594
GL_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
   595
{
slouken@1985
   596
    return -1;
slouken@1985
   597
}
slouken@1985
   598
slouken@1985
   599
static int
slouken@1985
   600
GL_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
   601
{
slouken@1985
   602
    switch (texture->blendMode) {
slouken@1985
   603
    case SDL_TEXTUREBLENDMODE_NONE:
slouken@1985
   604
    case SDL_TEXTUREBLENDMODE_MASK:
slouken@1985
   605
    case SDL_TEXTUREBLENDMODE_BLEND:
slouken@1985
   606
    case SDL_TEXTUREBLENDMODE_ADD:
slouken@1985
   607
    case SDL_TEXTUREBLENDMODE_MOD:
slouken@1985
   608
        return 0;
slouken@1985
   609
    default:
slouken@1985
   610
        SDL_Unsupported();
slouken@1985
   611
        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
slouken@1985
   612
        return -1;
slouken@1985
   613
    }
slouken@1985
   614
}
slouken@1985
   615
slouken@1985
   616
static int
slouken@1985
   617
GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1985
   618
{
slouken@1985
   619
    switch (texture->scaleMode) {
slouken@1985
   620
    case SDL_TEXTURESCALEMODE_NONE:
slouken@1985
   621
    case SDL_TEXTURESCALEMODE_FAST:
slouken@1985
   622
    case SDL_TEXTURESCALEMODE_SLOW:
slouken@1985
   623
        return 0;
slouken@1985
   624
    case SDL_TEXTURESCALEMODE_BEST:
slouken@1985
   625
        SDL_Unsupported();
slouken@1985
   626
        texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
slouken@1985
   627
        return -1;
slouken@1985
   628
    default:
slouken@1985
   629
        SDL_Unsupported();
slouken@1985
   630
        texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
slouken@1985
   631
        return -1;
slouken@1985
   632
    }
slouken@1985
   633
}
slouken@1985
   634
slouken@1985
   635
static int
slouken@1918
   636
GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
   637
                 const SDL_Rect * rect, const void *pixels, int pitch)
slouken@1918
   638
{
slouken@1927
   639
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   640
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1924
   641
    GLenum result;
slouken@1918
   642
slouken@1927
   643
    renderdata->glGetError();
slouken@1927
   644
    SetupTextureUpdate(renderdata, texture, pitch);
slouken@1927
   645
    renderdata->glBindTexture(data->type, data->texture);
slouken@1927
   646
    renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
slouken@1927
   647
                                rect->h, data->format, data->formattype,
slouken@1927
   648
                                pixels);
slouken@1927
   649
    result = renderdata->glGetError();
slouken@1924
   650
    if (result != GL_NO_ERROR) {
slouken@1924
   651
        GL_SetError("glTexSubImage2D()", result);
slouken@1924
   652
        return -1;
slouken@1924
   653
    }
slouken@1918
   654
    return 0;
slouken@1918
   655
}
slouken@1918
   656
slouken@1918
   657
static int
slouken@1918
   658
GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1918
   659
               const SDL_Rect * rect, int markDirty, void **pixels,
slouken@1918
   660
               int *pitch)
slouken@1918
   661
{
slouken@1918
   662
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1918
   663
slouken@1920
   664
    if (!data->pixels) {
slouken@1920
   665
        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
slouken@1920
   666
        data->pixels = SDL_malloc(texture->h * data->pitch);
slouken@1920
   667
        if (!data->pixels) {
slouken@1920
   668
            SDL_OutOfMemory();
slouken@1920
   669
            return -1;
slouken@1920
   670
        }
slouken@1918
   671
    }
slouken@1918
   672
slouken@1920
   673
    if (markDirty) {
slouken@1920
   674
        SDL_AddDirtyRect(&data->dirty, rect);
slouken@1920
   675
    }
slouken@1918
   676
slouken@1920
   677
    *pixels =
slouken@1920
   678
        (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
slouken@1920
   679
                  rect->x * SDL_BYTESPERPIXEL(texture->format));
slouken@1920
   680
    *pitch = data->pitch;
slouken@1918
   681
    return 0;
slouken@1918
   682
}
slouken@1918
   683
slouken@1918
   684
static void
slouken@1918
   685
GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
   686
{
slouken@1918
   687
}
slouken@1918
   688
slouken@1918
   689
static void
slouken@1918
   690
GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
slouken@1918
   691
                const SDL_Rect * rects)
slouken@1918
   692
{
slouken@1918
   693
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1918
   694
    int i;
slouken@1918
   695
slouken@1918
   696
    for (i = 0; i < numrects; ++i) {
slouken@1920
   697
        SDL_AddDirtyRect(&data->dirty, &rects[i]);
slouken@1918
   698
    }
slouken@1918
   699
}
slouken@1918
   700
slouken@1918
   701
static int
slouken@1985
   702
GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
slouken@1985
   703
              const SDL_Rect * rect)
slouken@1918
   704
{
slouken@1918
   705
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1918
   706
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@1918
   707
slouken@1985
   708
    data->glClearColor((GLclampf) r * inv255f, (GLclampf) g * inv255f,
slouken@1985
   709
                       (GLclampf) b * inv255f, (GLclampf) a * inv255f);
slouken@1927
   710
    data->glViewport(rect->x, window->h - rect->y, rect->w, rect->h);
slouken@1927
   711
    data->glClear(GL_COLOR_BUFFER_BIT);
slouken@1927
   712
    data->glViewport(0, 0, window->w, window->h);
slouken@1918
   713
    return 0;
slouken@1918
   714
}
slouken@1918
   715
slouken@1918
   716
static int
slouken@1918
   717
GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1985
   718
              const SDL_Rect * srcrect, const SDL_Rect * dstrect)
slouken@1918
   719
{
slouken@1918
   720
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1918
   721
    GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
slouken@1918
   722
    int minx, miny, maxx, maxy;
slouken@1918
   723
    GLfloat minu, maxu, minv, maxv;
slouken@1918
   724
slouken@1920
   725
    if (texturedata->dirty.count > 0) {
slouken@1920
   726
        SDL_DirtyRect *dirty;
slouken@1920
   727
        void *pixels;
slouken@1920
   728
        int bpp = SDL_BYTESPERPIXEL(texture->format);
slouken@1920
   729
        int pitch = texturedata->pitch;
slouken@1920
   730
slouken@1927
   731
        SetupTextureUpdate(data, texture, pitch);
slouken@1927
   732
        data->glBindTexture(texturedata->type, texturedata->texture);
slouken@1920
   733
        for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
slouken@1920
   734
            SDL_Rect *rect = &dirty->rect;
slouken@1920
   735
            pixels =
slouken@1920
   736
                (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch +
slouken@1920
   737
                          rect->x * bpp);
slouken@1927
   738
            data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
slouken@1927
   739
                                  rect->w, rect->h, texturedata->format,
slouken@1927
   740
                                  texturedata->formattype, pixels);
slouken@1920
   741
        }
slouken@1920
   742
        SDL_ClearDirtyRects(&texturedata->dirty);
slouken@1920
   743
    }
slouken@1920
   744
slouken@1918
   745
    minx = dstrect->x;
slouken@1918
   746
    miny = dstrect->y;
slouken@1918
   747
    maxx = dstrect->x + dstrect->w;
slouken@1918
   748
    maxy = dstrect->y + dstrect->h;
slouken@1918
   749
slouken@1918
   750
    minu = (GLfloat) srcrect->x / texture->w;
slouken@1920
   751
    minu *= texturedata->texw;
slouken@1918
   752
    maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
slouken@1920
   753
    maxu *= texturedata->texw;
slouken@1918
   754
    minv = (GLfloat) srcrect->y / texture->h;
slouken@1920
   755
    minv *= texturedata->texh;
slouken@1918
   756
    maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
slouken@1920
   757
    maxv *= texturedata->texh;
slouken@1918
   758
slouken@1927
   759
    data->glBindTexture(texturedata->type, texturedata->texture);
slouken@1918
   760
slouken@1985
   761
    if (texture->modMode) {
slouken@1985
   762
        data->glColor4f((GLfloat) texture->r * inv255f,
slouken@1985
   763
                        (GLfloat) texture->g * inv255f,
slouken@1985
   764
                        (GLfloat) texture->b * inv255f,
slouken@1985
   765
                        (GLfloat) texture->a * inv255f);
slouken@1985
   766
    } else {
slouken@1985
   767
        data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
slouken@1985
   768
    }
slouken@1985
   769
slouken@1985
   770
    if (texture->blendMode != data->blendMode) {
slouken@1985
   771
        switch (texture->blendMode) {
slouken@1965
   772
        case SDL_TEXTUREBLENDMODE_NONE:
slouken@1927
   773
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
slouken@1927
   774
            data->glDisable(GL_BLEND);
slouken@1927
   775
            break;
slouken@1965
   776
        case SDL_TEXTUREBLENDMODE_MASK:
slouken@1965
   777
        case SDL_TEXTUREBLENDMODE_BLEND:
slouken@1927
   778
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@1927
   779
            data->glEnable(GL_BLEND);
slouken@1927
   780
            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
slouken@1927
   781
            break;
slouken@1965
   782
        case SDL_TEXTUREBLENDMODE_ADD:
slouken@1927
   783
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@1927
   784
            data->glEnable(GL_BLEND);
slouken@1927
   785
            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
slouken@1927
   786
            break;
slouken@1965
   787
        case SDL_TEXTUREBLENDMODE_MOD:
slouken@1927
   788
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
slouken@1927
   789
            data->glEnable(GL_BLEND);
slouken@1927
   790
            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
slouken@1927
   791
            break;
slouken@1927
   792
        }
slouken@1985
   793
        data->blendMode = texture->blendMode;
slouken@1918
   794
    }
slouken@1918
   795
slouken@1985
   796
    if (texture->scaleMode != data->scaleMode) {
slouken@1985
   797
        switch (texture->scaleMode) {
slouken@1965
   798
        case SDL_TEXTURESCALEMODE_NONE:
slouken@1965
   799
        case SDL_TEXTURESCALEMODE_FAST:
slouken@1927
   800
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
slouken@1927
   801
                                  GL_NEAREST);
slouken@1927
   802
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
slouken@1927
   803
                                  GL_NEAREST);
slouken@1927
   804
            break;
slouken@1965
   805
        case SDL_TEXTURESCALEMODE_SLOW:
slouken@1965
   806
        case SDL_TEXTURESCALEMODE_BEST:
slouken@1927
   807
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
slouken@1927
   808
                                  GL_LINEAR);
slouken@1927
   809
            data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
slouken@1927
   810
                                  GL_LINEAR);
slouken@1927
   811
            break;
slouken@1927
   812
        }
slouken@1985
   813
        data->scaleMode = texture->scaleMode;
slouken@1918
   814
    }
slouken@1918
   815
slouken@1927
   816
    data->glBegin(GL_TRIANGLE_STRIP);
slouken@1927
   817
    data->glTexCoord2f(minu, minv);
slouken@1927
   818
    data->glVertex2i(minx, miny);
slouken@1927
   819
    data->glTexCoord2f(maxu, minv);
slouken@1927
   820
    data->glVertex2i(maxx, miny);
slouken@1927
   821
    data->glTexCoord2f(minu, maxv);
slouken@1927
   822
    data->glVertex2i(minx, maxy);
slouken@1927
   823
    data->glTexCoord2f(maxu, maxv);
slouken@1927
   824
    data->glVertex2i(maxx, maxy);
slouken@1927
   825
    data->glEnd();
slouken@1918
   826
slouken@1918
   827
    return 0;
slouken@1918
   828
}
slouken@1918
   829
slouken@1918
   830
static void
slouken@1918
   831
GL_RenderPresent(SDL_Renderer * renderer)
slouken@1918
   832
{
slouken@1918
   833
    SDL_GL_SwapWindow(renderer->window);
slouken@1918
   834
}
slouken@1918
   835
slouken@1918
   836
static void
slouken@1918
   837
GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1918
   838
{
slouken@1927
   839
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
slouken@1918
   840
    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
slouken@1918
   841
slouken@1918
   842
    if (!data) {
slouken@1918
   843
        return;
slouken@1918
   844
    }
slouken@1918
   845
    if (data->texture) {
slouken@1927
   846
        renderdata->glDeleteTextures(1, &data->texture);
slouken@1918
   847
    }
slouken@1974
   848
    if (data->palette) {
slouken@1974
   849
        SDL_free(data->palette);
slouken@1974
   850
    }
slouken@1920
   851
    if (data->pixels) {
slouken@1920
   852
        SDL_free(data->pixels);
slouken@1920
   853
    }
slouken@1920
   854
    SDL_FreeDirtyRects(&data->dirty);
slouken@1918
   855
    SDL_free(data);
slouken@1918
   856
    texture->driverdata = NULL;
slouken@1918
   857
}
slouken@1918
   858
slouken@1975
   859
static void
slouken@1918
   860
GL_DestroyRenderer(SDL_Renderer * renderer)
slouken@1918
   861
{
slouken@1918
   862
    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
slouken@1918
   863
slouken@1918
   864
    if (data) {
slouken@1920
   865
        if (data->context) {
slouken@1920
   866
            SDL_GL_MakeCurrent(0, NULL);
slouken@1920
   867
            SDL_GL_DeleteContext(data->context);
slouken@1918
   868
        }
slouken@1918
   869
        SDL_free(data);
slouken@1918
   870
    }
slouken@1918
   871
    SDL_free(renderer);
slouken@1918
   872
}
slouken@1918
   873
slouken@1952
   874
#endif /* SDL_VIDEO_RENDER_OGL */
slouken@1918
   875
slouken@1918
   876
/* vi: set ts=4 sw=4 expandtab: */