src/render/opengles2/SDL_render_gles2.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 07 Nov 2011 00:45:13 -0500
changeset 6052 263ef1203b76
parent 6044 35448a5ea044
child 6060 59d398ac031e
permissions -rw-r--r--
Fixed double-free in the shader cache at shutdown
slouken@5201
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@5535
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@5201
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@5201
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@5201
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@5201
    20
*/
slouken@5201
    21
#include "SDL_config.h"
slouken@5201
    22
slouken@5226
    23
#if SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED
slouken@5201
    24
slouken@5484
    25
#include "SDL_hints.h"
slouken@5204
    26
#include "SDL_opengles2.h"
slouken@5201
    27
#include "../SDL_sysrender.h"
slouken@5201
    28
#include "SDL_shaders_gles2.h"
slouken@5201
    29
slouken@5201
    30
/*************************************************************************************************
slouken@5201
    31
 * Bootstrap data                                                                                *
slouken@5201
    32
 *************************************************************************************************/
slouken@5201
    33
slouken@5201
    34
static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, Uint32 flags);
slouken@5201
    35
slouken@5201
    36
SDL_RenderDriver GLES2_RenderDriver = {
slouken@5201
    37
    GLES2_CreateRenderer,
slouken@5201
    38
    {
slouken@5201
    39
        "opengles2",
slouken@5201
    40
        (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
slouken@5202
    41
        1,
slouken@5202
    42
        {SDL_PIXELFORMAT_ABGR8888},
slouken@5201
    43
        0,
slouken@5201
    44
        0
slouken@5201
    45
    }
slouken@5201
    46
};
slouken@5201
    47
slouken@5201
    48
/*************************************************************************************************
slouken@5201
    49
 * Context structures                                                                            *
slouken@5201
    50
 *************************************************************************************************/
slouken@5201
    51
slouken@5201
    52
typedef struct GLES2_TextureData
slouken@5201
    53
{
slouken@5201
    54
    GLenum texture;
slouken@5201
    55
    GLenum texture_type;
slouken@5201
    56
    GLenum pixel_format;
slouken@5201
    57
    GLenum pixel_type;
slouken@5201
    58
    void *pixel_data;
slouken@5201
    59
    size_t pitch;
slouken@5201
    60
} GLES2_TextureData;
slouken@5201
    61
slouken@5201
    62
typedef struct GLES2_ShaderCacheEntry
slouken@5201
    63
{
slouken@5201
    64
    GLuint id;
slouken@5201
    65
    GLES2_ShaderType type;
slouken@5201
    66
    const GLES2_ShaderInstance *instance;
slouken@5201
    67
    int references;
slouken@5201
    68
    struct GLES2_ShaderCacheEntry *prev;
slouken@5201
    69
    struct GLES2_ShaderCacheEntry *next;
slouken@5201
    70
} GLES2_ShaderCacheEntry;
slouken@5201
    71
slouken@5201
    72
typedef struct GLES2_ShaderCache
slouken@5201
    73
{
slouken@5201
    74
    int count;
slouken@5201
    75
    GLES2_ShaderCacheEntry *head;
slouken@5201
    76
} GLES2_ShaderCache;
slouken@5201
    77
slouken@5201
    78
typedef struct GLES2_ProgramCacheEntry
slouken@5201
    79
{
slouken@5201
    80
    GLuint id;
slouken@5201
    81
    SDL_BlendMode blend_mode;
slouken@5201
    82
    GLES2_ShaderCacheEntry *vertex_shader;
slouken@5201
    83
    GLES2_ShaderCacheEntry *fragment_shader;
slouken@5201
    84
    GLuint uniform_locations[16];
slouken@5201
    85
    struct GLES2_ProgramCacheEntry *prev;
slouken@5201
    86
    struct GLES2_ProgramCacheEntry *next;
slouken@5201
    87
} GLES2_ProgramCacheEntry;
slouken@5201
    88
slouken@5201
    89
typedef struct GLES2_ProgramCache
slouken@5201
    90
{
slouken@5201
    91
    int count;
slouken@5201
    92
    GLES2_ProgramCacheEntry *head;
slouken@5201
    93
    GLES2_ProgramCacheEntry *tail;
slouken@5201
    94
} GLES2_ProgramCache;
slouken@5201
    95
slouken@5201
    96
typedef enum
slouken@5201
    97
{
slouken@5201
    98
    GLES2_ATTRIBUTE_POSITION = 0,
slouken@5201
    99
    GLES2_ATTRIBUTE_TEXCOORD = 1
slouken@5201
   100
} GLES2_Attribute;
slouken@5201
   101
slouken@5201
   102
typedef enum
slouken@5201
   103
{
slouken@5201
   104
    GLES2_UNIFORM_PROJECTION,
slouken@5201
   105
    GLES2_UNIFORM_TEXTURE,
slouken@5201
   106
    GLES2_UNIFORM_MODULATION,
slouken@5201
   107
    GLES2_UNIFORM_COLOR,
slouken@5201
   108
    GLES2_UNIFORM_COLORTABLE
slouken@5201
   109
} GLES2_Uniform;
slouken@5201
   110
slouken@5201
   111
typedef enum
slouken@5201
   112
{
slouken@5201
   113
    GLES2_IMAGESOURCE_SOLID,
slouken@5201
   114
    GLES2_IMAGESOURCE_TEXTURE
slouken@5201
   115
} GLES2_ImageSource;
slouken@5201
   116
slouken@5201
   117
typedef struct GLES2_DriverContext
slouken@5201
   118
{
slouken@5201
   119
    SDL_GLContext *context;
slouken@5355
   120
    struct {
slouken@5355
   121
        int blendMode;
slouken@5355
   122
        SDL_bool tex_coords;
slouken@5355
   123
    } current;
slouken@5355
   124
slouken@5201
   125
    int shader_format_count;
slouken@5201
   126
    GLenum *shader_formats;
slouken@5201
   127
    GLES2_ShaderCache shader_cache;
slouken@5201
   128
    GLES2_ProgramCache program_cache;
slouken@5201
   129
    GLES2_ProgramCacheEntry *current_program;
slouken@5201
   130
} GLES2_DriverContext;
slouken@5201
   131
slouken@5201
   132
#define GLES2_MAX_CACHED_PROGRAMS 8
slouken@5201
   133
slouken@5201
   134
/*************************************************************************************************
slouken@5201
   135
 * Renderer state APIs                                                                           *
slouken@5201
   136
 *************************************************************************************************/
slouken@5201
   137
slouken@5224
   138
static int GLES2_ActivateRenderer(SDL_Renderer *renderer);
slouken@5201
   139
static void GLES2_WindowEvent(SDL_Renderer * renderer,
slouken@5201
   140
                              const SDL_WindowEvent *event);
slouken@5297
   141
static int GLES2_UpdateViewport(SDL_Renderer * renderer);
slouken@5201
   142
static void GLES2_DestroyRenderer(SDL_Renderer *renderer);
slouken@5201
   143
slouken@5201
   144
static SDL_GLContext SDL_CurrentContext = NULL;
slouken@5201
   145
slouken@5201
   146
static int
slouken@5201
   147
GLES2_ActivateRenderer(SDL_Renderer * renderer)
slouken@5201
   148
{
slouken@5201
   149
    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
slouken@5201
   150
slouken@5201
   151
    if (SDL_CurrentContext != rdata->context) {
slouken@5201
   152
        /* Null out the current program to ensure we set it again */
slouken@5201
   153
        rdata->current_program = NULL;
slouken@5201
   154
slouken@5297
   155
        if (SDL_GL_MakeCurrent(renderer->window, rdata->context) < 0) {
slouken@5201
   156
            return -1;
slouken@5201
   157
        }
slouken@5201
   158
        SDL_CurrentContext = rdata->context;
slouken@5201
   159
slouken@5297
   160
        GLES2_UpdateViewport(renderer);
slouken@5201
   161
    }
slouken@5201
   162
    return 0;
slouken@5201
   163
}
slouken@5201
   164
slouken@5201
   165
static void
slouken@5201
   166
GLES2_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
slouken@5201
   167
{
slouken@5276
   168
    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
slouken@5201
   169
        /* Rebind the context to the window area */
slouken@5201
   170
        SDL_CurrentContext = NULL;
slouken@5201
   171
    }
slouken@5201
   172
}
slouken@5201
   173
slouken@5297
   174
static int
slouken@5297
   175
GLES2_UpdateViewport(SDL_Renderer * renderer)
slouken@5224
   176
{
slouken@5297
   177
    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
slouken@5224
   178
slouken@5297
   179
    if (SDL_CurrentContext != rdata->context) {
slouken@5297
   180
        /* We'll update the viewport after we rebind the context */
slouken@5297
   181
        return 0;
slouken@5297
   182
    }
slouken@5224
   183
slouken@5297
   184
    glViewport(renderer->viewport.x, renderer->viewport.y,
slouken@5297
   185
               renderer->viewport.w, renderer->viewport.h);
slouken@5297
   186
    return 0;
slouken@5224
   187
}
slouken@5224
   188
slouken@5224
   189
static void
slouken@5201
   190
GLES2_DestroyRenderer(SDL_Renderer *renderer)
slouken@5201
   191
{
slouken@5201
   192
    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
slouken@5201
   193
slouken@5209
   194
    /* Deallocate everything */
slouken@5209
   195
    if (rdata) {
slouken@5209
   196
        GLES2_ActivateRenderer(renderer);
slouken@5201
   197
slouken@6052
   198
	{
slouken@6052
   199
	    GLES2_ShaderCacheEntry *entry;
slouken@6052
   200
	    GLES2_ShaderCacheEntry *next;
slouken@6052
   201
	    entry = rdata->shader_cache.head;
slouken@6052
   202
	    while (entry)
slouken@6052
   203
	    {
slouken@6052
   204
                glDeleteShader(entry->id);
slouken@6052
   205
                next = entry->next;
slouken@6052
   206
                SDL_free(entry);
slouken@6052
   207
                entry = next;
slouken@6052
   208
	    }
slouken@6052
   209
	}
slouken@6052
   210
	{
slouken@6052
   211
	    GLES2_ProgramCacheEntry *entry;
slouken@6052
   212
	    GLES2_ProgramCacheEntry *next;
slouken@6052
   213
            entry = rdata->program_cache.head;
slouken@6052
   214
            while (entry) {
slouken@6052
   215
                glDeleteProgram(entry->id);
slouken@6052
   216
                next = entry->next;
slouken@6052
   217
                SDL_free(entry);
slouken@6052
   218
                entry = next;
slouken@6052
   219
            }
slouken@6052
   220
	}
slouken@5209
   221
        if (rdata->context) {
slouken@5209
   222
            SDL_GL_DeleteContext(rdata->context);
slouken@5209
   223
        }
slouken@5209
   224
        if (rdata->shader_formats) {
slouken@5209
   225
            SDL_free(rdata->shader_formats);
slouken@5209
   226
        }
slouken@5209
   227
        SDL_free(rdata);
slouken@5201
   228
    }
slouken@5201
   229
    SDL_free(renderer);
slouken@5201
   230
}
slouken@5201
   231
slouken@5201
   232
/*************************************************************************************************
slouken@5201
   233
 * Texture APIs                                                                                  *
slouken@5201
   234
 *************************************************************************************************/
slouken@5201
   235
slouken@5201
   236
static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture);
slouken@5201
   237
static void GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture);
slouken@5201
   238
static int GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
slouken@5201
   239
                             void **pixels, int *pitch);
slouken@5201
   240
static void GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture);
slouken@5201
   241
static int GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
slouken@5201
   242
                               const void *pixels, int pitch);
slouken@5201
   243
slouken@5484
   244
static GLenum
slouken@5484
   245
GetScaleQuality(void)
slouken@5484
   246
{
slouken@5484
   247
    const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
slouken@5484
   248
slouken@5484
   249
    if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
slouken@5484
   250
        return GL_NEAREST;
slouken@5484
   251
    } else {
slouken@5484
   252
        return GL_LINEAR;
slouken@5484
   253
    }
slouken@5484
   254
}
slouken@5484
   255
slouken@5201
   256
static int
slouken@5201
   257
GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
slouken@5201
   258
{
slouken@5201
   259
    GLES2_TextureData *tdata;
slouken@5201
   260
    GLenum format;
slouken@5201
   261
    GLenum type;
slouken@5503
   262
    GLenum scaleMode;
slouken@5201
   263
slouken@5201
   264
    GLES2_ActivateRenderer(renderer);
slouken@5201
   265
slouken@5201
   266
    /* Determine the corresponding GLES texture format params */
slouken@5201
   267
    switch (texture->format)
slouken@5201
   268
    {
slouken@5201
   269
    case SDL_PIXELFORMAT_ABGR8888:
slouken@5201
   270
        format = GL_RGBA;
slouken@5201
   271
        type = GL_UNSIGNED_BYTE;
slouken@5201
   272
        break;
slouken@5201
   273
    default:
slouken@5201
   274
        SDL_SetError("Texture format not supported");
slouken@5201
   275
        return -1;
slouken@5201
   276
    }
slouken@5201
   277
slouken@5201
   278
    /* Allocate a texture struct */
slouken@5201
   279
    tdata = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData));
slouken@5201
   280
    if (!tdata)
slouken@5201
   281
    {
slouken@5201
   282
        SDL_OutOfMemory();
slouken@5201
   283
        return -1;
slouken@5201
   284
    }
slouken@5201
   285
    tdata->texture = 0;
slouken@5201
   286
    tdata->texture_type = GL_TEXTURE_2D;
slouken@5201
   287
    tdata->pixel_format = format;
slouken@5201
   288
    tdata->pixel_type = type;
slouken@5503
   289
    scaleMode = GetScaleQuality();
slouken@5201
   290
slouken@5201
   291
    /* Allocate a blob for image data */
slouken@5201
   292
    if (texture->access == SDL_TEXTUREACCESS_STREAMING)
slouken@5201
   293
    {
slouken@5201
   294
        tdata->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
slouken@5402
   295
        tdata->pixel_data = SDL_calloc(1, tdata->pitch * texture->h);
slouken@5201
   296
        if (!tdata->pixel_data)
slouken@5201
   297
        {
slouken@5201
   298
            SDL_OutOfMemory();
slouken@5201
   299
            SDL_free(tdata);
slouken@5201
   300
            return -1;
slouken@5201
   301
        }
slouken@5201
   302
    }
slouken@5201
   303
slouken@5201
   304
    /* Allocate the texture */
slouken@5201
   305
    glGetError();
slouken@5201
   306
    glGenTextures(1, &tdata->texture);
slouken@5201
   307
    glActiveTexture(GL_TEXTURE0);
slouken@5201
   308
    glBindTexture(tdata->texture_type, tdata->texture);
slouken@5503
   309
    glTexParameteri(tdata->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode);
slouken@5503
   310
    glTexParameteri(tdata->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode);
slouken@5201
   311
    glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
slouken@5201
   312
    glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
slouken@5201
   313
    glTexImage2D(tdata->texture_type, 0, format, texture->w, texture->h, 0, format, type, NULL);
slouken@5201
   314
    if (glGetError() != GL_NO_ERROR)
slouken@5201
   315
    {
slouken@5201
   316
        SDL_SetError("Texture creation failed");
slouken@5201
   317
        glDeleteTextures(1, &tdata->texture);
slouken@5201
   318
        SDL_free(tdata);
slouken@5201
   319
        return -1;
slouken@5201
   320
    }
slouken@5201
   321
    texture->driverdata = tdata;
slouken@5201
   322
    return 0;
slouken@5201
   323
}
slouken@5201
   324
slouken@5201
   325
static void
slouken@5201
   326
GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
slouken@5201
   327
{
slouken@5201
   328
    GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
slouken@5201
   329
slouken@5201
   330
    GLES2_ActivateRenderer(renderer);
slouken@5201
   331
slouken@5201
   332
    /* Destroy the texture */
slouken@5201
   333
    if (tdata)
slouken@5201
   334
    {
slouken@5201
   335
        glDeleteTextures(1, &tdata->texture);
slouken@5201
   336
        SDL_free(tdata->pixel_data);
slouken@5201
   337
        SDL_free(tdata);
slouken@5201
   338
        texture->driverdata = NULL;
slouken@5201
   339
    }
slouken@5201
   340
}
slouken@5201
   341
slouken@5201
   342
static int
slouken@5201
   343
GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
slouken@5201
   344
                  void **pixels, int *pitch)
slouken@5201
   345
{
slouken@5201
   346
    GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
slouken@5201
   347
slouken@5201
   348
    /* Retrieve the buffer/pitch for the specified region */
slouken@5201
   349
    *pixels = (Uint8 *)tdata->pixel_data +
slouken@5201
   350
              (tdata->pitch * rect->y) +
slouken@5201
   351
              (rect->x * SDL_BYTESPERPIXEL(texture->format));
slouken@5201
   352
    *pitch = tdata->pitch;
slouken@5201
   353
slouken@5201
   354
    return 0;
slouken@5201
   355
}
slouken@5201
   356
slouken@5201
   357
static void
slouken@5201
   358
GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
slouken@5201
   359
{
slouken@5201
   360
    GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
slouken@5227
   361
    SDL_Rect rect;
slouken@5201
   362
slouken@5227
   363
    /* We do whole texture updates, at least for now */
slouken@5227
   364
    rect.x = 0;
slouken@5227
   365
    rect.y = 0;
slouken@5227
   366
    rect.w = texture->w;
slouken@5227
   367
    rect.h = texture->h;
slouken@5227
   368
    GLES2_UpdateTexture(renderer, texture, &rect, tdata->pixel_data, tdata->pitch);
slouken@5201
   369
}
slouken@5201
   370
slouken@5201
   371
static int
slouken@5201
   372
GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
slouken@5201
   373
                    const void *pixels, int pitch)
slouken@5201
   374
{
slouken@5201
   375
    GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
slouken@5201
   376
    Uint8 *blob = NULL;
slouken@5201
   377
    Uint8 *src;
slouken@5201
   378
    int srcPitch;
slouken@5201
   379
    int y;
slouken@5201
   380
slouken@5201
   381
    GLES2_ActivateRenderer(renderer);
slouken@5201
   382
slouken@5201
   383
    /* Bail out if we're supposed to update an empty rectangle */
slouken@5201
   384
    if (rect->w <= 0 || rect->h <= 0)
slouken@5201
   385
        return 0;
slouken@5201
   386
slouken@5201
   387
    /* Reformat the texture data into a tightly packed array */
slouken@5201
   388
    srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format);
slouken@5201
   389
    src = (Uint8 *)pixels;
slouken@5201
   390
    if (pitch != srcPitch)
slouken@5201
   391
    {
slouken@5201
   392
        blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
slouken@5201
   393
        if (!blob)
slouken@5201
   394
        {
slouken@5201
   395
            SDL_OutOfMemory();
slouken@5201
   396
            return -1;
slouken@5201
   397
        }
slouken@5201
   398
        src = blob;
slouken@5201
   399
        for (y = 0; y < rect->h; ++y)
slouken@5201
   400
        {
slouken@5201
   401
            SDL_memcpy(src, pixels, srcPitch);
slouken@5201
   402
            src += srcPitch;
slouken@5201
   403
            pixels = (Uint8 *)pixels + pitch;
slouken@5201
   404
        }
slouken@5201
   405
        src = blob;
slouken@5201
   406
    }
slouken@5201
   407
slouken@5201
   408
    /* Create a texture subimage with the supplied data */
slouken@5201
   409
    glGetError();
slouken@5201
   410
    glActiveTexture(GL_TEXTURE0);
slouken@5201
   411
    glBindTexture(tdata->texture_type, tdata->texture);
slouken@5201
   412
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
slouken@5201
   413
    glTexSubImage2D(tdata->texture_type,
slouken@5201
   414
                    0,
slouken@5201
   415
                    rect->x,
slouken@5201
   416
                    rect->y,
slouken@5201
   417
                    rect->w,
slouken@5201
   418
                    rect->h,
slouken@5201
   419
                    tdata->pixel_format,
slouken@5201
   420
                    tdata->pixel_type,
slouken@5201
   421
                    src);
slouken@5227
   422
    if (blob) {
slouken@5227
   423
        SDL_free(blob);
slouken@5227
   424
    }
slouken@5214
   425
slouken@5201
   426
    if (glGetError() != GL_NO_ERROR)
slouken@5201
   427
    {
slouken@5201
   428
        SDL_SetError("Failed to update texture");
slouken@5201
   429
        return -1;
slouken@5201
   430
    }
slouken@5201
   431
    return 0;
slouken@5201
   432
}
slouken@5201
   433
slouken@5201
   434
/*************************************************************************************************
slouken@5201
   435
 * Shader management functions                                                                   *
slouken@5201
   436
 *************************************************************************************************/
slouken@5201
   437
slouken@5201
   438
static GLES2_ShaderCacheEntry *GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type,
slouken@5201
   439
                                                 SDL_BlendMode blendMode);
slouken@5201
   440
static void GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry);
slouken@5201
   441
static GLES2_ProgramCacheEntry *GLES2_CacheProgram(SDL_Renderer *renderer,
slouken@5201
   442
                                                   GLES2_ShaderCacheEntry *vertex,
slouken@5201
   443
                                                   GLES2_ShaderCacheEntry *fragment,
slouken@5201
   444
                                                   SDL_BlendMode blendMode);
slouken@5201
   445
static int GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source,
slouken@5201
   446
                               SDL_BlendMode blendMode);
slouken@5201
   447
static int GLES2_SetOrthographicProjection(SDL_Renderer *renderer);
slouken@5201
   448
slouken@5201
   449
static GLES2_ProgramCacheEntry *
slouken@5201
   450
GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex,
slouken@5201
   451
                   GLES2_ShaderCacheEntry *fragment, SDL_BlendMode blendMode)
slouken@5201
   452
{
slouken@5201
   453
    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
slouken@5201
   454
    GLES2_ProgramCacheEntry *entry;
slouken@5201
   455
    GLES2_ShaderCacheEntry *shaderEntry;
slouken@5201
   456
    GLint linkSuccessful;
slouken@5201
   457
slouken@5201
   458
    /* Check if we've already cached this program */
slouken@5201
   459
    entry = rdata->program_cache.head;
slouken@5201
   460
    while (entry)
slouken@5201
   461
    {
slouken@5201
   462
        if (entry->vertex_shader == vertex && entry->fragment_shader == fragment)
slouken@5201
   463
            break;
slouken@5201
   464
        entry = entry->next;
slouken@5201
   465
    }
slouken@5201
   466
    if (entry)
slouken@5201
   467
    {
slouken@5201
   468
        if (rdata->program_cache.count > 1)
slouken@5201
   469
        {
slouken@5201
   470
            if (entry->next)
slouken@5201
   471
                entry->next->prev = entry->prev;
slouken@5201
   472
            if (entry->prev)
slouken@5201
   473
                entry->prev->next = entry->next;
slouken@5201
   474
            entry->prev = NULL;
slouken@5201
   475
            entry->next = rdata->program_cache.head;
slouken@5201
   476
            rdata->program_cache.head->prev = entry;
slouken@5201
   477
            rdata->program_cache.head = entry;
slouken@5201
   478
        }
slouken@5201
   479
        return entry;
slouken@5201
   480
    }
slouken@5201
   481
slouken@5201
   482
    /* Create a program cache entry */
slouken@5201
   483
    entry = (GLES2_ProgramCacheEntry *)SDL_calloc(1, sizeof(GLES2_ProgramCacheEntry));
slouken@5201
   484
    if (!entry)
slouken@5201
   485
    {
slouken@5201
   486
        SDL_OutOfMemory();
slouken@5201
   487
        return NULL;
slouken@5201
   488
    }
slouken@5201
   489
    entry->vertex_shader = vertex;
slouken@5201
   490
    entry->fragment_shader = fragment;
slouken@5201
   491
    entry->blend_mode = blendMode;
slouken@5201
   492
    
slouken@5201
   493
    /* Create the program and link it */
slouken@5201
   494
    glGetError();
slouken@5201
   495
    entry->id = glCreateProgram();
slouken@5201
   496
    glAttachShader(entry->id, vertex->id);
slouken@5201
   497
    glAttachShader(entry->id, fragment->id);
slouken@5201
   498
    glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_POSITION, "a_position");
slouken@5201
   499
    glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_TEXCOORD, "a_texCoord");
slouken@5201
   500
    glLinkProgram(entry->id);
slouken@5201
   501
    glGetProgramiv(entry->id, GL_LINK_STATUS, &linkSuccessful);
slouken@5201
   502
    if (glGetError() != GL_NO_ERROR || !linkSuccessful)
slouken@5201
   503
    {
slouken@5201
   504
        SDL_SetError("Failed to link shader program");
slouken@5201
   505
        glDeleteProgram(entry->id);
slouken@5201
   506
        SDL_free(entry);
slouken@5201
   507
        return NULL;
slouken@5201
   508
    }
slouken@5201
   509
    
slouken@5201
   510
    /* Predetermine locations of uniform variables */
slouken@5201
   511
    entry->uniform_locations[GLES2_UNIFORM_PROJECTION] =
slouken@5201
   512
        glGetUniformLocation(entry->id, "u_projection");
slouken@5201
   513
    entry->uniform_locations[GLES2_UNIFORM_TEXTURE] =
slouken@5201
   514
        glGetUniformLocation(entry->id, "u_texture");
slouken@5201
   515
    entry->uniform_locations[GLES2_UNIFORM_MODULATION] =
slouken@5201
   516
        glGetUniformLocation(entry->id, "u_modulation");
slouken@5201
   517
    entry->uniform_locations[GLES2_UNIFORM_COLOR] =
slouken@5201
   518
        glGetUniformLocation(entry->id, "u_color");
slouken@5201
   519
    entry->uniform_locations[GLES2_UNIFORM_COLORTABLE] =
slouken@5201
   520
        glGetUniformLocation(entry->id, "u_colorTable");
slouken@5201
   521
slouken@5201
   522
    /* Cache the linked program */
slouken@5201
   523
    if (rdata->program_cache.head)
slouken@5201
   524
    {
slouken@5201
   525
        entry->next = rdata->program_cache.head;
slouken@5201
   526
        rdata->program_cache.head->prev = entry;
slouken@5201
   527
    }
slouken@5201
   528
    else
slouken@5201
   529
    {
slouken@5201
   530
        rdata->program_cache.tail = entry;
slouken@5201
   531
    }
slouken@5201
   532
    rdata->program_cache.head = entry;
slouken@5201
   533
    ++rdata->program_cache.count;
slouken@5201
   534
slouken@5201
   535
    /* Increment the refcount of the shaders we're using */
slouken@5201
   536
    ++vertex->references;
slouken@5201
   537
    ++fragment->references;
slouken@5201
   538
slouken@5201
   539
    /* Evict the last entry from the cache if we exceed the limit */
slouken@5201
   540
    if (rdata->program_cache.count > GLES2_MAX_CACHED_PROGRAMS)
slouken@5201
   541
    {
slouken@5201
   542
        shaderEntry = rdata->program_cache.tail->vertex_shader;
slouken@5201
   543
        if (--shaderEntry->references <= 0)
slouken@5201
   544
            GLES2_EvictShader(renderer, shaderEntry);
slouken@5201
   545
        shaderEntry = rdata->program_cache.tail->fragment_shader;
slouken@5201
   546
        if (--shaderEntry->references <= 0)
slouken@5201
   547
            GLES2_EvictShader(renderer, shaderEntry);
slouken@5201
   548
        glDeleteProgram(rdata->program_cache.tail->id);
slouken@5201
   549
        rdata->program_cache.tail = rdata->program_cache.tail->prev;
slouken@5201
   550
        SDL_free(rdata->program_cache.tail->next);
slouken@5201
   551
        rdata->program_cache.tail->next = NULL;
slouken@5201
   552
        --rdata->program_cache.count;
slouken@5201
   553
    }
slouken@5201
   554
    return entry;
slouken@5201
   555
}
slouken@5201
   556
slouken@5201
   557
static GLES2_ShaderCacheEntry *
slouken@5201
   558
GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, SDL_BlendMode blendMode)
slouken@5201
   559
{
slouken@5201
   560
    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
slouken@5201
   561
    const GLES2_Shader *shader;
slouken@5201
   562
    const GLES2_ShaderInstance *instance = NULL;
slouken@5201
   563
    GLES2_ShaderCacheEntry *entry = NULL;
slouken@5201
   564
    GLint compileSuccessful = GL_FALSE;
slouken@5201
   565
    int i, j;
slouken@5201
   566
slouken@5201
   567
    /* Find the corresponding shader */
slouken@5201
   568
    shader = GLES2_GetShader(type, blendMode);
slouken@5201
   569
    if (!shader)
slouken@5201
   570
    {
slouken@5201
   571
        SDL_SetError("No shader matching the requested characteristics was found");
slouken@5201
   572
        return NULL;
slouken@5201
   573
    }
slouken@5201
   574
    
slouken@5201
   575
    /* Find a matching shader instance that's supported on this hardware */
slouken@5206
   576
    for (i = 0; i < shader->instance_count && !instance; ++i)
slouken@5201
   577
    {
slouken@5206
   578
        for (j = 0; j < rdata->shader_format_count && !instance; ++j)
slouken@5201
   579
        {
slouken@5201
   580
            if (!shader->instances)
slouken@5201
   581
                continue;
slouken@5206
   582
            if (!shader->instances[i])
slouken@5206
   583
                continue;
slouken@5201
   584
            if (shader->instances[i]->format != rdata->shader_formats[j])
slouken@5201
   585
                continue;
slouken@5201
   586
            instance = shader->instances[i];
slouken@5201
   587
        }
slouken@5201
   588
    }
slouken@5201
   589
    if (!instance)
slouken@5201
   590
    {
slouken@5201
   591
        SDL_SetError("The specified shader cannot be loaded on the current platform");
slouken@5201
   592
        return NULL;
slouken@5201
   593
    }
slouken@5201
   594
slouken@5201
   595
    /* Check if we've already cached this shader */
slouken@5201
   596
    entry = rdata->shader_cache.head;
slouken@5201
   597
    while (entry)
slouken@5201
   598
    {
slouken@5201
   599
        if (entry->instance == instance)
slouken@5201
   600
            break;
slouken@5201
   601
        entry = entry->next;
slouken@5201
   602
    }
slouken@5201
   603
    if (entry)
slouken@5201
   604
        return entry;
slouken@5201
   605
slouken@5201
   606
    /* Create a shader cache entry */
slouken@5201
   607
    entry = (GLES2_ShaderCacheEntry *)SDL_calloc(1, sizeof(GLES2_ShaderCacheEntry));
slouken@5201
   608
    if (!entry)
slouken@5201
   609
    {
slouken@5201
   610
        SDL_OutOfMemory();
slouken@5201
   611
        return NULL;
slouken@5201
   612
    }
slouken@5201
   613
    entry->type = type;
slouken@5201
   614
    entry->instance = instance;
slouken@5201
   615
slouken@5201
   616
    /* Compile or load the selected shader instance */
slouken@5201
   617
    glGetError();
slouken@5201
   618
    entry->id = glCreateShader(instance->type);
slouken@5201
   619
    if (instance->format == (GLenum)-1)
slouken@5201
   620
    {
slouken@5212
   621
        glShaderSource(entry->id, 1, (const char **)&instance->data, NULL);
slouken@5201
   622
        glCompileShader(entry->id);
slouken@5201
   623
        glGetShaderiv(entry->id, GL_COMPILE_STATUS, &compileSuccessful);
slouken@5201
   624
    }
slouken@5201
   625
    else
slouken@5201
   626
    {
slouken@5201
   627
        glShaderBinary(1, &entry->id, instance->format, instance->data, instance->length);
slouken@5201
   628
        compileSuccessful = GL_TRUE;
slouken@5201
   629
    }
slouken@5201
   630
    if (glGetError() != GL_NO_ERROR || !compileSuccessful)
slouken@5201
   631
    {
slouken@5212
   632
        char *info = NULL;
slouken@5212
   633
        int length;
slouken@5212
   634
slouken@5212
   635
        glGetShaderiv(entry->id, GL_INFO_LOG_LENGTH, &length);
slouken@5212
   636
        if (length > 0) {
slouken@5212
   637
            info = SDL_stack_alloc(char, length);
slouken@5212
   638
            if (info) {
slouken@5212
   639
                glGetShaderInfoLog(entry->id, length, &length, info);
slouken@5212
   640
            }
slouken@5212
   641
        }
slouken@5212
   642
        if (info) {
slouken@5212
   643
            SDL_SetError("Failed to load the shader: %s", info);
slouken@5212
   644
            SDL_stack_free(info);
slouken@5212
   645
        } else {
slouken@5212
   646
            SDL_SetError("Failed to load the shader");
slouken@5212
   647
        }
slouken@5201
   648
        glDeleteShader(entry->id);
slouken@5201
   649
        SDL_free(entry);
slouken@5201
   650
        return NULL;
slouken@5201
   651
    }
slouken@5201
   652
slouken@5201
   653
    /* Link the shader entry in at the front of the cache */
slouken@5201
   654
    if (rdata->shader_cache.head)
slouken@5201
   655
    {
slouken@5201
   656
        entry->next = rdata->shader_cache.head;
slouken@5201
   657
        rdata->shader_cache.head->prev = entry;
slouken@5201
   658
    }
slouken@5201
   659
    rdata->shader_cache.head = entry;
slouken@5201
   660
    ++rdata->shader_cache.count;
slouken@5201
   661
    return entry;
slouken@5201
   662
}
slouken@5201
   663
slouken@5201
   664
static void
slouken@5201
   665
GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry)
slouken@5201
   666
{
slouken@5201
   667
    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
slouken@5201
   668
slouken@5201
   669
    /* Unlink the shader from the cache */
slouken@5201
   670
    if (entry->next)
slouken@5201
   671
        entry->next->prev = entry->prev;
slouken@5201
   672
    if (entry->prev)
slouken@5201
   673
        entry->prev->next = entry->next;
slouken@5201
   674
    if (rdata->shader_cache.head == entry)
slouken@5201
   675
        rdata->shader_cache.head = entry->next;
slouken@5201
   676
    --rdata->shader_cache.count;
slouken@5201
   677
slouken@5201
   678
    /* Deallocate the shader */
slouken@5201
   679
    glDeleteShader(entry->id);
slouken@5201
   680
    SDL_free(entry);
slouken@5201
   681
}
slouken@5201
   682
slouken@5201
   683
static int
slouken@5201
   684
GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, SDL_BlendMode blendMode)
slouken@5201
   685
{
slouken@5201
   686
    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
slouken@5201
   687
    GLES2_ShaderCacheEntry *vertex = NULL;
slouken@5201
   688
    GLES2_ShaderCacheEntry *fragment = NULL;
slouken@5201
   689
    GLES2_ShaderType vtype, ftype;
slouken@5201
   690
    GLES2_ProgramCacheEntry *program;
slouken@5201
   691
slouken@5201
   692
    /* Select an appropriate shader pair for the specified modes */
slouken@5201
   693
    vtype = GLES2_SHADER_VERTEX_DEFAULT;
slouken@5201
   694
    switch (source)
slouken@5201
   695
    {
slouken@5201
   696
    case GLES2_IMAGESOURCE_SOLID:
slouken@5201
   697
        ftype = GLES2_SHADER_FRAGMENT_SOLID_SRC;
slouken@5201
   698
        break;
slouken@5201
   699
    case GLES2_IMAGESOURCE_TEXTURE:
slouken@5201
   700
        ftype = GLES2_SHADER_FRAGMENT_TEXTURE_SRC;
slouken@5201
   701
        break;
slouken@5201
   702
    }
slouken@5201
   703
slouken@5201
   704
    /* Load the requested shaders */
slouken@5201
   705
    vertex = GLES2_CacheShader(renderer, vtype, blendMode);
slouken@5201
   706
    if (!vertex)
slouken@5201
   707
        goto fault;
slouken@5201
   708
    fragment = GLES2_CacheShader(renderer, ftype, blendMode);
slouken@5201
   709
    if (!fragment)
slouken@5201
   710
        goto fault;
slouken@5201
   711
slouken@5201
   712
    /* Check if we need to change programs at all */
slouken@5201
   713
    if (rdata->current_program &&
slouken@5201
   714
        rdata->current_program->vertex_shader == vertex &&
slouken@5201
   715
        rdata->current_program->fragment_shader == fragment)
slouken@5201
   716
        return 0;
slouken@5201
   717
slouken@5201
   718
    /* Generate a matching program */
slouken@5201
   719
    program = GLES2_CacheProgram(renderer, vertex, fragment, blendMode);
slouken@5201
   720
    if (!program)
slouken@5201
   721
        goto fault;
slouken@5201
   722
slouken@5201
   723
    /* Select that program in OpenGL */
slouken@5201
   724
    glGetError();
slouken@5201
   725
    glUseProgram(program->id);
slouken@5201
   726
    if (glGetError() != GL_NO_ERROR)
slouken@5201
   727
    {
slouken@5201
   728
        SDL_SetError("Failed to select program");
slouken@5201
   729
        goto fault;
slouken@5201
   730
    }
slouken@5201
   731
slouken@5201
   732
    /* Set the current program */
slouken@5201
   733
    rdata->current_program = program;
slouken@5201
   734
slouken@5201
   735
    /* Activate an orthographic projection */
slouken@5201
   736
    if (GLES2_SetOrthographicProjection(renderer) < 0)
slouken@5201
   737
        goto fault;
slouken@5201
   738
slouken@5201
   739
    /* Clean up and return */
slouken@5201
   740
    return 0;
slouken@5201
   741
fault:
slouken@5201
   742
    if (vertex && vertex->references <= 0)
slouken@5201
   743
        GLES2_EvictShader(renderer, vertex);
slouken@5201
   744
    if (fragment && fragment->references <= 0)
slouken@5201
   745
        GLES2_EvictShader(renderer, fragment);
slouken@5201
   746
    rdata->current_program = NULL;
slouken@5201
   747
    return -1;
slouken@5201
   748
}
slouken@5201
   749
slouken@5201
   750
static int
slouken@5201
   751
GLES2_SetOrthographicProjection(SDL_Renderer *renderer)
slouken@5201
   752
{
slouken@5201
   753
    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
slouken@5201
   754
    GLfloat projection[4][4];
slouken@5201
   755
    GLuint locProjection;
slouken@5201
   756
slouken@5201
   757
    /* Prepare an orthographic projection */
slouken@5297
   758
    projection[0][0] = 2.0f / renderer->viewport.w;
slouken@5201
   759
    projection[0][1] = 0.0f;
slouken@5201
   760
    projection[0][2] = 0.0f;
slouken@5201
   761
    projection[0][3] = 0.0f;
slouken@5201
   762
    projection[1][0] = 0.0f;
slouken@5297
   763
    projection[1][1] = -2.0f / renderer->viewport.h;
slouken@5201
   764
    projection[1][2] = 0.0f;
slouken@5201
   765
    projection[1][3] = 0.0f;
slouken@5201
   766
    projection[2][0] = 0.0f;
slouken@5201
   767
    projection[2][1] = 0.0f;
slouken@5201
   768
    projection[2][2] = 1.0f;
slouken@5201
   769
    projection[2][3] = 0.0f;
slouken@5201
   770
    projection[3][0] = -1.0f;
slouken@5201
   771
    projection[3][1] = 1.0f;
slouken@5201
   772
    projection[3][2] = 0.0f;
slouken@5201
   773
    projection[3][3] = 1.0f;
slouken@5201
   774
slouken@5201
   775
    /* Set the projection matrix */
slouken@5201
   776
    locProjection = rdata->current_program->uniform_locations[GLES2_UNIFORM_PROJECTION];
slouken@5201
   777
    glGetError();
slouken@5201
   778
    glUniformMatrix4fv(locProjection, 1, GL_FALSE, (GLfloat *)projection);
slouken@5201
   779
    if (glGetError() != GL_NO_ERROR)
slouken@5201
   780
    {
slouken@5201
   781
        SDL_SetError("Failed to set orthographic projection");
slouken@5201
   782
        return -1;
slouken@5201
   783
    }
slouken@5201
   784
    return 0;
slouken@5201
   785
}
slouken@5201
   786
slouken@5201
   787
/*************************************************************************************************
slouken@5201
   788
 * Rendering functions                                                                           *
slouken@5201
   789
 *************************************************************************************************/
slouken@5201
   790
slouken@5224
   791
static const float inv255f = 1.0f / 255.0f;
slouken@5224
   792
slouken@5201
   793
static int GLES2_RenderClear(SDL_Renderer *renderer);
slouken@5201
   794
static int GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count);
slouken@5201
   795
static int GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count);
slouken@5297
   796
static int GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count);
slouken@5201
   797
static int GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
slouken@5201
   798
                            const SDL_Rect *dstrect);
slouken@6042
   799
static int GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@6042
   800
                    Uint32 pixel_format, void * pixels, int pitch);
slouken@5201
   801
static void GLES2_RenderPresent(SDL_Renderer *renderer);
slouken@5201
   802
slouken@5333
   803
slouken@5201
   804
static int
slouken@5333
   805
GLES2_RenderClear(SDL_Renderer * renderer)
slouken@5201
   806
{
slouken@5201
   807
    GLES2_ActivateRenderer(renderer);
slouken@5201
   808
slouken@5333
   809
    glClearColor((GLfloat) renderer->r * inv255f,
slouken@5333
   810
                 (GLfloat) renderer->g * inv255f,
slouken@5333
   811
                 (GLfloat) renderer->b * inv255f,
slouken@5333
   812
                 (GLfloat) renderer->a * inv255f);
slouken@5333
   813
slouken@5201
   814
    glClear(GL_COLOR_BUFFER_BIT);
slouken@5333
   815
slouken@5201
   816
    return 0;
slouken@5201
   817
}
slouken@5201
   818
slouken@5201
   819
static void
slouken@5355
   820
GLES2_SetBlendMode(GLES2_DriverContext *rdata, int blendMode)
slouken@5201
   821
{
slouken@5355
   822
    if (blendMode != rdata->current.blendMode) {
slouken@5355
   823
        switch (blendMode) {
slouken@5355
   824
        default:
slouken@5355
   825
        case SDL_BLENDMODE_NONE:
slouken@5355
   826
            glDisable(GL_BLEND);
slouken@5355
   827
            break;
slouken@5355
   828
        case SDL_BLENDMODE_BLEND:
slouken@5355
   829
            glEnable(GL_BLEND);
slouken@5355
   830
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
slouken@5355
   831
            break;
slouken@5355
   832
        case SDL_BLENDMODE_ADD:
slouken@5355
   833
            glEnable(GL_BLEND);
slouken@5355
   834
            glBlendFunc(GL_SRC_ALPHA, GL_ONE);
slouken@5355
   835
            break;
slouken@5355
   836
        case SDL_BLENDMODE_MOD:
slouken@5355
   837
            glEnable(GL_BLEND);
slouken@5355
   838
            glBlendFunc(GL_ZERO, GL_SRC_COLOR);
slouken@5355
   839
            break;
slouken@5355
   840
        }
slouken@5355
   841
        rdata->current.blendMode = blendMode;
slouken@5201
   842
    }
slouken@5201
   843
}
slouken@5201
   844
slouken@5355
   845
static void
slouken@5355
   846
GLES2_SetTexCoords(GLES2_DriverContext * rdata, SDL_bool enabled)
slouken@5355
   847
{
slouken@5355
   848
    if (enabled != rdata->current.tex_coords) {
slouken@5355
   849
        if (enabled) {
slouken@5355
   850
            glEnableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
slouken@5355
   851
        } else {
slouken@5355
   852
            glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
slouken@5355
   853
        }
slouken@5355
   854
        rdata->current.tex_coords = enabled;
slouken@5355
   855
    }
slouken@5355
   856
}
slouken@5355
   857
slouken@5355
   858
static int
slouken@5355
   859
GLES2_SetDrawingState(SDL_Renderer * renderer)
slouken@5355
   860
{
slouken@5355
   861
    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
slouken@5355
   862
    int blendMode = renderer->blendMode;
slouken@5355
   863
    GLuint locColor;
slouken@5355
   864
slouken@5355
   865
    glGetError();
slouken@5355
   866
slouken@5355
   867
    GLES2_ActivateRenderer(renderer);
slouken@5355
   868
slouken@5355
   869
    GLES2_SetBlendMode(rdata, blendMode);
slouken@5355
   870
slouken@5355
   871
    GLES2_SetTexCoords(rdata, SDL_FALSE);
slouken@5355
   872
slouken@5355
   873
    /* Activate an appropriate shader and set the projection matrix */
slouken@5355
   874
    if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, blendMode) < 0)
slouken@5355
   875
        return -1;
slouken@5355
   876
slouken@5355
   877
    /* Select the color to draw with */
slouken@5355
   878
    locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR];
slouken@5355
   879
    glUniform4f(locColor,
slouken@5355
   880
                renderer->r * inv255f,
slouken@5355
   881
                renderer->g * inv255f,
slouken@5355
   882
                renderer->b * inv255f,
slouken@5355
   883
                renderer->a * inv255f);
slouken@5355
   884
    return 0;
slouken@5355
   885
}
slouken@5355
   886
slouken@5201
   887
static int
slouken@5201
   888
GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count)
slouken@5201
   889
{
slouken@5201
   890
    GLfloat *vertices;
slouken@5201
   891
    int idx;
slouken@5201
   892
slouken@5355
   893
    if (GLES2_SetDrawingState(renderer) < 0) {
slouken@5201
   894
        return -1;
slouken@5355
   895
    }
slouken@5201
   896
slouken@5201
   897
    /* Emit the specified vertices as points */
slouken@5201
   898
    vertices = SDL_stack_alloc(GLfloat, count * 2);
slouken@5201
   899
    for (idx = 0; idx < count; ++idx)
slouken@5201
   900
    {
slouken@5201
   901
        GLfloat x = (GLfloat)points[idx].x + 0.5f;
slouken@5201
   902
        GLfloat y = (GLfloat)points[idx].y + 0.5f;
slouken@5201
   903
slouken@5201
   904
        vertices[idx * 2] = x;
slouken@5201
   905
        vertices[(idx * 2) + 1] = y;
slouken@5201
   906
    }
slouken@5355
   907
    glGetError();
slouken@5201
   908
    glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
slouken@5201
   909
    glDrawArrays(GL_POINTS, 0, count);
slouken@5201
   910
    SDL_stack_free(vertices);
slouken@5201
   911
    if (glGetError() != GL_NO_ERROR)
slouken@5201
   912
    {
slouken@5201
   913
        SDL_SetError("Failed to render lines");
slouken@5201
   914
        return -1;
slouken@5201
   915
    }
slouken@5201
   916
    return 0;
slouken@5201
   917
}
slouken@5201
   918
slouken@5201
   919
static int
slouken@5201
   920
GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count)
slouken@5201
   921
{
slouken@5201
   922
    GLfloat *vertices;
slouken@5201
   923
    int idx;
slouken@5201
   924
slouken@5355
   925
    if (GLES2_SetDrawingState(renderer) < 0) {
slouken@5201
   926
        return -1;
slouken@5355
   927
    }
slouken@5201
   928
slouken@5201
   929
    /* Emit a line strip including the specified vertices */
slouken@5201
   930
    vertices = SDL_stack_alloc(GLfloat, count * 2);
slouken@5201
   931
    for (idx = 0; idx < count; ++idx)
slouken@5201
   932
    {
slouken@5201
   933
        GLfloat x = (GLfloat)points[idx].x + 0.5f;
slouken@5201
   934
        GLfloat y = (GLfloat)points[idx].y + 0.5f;
slouken@5201
   935
slouken@5201
   936
        vertices[idx * 2] = x;
slouken@5201
   937
        vertices[(idx * 2) + 1] = y;
slouken@5201
   938
    }
slouken@5355
   939
    glGetError();
slouken@5201
   940
    glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
slouken@5201
   941
    glDrawArrays(GL_LINE_STRIP, 0, count);
slouken@5201
   942
    SDL_stack_free(vertices);
slouken@5201
   943
    if (glGetError() != GL_NO_ERROR)
slouken@5201
   944
    {
slouken@5201
   945
        SDL_SetError("Failed to render lines");
slouken@5201
   946
        return -1;
slouken@5201
   947
    }
slouken@5201
   948
    return 0;
slouken@5201
   949
}
slouken@5201
   950
slouken@5201
   951
static int
slouken@5297
   952
GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
slouken@5201
   953
{
slouken@5201
   954
    GLfloat vertices[8];
slouken@5201
   955
    int idx;
slouken@5201
   956
slouken@5355
   957
    if (GLES2_SetDrawingState(renderer) < 0) {
slouken@5201
   958
        return -1;
slouken@5355
   959
    }
slouken@5201
   960
slouken@5201
   961
    /* Emit a line loop for each rectangle */
slouken@5355
   962
    glGetError();
slouken@5297
   963
    for (idx = 0; idx < count; ++idx) {
slouken@5297
   964
        const SDL_Rect *rect = &rects[idx];
slouken@5297
   965
slouken@5297
   966
        GLfloat xMin = (GLfloat)rect->x;
slouken@5297
   967
        GLfloat xMax = (GLfloat)(rect->x + rect->w);
slouken@5297
   968
        GLfloat yMin = (GLfloat)rect->y;
slouken@5297
   969
        GLfloat yMax = (GLfloat)(rect->y + rect->h);
slouken@5201
   970
slouken@5201
   971
        vertices[0] = xMin;
slouken@5201
   972
        vertices[1] = yMin;
slouken@5201
   973
        vertices[2] = xMax;
slouken@5201
   974
        vertices[3] = yMin;
slouken@5201
   975
        vertices[4] = xMin;
slouken@5201
   976
        vertices[5] = yMax;
slouken@5201
   977
        vertices[6] = xMax;
slouken@5201
   978
        vertices[7] = yMax;
slouken@5201
   979
        glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
slouken@5201
   980
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
slouken@5201
   981
    }
slouken@5201
   982
    if (glGetError() != GL_NO_ERROR)
slouken@5201
   983
    {
slouken@5201
   984
        SDL_SetError("Failed to render lines");
slouken@5201
   985
        return -1;
slouken@5201
   986
    }
slouken@5201
   987
    return 0;
slouken@5201
   988
}
slouken@5201
   989
slouken@5201
   990
static int
slouken@5201
   991
GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
slouken@5201
   992
                 const SDL_Rect *dstrect)
slouken@5201
   993
{
slouken@5201
   994
    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
slouken@5201
   995
    GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
slouken@5201
   996
    GLES2_ImageSource sourceType;
slouken@5201
   997
    SDL_BlendMode blendMode;
slouken@5201
   998
    GLfloat vertices[8];
slouken@5201
   999
    GLfloat texCoords[8];
slouken@5201
  1000
    GLuint locTexture;
slouken@5201
  1001
    GLuint locModulation;
slouken@5201
  1002
slouken@5201
  1003
    GLES2_ActivateRenderer(renderer);
slouken@5201
  1004
slouken@5201
  1005
    /* Activate an appropriate shader and set the projection matrix */
slouken@5201
  1006
    blendMode = texture->blendMode;
slouken@5201
  1007
    sourceType = GLES2_IMAGESOURCE_TEXTURE;
slouken@5201
  1008
    if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0)
slouken@5201
  1009
        return -1;
slouken@5201
  1010
slouken@5201
  1011
    /* Select the target texture */
slouken@5201
  1012
    locTexture = rdata->current_program->uniform_locations[GLES2_UNIFORM_TEXTURE];
slouken@5201
  1013
    glGetError();
slouken@5201
  1014
    glActiveTexture(GL_TEXTURE0);
slouken@5201
  1015
    glBindTexture(tdata->texture_type, tdata->texture);
slouken@5201
  1016
    glUniform1i(locTexture, 0);
slouken@5201
  1017
slouken@5201
  1018
    /* Configure color modulation */
slouken@5201
  1019
    locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION];
slouken@5201
  1020
    glUniform4f(locModulation,
slouken@5224
  1021
                texture->r * inv255f,
slouken@5224
  1022
                texture->g * inv255f,
slouken@5224
  1023
                texture->b * inv255f,
slouken@5355
  1024
                texture->a * inv255f);
slouken@5355
  1025
slouken@5355
  1026
    /* Configure texture blending */
slouken@5355
  1027
    GLES2_SetBlendMode(rdata, blendMode);
slouken@5355
  1028
slouken@5355
  1029
    GLES2_SetTexCoords(rdata, SDL_TRUE);
slouken@5201
  1030
slouken@5201
  1031
    /* Emit the textured quad */
slouken@5201
  1032
    vertices[0] = (GLfloat)dstrect->x;
slouken@5201
  1033
    vertices[1] = (GLfloat)dstrect->y;
slouken@5201
  1034
    vertices[2] = (GLfloat)(dstrect->x + dstrect->w);
slouken@5201
  1035
    vertices[3] = (GLfloat)dstrect->y;
slouken@5201
  1036
    vertices[4] = (GLfloat)dstrect->x;
slouken@5201
  1037
    vertices[5] = (GLfloat)(dstrect->y + dstrect->h);
slouken@5201
  1038
    vertices[6] = (GLfloat)(dstrect->x + dstrect->w);
slouken@5201
  1039
    vertices[7] = (GLfloat)(dstrect->y + dstrect->h);
slouken@5201
  1040
    glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
slouken@5201
  1041
    texCoords[0] = srcrect->x / (GLfloat)texture->w;
slouken@5201
  1042
    texCoords[1] = srcrect->y / (GLfloat)texture->h;
slouken@5201
  1043
    texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
slouken@5201
  1044
    texCoords[3] = srcrect->y / (GLfloat)texture->h;
slouken@5201
  1045
    texCoords[4] = srcrect->x / (GLfloat)texture->w;
slouken@5201
  1046
    texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
slouken@5201
  1047
    texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
slouken@5201
  1048
    texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
slouken@5201
  1049
    glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
slouken@5201
  1050
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
slouken@5201
  1051
    if (glGetError() != GL_NO_ERROR)
slouken@5201
  1052
    {
slouken@5201
  1053
        SDL_SetError("Failed to render texture");
slouken@5201
  1054
        return -1;
slouken@5201
  1055
    }
slouken@5201
  1056
    return 0;
slouken@5201
  1057
}
slouken@5201
  1058
slouken@6042
  1059
static int
slouken@6042
  1060
GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@6042
  1061
                    Uint32 pixel_format, void * pixels, int pitch)
slouken@6042
  1062
{
slouken@6042
  1063
    SDL_Window *window = renderer->window;
slouken@6042
  1064
    Uint32 temp_format = SDL_PIXELFORMAT_ABGR8888;
slouken@6042
  1065
    void *temp_pixels;
slouken@6042
  1066
    int temp_pitch;
slouken@6042
  1067
    Uint8 *src, *dst, *tmp;
slouken@6042
  1068
    int w, h, length, rows;
slouken@6042
  1069
    int status;
slouken@6042
  1070
slouken@6042
  1071
    GLES2_ActivateRenderer(renderer);
slouken@6042
  1072
slouken@6042
  1073
    temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
slouken@6042
  1074
    temp_pixels = SDL_malloc(rect->h * temp_pitch);
slouken@6042
  1075
    if (!temp_pixels) {
slouken@6042
  1076
        SDL_OutOfMemory();
slouken@6042
  1077
        return -1;
slouken@6042
  1078
    }
slouken@6042
  1079
slouken@6042
  1080
    SDL_GetWindowSize(window, &w, &h);
slouken@6042
  1081
slouken@6042
  1082
    glPixelStorei(GL_PACK_ALIGNMENT, 1);
slouken@6042
  1083
slouken@6042
  1084
    glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
slouken@6042
  1085
                       GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
slouken@6042
  1086
slouken@6042
  1087
    /* Flip the rows to be top-down */
slouken@6042
  1088
    length = rect->w * SDL_BYTESPERPIXEL(temp_format);
slouken@6042
  1089
    src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
slouken@6042
  1090
    dst = (Uint8*)temp_pixels;
slouken@6042
  1091
    tmp = SDL_stack_alloc(Uint8, length);
slouken@6042
  1092
    rows = rect->h / 2;
slouken@6042
  1093
    while (rows--) {
slouken@6042
  1094
        SDL_memcpy(tmp, dst, length);
slouken@6042
  1095
        SDL_memcpy(dst, src, length);
slouken@6042
  1096
        SDL_memcpy(src, tmp, length);
slouken@6042
  1097
        dst += temp_pitch;
slouken@6042
  1098
        src -= temp_pitch;
slouken@6042
  1099
    }
slouken@6042
  1100
    SDL_stack_free(tmp);
slouken@6042
  1101
slouken@6042
  1102
    status = SDL_ConvertPixels(rect->w, rect->h,
slouken@6042
  1103
                               temp_format, temp_pixels, temp_pitch,
slouken@6042
  1104
                               pixel_format, pixels, pitch);
slouken@6042
  1105
    SDL_free(temp_pixels);
slouken@6042
  1106
slouken@6042
  1107
    return status;
slouken@6042
  1108
}
slouken@6042
  1109
slouken@5201
  1110
static void
slouken@5201
  1111
GLES2_RenderPresent(SDL_Renderer *renderer)
slouken@5201
  1112
{
slouken@5201
  1113
    GLES2_ActivateRenderer(renderer);
slouken@5201
  1114
slouken@5201
  1115
    /* Tell the video driver to swap buffers */
slouken@5201
  1116
    SDL_GL_SwapWindow(renderer->window);
slouken@5201
  1117
}
slouken@5201
  1118
slouken@5201
  1119
/*************************************************************************************************
slouken@5201
  1120
 * Renderer instantiation                                                                        *
slouken@5201
  1121
 *************************************************************************************************/
slouken@5201
  1122
slouken@5201
  1123
#define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B
slouken@5201
  1124
slouken@5355
  1125
static void
slouken@5355
  1126
GLES2_ResetState(SDL_Renderer *renderer)
slouken@5355
  1127
{
slouken@5355
  1128
    GLES2_DriverContext *rdata = (GLES2_DriverContext *) renderer->driverdata;
slouken@5355
  1129
slouken@5355
  1130
    if (SDL_CurrentContext == rdata->context) {
slouken@5355
  1131
        GLES2_UpdateViewport(renderer);
slouken@5355
  1132
    } else {
slouken@5355
  1133
        GLES2_ActivateRenderer(renderer);
slouken@5355
  1134
    }
slouken@5355
  1135
slouken@5355
  1136
    rdata->current.blendMode = -1;
slouken@5355
  1137
    rdata->current.tex_coords = SDL_FALSE;
slouken@5355
  1138
slouken@5355
  1139
    glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
slouken@5355
  1140
    glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
slouken@5355
  1141
}
slouken@5355
  1142
slouken@5201
  1143
static SDL_Renderer *
slouken@5201
  1144
GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
slouken@5201
  1145
{
slouken@5201
  1146
    SDL_Renderer *renderer;
slouken@5201
  1147
    GLES2_DriverContext *rdata;
slouken@5201
  1148
    GLint nFormats;
slouken@5201
  1149
#ifndef ZUNE_HD
slouken@5201
  1150
    GLboolean hasCompiler;
slouken@5201
  1151
#endif
slouken@5201
  1152
slouken@5201
  1153
    /* Create the renderer struct */
slouken@5201
  1154
    renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer));
slouken@5209
  1155
    if (!renderer) {
slouken@5209
  1156
        SDL_OutOfMemory();
slouken@5209
  1157
        return NULL;
slouken@5209
  1158
    }
slouken@5209
  1159
slouken@5201
  1160
    rdata = (GLES2_DriverContext *)SDL_calloc(1, sizeof(GLES2_DriverContext));
slouken@5209
  1161
    if (!rdata) {
slouken@5209
  1162
        GLES2_DestroyRenderer(renderer);
slouken@5201
  1163
        SDL_OutOfMemory();
slouken@5201
  1164
        return NULL;
slouken@5201
  1165
    }
slouken@5201
  1166
    renderer->info = GLES2_RenderDriver.info;
slouken@5297
  1167
    renderer->info.flags = SDL_RENDERER_ACCELERATED;
slouken@5201
  1168
    renderer->driverdata = rdata;
slouken@5201
  1169
slouken@5209
  1170
    /* Create an OpenGL ES 2.0 context */
slouken@5209
  1171
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
slouken@5209
  1172
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
slouken@5209
  1173
slouken@5201
  1174
    rdata->context = SDL_GL_CreateContext(window);
slouken@5201
  1175
    if (!rdata->context)
slouken@5201
  1176
    {
slouken@5209
  1177
        GLES2_DestroyRenderer(renderer);
slouken@5201
  1178
        return NULL;
slouken@5201
  1179
    }
slouken@5202
  1180
    if (SDL_GL_MakeCurrent(window, rdata->context) < 0) {
slouken@5209
  1181
        GLES2_DestroyRenderer(renderer);
slouken@5202
  1182
        return NULL;
slouken@5202
  1183
    }
slouken@5202
  1184
slouken@5202
  1185
    if (flags & SDL_RENDERER_PRESENTVSYNC) {
slouken@5202
  1186
        SDL_GL_SetSwapInterval(1);
slouken@5202
  1187
    } else {
slouken@5202
  1188
        SDL_GL_SetSwapInterval(0);
slouken@5202
  1189
    }
slouken@5202
  1190
    if (SDL_GL_GetSwapInterval() > 0) {
slouken@5202
  1191
        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
slouken@5202
  1192
    }
slouken@5201
  1193
slouken@5201
  1194
    /* Determine supported shader formats */
slouken@5201
  1195
    /* HACK: glGetInteger is broken on the Zune HD's compositor, so we just hardcode this */
slouken@5201
  1196
    glGetError();
slouken@5201
  1197
#ifdef ZUNE_HD
slouken@5201
  1198
    nFormats = 1;
slouken@5201
  1199
#else /* !ZUNE_HD */
slouken@5201
  1200
    glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &nFormats);
slouken@5201
  1201
    glGetBooleanv(GL_SHADER_COMPILER, &hasCompiler);
slouken@5201
  1202
    if (hasCompiler)
slouken@5201
  1203
        ++nFormats;
slouken@5201
  1204
#endif /* ZUNE_HD */
slouken@5201
  1205
    rdata->shader_formats = (GLenum *)SDL_calloc(nFormats, sizeof(GLenum));
slouken@5201
  1206
    if (!rdata->shader_formats)
slouken@5201
  1207
    {
slouken@5209
  1208
        GLES2_DestroyRenderer(renderer);
slouken@5201
  1209
        SDL_OutOfMemory();
slouken@5201
  1210
        return NULL;
slouken@5201
  1211
    }
slouken@5201
  1212
    rdata->shader_format_count = nFormats;
slouken@5201
  1213
#ifdef ZUNE_HD
slouken@5201
  1214
    rdata->shader_formats[0] = GL_NVIDIA_PLATFORM_BINARY_NV;
slouken@5201
  1215
#else /* !ZUNE_HD */
slouken@5201
  1216
    glGetIntegerv(GL_SHADER_BINARY_FORMATS, (GLint *)rdata->shader_formats);
slouken@5201
  1217
    if (glGetError() != GL_NO_ERROR)
slouken@5201
  1218
    {
slouken@5209
  1219
        GLES2_DestroyRenderer(renderer);
slouken@5201
  1220
        SDL_SetError("Failed to query supported shader formats");
slouken@5201
  1221
        return NULL;
slouken@5201
  1222
    }
slouken@5201
  1223
    if (hasCompiler)
slouken@5201
  1224
        rdata->shader_formats[nFormats - 1] = (GLenum)-1;
slouken@5201
  1225
#endif /* ZUNE_HD */
slouken@5201
  1226
slouken@5201
  1227
    /* Populate the function pointers for the module */
slouken@5201
  1228
    renderer->WindowEvent         = &GLES2_WindowEvent;
slouken@5201
  1229
    renderer->CreateTexture       = &GLES2_CreateTexture;
slouken@5201
  1230
    renderer->UpdateTexture       = &GLES2_UpdateTexture;
slouken@5201
  1231
    renderer->LockTexture         = &GLES2_LockTexture;
slouken@5201
  1232
    renderer->UnlockTexture       = &GLES2_UnlockTexture;
slouken@5297
  1233
    renderer->UpdateViewport      = &GLES2_UpdateViewport;
slouken@5201
  1234
    renderer->RenderClear         = &GLES2_RenderClear;
slouken@5201
  1235
    renderer->RenderDrawPoints    = &GLES2_RenderDrawPoints;
slouken@5201
  1236
    renderer->RenderDrawLines     = &GLES2_RenderDrawLines;
slouken@5201
  1237
    renderer->RenderFillRects     = &GLES2_RenderFillRects;
slouken@5201
  1238
    renderer->RenderCopy          = &GLES2_RenderCopy;
slouken@6042
  1239
    renderer->RenderReadPixels    = &GLES2_RenderReadPixels;
slouken@5201
  1240
    renderer->RenderPresent       = &GLES2_RenderPresent;
slouken@5201
  1241
    renderer->DestroyTexture      = &GLES2_DestroyTexture;
slouken@5201
  1242
    renderer->DestroyRenderer     = &GLES2_DestroyRenderer;
slouken@5355
  1243
slouken@5355
  1244
    GLES2_ResetState(renderer);
slouken@5355
  1245
slouken@5201
  1246
    return renderer;
slouken@5201
  1247
}
slouken@5201
  1248
slouken@5226
  1249
#endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */
slouken@5201
  1250
slouken@5201
  1251
/* vi: set ts=4 sw=4 expandtab: */