src/render/opengles/SDL_render_gles.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 12 May 2013 13:40:02 +0200
changeset 7169 d27e9ee7310f
parent 7160 bfb5f8f4f006
child 7173 fc45e51373ea
permissions -rw-r--r--
Fixed bug 1844 - glScissor calls are wrong - Patch attached Martin Gerhardy the coordinate system from sdl is not correctly transformed to the coordinate system of opengl. glScissor expects them to be a little bit different. Attached is a patch that fixes this
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",
6237
240f1bced46b Added a renderer flag to expose whether a renderer supports render to texture.
Sam Lantinga <slouken@libsdl.org>
parents: 6232
diff changeset
    99
     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
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;
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   116
#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
   117
#undef SDL_PROC
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   118
    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
   119
    GLES_FBOList *framebuffers;
6271
d1ba86bc57a5 Fixed magenta texture on iOS with OpenGL ES 2.0
Sam Lantinga <slouken@libsdl.org>
parents: 6269
diff changeset
   120
    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
   121
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   122
    SDL_bool useDrawTexture;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   123
    SDL_bool GL_OES_draw_texture_supported;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   124
} 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
   125
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   126
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
   127
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
    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
   129
    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
   130
    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
   131
    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
   132
    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
   133
    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
   134
    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
   135
    int pitch;
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   136
    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
   137
} 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
   138
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   139
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
   140
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
   141
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   142
    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
   143
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   144
    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
   145
    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
   146
        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
   147
        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
   148
    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
   149
        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
   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_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
   152
        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
   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_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
   155
        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
   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_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
   158
        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
   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_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
   161
        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
   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_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
   164
        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
   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
    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
   167
        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
   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
    }
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   170
    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
   171
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   173
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
   174
{
6190
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   175
#if SDL_VIDEO_DRIVER_UIKIT
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   176
#define __SDL_NOGETPROCADDR__
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   177
#elif SDL_VIDEO_DRIVER_ANDROID
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   178
#define __SDL_NOGETPROCADDR__
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   179
#elif SDL_VIDEO_DRIVER_PANDORA
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   180
#define __SDL_NOGETPROCADDR__
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   181
#endif
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   182
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   183
#ifdef __SDL_NOGETPROCADDR__
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   184
#define SDL_PROC(ret,func,params) data->func=func;
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   185
#else
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   186
#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
   187
    do { \
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   188
        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
   189
        if ( ! data->func ) { \
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   190
            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
   191
        } \
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   192
    } while ( 0 );  
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   193
#endif /* _SDL_NOGETPROCADDR_ */
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   194
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   195
#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
   196
#undef SDL_PROC
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   197
    return 0;
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   198
}
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   199
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   200
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
   201
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   202
GLES_FBOList *
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   203
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
   204
{
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   205
   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
   206
   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
   207
   {
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   208
       result = result->next;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   209
   }
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   210
   if (result == NULL)
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   211
   {
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   212
       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
   213
       result->w = w;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   214
       result->h = h;
6269
07e08cb58696 Added glGenFramebuffers() to the function pointer list
Sam Lantinga <slouken@libsdl.org>
parents: 6260
diff changeset
   215
       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
   216
       result->next = data->framebuffers;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   217
       data->framebuffers = result;
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
   return result;
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
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   222
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   223
static int
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   224
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
   225
{
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   226
    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
   227
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   228
    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
   229
        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
   230
            return -1;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   231
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   232
        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
   233
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   234
        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
   235
    }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   236
    return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   237
}
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   238
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   239
/* 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
   240
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   241
GLES_ResetState(SDL_Renderer *renderer)
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   242
{
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   243
    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
   244
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   245
    if (SDL_CurrentContext == data->context) {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   246
        GLES_UpdateViewport(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   247
    } else {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   248
        GLES_ActivateRenderer(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   249
    }
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   250
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   251
    data->current.color = 0;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   252
    data->current.blendMode = -1;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   253
    data->current.tex_coords = SDL_FALSE;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   254
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   255
    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
   256
    data->glDisable(GL_CULL_FACE);
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   257
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   258
    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
   259
    data->glLoadIdentity();
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   260
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   261
    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
   262
    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
   263
}
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   264
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   265
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
   266
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
   267
{
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   268
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
   269
    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
   270
    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
   271
    GLint value;
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   272
    Uint32 windowFlags;
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   273
    
6371
a6b1a0c31880 Switch the OpenGL ES renderers to request EGL OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents: 6320
diff changeset
   274
    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
   275
    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
   276
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   277
    
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   278
    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
   279
    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
   280
        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
   281
            /* 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
   282
            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
   283
            return NULL;
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   284
        }
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   285
    }
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
   286
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   287
    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
   288
    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
   289
        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
   290
        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
   291
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   292
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   293
    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
   294
    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
   295
        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
   296
        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
   297
        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
   298
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
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
   300
    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
   301
    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
   302
    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
   303
    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
   304
    renderer->UnlockTexture = GLES_UnlockTexture;
6247
b6212690f78d Renamed SetTargetTexture() to SetRenderTarget()
Sam Lantinga <slouken@libsdl.org>
parents: 6246
diff changeset
   305
    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
   306
    renderer->UpdateViewport = GLES_UpdateViewport;
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   307
    renderer->UpdateClipRect = GLES_UpdateClipRect;
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   308
    renderer->RenderClear = GLES_RenderClear;
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   309
    renderer->RenderDrawPoints = GLES_RenderDrawPoints;
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   310
    renderer->RenderDrawLines = GLES_RenderDrawLines;
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   311
    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
   312
    renderer->RenderCopy = GLES_RenderCopy;
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   313
    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
   314
    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
   315
    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
   316
    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
   317
    renderer->DestroyRenderer = GLES_DestroyRenderer;
6414
df50b0d6c1c3 Implements SDL_GL_BindTexture and SDL_GL_UnbindTexture (#1576)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6371
diff changeset
   318
    renderer->GL_BindTexture = GLES_BindTexture;
df50b0d6c1c3 Implements SDL_GL_BindTexture and SDL_GL_UnbindTexture (#1576)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6371
diff changeset
   319
    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
   320
    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
   321
    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
   322
    renderer->driverdata = data;
6171
7b9126fde949 Fixed bug 1256 - Invalid window warning in GL_CreateRenderer
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   323
    renderer->window = window;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   324
3688
6512cba48440 Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
   325
    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
   326
    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
   327
        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
   328
        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
   329
    }
3688
6512cba48440 Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
   330
    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
   331
        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
   332
        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
   333
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   334
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   335
    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
   336
        GLES_DestroyRenderer(renderer);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   337
        return NULL;
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   338
    }
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   339
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
    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
   341
        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
   342
    } 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
   343
        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
   344
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   345
    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
   346
        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
   347
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   348
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   349
#if SDL_VIDEO_DRIVER_PANDORA
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   350
    data->GL_OES_draw_texture_supported = SDL_FALSE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   351
    data->useDrawTexture = SDL_FALSE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   352
#else
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   353
    if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   354
        data->GL_OES_draw_texture_supported = SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   355
        data->useDrawTexture = SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   356
    } else {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   357
        data->GL_OES_draw_texture_supported = SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   358
        data->useDrawTexture = SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   359
    }
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   360
#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
   361
6274
246cde9a6cf3 Fixed OpenGL ES 1.1 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6271
diff changeset
   362
    value = 0;
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   363
    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
   364
    renderer->info.max_texture_width = value;
6274
246cde9a6cf3 Fixed OpenGL ES 1.1 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6271
diff changeset
   365
    value = 0;
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   366
    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
   367
    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
   368
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   369
    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
   370
        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
   371
        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
   372
6274
246cde9a6cf3 Fixed OpenGL ES 1.1 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6271
diff changeset
   373
        value = 0;
6271
d1ba86bc57a5 Fixed magenta texture on iOS with OpenGL ES 2.0
Sam Lantinga <slouken@libsdl.org>
parents: 6269
diff changeset
   374
        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
   375
        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
   376
    }
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   377
    data->framebuffers = NULL;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   378
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
   379
    /* Set up parameters for rendering */
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   380
    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
   381
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   382
    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
   383
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   384
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
   385
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
   386
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
   387
{
6190
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   388
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
519380462400 X11 OpenGL ES minor corrections
Sam Lantinga <slouken@libsdl.org>
parents: 6188
diff changeset
   389
    
6260
fd494c5f305b Fixed loading textures when the window starts hidden.
Sam Lantinga <slouken@libsdl.org>
parents: 6247
diff changeset
   390
    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
   391
        event->event == SDL_WINDOWEVENT_SHOWN ||
fd494c5f305b Fixed loading textures when the window starts hidden.
Sam Lantinga <slouken@libsdl.org>
parents: 6247
diff changeset
   392
        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
   393
        /* 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
   394
        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
   395
    }
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
   396
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
   397
    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
   398
        /* 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
   399
        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
   400
    }
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
   401
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   402
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   403
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
   404
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
   405
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   406
    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
   407
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   408
    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
   409
        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
   410
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   411
    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
   412
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   413
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
   414
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
   415
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
   416
{
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   417
    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
   418
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   419
    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
   420
        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
   421
    } 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
   422
        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
   423
    }
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   424
}
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5402
diff changeset
   425
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
   426
static int
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   427
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
   428
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   429
    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
   430
    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
   431
    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
   432
    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
   433
    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
   434
    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
   435
    GLenum result;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2964
diff changeset
   436
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
   437
    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
   438
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   439
    switch (texture->format) {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   440
    case SDL_PIXELFORMAT_ABGR8888:
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   441
        internalFormat = GL_RGBA;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   442
        format = GL_RGBA;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   443
        type = GL_UNSIGNED_BYTE;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   444
        break;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   445
    default:
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   446
        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
   447
    }
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   448
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   449
    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
   450
    if (!data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   451
        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
   452
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   453
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   454
    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
   455
        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
   456
        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
   457
        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
   458
            SDL_free(data);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   459
            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
   460
        }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   461
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   462
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
    texture->driverdata = data;
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   464
    if (texture->access == SDL_TEXTUREACCESS_TARGET) {
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   465
       data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h);
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   466
    } else {
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   467
       data->fbo = NULL;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   468
    }
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
   469
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   470
    renderdata->glGetError();
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   471
    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
   472
    renderdata->glGenTextures(1, &data->texture);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   473
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   474
    data->type = GL_TEXTURE_2D;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   475
    /* no NPOV textures allowed in OpenGL ES (yet) */
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   476
    texture_w = power_of_2(texture->w);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   477
    texture_h = power_of_2(texture->h);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   478
    data->texw = (GLfloat) texture->w / texture_w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   479
    data->texh = (GLfloat) texture->h / texture_h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   480
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
   481
    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
   482
    data->formattype = type;
5503
be88d105e91c The scale mode is per texture, not per texture unit.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
   483
    scaleMode = GetScaleQuality();
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   484
    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
   485
    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
   486
    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
   487
    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
   488
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   489
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   490
    renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   491
                             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
   492
    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
   493
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   494
    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
   495
    if (result != GL_NO_ERROR) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   496
        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
   497
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   498
    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
   499
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   500
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   501
static int
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   502
GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
   503
                   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
   504
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   505
    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
   506
    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
   507
    Uint8 *blob = NULL;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   508
    Uint8 *src;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   509
    int srcPitch;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   510
    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
   511
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
   512
    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
   513
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   514
    /* 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
   515
    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
   516
        return 0;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   517
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   518
    /* 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
   519
    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
   520
    src = (Uint8 *)pixels;
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   521
    if (pitch != srcPitch) {
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   522
        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
   523
        if (!blob) {
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   524
            return SDL_OutOfMemory();
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   525
        }
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   526
        src = blob;
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   527
        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
   528
            SDL_memcpy(src, pixels, srcPitch);
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   529
            src += srcPitch;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   530
            pixels = (Uint8 *)pixels + pitch;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   531
        }
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   532
        src = blob;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   533
    }
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   534
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   535
    /* 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
   536
    renderdata->glGetError();
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   537
    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
   538
    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
   539
    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
   540
    renderdata->glTexSubImage2D(data->type,
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   541
                    0,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   542
                    rect->x,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   543
                    rect->y,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   544
                    rect->w,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   545
                    rect->h,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   546
                    data->format,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   547
                    data->formattype,
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   548
                    src);
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   549
    if (blob) {
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   550
        SDL_free(blob);
5052
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
   551
    }
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
   552
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   553
    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
   554
    {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6954
diff changeset
   555
        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
   556
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   557
    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
   558
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   559
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   560
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
   561
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
   562
                 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
   563
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   564
    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
   565
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   566
    *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
   567
        (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
   568
                  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
   569
    *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
   570
    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
   571
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   572
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   573
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
   574
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
   575
{
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
   576
    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
   577
    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
   578
5227
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   579
    /* 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
   580
    rect.x = 0;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   581
    rect.y = 0;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   582
    rect.w = texture->w;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   583
    rect.h = texture->h;
9c0c4d767ef6 Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
   584
    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
   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
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   587
static int
6247
b6212690f78d Renamed SetTargetTexture() to SetRenderTarget()
Sam Lantinga <slouken@libsdl.org>
parents: 6246
diff changeset
   588
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
   589
{
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
   590
    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
   591
    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
   592
    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
   593
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
   594
    GLES_ActivateRenderer(renderer);
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
   595
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
   596
    if (texture == NULL) {
6271
d1ba86bc57a5 Fixed magenta texture on iOS with OpenGL ES 2.0
Sam Lantinga <slouken@libsdl.org>
parents: 6269
diff changeset
   597
        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
   598
        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
   599
    }
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
   600
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
   601
    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
   602
    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
   603
    /* 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
   604
    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
   605
    /* 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
   606
    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
   607
    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
   608
        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
   609
    }
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
   610
    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
   611
}
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
   612
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
   613
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
   614
GLES_UpdateViewport(SDL_Renderer * renderer)
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   615
{
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   616
    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
   617
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   618
    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
   619
        /* 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
   620
        return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   621
    }
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   622
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   623
    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
   624
               renderer->viewport.w, renderer->viewport.h);
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   625
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   626
    data->glMatrixMode(GL_PROJECTION);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   627
    data->glLoadIdentity();
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   628
    data->glOrthof((GLfloat) 0,
6075
a682a5c9a941 Fixed an offset issue with glDrawTexiOES() when the viewport is set.
Sam Lantinga <slouken@libsdl.org>
parents: 6060
diff changeset
   629
             (GLfloat) renderer->viewport.w,
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   630
             (GLfloat) renderer->viewport.h,
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   631
             (GLfloat) 0, 0.0, 1.0);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
   632
    return 0;
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   633
}
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   634
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   635
static int
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   636
GLES_UpdateClipRect(SDL_Renderer * renderer)
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   637
{
7160
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   638
    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
   639
    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
   640
7160
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   641
    if (SDL_CurrentContext != data->context) {
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   642
        /* 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
   643
        return 0;
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   644
    }
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   645
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   646
    if (!SDL_RectEmpty(rect)) {
7160
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   647
        data->glEnable(GL_SCISSOR_TEST);
7169
d27e9ee7310f Fixed bug 1844 - glScissor calls are wrong - Patch attached
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7160
diff changeset
   648
        int lowerLeft = renderer->viewport.h - rect->y - rect->h;
d27e9ee7310f Fixed bug 1844 - glScissor calls are wrong - Patch attached
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7160
diff changeset
   649
        data->glScissor(rect->x, lowerLeft, rect->w, rect->h);
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   650
    } else {
7160
bfb5f8f4f006 Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7141
diff changeset
   651
        data->glDisable(GL_SCISSOR_TEST);
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   652
    }
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   653
    return 0;
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   654
}
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   655
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   656
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   657
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
   658
{
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   659
    Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b);
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   660
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   661
    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
   662
        data->glColor4f((GLfloat) r * inv255f,
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   663
                        (GLfloat) g * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   664
                        (GLfloat) b * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   665
                        (GLfloat) a * inv255f);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   666
        data->current.color = color;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   667
    }
5333
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   668
}
5d3a2cd4e8c9 Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents: 5330
diff changeset
   669
5224
2178ffe17222 Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents: 5209
diff changeset
   670
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
   671
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
   672
{
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   673
    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
   674
        switch (blendMode) {
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   675
        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
   676
            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
   677
            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
   678
            break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   679
        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
   680
            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
   681
            data->glEnable(GL_BLEND);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   682
            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   683
            break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   684
        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
   685
            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
   686
            data->glEnable(GL_BLEND);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   687
            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   688
            break;
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   689
        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
   690
            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
   691
            data->glEnable(GL_BLEND);
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   692
            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   693
            break;
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   694
        }
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   695
        data->current.blendMode = blendMode;
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   696
    }
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   697
}
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   698
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   699
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   700
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
   701
{
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   702
    if (enabled != data->current.tex_coords) {
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   703
        if (enabled) {
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   704
            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
   705
        } else {
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   706
            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
   707
        }
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   708
        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
   709
    }
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   710
}
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   711
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   712
static void
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   713
GLES_SetDrawingState(SDL_Renderer * renderer)
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   714
{
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   715
    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
   716
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   717
    GLES_ActivateRenderer(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   718
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   719
    GLES_SetColor(data, (GLfloat) renderer->r,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   720
                        (GLfloat) renderer->g,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   721
                        (GLfloat) renderer->b,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   722
                        (GLfloat) renderer->a);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   723
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   724
    GLES_SetBlendMode(data, renderer->blendMode);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   725
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   726
    GLES_SetTexCoords(data, SDL_FALSE);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   727
}
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   728
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   729
static int
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   730
GLES_RenderClear(SDL_Renderer * renderer)
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   731
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   732
    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
   733
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   734
    GLES_ActivateRenderer(renderer);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   735
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   736
    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
   737
                 (GLfloat) renderer->g * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   738
                 (GLfloat) renderer->b * inv255f,
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   739
                 (GLfloat) renderer->a * inv255f);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   740
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   741
    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
   742
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   743
    return 0;
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
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
   746
static int
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   747
GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   748
                      int count)
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   749
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   750
    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
   751
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   752
    GLES_SetDrawingState(renderer);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   753
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   754
    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
   755
    data->glDrawArrays(GL_POINTS, 0, count);
2964
Sam Lantinga <slouken@libsdl.org>
parents: 2949
diff changeset
   756
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   757
    return 0;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   758
}
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   759
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   760
static int
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   761
GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   762
                     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
   763
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   764
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   765
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   766
    GLES_SetDrawingState(renderer);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   767
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   768
    data->glVertexPointer(2, GL_FLOAT, 0, points);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   769
    if (count > 2 && 
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   770
        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
   771
        /* 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
   772
        --count;
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   773
        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
   774
    } else {
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   775
        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
   776
        /* 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
   777
        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
   778
    }
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
   779
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   780
    return 0;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   781
}
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   782
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   783
static int
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   784
GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects,
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
   785
                     int count)
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
   786
{
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   787
    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
   788
    int i;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   789
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   790
    GLES_SetDrawingState(renderer);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   791
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   792
    for (i = 0; i < count; ++i) {
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   793
        const SDL_FRect *rect = &rects[i];
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   794
        GLfloat minx = rect->x;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   795
        GLfloat maxx = rect->x + rect->w;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   796
        GLfloat miny = rect->y;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   797
        GLfloat maxy = rect->y + rect->h;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   798
        GLfloat vertices[8];
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   799
        vertices[0] = minx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   800
        vertices[1] = miny;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   801
        vertices[2] = maxx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   802
        vertices[3] = miny;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   803
        vertices[4] = minx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   804
        vertices[5] = maxy;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   805
        vertices[6] = maxx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   806
        vertices[7] = maxy;
2964
Sam Lantinga <slouken@libsdl.org>
parents: 2949
diff changeset
   807
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   808
        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
   809
        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
   810
    }
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
   811
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   812
    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
   813
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   814
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   815
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
   816
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
   817
                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
   818
{
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   819
    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
   820
    GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   821
    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
   822
    GLfloat minu, maxu, minv, maxv;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   823
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
   824
    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
   825
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   826
    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
   827
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   828
    data->glBindTexture(texturedata->type, texturedata->texture);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   829
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
   830
    if (texture->modMode) {
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   831
        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
   832
    } else {
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   833
        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
   834
    }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   835
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
   836
    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
   837
5355
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   838
    GLES_SetTexCoords(data, SDL_TRUE);
cc2215cda170 Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents: 5333
diff changeset
   839
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   840
    if (data->GL_OES_draw_texture_supported && data->useDrawTexture) {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   841
        /* 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
   842
        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
   843
        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
   844
        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
   845
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
   846
        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
   847
        if (renderer->target) {
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   848
            cropRect[0] = srcrect->x;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   849
            cropRect[1] = srcrect->y;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   850
            cropRect[2] = srcrect->w;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   851
            cropRect[3] = srcrect->h;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   852
            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
   853
                                   cropRect);
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   854
            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
   855
                                dstrect->w, dstrect->h);
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   856
        } else {
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   857
            cropRect[0] = srcrect->x;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   858
            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
   859
            cropRect[2] = srcrect->w;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   860
            cropRect[3] = -srcrect->h;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   861
            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
   862
                                   cropRect);
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   863
            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
   864
                        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
   865
                        dstrect->w, dstrect->h);
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6190
diff changeset
   866
        }
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   867
    } else {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   868
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   869
        minx = dstrect->x;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   870
        miny = dstrect->y;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   871
        maxx = dstrect->x + dstrect->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   872
        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
   873
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   874
        minu = (GLfloat) srcrect->x / texture->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   875
        minu *= texturedata->texw;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   876
        maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   877
        maxu *= texturedata->texw;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   878
        minv = (GLfloat) srcrect->y / texture->h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   879
        minv *= texturedata->texh;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   880
        maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   881
        maxv *= texturedata->texh;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   882
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   883
        GLfloat vertices[8];
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   884
        GLfloat texCoords[8];
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   885
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   886
        vertices[0] = minx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   887
        vertices[1] = miny;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   888
        vertices[2] = maxx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   889
        vertices[3] = miny;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   890
        vertices[4] = minx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   891
        vertices[5] = maxy;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   892
        vertices[6] = maxx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   893
        vertices[7] = maxy;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   894
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   895
        texCoords[0] = minu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   896
        texCoords[1] = minv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   897
        texCoords[2] = maxu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   898
        texCoords[3] = minv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   899
        texCoords[4] = minu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   900
        texCoords[5] = maxv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   901
        texCoords[6] = maxu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   902
        texCoords[7] = maxv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   903
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   904
        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
   905
        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
   906
        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
   907
    }
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6171
diff changeset
   908
    data->glDisable(GL_TEXTURE_2D);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
   909
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
   910
    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
   911
}
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
   912
6043
46d78e48ae8b This code works for OpenGL ES 1.1 as well! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   913
static int
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   914
GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   915
                const SDL_Rect * srcrect, const SDL_FRect * dstrect,
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   916
                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
   917
{
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   918
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   919
    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   920
    GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   921
    GLfloat minx, miny, maxx, maxy;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   922
    GLfloat minu, maxu, minv, maxv;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   923
    GLfloat centerx, centery;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   924
    
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   925
    GLES_ActivateRenderer(renderer);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   926
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   927
    data->glEnable(GL_TEXTURE_2D);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   928
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   929
    data->glBindTexture(texturedata->type, texturedata->texture);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   930
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   931
    if (texture->modMode) {
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   932
        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
   933
    } else {
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   934
        GLES_SetColor(data, 255, 255, 255, 255);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   935
    }
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   936
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   937
    GLES_SetBlendMode(data, texture->blendMode);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   938
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   939
    GLES_SetTexCoords(data, SDL_TRUE);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   940
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   941
    centerx = center->x;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   942
    centery = center->y;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   943
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   944
    // Rotate and translate
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   945
    data->glPushMatrix();
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   946
    data->glTranslatef(dstrect->x + centerx, dstrect->y + centery, 0.0f);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   947
    data->glRotatef((GLfloat)angle, 0.0f, 0.0f, 1.0f);
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   948
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   949
    if (flip & SDL_FLIP_HORIZONTAL) {
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   950
        minx =  dstrect->w - centerx;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   951
        maxx = -centerx;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   952
    } else {
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   953
        minx = -centerx;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   954
        maxx = dstrect->w - centerx;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   955
    }
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   956
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   957
    if (flip & SDL_FLIP_VERTICAL) {
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   958
        miny = dstrect->h - centery;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   959
        maxy = -centery;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   960
    } else {
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   961
        miny = -centery;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   962
        maxy = dstrect->h - centery;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   963
    }
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   964
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   965
    minu = (GLfloat) srcrect->x / texture->w;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   966
    minu *= texturedata->texw;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   967
    maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   968
    maxu *= texturedata->texw;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   969
    minv = (GLfloat) srcrect->y / texture->h;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   970
    minv *= texturedata->texh;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   971
    maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   972
    maxv *= texturedata->texh;
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
    GLfloat vertices[8];
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   975
    GLfloat texCoords[8];
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   976
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   977
    vertices[0] = minx;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   978
    vertices[1] = miny;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   979
    vertices[2] = maxx;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   980
    vertices[3] = miny;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   981
    vertices[4] = minx;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   982
    vertices[5] = maxy;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   983
    vertices[6] = maxx;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   984
    vertices[7] = maxy;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   985
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   986
    texCoords[0] = minu;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   987
    texCoords[1] = minv;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   988
    texCoords[2] = maxu;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   989
    texCoords[3] = minv;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   990
    texCoords[4] = minu;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   991
    texCoords[5] = maxv;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   992
    texCoords[6] = maxu;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff changeset
   993
    texCoords[7] = maxv;
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6414
diff cha