src/render/opengles/SDL_render_gles.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 19 Feb 2011 21:51:21 -0800
changeset 5355 cc2215cda170
parent 5333 5d3a2cd4e8c9
child 5402 5d102cd8aef3
permissions -rw-r--r--
Added OpenGL state caching for decent speed improvement.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
     1
/*
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5249
diff changeset
     3
    Copyright (C) 1997-2011 Sam Lantinga
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
     4
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
     9
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    13
    Lesser General Public License for more details.
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    14
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free Software
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    18
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    19
    Sam Lantinga
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    20
    slouken@libsdl.org
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    21
*/
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    22
#include "SDL_config.h"
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    23
5226
710d00cb3a6a Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents: 5224
diff changeset
    24
#if SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    25
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    26
#include "SDL_opengles.h"
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5150
diff changeset
    27
#include "../SDL_sysrender.h"
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    28
5150
1435f8a6425c Nobody is currently maintaining the QNX code, so removing it for now.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    29
#if defined(SDL_VIDEO_DRIVER_PANDORA)
3165
7168651d5706 QNX quirk has been added, QNX OpenGL ES implementation is broken regarding support of textures with packed pixel formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3163
diff changeset
    30
7168651d5706 QNX quirk has been added, QNX OpenGL ES implementation is broken regarding support of textures with packed pixel formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3163
diff changeset
    31
/* Empty function stub to get OpenGL ES 1.x support without  */
7168651d5706 QNX quirk has been added, QNX OpenGL ES implementation is broken regarding support of textures with packed pixel formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3163
diff changeset
    32
/* OpenGL ES extension GL_OES_draw_texture supported         */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
    33
GL_API void GL_APIENTRY
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
    34
glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2964
diff changeset
    35
{
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
    36
    return;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2964
diff changeset
    37
}
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2964
diff changeset
    38
5150
1435f8a6425c Nobody is currently maintaining the QNX code, so removing it for now.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    39
#endif /* PANDORA */
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    40
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    41
/* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    42
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    43
static const float inv255f = 1.0f / 255.0f;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    44
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    45
static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags);
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
    46
static void GLES_WindowEvent(SDL_Renderer * renderer,
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
    47
                             const SDL_WindowEvent *event);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    48
static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    49
static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    50
                              const SDL_Rect * rect, const void *pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    51
                              int pitch);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    52
static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
    53
                            const SDL_Rect * rect, void **pixels, int *pitch);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    54
static void GLES_UnlockTexture(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    55
                               SDL_Texture * texture);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
    56
static int GLES_UpdateViewport(SDL_Renderer * renderer);
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
    57
static int GLES_RenderClear(SDL_Renderer * renderer);
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
    58
static int GLES_RenderDrawPoints(SDL_Renderer * renderer,
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
    59
                                 const SDL_Point * points, int count);
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
    60
static int GLES_RenderDrawLines(SDL_Renderer * renderer,
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
    61
                                const SDL_Point * points, int count);
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
    62
static int GLES_RenderFillRects(SDL_Renderer * renderer,
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
    63
                                const SDL_Rect * rects, int count);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    64
static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    65
                           const SDL_Rect * srcrect,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    66
                           const SDL_Rect * dstrect);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    67
static void GLES_RenderPresent(SDL_Renderer * renderer);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    68
static void GLES_DestroyTexture(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    69
                                SDL_Texture * texture);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    70
static void GLES_DestroyRenderer(SDL_Renderer * renderer);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    71
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    72
5201
523409574510 Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents: 5195
diff changeset
    73
SDL_RenderDriver GLES_RenderDriver = {
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    74
    GLES_CreateRenderer,
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    75
    {
5203
25ffd4e5255c Minor consistency cleanup and documentation link update.
Sam Lantinga <slouken@libsdl.org>
parents: 5201
diff changeset
    76
     "opengles",
25ffd4e5255c Minor consistency cleanup and documentation link update.
Sam Lantinga <slouken@libsdl.org>
parents: 5201
diff changeset
    77
     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
    78
     1,
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
    79
     {SDL_PIXELFORMAT_ABGR8888},
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    80
     0,
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    81
     0}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    82
};
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    83
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    84
typedef struct
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    85
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    86
    SDL_GLContext context;
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
    87
    struct {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
    88
        Uint32 color;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
    89
        int blendMode;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
    90
        GLenum scaleMode;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
    91
        SDL_bool tex_coords;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
    92
    } current;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    93
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    94
    SDL_bool useDrawTexture;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    95
    SDL_bool GL_OES_draw_texture_supported;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    96
} GLES_RenderData;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    97
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    98
typedef struct
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    99
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   100
    GLuint texture;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   101
    GLenum type;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   102
    GLfloat texw;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   103
    GLfloat texh;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   104
    GLenum format;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   105
    GLenum formattype;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   106
    void *pixels;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   107
    int pitch;
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   108
    GLenum scaleMode;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   109
} GLES_TextureData;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   110
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   111
static void
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   112
GLES_SetError(const char *prefix, GLenum result)
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   113
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   114
    const char *error;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   115
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   116
    switch (result) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   117
    case GL_NO_ERROR:
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   118
        error = "GL_NO_ERROR";
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   119
        break;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   120
    case GL_INVALID_ENUM:
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   121
        error = "GL_INVALID_ENUM";
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   122
        break;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   123
    case GL_INVALID_VALUE:
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   124
        error = "GL_INVALID_VALUE";
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   125
        break;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   126
    case GL_INVALID_OPERATION:
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   127
        error = "GL_INVALID_OPERATION";
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   128
        break;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   129
    case GL_STACK_OVERFLOW:
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   130
        error = "GL_STACK_OVERFLOW";
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   131
        break;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   132
    case GL_STACK_UNDERFLOW:
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   133
        error = "GL_STACK_UNDERFLOW";
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   134
        break;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   135
    case GL_OUT_OF_MEMORY:
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   136
        error = "GL_OUT_OF_MEMORY";
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   137
        break;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   138
    default:
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   139
        error = "UNKNOWN";
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   140
        break;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   141
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   142
    SDL_SetError("%s: %s", prefix, error);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   143
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   144
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   145
static SDL_GLContext SDL_CurrentContext = NULL;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   146
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   147
static int
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   148
GLES_ActivateRenderer(SDL_Renderer * renderer)
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   149
{
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   150
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   151
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   152
    if (SDL_CurrentContext != data->context) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   153
        if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   154
            return -1;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   155
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   156
        SDL_CurrentContext = data->context;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   157
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   158
        GLES_UpdateViewport(renderer);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   159
    }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   160
    return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   161
}
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   162
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   163
/* This is called if we need to invalidate all of the SDL OpenGL state */
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   164
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   165
GLES_ResetState(SDL_Renderer *renderer)
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   166
{
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   167
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   168
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   169
    if (SDL_CurrentContext == data->context) {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   170
        GLES_UpdateViewport(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   171
    } else {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   172
        GLES_ActivateRenderer(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   173
    }
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   174
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   175
    data->current.color = 0;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   176
    data->current.blendMode = -1;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   177
    data->current.scaleMode = 0;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   178
    data->current.tex_coords = SDL_FALSE;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   179
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   180
    glDisable(GL_DEPTH_TEST);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   181
    glDisable(GL_CULL_FACE);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   182
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   183
    glMatrixMode(GL_MODELVIEW);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   184
    glLoadIdentity();
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   185
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   186
    glEnableClientState(GL_VERTEX_ARRAY);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   187
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   188
}
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   189
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   190
SDL_Renderer *
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   191
GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   192
{
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   193
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   194
    SDL_Renderer *renderer;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   195
    GLES_RenderData *data;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   196
    GLint value;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   197
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   198
    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   199
    if (!renderer) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   200
        SDL_OutOfMemory();
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   201
        return NULL;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   202
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   203
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   204
    data = (GLES_RenderData *) SDL_calloc(1, sizeof(*data));
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   205
    if (!data) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   206
        GLES_DestroyRenderer(renderer);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   207
        SDL_OutOfMemory();
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   208
        return NULL;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   209
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   210
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   211
    renderer->WindowEvent = GLES_WindowEvent;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   212
    renderer->CreateTexture = GLES_CreateTexture;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   213
    renderer->UpdateTexture = GLES_UpdateTexture;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   214
    renderer->LockTexture = GLES_LockTexture;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   215
    renderer->UnlockTexture = GLES_UnlockTexture;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   216
    renderer->UpdateViewport = GLES_UpdateViewport;
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   217
    renderer->RenderClear = GLES_RenderClear;
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   218
    renderer->RenderDrawPoints = GLES_RenderDrawPoints;
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   219
    renderer->RenderDrawLines = GLES_RenderDrawLines;
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   220
    renderer->RenderFillRects = GLES_RenderFillRects;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   221
    renderer->RenderCopy = GLES_RenderCopy;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   222
    renderer->RenderPresent = GLES_RenderPresent;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   223
    renderer->DestroyTexture = GLES_DestroyTexture;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   224
    renderer->DestroyRenderer = GLES_DestroyRenderer;
5201
523409574510 Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents: 5195
diff changeset
   225
    renderer->info = GLES_RenderDriver.info;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   226
    renderer->info.flags = SDL_RENDERER_ACCELERATED;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   227
    renderer->driverdata = data;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   228
5209
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5204
diff changeset
   229
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5204
diff changeset
   230
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5204
diff changeset
   231
3688
6512cba48440 Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
   232
    data->context = SDL_GL_CreateContext(window);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   233
    if (!data->context) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   234
        GLES_DestroyRenderer(renderer);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   235
        return NULL;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   236
    }
3688
6512cba48440 Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
   237
    if (SDL_GL_MakeCurrent(window, data->context) < 0) {
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   238
        GLES_DestroyRenderer(renderer);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   239
        return NULL;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   240
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   241
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   242
    if (flags & SDL_RENDERER_PRESENTVSYNC) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   243
        SDL_GL_SetSwapInterval(1);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   244
    } else {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   245
        SDL_GL_SetSwapInterval(0);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   246
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   247
    if (SDL_GL_GetSwapInterval() > 0) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   248
        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   249
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   250
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   251
#if SDL_VIDEO_DRIVER_PANDORA
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   252
    data->GL_OES_draw_texture_supported = SDL_FALSE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   253
    data->useDrawTexture = SDL_FALSE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   254
#else
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   255
    if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   256
        data->GL_OES_draw_texture_supported = SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   257
        data->useDrawTexture = SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   258
    } else {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   259
        data->GL_OES_draw_texture_supported = SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   260
        data->useDrawTexture = SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   261
    }
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   262
#endif
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   263
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   264
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   265
    renderer->info.max_texture_width = value;
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   266
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   267
    renderer->info.max_texture_height = value;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   268
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   269
    /* Set up parameters for rendering */
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   270
    GLES_ResetState(renderer);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   271
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   272
    return renderer;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   273
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   274
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   275
static void
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   276
GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   277
{
5276
8e421890cdb8 Fixed bug #1117
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   278
    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   279
        /* Rebind the context to the window area and update matrices */
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   280
        SDL_CurrentContext = NULL;
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   281
    }
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   282
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   283
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   284
static __inline__ int
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   285
power_of_2(int input)
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   286
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   287
    int value = 1;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   288
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   289
    while (value < input) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   290
        value <<= 1;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   291
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   292
    return value;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   293
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   294
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   295
static int
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   296
GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   297
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   298
    GLES_TextureData *data;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   299
    GLint internalFormat;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   300
    GLenum format, type;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   301
    int texture_w, texture_h;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   302
    GLenum result;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2964
diff changeset
   303
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   304
    GLES_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   305
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   306
    switch (texture->format) {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   307
    case SDL_PIXELFORMAT_ABGR8888:
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   308
        internalFormat = GL_RGBA;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   309
        format = GL_RGBA;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   310
        type = GL_UNSIGNED_BYTE;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   311
        break;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   312
    default:
5203
25ffd4e5255c Minor consistency cleanup and documentation link update.
Sam Lantinga <slouken@libsdl.org>
parents: 5201
diff changeset
   313
        SDL_SetError("Texture format not supported");
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   314
        return -1;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   315
    }
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   316
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   317
    data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data));
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   318
    if (!data) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   319
        SDL_OutOfMemory();
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   320
        return -1;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   321
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   322
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   323
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   324
        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   325
        data->pixels = SDL_malloc(texture->h * data->pitch);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   326
        if (!data->pixels) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   327
            SDL_OutOfMemory();
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   328
            SDL_free(data);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   329
            return -1;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   330
        }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   331
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   332
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   333
    texture->driverdata = data;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   334
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   335
    glGetError();
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   336
    glEnable(GL_TEXTURE_2D);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   337
    glGenTextures(1, &data->texture);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   338
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   339
    data->type = GL_TEXTURE_2D;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   340
    /* no NPOV textures allowed in OpenGL ES (yet) */
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   341
    texture_w = power_of_2(texture->w);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   342
    texture_h = power_of_2(texture->h);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   343
    data->texw = (GLfloat) texture->w / texture_w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   344
    data->texh = (GLfloat) texture->h / texture_h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   345
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   346
    data->format = format;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   347
    data->formattype = type;
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   348
    data->scaleMode = GL_LINEAR;
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   349
    glBindTexture(data->type, data->texture);
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   350
    glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   351
    glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   352
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   353
    glTexImage2D(data->type, 0, internalFormat, texture_w,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   354
                             texture_h, 0, format, type, NULL);
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   355
    glDisable(GL_TEXTURE_2D);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   356
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   357
    result = glGetError();
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   358
    if (result != GL_NO_ERROR) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   359
        GLES_SetError("glTexImage2D()", result);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   360
        return -1;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   361
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   362
    return 0;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   363
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   364
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   365
static int
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   366
GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   367
                   const SDL_Rect * rect, const void *pixels, int pitch)
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   368
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   369
    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   370
    Uint8 *blob = NULL;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   371
    Uint8 *src;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   372
    int srcPitch;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   373
    int y;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   374
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   375
    GLES_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   376
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   377
    /* Bail out if we're supposed to update an empty rectangle */
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   378
    if (rect->w <= 0 || rect->h <= 0)
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   379
        return 0;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   380
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   381
    /* Reformat the texture data into a tightly packed array */
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   382
    srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format);
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   383
    src = (Uint8 *)pixels;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   384
    if (pitch != srcPitch)
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   385
    {
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   386
        blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   387
        if (!blob)
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   388
        {
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   389
            SDL_OutOfMemory();
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   390
            return -1;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   391
        }
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   392
        src = blob;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   393
        for (y = 0; y < rect->h; ++y)
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   394
        {
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   395
            SDL_memcpy(src, pixels, srcPitch);
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   396
            src += srcPitch;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   397
            pixels = (Uint8 *)pixels + pitch;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   398
        }
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   399
        src = blob;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   400
    }
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   401
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   402
    /* Create a texture subimage with the supplied data */
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   403
    glGetError();
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   404
    glEnable(data->type);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   405
    glBindTexture(data->type, data->texture);
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   406
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   407
    glTexSubImage2D(data->type,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   408
                    0,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   409
                    rect->x,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   410
                    rect->y,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   411
                    rect->w,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   412
                    rect->h,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   413
                    data->format,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   414
                    data->formattype,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   415
                    src);
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   416
    if (blob) {
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   417
        SDL_free(blob);
5052
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
   418
    }
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
   419
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   420
    if (glGetError() != GL_NO_ERROR)
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   421
    {
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   422
        SDL_SetError("Failed to update texture");
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   423
        return -1;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   424
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   425
    return 0;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   426
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   427
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   428
static int
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   429
GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   430
                 const SDL_Rect * rect, void **pixels, int *pitch)
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   431
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   432
    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   433
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   434
    *pixels =
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   435
        (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   436
                  rect->x * SDL_BYTESPERPIXEL(texture->format));
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   437
    *pitch = data->pitch;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   438
    return 0;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   439
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   440
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   441
static void
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   442
GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   443
{
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   444
    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   445
    SDL_Rect rect;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   446
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   447
    /* We do whole texture updates, at least for now */
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   448
    rect.x = 0;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   449
    rect.y = 0;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   450
    rect.w = texture->w;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   451
    rect.h = texture->h;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   452
    GLES_UpdateTexture(renderer, texture, &rect, data->pixels, data->pitch);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   453
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   454
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   455
static int
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   456
GLES_UpdateViewport(SDL_Renderer * renderer)
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   457
{
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   458
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   459
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   460
    if (SDL_CurrentContext != data->context) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   461
        /* We'll update the viewport after we rebind the context */
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   462
        return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   463
    }
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   464
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   465
    glViewport(renderer->viewport.x, renderer->viewport.y,
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   466
               renderer->viewport.w, renderer->viewport.h);
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   467
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   468
    glMatrixMode(GL_PROJECTION);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   469
    glLoadIdentity();
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   470
    glOrthof((GLfloat) 0,
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   471
			 (GLfloat) renderer->viewport.w,
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   472
             (GLfloat) renderer->viewport.h,
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   473
             (GLfloat) 0, 0.0, 1.0);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   474
    return 0;
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   475
}
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   476
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   477
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   478
GLES_SetColor(GLES_RenderData * data, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   479
{
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   480
    Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b);
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   481
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   482
    if (color != data->current.color) {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   483
        glColor4f((GLfloat) r * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   484
                        (GLfloat) g * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   485
                        (GLfloat) b * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   486
                        (GLfloat) a * inv255f);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   487
        data->current.color = color;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   488
    }
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   489
}
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   490
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   491
static void
5140
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5138
diff changeset
   492
GLES_SetBlendMode(GLES_RenderData * data, int blendMode)
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   493
{
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   494
    if (blendMode != data->current.blendMode) {
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   495
        switch (blendMode) {
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   496
        case SDL_BLENDMODE_NONE:
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   497
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   498
            glDisable(GL_BLEND);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   499
            break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   500
        case SDL_BLENDMODE_BLEND:
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   501
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   502
            glEnable(GL_BLEND);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   503
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   504
            break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   505
        case SDL_BLENDMODE_ADD:
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   506
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   507
            glEnable(GL_BLEND);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   508
            glBlendFunc(GL_SRC_ALPHA, GL_ONE);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   509
            break;
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   510
        case SDL_BLENDMODE_MOD:
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   511
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   512
            glEnable(GL_BLEND);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   513
            glBlendFunc(GL_ZERO, GL_SRC_COLOR);
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   514
            break;
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   515
        }
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   516
        data->current.blendMode = blendMode;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   517
    }
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   518
}
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   519
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   520
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   521
GLES_SetTexCoords(GLES_RenderData * data, SDL_bool enabled)
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   522
{
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   523
    if (enabled != data->current.tex_coords) {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   524
        if (enabled) {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   525
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   526
        } else {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   527
            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   528
        }
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   529
        data->current.tex_coords = enabled;
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   530
    }
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   531
}
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   532
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   533
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   534
GLES_SetDrawingState(SDL_Renderer * renderer)
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   535
{
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   536
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   537
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   538
    GLES_ActivateRenderer(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   539
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   540
    GLES_SetColor(data, (GLfloat) renderer->r,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   541
                        (GLfloat) renderer->g,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   542
                        (GLfloat) renderer->b,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   543
                        (GLfloat) renderer->a);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   544
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   545
    GLES_SetBlendMode(data, renderer->blendMode);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   546
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   547
    GLES_SetTexCoords(data, SDL_FALSE);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   548
}
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   549
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   550
static int
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   551
GLES_RenderClear(SDL_Renderer * renderer)
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   552
{
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   553
    GLES_ActivateRenderer(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   554
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   555
    glClearColor((GLfloat) renderer->r * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   556
                 (GLfloat) renderer->g * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   557
                 (GLfloat) renderer->b * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   558
                 (GLfloat) renderer->a * inv255f);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   559
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   560
    glClear(GL_COLOR_BUFFER_BIT);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   561
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   562
    return 0;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   563
}
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   564
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   565
static int
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   566
GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   567
                      int count)
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   568
{
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   569
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   570
    int i;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   571
    GLshort *vertices;
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   572
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   573
    GLES_SetDrawingState(renderer);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   574
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   575
    vertices = SDL_stack_alloc(GLshort, count*2);
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   576
    for (i = 0; i < count; ++i) {
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   577
        vertices[2*i+0] = (GLshort)points[i].x;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   578
        vertices[2*i+1] = (GLshort)points[i].y;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   579
    }
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   580
    glVertexPointer(2, GL_SHORT, 0, vertices);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   581
    glDrawArrays(GL_POINTS, 0, count);
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   582
    SDL_stack_free(vertices);
2964
Sam Lantinga <slouken@libsdl.org>
parents: 2949
diff changeset
   583
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   584
    return 0;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   585
}
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   586
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   587
static int
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   588
GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   589
                     int count)
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   590
{
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   591
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   592
    int i;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   593
    GLshort *vertices;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   594
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   595
    GLES_SetDrawingState(renderer);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   596
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   597
    vertices = SDL_stack_alloc(GLshort, count*2);
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   598
    for (i = 0; i < count; ++i) {
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   599
        vertices[2*i+0] = (GLshort)points[i].x;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   600
        vertices[2*i+1] = (GLshort)points[i].y;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   601
    }
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   602
    glVertexPointer(2, GL_SHORT, 0, vertices);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   603
    if (count > 2 && 
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   604
        points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   605
        /* GL_LINE_LOOP takes care of the final segment */
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   606
        --count;
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   607
        glDrawArrays(GL_LINE_LOOP, 0, count);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   608
    } else {
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   609
        glDrawArrays(GL_LINE_STRIP, 0, count);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   610
    }
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
   611
    SDL_stack_free(vertices);
2949
4eabc35fbb4a Modified OpenGL ES render driver to support new SDL_RenderFill, SDL_RenderLine, and SDL_RenderPoint.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2937
diff changeset
   612
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   613
    return 0;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   614
}
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   615
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   616
static int
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   617
GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects,
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   618
                     int count)
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   619
{
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   620
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   621
    int i;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   622
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   623
    GLES_SetDrawingState(renderer);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   624
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   625
    for (i = 0; i < count; ++i) {
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   626
        const SDL_Rect *rect = &rects[i];
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   627
        GLshort minx = rect->x;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   628
        GLshort maxx = rect->x + rect->w;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   629
        GLshort miny = rect->y;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   630
        GLshort maxy = rect->y + rect->h;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   631
        GLshort vertices[8];
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   632
        vertices[0] = minx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   633
        vertices[1] = miny;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   634
        vertices[2] = maxx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   635
        vertices[3] = miny;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   636
        vertices[4] = minx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   637
        vertices[5] = maxy;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   638
        vertices[6] = maxx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   639
        vertices[7] = maxy;
2964
Sam Lantinga <slouken@libsdl.org>
parents: 2949
diff changeset
   640
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   641
        glVertexPointer(2, GL_SHORT, 0, vertices);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   642
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   643
    }
2949
4eabc35fbb4a Modified OpenGL ES render driver to support new SDL_RenderFill, SDL_RenderLine, and SDL_RenderPoint.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2937
diff changeset
   644
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   645
    return 0;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   646
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   647
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   648
static int
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   649
GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   650
                const SDL_Rect * srcrect, const SDL_Rect * dstrect)
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   651
{
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   652
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   653
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   654
    GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   655
    int minx, miny, maxx, maxy;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   656
    GLfloat minu, maxu, minv, maxv;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   657
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   658
    GLES_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   659
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   660
    glEnable(GL_TEXTURE_2D);
3122
6c98826d88b0 OpenGL ES renderer state fixes. Now GL_TEXTURE_2D is not enabled by default.
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   661
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   662
    glBindTexture(texturedata->type, texturedata->texture);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   663
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   664
    if (texturedata->scaleMode != data->current.scaleMode) {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   665
        glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   666
                        texturedata->scaleMode);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   667
        glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   668
                        texturedata->scaleMode);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   669
        data->current.scaleMode = texturedata->scaleMode;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   670
    }
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   671
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   672
    if (texture->modMode) {
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   673
        GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   674
    } else {
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   675
        GLES_SetColor(data, 255, 255, 255, 255);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   676
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   677
5140
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5138
diff changeset
   678
    GLES_SetBlendMode(data, texture->blendMode);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   679
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   680
    GLES_SetTexCoords(data, SDL_TRUE);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   681
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   682
    if (data->GL_OES_draw_texture_supported && data->useDrawTexture) {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   683
        /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5150
diff changeset
   684
        GLint cropRect[4];
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5150
diff changeset
   685
        int w, h;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3641
diff changeset
   686
        SDL_Window *window = renderer->window;
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5150
diff changeset
   687
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5150
diff changeset
   688
        SDL_GetWindowSize(window, &w, &h);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   689
        cropRect[0] = srcrect->x;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   690
        cropRect[1] = srcrect->y + srcrect->h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   691
        cropRect[2] = srcrect->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   692
        cropRect[3] = -srcrect->h;
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   693
        glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   694
                               cropRect);
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   695
        glDrawTexiOES(dstrect->x, h - dstrect->y - dstrect->h, 0,
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5150
diff changeset
   696
                            dstrect->w, dstrect->h);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   697
    } else {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   698
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   699
        minx = dstrect->x;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   700
        miny = dstrect->y;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   701
        maxx = dstrect->x + dstrect->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   702
        maxy = dstrect->y + dstrect->h;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   703
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   704
        minu = (GLfloat) srcrect->x / texture->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   705
        minu *= texturedata->texw;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   706
        maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   707
        maxu *= texturedata->texw;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   708
        minv = (GLfloat) srcrect->y / texture->h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   709
        minv *= texturedata->texh;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   710
        maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   711
        maxv *= texturedata->texh;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   712
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   713
        GLshort vertices[8];
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   714
        GLfloat texCoords[8];
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   715
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   716
        vertices[0] = minx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   717
        vertices[1] = miny;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   718
        vertices[2] = maxx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   719
        vertices[3] = miny;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   720
        vertices[4] = minx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   721
        vertices[5] = maxy;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   722
        vertices[6] = maxx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   723
        vertices[7] = maxy;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   724
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   725
        texCoords[0] = minu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   726
        texCoords[1] = minv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   727
        texCoords[2] = maxu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   728
        texCoords[3] = minv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   729
        texCoords[4] = minu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   730
        texCoords[5] = maxv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   731
        texCoords[6] = maxu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   732
        texCoords[7] = maxv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   733
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   734
        glVertexPointer(2, GL_SHORT, 0, vertices);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   735
        glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   736
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
3122
6c98826d88b0 OpenGL ES renderer state fixes. Now GL_TEXTURE_2D is not enabled by default.
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   737
    }
5204
daa5463466c5 Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents: 5203
diff changeset
   738
    glDisable(GL_TEXTURE_2D);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   739
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   740
    return 0;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   741
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   742
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   743
static void
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   744
GLES_RenderPresent(SDL_Renderer * renderer)
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   745
{
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   746
    GLES_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   747
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   748
    SDL_GL_SwapWindow(renderer->window);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   749
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   750
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   751
static void
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   752
GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   753
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   754
    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   755
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   756
    GLES_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5142
diff changeset
   757
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   758
    if (!data) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   759
        return;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   760
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   761
    if (data->texture) {
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   762
        glDeleteTextures(1, &data->texture);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   763
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   764
    if (data->pixels) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   765
        SDL_free(data->pixels);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   766
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   767
    SDL_free(data);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   768
    texture->driverdata = NULL;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   769
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   770
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   771
static void
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   772
GLES_DestroyRenderer(SDL_Renderer * renderer)
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   773
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   774
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   775
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   776
    if (data) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   777
        if (data->context) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   778
            SDL_GL_DeleteContext(data->context);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   779
        }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   780
        SDL_free(data);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   781
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   782
    SDL_free(renderer);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   783
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   784
5226
710d00cb3a6a Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents: 5224
diff changeset
   785
#endif /* SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED */
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   786
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   787
/* vi: set ts=4 sw=4 expandtab: */