src/render/opengles/SDL_render_gles.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 16 Aug 2013 12:51:29 -0400
changeset 7643 bae07d884b52
parent 7642 303214c66577
child 7644 037e5a9af745
permissions -rw-r--r--
Patched to compile.
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
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6528
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
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
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
     7
  arising from the use of this software.
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
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
    11
  freely, subject to the following restrictions:
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
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5503
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
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
    20
*/
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
#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
    22
5226
710d00cb3a6a Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents: 5224
diff changeset
    23
#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
    24
5484
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
    25
#include "SDL_hints.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
    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
6190
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
    43
/* Used to re-create the window with OpenGL ES capability */
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
    44
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
    45
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
    46
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
    47
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 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
    49
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
    50
                             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
    51
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
    52
static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    53
                              const SDL_Rect * rect, const void *pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    54
                              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
    55
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
    56
                            const SDL_Rect * rect, void **pixels, int *pitch);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    57
static void GLES_UnlockTexture(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    58
                               SDL_Texture * texture);
6247
b6212690f78d Renamed SetTargetTexture() to SetRenderTarget()
Sam Lantinga <slouken@libsdl.org>
parents: 6246
diff changeset
    59
static int GLES_SetRenderTarget(SDL_Renderer * renderer,
6246
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
    60
                                 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
    61
static int GLES_UpdateViewport(SDL_Renderer * renderer);
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
    62
static int GLES_UpdateClipRect(SDL_Renderer * renderer);
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
    63
static int GLES_RenderClear(SDL_Renderer * renderer);
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
    64
static int GLES_RenderDrawPoints(SDL_Renderer * renderer,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
    65
                                 const SDL_FPoint * points, int count);
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
    66
static int GLES_RenderDrawLines(SDL_Renderer * renderer,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
    67
                                const SDL_FPoint * points, int count);
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
    68
static int GLES_RenderFillRects(SDL_Renderer * renderer,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
    69
                                const SDL_FRect * 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
    70
static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    71
                           const SDL_Rect * srcrect,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
    72
                           const SDL_FRect * dstrect);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
    73
static int GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
    74
                         const SDL_Rect * srcrect, const SDL_FRect * dstrect,
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
    75
                         const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
6043
46d78e48ae8b This code works for OpenGL ES 1.1 as well! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    76
static int GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
46d78e48ae8b This code works for OpenGL ES 1.1 as well! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    77
                    Uint32 pixel_format, 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
    78
static void GLES_RenderPresent(SDL_Renderer * renderer);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    79
static void GLES_DestroyTexture(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
    80
                                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
    81
static void GLES_DestroyRenderer(SDL_Renderer * renderer);
6414
df50b0d6c1c3 Implements SDL_GL_BindTexture and SDL_GL_UnbindTexture (#1576)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6371
diff changeset
    82
static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
df50b0d6c1c3 Implements SDL_GL_BindTexture and SDL_GL_UnbindTexture (#1576)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6371
diff changeset
    83
static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture);
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
    84
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
    85
typedef struct GLES_FBOList GLES_FBOList;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
    86
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
    87
struct GLES_FBOList
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
    88
{
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
    89
   Uint32 w, h;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
    90
   GLuint FBO;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
    91
   GLES_FBOList *next;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
    92
};
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
    93
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
    94
5201
523409574510 Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents: 5195
diff changeset
    95
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
    96
    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
    97
    {
5203
25ffd4e5255c Minor consistency cleanup and documentation link update.
Sam Lantinga <slouken@libsdl.org>
parents: 5201
diff changeset
    98
     "opengles",
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
    99
     (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
   100
     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
   101
     {SDL_PIXELFORMAT_ABGR8888},
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   102
     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
   103
     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
   104
};
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
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
   107
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   108
    SDL_GLContext context;
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   109
    struct {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   110
        Uint32 color;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   111
        int blendMode;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   112
        SDL_bool tex_coords;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   113
    } current;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   114
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   115
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   116
#define SDL_PROC_OES SDL_PROC
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   117
#include "SDL_glesfuncs.h"
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   118
#undef SDL_PROC
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   119
#undef SDL_PROC_OES
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   120
    SDL_bool GL_OES_framebuffer_object_supported;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   121
    GLES_FBOList *framebuffers;
6271
d1ba86bc57a5 Fixed magenta texture on iOS with OpenGL ES 2.0
Sam Lantinga <slouken@libsdl.org>
parents: 6269
diff changeset
   122
    GLuint window_framebuffer;
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   123
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   124
    SDL_bool useDrawTexture;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   125
    SDL_bool GL_OES_draw_texture_supported;
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   126
    SDL_bool GL_OES_blend_func_separate_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
   127
} 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
   128
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
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
   130
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
    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
   132
    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
   133
    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
   134
    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
   135
    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
   136
    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
   137
    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
   138
    int pitch;
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   139
    GLES_FBOList *fbo;
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
   140
} 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
   141
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   142
static int
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
   143
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
   144
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   145
    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
   146
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   147
    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
   148
    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
   149
        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
   150
        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
   151
    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
   152
        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
   153
        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
   154
    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
   155
        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
   156
        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
   157
    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
   158
        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
   159
        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
   160
    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
   161
        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
   162
        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
   163
    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
   164
        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
   165
        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
   166
    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
   167
        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
   168
        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
   169
    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
   170
        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
   171
        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
   172
    }
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   173
    return SDL_SetError("%s: %s", prefix, error);
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
   174
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   175
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   176
static int GLES_LoadFunctions(GLES_RenderData * data)
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   177
{
6190
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   178
#if SDL_VIDEO_DRIVER_UIKIT
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   179
#define __SDL_NOGETPROCADDR__
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   180
#elif SDL_VIDEO_DRIVER_ANDROID
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   181
#define __SDL_NOGETPROCADDR__
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   182
#elif SDL_VIDEO_DRIVER_PANDORA
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   183
#define __SDL_NOGETPROCADDR__
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   184
#endif
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   185
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   186
#ifdef __SDL_NOGETPROCADDR__
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   187
#define SDL_PROC(ret,func,params) data->func=func;
7643
bae07d884b52 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 7642
diff changeset
   188
#define SDL_PROC_OES(ret,func,params) data->func=func;
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   189
#else
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   190
#define SDL_PROC(ret,func,params) \
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   191
    do { \
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   192
        data->func = SDL_GL_GetProcAddress(#func); \
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   193
        if ( ! data->func ) { \
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   194
            return SDL_SetError("Couldn't load GLES function %s: %s\n", #func, SDL_GetError()); \
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   195
        } \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7173
diff changeset
   196
    } while ( 0 );
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   197
#define SDL_PROC_OES(ret,func,params) \
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   198
    do { \
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   199
        data->func = SDL_GL_GetProcAddress(#func); \
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   200
    } while ( 0 );    
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   201
#endif /* _SDL_NOGETPROCADDR_ */
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   202
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   203
#include "SDL_glesfuncs.h"
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   204
#undef SDL_PROC
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   205
#undef SDL_PROC_OES
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   206
    return 0;
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   207
}
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   208
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   209
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
   210
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   211
GLES_FBOList *
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   212
GLES_GetFBO(GLES_RenderData *data, Uint32 w, Uint32 h)
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   213
{
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   214
   GLES_FBOList *result = data->framebuffers;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   215
   while ((result) && ((result->w != w) || (result->h != h)) )
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   216
   {
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   217
       result = result->next;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   218
   }
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   219
   if (result == NULL)
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   220
   {
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   221
       result = SDL_malloc(sizeof(GLES_FBOList));
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   222
       result->w = w;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   223
       result->h = h;
6269
07e08cb58696 Added glGenFramebuffers() to the function pointer list
Sam Lantinga <slouken@libsdl.org>
parents: 6260
diff changeset
   224
       data->glGenFramebuffersOES(1, &result->FBO);
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   225
       result->next = data->framebuffers;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   226
       data->framebuffers = result;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   227
   }
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   228
   return result;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   229
}
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   230
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   231
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   232
static int
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   233
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
   234
{
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   235
    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
   236
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   237
    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
   238
        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
   239
            return -1;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   240
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   241
        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
   242
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   243
        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
   244
    }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   245
    return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   246
}
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   247
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   248
/* 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
   249
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   250
GLES_ResetState(SDL_Renderer *renderer)
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   251
{
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   252
    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
   253
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   254
    if (SDL_CurrentContext == data->context) {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   255
        GLES_UpdateViewport(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   256
    } else {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   257
        GLES_ActivateRenderer(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   258
    }
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   259
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   260
    data->current.color = 0;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   261
    data->current.blendMode = -1;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   262
    data->current.tex_coords = SDL_FALSE;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   263
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   264
    data->glDisable(GL_DEPTH_TEST);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   265
    data->glDisable(GL_CULL_FACE);
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   266
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   267
    data->glMatrixMode(GL_MODELVIEW);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   268
    data->glLoadIdentity();
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   269
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   270
    data->glEnableClientState(GL_VERTEX_ARRAY);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   271
    data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   272
}
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   273
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
   274
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
   275
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
   276
{
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   277
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
   278
    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
   279
    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
   280
    GLint value;
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   281
    Uint32 windowFlags;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7173
diff changeset
   282
6371
a6b1a0c31880 Switch the OpenGL ES renderers to request EGL OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 6320
diff changeset
   283
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   284
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   285
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7173
diff changeset
   286
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   287
    windowFlags = SDL_GetWindowFlags(window);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   288
    if (!(windowFlags & SDL_WINDOW_OPENGL)) {
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   289
        if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   290
            /* Uh oh, better try to put it back... */
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   291
            SDL_RecreateWindow(window, windowFlags);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   292
            return NULL;
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   293
        }
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   294
    }
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
   295
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   296
    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
   297
    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
   298
        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
   299
        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
   300
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
    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
   303
    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
   304
        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
   305
        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
   306
        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
   307
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   308
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
   309
    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
   310
    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
   311
    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
   312
    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
   313
    renderer->UnlockTexture = GLES_UnlockTexture;
6247
b6212690f78d Renamed SetTargetTexture() to SetRenderTarget()
Sam Lantinga <slouken@libsdl.org>
parents: 6246
diff changeset
   314
    renderer->SetRenderTarget = GLES_SetRenderTarget;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   315
    renderer->UpdateViewport = GLES_UpdateViewport;
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   316
    renderer->UpdateClipRect = GLES_UpdateClipRect;
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   317
    renderer->RenderClear = GLES_RenderClear;
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   318
    renderer->RenderDrawPoints = GLES_RenderDrawPoints;
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   319
    renderer->RenderDrawLines = GLES_RenderDrawLines;
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   320
    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
   321
    renderer->RenderCopy = GLES_RenderCopy;
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   322
    renderer->RenderCopyEx = GLES_RenderCopyEx;
6043
46d78e48ae8b This code works for OpenGL ES 1.1 as well! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   323
    renderer->RenderReadPixels = GLES_RenderReadPixels;
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
   324
    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
   325
    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
   326
    renderer->DestroyRenderer = GLES_DestroyRenderer;
6414
df50b0d6c1c3 Implements SDL_GL_BindTexture and SDL_GL_UnbindTexture (#1576)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6371
diff changeset
   327
    renderer->GL_BindTexture = GLES_BindTexture;
df50b0d6c1c3 Implements SDL_GL_BindTexture and SDL_GL_UnbindTexture (#1576)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6371
diff changeset
   328
    renderer->GL_UnbindTexture = GLES_UnbindTexture;
5201
523409574510 Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents: 5195
diff changeset
   329
    renderer->info = GLES_RenderDriver.info;
6246
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   330
    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
   331
    renderer->driverdata = data;
6171
7b9126fde949 Fixed bug 1256 - Invalid window warning in GL_CreateRenderer
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   332
    renderer->window = window;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   333
3688
6512cba48440 Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
   334
    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
   335
    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
   336
        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
   337
        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
   338
    }
3688
6512cba48440 Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
   339
    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
   340
        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
   341
        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
   342
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   343
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   344
    if (GLES_LoadFunctions(data) < 0) {
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   345
        GLES_DestroyRenderer(renderer);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   346
        return NULL;
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   347
    }
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   348
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
   349
    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
   350
        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
   351
    } 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
   352
        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
   353
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   354
    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
   355
        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
   356
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   357
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   358
#if SDL_VIDEO_DRIVER_PANDORA
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   359
    data->GL_OES_draw_texture_supported = SDL_FALSE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   360
    data->useDrawTexture = SDL_FALSE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   361
#else
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   362
    if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   363
        data->GL_OES_draw_texture_supported = SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   364
        data->useDrawTexture = SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   365
    } else {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   366
        data->GL_OES_draw_texture_supported = SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   367
        data->useDrawTexture = SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   368
    }
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   369
#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
   370
6274
246cde9a6cf3 Fixed OpenGL ES 1.1 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6271
diff changeset
   371
    value = 0;
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   372
    data->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
   373
    renderer->info.max_texture_width = value;
6274
246cde9a6cf3 Fixed OpenGL ES 1.1 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6271
diff changeset
   374
    value = 0;
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   375
    data->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
   376
    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
   377
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   378
    if (SDL_GL_ExtensionSupported("GL_OES_framebuffer_object")) {
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   379
        data->GL_OES_framebuffer_object_supported = SDL_TRUE;
6246
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   380
        renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
6271
d1ba86bc57a5 Fixed magenta texture on iOS with OpenGL ES 2.0
Sam Lantinga <slouken@libsdl.org>
parents: 6269
diff changeset
   381
6274
246cde9a6cf3 Fixed OpenGL ES 1.1 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6271
diff changeset
   382
        value = 0;
6271
d1ba86bc57a5 Fixed magenta texture on iOS with OpenGL ES 2.0
Sam Lantinga <slouken@libsdl.org>
parents: 6269
diff changeset
   383
        data->glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &value);
d1ba86bc57a5 Fixed magenta texture on iOS with OpenGL ES 2.0
Sam Lantinga <slouken@libsdl.org>
parents: 6269
diff changeset
   384
        data->window_framebuffer = (GLuint)value;
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   385
    }
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   386
    data->framebuffers = NULL;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   387
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   388
    if (SDL_GL_ExtensionSupported("GL_OES_blend_func_separate")) {
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   389
        data->GL_OES_blend_func_separate_supported = SDL_TRUE;
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   390
    }
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   391
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
   392
    /* Set up parameters for rendering */
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   393
    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
   394
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   395
    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
   396
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   397
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
   398
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
   399
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
   400
{
6190
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   401
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7173
diff changeset
   402
6260
fd494c5f305b Fixed loading textures when the window starts hidden.
Sam Lantinga <slouken@libsdl.org>
parents: 6247
diff changeset
   403
    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
fd494c5f305b Fixed loading textures when the window starts hidden.
Sam Lantinga <slouken@libsdl.org>
parents: 6247
diff changeset
   404
        event->event == SDL_WINDOWEVENT_SHOWN ||
fd494c5f305b Fixed loading textures when the window starts hidden.
Sam Lantinga <slouken@libsdl.org>
parents: 6247
diff changeset
   405
        event->event == SDL_WINDOWEVENT_HIDDEN) {
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
   406
        /* 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
   407
        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
   408
    }
6060
59d398ac031e Fixed SDL applications being killed immediately after being backgrounded, because they were trying to draw while minimized.
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
   409
59d398ac031e Fixed SDL applications being killed immediately after being backgrounded, because they were trying to draw while minimized.
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
   410
    if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
59d398ac031e Fixed SDL applications being killed immediately after being backgrounded, because they were trying to draw while minimized.
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
   411
        /* According to Apple documentation, we need to finish drawing NOW! */
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   412
        data->glFinish();
6060
59d398ac031e Fixed SDL applications being killed immediately after being backgrounded, because they were trying to draw while minimized.
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
   413
    }
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
   414
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   415
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   416
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
   417
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
   418
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   419
    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
   420
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   421
    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
   422
        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
   423
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
    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
   425
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
5484
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   427
static GLenum
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   428
GetScaleQuality(void)
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   429
{
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   430
    const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   431
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   432
    if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   433
        return GL_NEAREST;
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   434
    } else {
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   435
        return GL_LINEAR;
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   436
    }
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   437
}
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   438
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
   439
static int
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   440
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
   441
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   442
    GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
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
   443
    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
   444
    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
   445
    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
   446
    int texture_w, texture_h;
5503
be88d105e91c The scale mode is per texture, not per texture unit.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
   447
    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
   448
    GLenum result;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2964
diff changeset
   449
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
   450
    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
   451
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   452
    switch (texture->format) {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   453
    case SDL_PIXELFORMAT_ABGR8888:
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   454
        internalFormat = GL_RGBA;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   455
        format = GL_RGBA;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   456
        type = GL_UNSIGNED_BYTE;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   457
        break;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   458
    default:
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   459
        return SDL_SetError("Texture format not 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
   460
    }
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   461
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   462
    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
   463
    if (!data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   464
        return SDL_OutOfMemory();
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
   465
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   466
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   467
    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
   468
        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
5402
5d102cd8aef3 Zero streaming textures at the driver level
Sam Lantinga <slouken@libsdl.org>
parents: 5355
diff changeset
   469
        data->pixels = SDL_calloc(1, texture->h * 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
   470
        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
   471
            SDL_free(data);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   472
            return SDL_OutOfMemory();
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
   473
        }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   474
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   475
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   476
    
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   477
    if (texture->access == SDL_TEXTUREACCESS_TARGET) {
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   478
        if (!renderdata->GL_OES_framebuffer_object_supported) {
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   479
            SDL_free(data);
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   480
            return SDL_SetError("GL_OES_framebuffer_object not supported");
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   481
        }
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   482
        data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h);
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   483
    } else {
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   484
        data->fbo = NULL;
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   485
    }
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   486
    
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
   487
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   488
    renderdata->glGetError();
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   489
    renderdata->glEnable(GL_TEXTURE_2D);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   490
    renderdata->glGenTextures(1, &data->texture);
7624
ac9f3b12c42a Check the return value of glGenTextures()
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   491
    result = renderdata->glGetError();
ac9f3b12c42a Check the return value of glGenTextures()
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   492
    if (result != GL_NO_ERROR) {
ac9f3b12c42a Check the return value of glGenTextures()
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   493
        SDL_free(data);
ac9f3b12c42a Check the return value of glGenTextures()
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   494
        return GLES_SetError("glGenTextures()", result);
ac9f3b12c42a Check the return value of glGenTextures()
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   495
    }
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   496
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   497
    data->type = GL_TEXTURE_2D;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   498
    /* no NPOV textures allowed in OpenGL ES (yet) */
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   499
    texture_w = power_of_2(texture->w);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   500
    texture_h = power_of_2(texture->h);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   501
    data->texw = (GLfloat) texture->w / texture_w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   502
    data->texh = (GLfloat) texture->h / texture_h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   503
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
   504
    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
   505
    data->formattype = type;
5503
be88d105e91c The scale mode is per texture, not per texture unit.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
   506
    scaleMode = GetScaleQuality();
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   507
    renderdata->glBindTexture(data->type, data->texture);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   508
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   509
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   510
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   511
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   512
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   513
    renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   514
                             texture_h, 0, format, type, NULL);
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   515
    renderdata->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
   516
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   517
    result = renderdata->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
   518
    if (result != GL_NO_ERROR) {
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   519
        SDL_free(data);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   520
        return GLES_SetError("glTexImage2D()", result);
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
   521
    }
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   522
    
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   523
    texture->driverdata = 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
   524
    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
   525
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   526
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   527
static int
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   528
GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   529
                   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
   530
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   531
    GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
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
   532
    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
   533
    Uint8 *blob = NULL;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   534
    Uint8 *src;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   535
    int srcPitch;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   536
    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
   537
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
   538
    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
   539
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   540
    /* 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
   541
    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
   542
        return 0;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   543
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   544
    /* 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
   545
    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
   546
    src = (Uint8 *)pixels;
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   547
    if (pitch != srcPitch) {
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   548
        blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   549
        if (!blob) {
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   550
            return SDL_OutOfMemory();
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   551
        }
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   552
        src = blob;
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   553
        for (y = 0; y < rect->h; ++y) {
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   554
            SDL_memcpy(src, pixels, srcPitch);
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   555
            src += srcPitch;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   556
            pixels = (Uint8 *)pixels + pitch;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   557
        }
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   558
        src = blob;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   559
    }
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   560
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   561
    /* Create a texture subimage with the supplied data */
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   562
    renderdata->glGetError();
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   563
    renderdata->glEnable(data->type);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   564
    renderdata->glBindTexture(data->type, data->texture);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   565
    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   566
    renderdata->glTexSubImage2D(data->type,
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   567
                    0,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   568
                    rect->x,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   569
                    rect->y,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   570
                    rect->w,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   571
                    rect->h,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   572
                    data->format,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   573
                    data->formattype,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   574
                    src);
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   575
    if (blob) {
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   576
        SDL_free(blob);
5052
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
   577
    }
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
   578
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   579
    if (renderdata->glGetError() != GL_NO_ERROR)
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   580
    {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   581
        return 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
   582
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   583
    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
   584
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   585
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   586
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
   587
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
   588
                 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
   589
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
    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
   591
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   592
    *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
   593
        (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
   594
                  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
   595
    *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
   596
    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
   597
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   598
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   599
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
   600
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
   601
{
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
   602
    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
   603
    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
   604
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   605
    /* 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
   606
    rect.x = 0;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   607
    rect.y = 0;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   608
    rect.w = texture->w;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   609
    rect.h = texture->h;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   610
    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
   611
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   612
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   613
static int
6247
b6212690f78d Renamed SetTargetTexture() to SetRenderTarget()
Sam Lantinga <slouken@libsdl.org>
parents: 6246
diff changeset
   614
GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
6246
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   615
{
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   616
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   617
    GLES_TextureData *texturedata = NULL;
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   618
    GLenum status;
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   619
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   620
    GLES_ActivateRenderer(renderer);
7642
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   621
    
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   622
    if (!data->GL_OES_framebuffer_object_supported) {
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   623
        return SDL_SetError("Can't enable render target support in this renderer");
303214c66577 [Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7624
diff changeset
   624
    }
6246
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   625
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   626
    if (texture == NULL) {
6271
d1ba86bc57a5 Fixed magenta texture on iOS with OpenGL ES 2.0
Sam Lantinga <slouken@libsdl.org>
parents: 6269
diff changeset
   627
        data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, data->window_framebuffer);
6246
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   628
        return 0;
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   629
    }
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   630
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   631
    texturedata = (GLES_TextureData *) texture->driverdata;
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   632
    data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, texturedata->fbo->FBO);
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   633
    /* TODO: check if texture pixel format allows this operation */
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   634
    data->glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, texturedata->type, texturedata->texture, 0);
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   635
    /* Check FBO status */
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   636
    status = data->glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   637
    if (status != GL_FRAMEBUFFER_COMPLETE_OES) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   638
        return SDL_SetError("glFramebufferTexture2DOES() failed");
6246
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   639
    }
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   640
    return 0;
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   641
}
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   642
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   643
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
   644
GLES_UpdateViewport(SDL_Renderer * renderer)
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   645
{
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   646
    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
   647
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   648
    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
   649
        /* 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
   650
        return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   651
    }
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   652
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   653
    data->glViewport(renderer->viewport.x, renderer->viewport.y,
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   654
               renderer->viewport.w, renderer->viewport.h);
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   655
7239
04dda95ba22c Fixed bug 1622 - SDL_RenderSetViewport with empty SDL_Rect raises wrong error for OpenGL rendering backend
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   656
    if (renderer->viewport.w && renderer->viewport.h) {
04dda95ba22c Fixed bug 1622 - SDL_RenderSetViewport with empty SDL_Rect raises wrong error for OpenGL rendering backend
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   657
        data->glMatrixMode(GL_PROJECTION);
04dda95ba22c Fixed bug 1622 - SDL_RenderSetViewport with empty SDL_Rect raises wrong error for OpenGL rendering backend
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   658
        data->glLoadIdentity();
04dda95ba22c Fixed bug 1622 - SDL_RenderSetViewport with empty SDL_Rect raises wrong error for OpenGL rendering backend
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   659
        data->glOrthof((GLfloat) 0,
04dda95ba22c Fixed bug 1622 - SDL_RenderSetViewport with empty SDL_Rect raises wrong error for OpenGL rendering backend
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   660
                 (GLfloat) renderer->viewport.w,
04dda95ba22c Fixed bug 1622 - SDL_RenderSetViewport with empty SDL_Rect raises wrong error for OpenGL rendering backend
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   661
                 (GLfloat) renderer->viewport.h,
04dda95ba22c Fixed bug 1622 - SDL_RenderSetViewport with empty SDL_Rect raises wrong error for OpenGL rendering backend
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   662
                 (GLfloat) 0, 0.0, 1.0);
04dda95ba22c Fixed bug 1622 - SDL_RenderSetViewport with empty SDL_Rect raises wrong error for OpenGL rendering backend
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   663
    }
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   664
    return 0;
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   665
}
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   666
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   667
static int
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   668
GLES_UpdateClipRect(SDL_Renderer * renderer)
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   669
{
7160
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   670
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   671
    const SDL_Rect *rect = &renderer->clip_rect;
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   672
7160
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   673
    if (SDL_CurrentContext != data->context) {
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   674
        /* We'll update the clip rect after we rebind the context */
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   675
        return 0;
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   676
    }
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   677
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   678
    if (!SDL_RectEmpty(rect)) {
7160
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   679
        data->glEnable(GL_SCISSOR_TEST);
7173
fc45e51373ea Inlined expression for consistency in render source.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7169
diff changeset
   680
        data->glScissor(rect->x, renderer->viewport.h - rect->y - rect->h, rect->w, rect->h);
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   681
    } else {
7160
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   682
        data->glDisable(GL_SCISSOR_TEST);
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   683
    }
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   684
    return 0;
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   685
}
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   686
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   687
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   688
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
   689
{
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   690
    Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b);
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   691
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   692
    if (color != data->current.color) {
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   693
        data->glColor4f((GLfloat) r * inv255f,
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   694
                        (GLfloat) g * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   695
                        (GLfloat) b * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   696
                        (GLfloat) a * inv255f);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   697
        data->current.color = color;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   698
    }
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   699
}
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   700
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   701
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
   702
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
   703
{
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   704
    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
   705
        switch (blendMode) {
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   706
        case SDL_BLENDMODE_NONE:
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   707
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   708
            data->glDisable(GL_BLEND);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   709
            break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   710
        case SDL_BLENDMODE_BLEND:
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   711
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   712
            data->glEnable(GL_BLEND);
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   713
            if (data->GL_OES_blend_func_separate_supported) {
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   714
                data->glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   715
            } else {
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   716
                data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   717
            }
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   718
            break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   719
        case SDL_BLENDMODE_ADD:
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   720
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   721
            data->glEnable(GL_BLEND);
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   722
            if (data->GL_OES_blend_func_separate_supported) {
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   723
                data->glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   724
            } else {
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   725
                data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   726
            }
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   727
            break;
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   728
        case SDL_BLENDMODE_MOD:
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   729
            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   730
            data->glEnable(GL_BLEND);
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   731
            if (data->GL_OES_blend_func_separate_supported) {
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   732
                data->glBlendFuncSeparateOES(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE);
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   733
            } else {
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   734
                data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7420
diff changeset
   735
            }
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   736
            break;
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   737
        }
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   738
        data->current.blendMode = blendMode;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   739
    }
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   740
}
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   741
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   742
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   743
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
   744
{
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   745
    if (enabled != data->current.tex_coords) {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   746
        if (enabled) {
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   747
            data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   748
        } else {
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   749
            data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   750
        }
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   751
        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
   752
    }
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   753
}
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   754
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   755
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   756
GLES_SetDrawingState(SDL_Renderer * renderer)
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   757
{
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   758
    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
   759
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   760
    GLES_ActivateRenderer(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   761
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   762
    GLES_SetColor(data, (GLfloat) renderer->r,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   763
                        (GLfloat) renderer->g,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   764
                        (GLfloat) renderer->b,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   765
                        (GLfloat) renderer->a);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   766
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   767
    GLES_SetBlendMode(data, renderer->blendMode);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   768
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   769
    GLES_SetTexCoords(data, SDL_FALSE);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   770
}
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   771
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   772
static int
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   773
GLES_RenderClear(SDL_Renderer * renderer)
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   774
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   775
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   776
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   777
    GLES_ActivateRenderer(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   778
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   779
    data->glClearColor((GLfloat) renderer->r * inv255f,
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   780
                 (GLfloat) renderer->g * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   781
                 (GLfloat) renderer->b * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   782
                 (GLfloat) renderer->a * inv255f);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   783
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   784
    data->glClear(GL_COLOR_BUFFER_BIT);
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   785
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   786
    return 0;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   787
}
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   788
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
   789
static int
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   790
GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   791
                      int count)
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   792
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   793
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   794
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   795
    GLES_SetDrawingState(renderer);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   796
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   797
    data->glVertexPointer(2, GL_FLOAT, 0, points);
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   798
    data->glDrawArrays(GL_POINTS, 0, count);
2964
Sam Lantinga <slouken@libsdl.org>
parents: 2949
diff changeset
   799
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   800
    return 0;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   801
}
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   802
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   803
static int
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   804
GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   805
                     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
   806
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   807
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   808
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   809
    GLES_SetDrawingState(renderer);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   810
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   811
    data->glVertexPointer(2, GL_FLOAT, 0, points);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7173
diff changeset
   812
    if (count > 2 &&
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   813
        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
   814
        /* 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
   815
        --count;
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   816
        data->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
   817
    } else {
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   818
        data->glDrawArrays(GL_LINE_STRIP, 0, count);
6076
e69b1bd26e0b Fixed issues closing lines with the OpenGL ES renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 6075
diff changeset
   819
        /* We need to close the endpoint of the line */
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   820
        data->glDrawArrays(GL_POINTS, count-1, 1);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   821
    }
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
   822
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   823
    return 0;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   824
}
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   825
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   826
static int
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   827
GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects,
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   828
                     int count)
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   829
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   830
    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
   831
    int i;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   832
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   833
    GLES_SetDrawingState(renderer);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   834
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   835
    for (i = 0; i < count; ++i) {
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   836
        const SDL_FRect *rect = &rects[i];
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   837
        GLfloat minx = rect->x;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   838
        GLfloat maxx = rect->x + rect->w;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   839
        GLfloat miny = rect->y;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   840
        GLfloat maxy = rect->y + rect->h;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   841
        GLfloat vertices[8];
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   842
        vertices[0] = minx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   843
        vertices[1] = miny;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   844
        vertices[2] = maxx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   845
        vertices[3] = miny;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   846
        vertices[4] = minx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   847
        vertices[5] = maxy;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   848
        vertices[6] = maxx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   849
        vertices[7] = maxy;
2964
Sam Lantinga <slouken@libsdl.org>
parents: 2949
diff changeset
   850
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   851
        data->glVertexPointer(2, GL_FLOAT, 0, vertices);
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   852
        data->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
   853
    }
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
   854
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   855
    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
   856
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   857
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   858
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
   859
GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   860
                const SDL_Rect * srcrect, const SDL_FRect * 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
   861
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   862
    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
   863
    GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   864
    GLfloat minx, miny, maxx, maxy;
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
   865
    GLfloat minu, maxu, minv, maxv;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   866
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
   867
    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
   868
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   869
    data->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
   870
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   871
    data->glBindTexture(texturedata->type, texturedata->texture);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   872
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
   873
    if (texture->modMode) {
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   874
        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
   875
    } else {
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   876
        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
   877
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   878
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
   879
    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
   880
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   881
    GLES_SetTexCoords(data, SDL_TRUE);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   882
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   883
    if (data->GL_OES_draw_texture_supported && data->useDrawTexture) {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   884
        /* 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
   885
        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
   886
        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
   887
        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
   888
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
   889
        SDL_GetWindowSize(window, &w, &h);
6246
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6237
diff changeset
   890
        if (renderer->target) {
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   891
            cropRect[0] = srcrect->x;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   892
            cropRect[1] = srcrect->y;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   893
            cropRect[2] = srcrect->w;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   894
            cropRect[3] = srcrect->h;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   895
            data->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   896
                                   cropRect);
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   897
            data->glDrawTexfOES(renderer->viewport.x + dstrect->x, renderer->viewport.y + dstrect->y, 0,
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   898
                                dstrect->w, dstrect->h);
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   899
        } else {
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   900
            cropRect[0] = srcrect->x;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   901
            cropRect[1] = srcrect->y + srcrect->h;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   902
            cropRect[2] = srcrect->w;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   903
            cropRect[3] = -srcrect->h;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   904
            data->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   905
                                   cropRect);
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   906
            data->glDrawTexfOES(renderer->viewport.x + dstrect->x,
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   907
                        h - (renderer->viewport.y + dstrect->y) - dstrect->h, 0,
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   908
                        dstrect->w, dstrect->h);
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   909
        }
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   910
    } else {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   911
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   912
        minx = dstrect->x;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   913
        miny = dstrect->y;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   914
        maxx = dstrect->x + dstrect->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   915
        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
   916
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   917
        minu = (GLfloat) srcrect->x / texture->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   918
        minu *= texturedata->texw;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   919
        maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   920
        maxu *= texturedata->texw;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   921
        minv = (GLfloat) srcrect->y / texture->h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   922
        minv *= texturedata->texh;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   923
        maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   924
        maxv *= texturedata->texh;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   925
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   926
        GLfloat vertices[8];
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   927
        GLfloat texCoords[8];
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   928
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   929
        vertices[0] = minx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   930
        vertices[1] = miny;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   931
        vertices[2] = maxx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   932
        vertices[3] = miny;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   933
        vertices[4] = minx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   934
        vertices[5] = maxy;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   935
        vertices[6] = maxx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   936
        vertices[7] = maxy;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   937
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   938
        texCoords[0] = minu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   939
        texCoords[1] = minv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   940
        texCoords[2] = maxu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   941
        texCoords[3] = minv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   942
        texCoords[4] = minu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   943
        texCoords[5] = maxv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   944
        texCoords[6] = maxu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   945
        texCoords[7] = maxv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   946
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   947
        data->glVertexPointer(2, GL_FLOAT, 0, vertices);
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   948
        data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   949
        data->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
   950
    }
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   951
    data->glDisable(GL_TEXTURE_2D);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   952
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
   953
    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
   954
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   955
6043
46d78e48ae8b This code works for OpenGL ES 1.1 as well! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   956
static int
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   957
GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   958
                const SDL_Rect * srcrect, const SDL_FRect * dstrect,
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   959
                const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   960
{
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   961
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   962
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   963
    GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   964
    GLfloat minx, miny, maxx, maxy;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   965
    GLfloat minu, maxu, minv, maxv;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   966
    GLfloat centerx, centery;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7173
diff changeset
   967
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   968
    GLES_ActivateRenderer(renderer);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   969
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   970
    data->glEnable(GL_TEXTURE_2D);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   971
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   972
    data->glBindTexture(texturedata->type, texturedata->texture);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   973
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   974
    if (texture->modMode) {
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   975
        GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   976
    } else {
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   977
        GLES_SetColor(data, 255, 255, 255, 255);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   978
    }
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   979
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   980
    GLES_SetBlendMode(data, texture->blendMode);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   981
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   982
    GLES_SetTexCoords(data, SDL_TRUE);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   983
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   984
    centerx = center->x;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   985
    centery = center->y;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   986
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7173
diff changeset
   987
    /* Rotate and translate */
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   988
    data->glPushMatrix();
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   989
    data->glTranslatef(dstrect->x + centerx, ds