annotate src/render/opengles/SDL_renderer_gles.c @ 5157: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.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 02 Feb 2011 14:34:54 -0800
parents src/video/SDL_renderer_gles.c@1435f8a6425c
children 307ccc9c135e
rev   line source
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
1 /*
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3688
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
4
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
9
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
13 Lesser General Public License for more details.
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
14
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
18
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
19 Sam Lantinga
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
20 slouken@libsdl.org
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
21 */
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
22 #include "SDL_config.h"
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
23
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 #if SDL_VIDEO_RENDER_OGL_ES
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
25
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
26 #include "SDL_opengles.h"
5157
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: 5153
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
5153
1435f8a6425c Nobody is currently maintaining the QNX code, so removing it for now.
Sam Lantinga <slouken@libsdl.org>
parents: 5152
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
5153
1435f8a6425c Nobody is currently maintaining the QNX code, so removing it for now.
Sam Lantinga <slouken@libsdl.org>
parents: 5152
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
5157
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: 5153
diff changeset
43 /* Used to re-create the window with OpenGL capability */
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: 5153
diff changeset
44 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
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: 5153
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);
5150
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: 5145
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: 5145
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_QueryTexturePixels(SDL_Renderer * renderer,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
53 SDL_Texture * texture, 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_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
56 const SDL_Rect * rect, const void *pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
57 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
58 static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
59 const SDL_Rect * rect, int markDirty,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
60 void **pixels, int *pitch);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
61 static void GLES_UnlockTexture(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
62 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
63 static void GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
64 int numrects, const SDL_Rect * rects);
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
65 static int GLES_RenderDrawPoints(SDL_Renderer * renderer,
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
66 const SDL_Point * points, int count);
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
67 static int GLES_RenderDrawLines(SDL_Renderer * renderer,
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
68 const SDL_Point * points, int count);
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
69 static int GLES_RenderFillRects(SDL_Renderer * renderer,
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
70 const SDL_Rect ** rects, int count);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
71 static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
72 const SDL_Rect * srcrect,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
73 const SDL_Rect * dstrect);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
74 static void GLES_RenderPresent(SDL_Renderer * renderer);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
75 static void GLES_DestroyTexture(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
76 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
77 static void GLES_DestroyRenderer(SDL_Renderer * renderer);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
78
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
79
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
80 SDL_RenderDriver GL_ES_RenderDriver = {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 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
82 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
83 "opengl_es",
5145
c8e049de174c Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents: 5144
diff changeset
84 (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
5157
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: 5153
diff changeset
85 6,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
86 {
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
87 /* OpenGL ES 1.x supported formats list */
4985
047a580d30f3 Fixed blue-red channel swap in OpenGL ES 16-bit texture formats
Sam Lantinga <slouken@libsdl.org>
parents: 4963
diff changeset
88 SDL_PIXELFORMAT_RGBA4444,
047a580d30f3 Fixed blue-red channel swap in OpenGL ES 16-bit texture formats
Sam Lantinga <slouken@libsdl.org>
parents: 4963
diff changeset
89 SDL_PIXELFORMAT_RGBA5551,
047a580d30f3 Fixed blue-red channel swap in OpenGL ES 16-bit texture formats
Sam Lantinga <slouken@libsdl.org>
parents: 4963
diff changeset
90 SDL_PIXELFORMAT_RGB565,
4963
604077962776 Fixed screen texture format on Android
Sam Lantinga <slouken@libsdl.org>
parents: 4929
diff changeset
91 SDL_PIXELFORMAT_RGB24,
604077962776 Fixed screen texture format on Android
Sam Lantinga <slouken@libsdl.org>
parents: 4929
diff changeset
92 SDL_PIXELFORMAT_BGR888,
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
93 SDL_PIXELFORMAT_ABGR8888},
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
94 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
95 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
96 };
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
97
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
98 typedef struct
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
99 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
100 SDL_GLContext 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
101 SDL_bool updateSize;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
102 int blendMode;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
103
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
104 #ifndef APIENTRY
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 #define APIENTRY
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 #endif
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
107
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
108 SDL_bool useDrawTexture;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
109 SDL_bool GL_OES_draw_texture_supported;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
110
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
111 /* OpenGL ES functions */
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
112 #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
113 #include "SDL_glesfuncs.h"
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
114 #undef SDL_PROC
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
115
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
116 } 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
117
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
118 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
119 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 int 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
128 SDL_DirtyRectList dirty;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 } 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
130
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
131 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
132 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
133 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 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
135
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 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
161 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 SDL_SetError("%s: %s", prefix, error);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
163 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 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
166 GLES_LoadFunctions(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
167 {
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
168
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
169 #define SDL_PROC(ret,func,params) \
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
170 data->func = func;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
171 #include "SDL_glesfuncs.h"
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
172 #undef SDL_PROC
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
173
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
174 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
175 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
176
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
177 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
178 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
179 {
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
180
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
181 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
182 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
183 GLint value;
5157
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: 5153
diff changeset
184 Uint32 window_flags;
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
185
5157
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: 5153
diff changeset
186 window_flags = SDL_GetWindowFlags(window);
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: 5153
diff changeset
187 if (!(window_flags & SDL_WINDOW_OPENGL)) {
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: 5153
diff changeset
188 if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 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
189 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
190 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
191 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
192
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
193 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
194 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
195 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
196 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
197 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
198
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
199 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
200 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
201 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
202 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
203 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
204 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
205
5150
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: 5145
diff changeset
206 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
207 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
208 renderer->QueryTexturePixels = GLES_QueryTexturePixels;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
209 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
210 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
211 renderer->UnlockTexture = GLES_UnlockTexture;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
212 renderer->DirtyTexture = GLES_DirtyTexture;
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
213 renderer->RenderDrawPoints = GLES_RenderDrawPoints;
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
214 renderer->RenderDrawLines = GLES_RenderDrawLines;
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
215 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
216 renderer->RenderCopy = GLES_RenderCopy;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
217 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
218 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
219 renderer->DestroyRenderer = GLES_DestroyRenderer;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
220 renderer->info = GL_ES_RenderDriver.info;
3688
6512cba48440 Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
221 renderer->window = 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
222 renderer->driverdata = data;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
223
5145
c8e049de174c Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents: 5144
diff changeset
224 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
225
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
226 if (GLES_LoadFunctions(data) < 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
227 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
228 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
229 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
230
3688
6512cba48440 Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
231 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
232 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
233 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
234 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
235 }
3688
6512cba48440 Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
236 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
237 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
238 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
239 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
240
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
241 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
242 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
243 } 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
244 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
245 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
246 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
247 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
248 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
249
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
250 #if SDL_VIDEO_DRIVER_PANDORA
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
251 data->GL_OES_draw_texture_supported = SDL_FALSE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
252 data->useDrawTexture = SDL_FALSE;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
253 #else
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
254 if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
255 data->GL_OES_draw_texture_supported = SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
256 data->useDrawTexture = SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
257 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
258 data->GL_OES_draw_texture_supported = SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
259 data->useDrawTexture = SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
260 }
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
261 #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
262
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
263 data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &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
264 renderer->info.max_texture_width = 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
265 data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &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
266 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
267
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
268 /* Set up parameters for rendering */
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 data->blendMode = -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
270 data->glDisable(GL_DEPTH_TEST);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 data->glDisable(GL_CULL_FACE);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
272 data->updateSize = SDL_TRUE;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
273
5053
b5b42be9333c Fixed bug #1026
Sam Lantinga <slouken@libsdl.org>
parents: 5052
diff changeset
274 data->glEnableClientState(GL_VERTEX_ARRAY);
b5b42be9333c Fixed bug #1026
Sam Lantinga <slouken@libsdl.org>
parents: 5052
diff changeset
275 data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
b5b42be9333c Fixed bug #1026
Sam Lantinga <slouken@libsdl.org>
parents: 5052
diff changeset
276
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
277 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
278 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
279
5150
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: 5145
diff changeset
280 static SDL_GLContext 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: 5145
diff changeset
281
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
282 static int
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
283 GLES_ActivateRenderer(SDL_Renderer * renderer)
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
284 {
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
285
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
286 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
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
287 SDL_Window *window = renderer->window;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
288
5150
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: 5145
diff changeset
289 if (SDL_CurrentContext != data->context) {
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: 5145
diff changeset
290 if (SDL_GL_MakeCurrent(window, data->context) < 0) {
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: 5145
diff changeset
291 return -1;
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: 5145
diff changeset
292 }
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: 5145
diff changeset
293 SDL_CurrentContext = data->context;
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
294 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
295 if (data->updateSize) {
5157
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: 5153
diff changeset
296 int w, h;
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: 5153
diff changeset
297
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: 5153
diff changeset
298 SDL_GetWindowSize(window, &w, &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
299 data->glMatrixMode(GL_PROJECTION);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
300 data->glLoadIdentity();
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 data->glMatrixMode(GL_MODELVIEW);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
302 data->glLoadIdentity();
5157
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: 5153
diff changeset
303 data->glViewport(0, 0, w, h);
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: 5153
diff changeset
304 data->glOrthof(0.0, (GLfloat) w, (GLfloat) h, 0.0, 0.0, 1.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
305 data->updateSize = SDL_FALSE;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
306 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
307 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
308 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
309
5150
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: 5145
diff changeset
310 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: 5145
diff changeset
311 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
312 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
313 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
314
5150
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: 5145
diff changeset
315 if (event->event == SDL_WINDOWEVENT_RESIZED) {
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: 5145
diff changeset
316 /* 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: 5145
diff changeset
317 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: 5145
diff changeset
318 data->updateSize = SDL_TRUE;
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: 5145
diff changeset
319 }
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
320 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
321
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
322 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
323 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
324 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
325 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
326
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 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
328 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
329 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
330 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
331 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
332
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
333 static int
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
334 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
335 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
336 GLES_RenderData *renderdata = (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
337 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
338 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
339 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
340 int texture_w, texture_h;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
341 GLenum result;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2964
diff changeset
342
5150
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: 5145
diff changeset
343 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: 5145
diff changeset
344
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
345 switch (texture->format) {
4963
604077962776 Fixed screen texture format on Android
Sam Lantinga <slouken@libsdl.org>
parents: 4929
diff changeset
346 case SDL_PIXELFORMAT_RGB24:
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
347 internalFormat = GL_RGB;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
348 format = GL_RGB;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
349 type = GL_UNSIGNED_BYTE;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
350 break;
4963
604077962776 Fixed screen texture format on Android
Sam Lantinga <slouken@libsdl.org>
parents: 4929
diff changeset
351 case SDL_PIXELFORMAT_BGR888:
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
352 case SDL_PIXELFORMAT_ABGR8888:
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
353 internalFormat = GL_RGBA;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
354 format = GL_RGBA;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
355 type = GL_UNSIGNED_BYTE;
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
356 break;
4985
047a580d30f3 Fixed blue-red channel swap in OpenGL ES 16-bit texture formats
Sam Lantinga <slouken@libsdl.org>
parents: 4963
diff changeset
357 case SDL_PIXELFORMAT_RGB565:
3163
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
358 internalFormat = GL_RGB;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
359 format = GL_RGB;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
360 type = GL_UNSIGNED_SHORT_5_6_5;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
361 break;
4985
047a580d30f3 Fixed blue-red channel swap in OpenGL ES 16-bit texture formats
Sam Lantinga <slouken@libsdl.org>
parents: 4963
diff changeset
362 case SDL_PIXELFORMAT_RGBA5551:
3163
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
363 internalFormat = GL_RGBA;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
364 format = GL_RGBA;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
365 type = GL_UNSIGNED_SHORT_5_5_5_1;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
366 break;
4985
047a580d30f3 Fixed blue-red channel swap in OpenGL ES 16-bit texture formats
Sam Lantinga <slouken@libsdl.org>
parents: 4963
diff changeset
367 case SDL_PIXELFORMAT_RGBA4444:
3163
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
368 internalFormat = GL_RGBA;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
369 format = GL_RGBA;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
370 type = GL_UNSIGNED_SHORT_4_4_4_4;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 3161
diff changeset
371 break;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
372 default:
4990
397e748d901a Improved error message for unsupported texture format
Sam Lantinga <slouken@libsdl.org>
parents: 4986
diff changeset
373 SDL_SetError("Texture format %s not supported by OpenGL ES",
397e748d901a Improved error message for unsupported texture format
Sam Lantinga <slouken@libsdl.org>
parents: 4986
diff changeset
374 SDL_GetPixelFormatName(texture->format));
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
375 return -1;
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
376 }
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
377
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
378 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
379 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
380 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
381 return -1;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
382 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 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
385 data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
386 data->pixels = SDL_malloc(texture->h * data->pitch);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
387 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
388 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
389 SDL_free(data);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
390 return -1;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
391 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
392 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
393
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
394 texture->driverdata = data;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
395
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
396 renderdata->glGetError();
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
397 renderdata->glEnable(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
398 renderdata->glGenTextures(1, &data->texture);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
399
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
400 data->type = GL_TEXTURE_2D;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
401 /* no NPOV textures allowed in OpenGL ES (yet) */
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
402 texture_w = power_of_2(texture->w);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
403 texture_h = power_of_2(texture->h);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
404 data->texw = (GLfloat) texture->w / texture_w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
405 data->texh = (GLfloat) texture->h / texture_h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
406
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
407 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
408 data->formattype = 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
409 renderdata->glBindTexture(data->type, data->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
410 renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
5141
da10636e5eca Making the API simpler, scaling is always defined as linear interpolation and should be supported as much as possible on all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5053
diff changeset
411 GL_LINEAR);
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
412 renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
5141
da10636e5eca Making the API simpler, scaling is always defined as linear interpolation and should be supported as much as possible on all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5053
diff changeset
413 GL_LINEAR);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
414 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
415 GL_CLAMP_TO_EDGE);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
416 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
417 GL_CLAMP_TO_EDGE);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
418
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
419 renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
420 texture_h, 0, format, type, NULL);
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
421 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
422
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
423 result = renderdata->glGetError();
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
424 if (result != GL_NO_ERROR) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
425 GLES_SetError("glTexImage2D()", result);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
426 return -1;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
427 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
428 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
429 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 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
432 GLES_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
433 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
434 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 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
436
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
437 *pixels = 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
438 *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
439 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
440 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
441
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
442 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
443 SetupTextureUpdate(GLES_RenderData * renderdata, 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
444 int 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
445 {
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
446 GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
447 renderdata->glBindTexture(data->type, data->texture);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
448 renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 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
449 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
451 static int
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
452 GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
453 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
454 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 GLES_RenderData *renderdata = (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
456 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
457 GLenum result;
5052
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
458 int bpp = SDL_BYTESPERPIXEL(texture->format);
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
459 void * temp_buffer;
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
460 void * temp_ptr;
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
461 int i;
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
462
5150
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: 5145
diff changeset
463 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: 5145
diff changeset
464
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
465 renderdata->glGetError();
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
466 renderdata->glEnable(data->type);
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
467 SetupTextureUpdate(renderdata, texture, pitch);
5052
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
468
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
469 if( rect->w * bpp == pitch ) {
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
470 temp_buffer = (void *)pixels; /* No need to reformat */
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
471 } else {
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
472 /* Reformatting of mem area required */
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
473 temp_buffer = SDL_malloc(rect->w * rect->h * bpp);
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
474 temp_ptr = temp_buffer;
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
475 for (i = 0; i < rect->h; i++) {
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
476 SDL_memcpy(temp_ptr, pixels, rect->w * bpp);
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
477 temp_ptr += rect->w * bpp;
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
478 pixels += pitch;
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
479 }
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
480 }
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
481
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
482 renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
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
483 rect->h, data->format, data->formattype,
5052
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
484 temp_buffer);
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
485
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
486 if( temp_buffer != pixels ) {
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
487 SDL_free(temp_buffer);
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
488 }
4cb4b18cbae3 Fixed bug #1028
Sam Lantinga <slouken@libsdl.org>
parents: 4990
diff changeset
489
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
490 renderdata->glDisable(data->type);
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
491 result = renderdata->glGetError();
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
492 if (result != GL_NO_ERROR) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
493 GLES_SetError("glTexSubImage2D()", 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
494 return -1;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
495 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
496 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
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
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 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
500 GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
501 const SDL_Rect * rect, int markDirty, void **pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
502 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
503 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 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
505
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 if (markDirty) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
507 SDL_AddDirtyRect(&data->dirty, rect);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
508 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
509
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
510 *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
511 (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
512 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
513 *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
514 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
515 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
516
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
517 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
518 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
519 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
520 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
521
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
522 static void
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
523 GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
524 int numrects, const SDL_Rect * rects)
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
525 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
526 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
527 int i;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
528
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
529 for (i = 0; i < numrects; ++i) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
530 SDL_AddDirtyRect(&data->dirty, &rects[i]);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
531 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
532 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
533
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
534 static void
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
535 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
536 {
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
537 if (blendMode != data->blendMode) {
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
538 switch (blendMode) {
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
539 case SDL_BLENDMODE_NONE:
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
540 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
541 data->glDisable(GL_BLEND);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
542 break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
543 case SDL_BLENDMODE_BLEND:
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
544 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
545 data->glEnable(GL_BLEND);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
546 data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
547 break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
548 case SDL_BLENDMODE_ADD:
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
549 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
550 data->glEnable(GL_BLEND);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
551 data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
552 break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
553 }
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
554 data->blendMode = blendMode;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
555 }
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
556 }
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
557
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
558 static int
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
559 GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
560 int count)
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
561 {
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
562 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
563 int i;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
564 GLshort *vertices;
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
565
5150
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: 5145
diff changeset
566 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: 5145
diff changeset
567
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
568 GLES_SetBlendMode(data, renderer->blendMode);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
569
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
570 data->glColor4f((GLfloat) renderer->r * inv255f,
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
571 (GLfloat) renderer->g * inv255f,
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
572 (GLfloat) renderer->b * inv255f,
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
573 (GLfloat) renderer->a * inv255f);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
574
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
575 vertices = SDL_stack_alloc(GLshort, count*2);
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
576 for (i = 0; i < count; ++i) {
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
577 vertices[2*i+0] = (GLshort)points[i].x;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
578 vertices[2*i+1] = (GLshort)points[i].y;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
579 }
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
580 data->glVertexPointer(2, GL_SHORT, 0, vertices);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
581 data->glDrawArrays(GL_POINTS, 0, count);
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
582 SDL_stack_free(vertices);
2964
Sam Lantinga <slouken@libsdl.org>
parents: 2949
diff changeset
583
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
584 return 0;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
585 }
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
586
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
587 static int
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
588 GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
589 int count)
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
590 {
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
591 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
592 int i;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
593 GLshort *vertices;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
594
5150
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: 5145
diff changeset
595 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: 5145
diff changeset
596
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
597 GLES_SetBlendMode(data, renderer->blendMode);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
598
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
599 data->glColor4f((GLfloat) renderer->r * inv255f,
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
600 (GLfloat) renderer->g * inv255f,
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
601 (GLfloat) renderer->b * inv255f,
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
602 (GLfloat) renderer->a * inv255f);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
603
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
604 vertices = SDL_stack_alloc(GLshort, count*2);
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
605 for (i = 0; i < count; ++i) {
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
606 vertices[2*i+0] = (GLshort)points[i].x;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
607 vertices[2*i+1] = (GLshort)points[i].y;
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
608 }
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
609 data->glVertexPointer(2, GL_SHORT, 0, vertices);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
610 if (count > 2 &&
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
611 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
612 /* 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
613 --count;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
614 data->glDrawArrays(GL_LINE_LOOP, 0, count);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
615 } else {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
616 data->glDrawArrays(GL_LINE_STRIP, 0, count);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
617 }
3547
8b18669c2663 Fixed building on iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
618 SDL_stack_free(vertices);
2949
4eabc35fbb4a Modified OpenGL ES render driver to support new SDL_RenderFill, SDL_RenderLine, and SDL_RenderPoint.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents: 2937
diff changeset
619
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
620 return 0;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
621 }
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
622
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
623 static int
3641
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
624 GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
1e2e19d51265 Fixed iPhone build
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
625 int count)
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
626 {
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
627 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
628 int i;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
629
5150
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: 5145
diff changeset
630 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: 5145
diff changeset
631
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
632 GLES_SetBlendMode(data, renderer->blendMode);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
633
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
634 data->glColor4f((GLfloat) renderer->r * inv255f,
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
635 (GLfloat) renderer->g * inv255f,
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
636 (GLfloat) renderer->b * inv255f,
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
637 (GLfloat) renderer->a * inv255f);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
638
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
639 for (i = 0; i < count; ++i) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
640 const SDL_Rect *rect = rects[i];
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
641 GLshort minx = rect->x;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
642 GLshort maxx = rect->x + rect->w;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
643 GLshort miny = rect->y;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
644 GLshort maxy = rect->y + rect->h;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
645 GLshort vertices[8];
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
646 vertices[0] = minx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
647 vertices[1] = miny;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
648 vertices[2] = maxx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
649 vertices[3] = miny;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
650 vertices[4] = minx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
651 vertices[5] = maxy;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
652 vertices[6] = maxx;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
653 vertices[7] = maxy;
2964
Sam Lantinga <slouken@libsdl.org>
parents: 2949
diff changeset
654
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
655 data->glVertexPointer(2, GL_SHORT, 0, vertices);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
656 data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
657 }
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
658
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
659 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
660 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
661
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
662 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
663 GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
664 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
665 {
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
666
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
667 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
668 GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
669 int minx, miny, maxx, maxy;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
670 GLfloat minu, maxu, minv, maxv;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
671 int i;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
672 void *temp_buffer; /* used for reformatting dirty rect pixels */
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
673 void *temp_ptr;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
674
5150
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: 5145
diff changeset
675 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: 5145
diff changeset
676
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
677 data->glEnable(GL_TEXTURE_2D);
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
678
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
679 if (texturedata->dirty.list) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
680 SDL_DirtyRect *dirty;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
681 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
682 int bpp = 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
683 int pitch = texturedata->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
684
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
685 SetupTextureUpdate(data, texture, pitch);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
686
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
687 data->glBindTexture(texturedata->type, texturedata->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
688 for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
689 SDL_Rect *rect = &dirty->rect;
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
690 pixels =
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
691 (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch +
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
692 rect->x * bpp);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
693 /* There is no GL_UNPACK_ROW_LENGTH in OpenGLES
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
694 we must do this reformatting ourselves(!)
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
695
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
696 maybe it'd be a good idea to keep a temp buffer around
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
697 for this purpose rather than allocating it each time
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
698 */
4525
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
699 if( rect->x == 0 && rect->w * bpp == pitch ) {
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
700 temp_buffer = pixels; /* Updating whole texture, no need to reformat */
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
701 } else {
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
702 temp_buffer = SDL_malloc(rect->w * rect->h * bpp);
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
703 temp_ptr = temp_buffer;
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
704 for (i = 0; i < rect->h; i++) {
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
705 SDL_memcpy(temp_ptr, pixels, rect->w * bpp);
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
706 temp_ptr += rect->w * bpp;
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
707 pixels += pitch;
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
708 }
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
709 }
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
710
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
711 data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
712 rect->w, rect->h, texturedata->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
713 texturedata->formattype, temp_buffer);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
714
4525
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
715 if( temp_buffer != pixels ) {
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
716 SDL_free(temp_buffer);
3abf0b9cafad pelya 2010-07-12 03:53:48 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
717 }
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
718 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
719 SDL_ClearDirtyRects(&texturedata->dirty);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
720 }
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
721
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
722 data->glBindTexture(texturedata->type, texturedata->texture);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
723
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
724 if (texture->modMode) {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
725 data->glColor4f((GLfloat) texture->r * inv255f,
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
726 (GLfloat) texture->g * inv255f,
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
727 (GLfloat) texture->b * inv255f,
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
728 (GLfloat) texture->a * inv255f);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
729 } 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
730 data->glColor4f(1.0f, 1.0f, 1.0f, 1.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
731 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
732
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
733 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
734
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
735 if (data->GL_OES_draw_texture_supported && data->useDrawTexture) {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
736 /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */
5157
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: 5153
diff changeset
737 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: 5153
diff changeset
738 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
739 SDL_Window *window = renderer->window;
5157
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: 5153
diff changeset
740
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: 5153
diff changeset
741 SDL_GetWindowSize(window, &w, &h);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
742 cropRect[0] = srcrect->x;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
743 cropRect[1] = srcrect->y + srcrect->h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
744 cropRect[2] = srcrect->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
745 cropRect[3] = -srcrect->h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
746 data->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
747 cropRect);
5157
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: 5153
diff changeset
748 data->glDrawTexiOES(dstrect->x, h - dstrect->y - dstrect->h, 0,
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: 5153
diff changeset
749 dstrect->w, dstrect->h);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
750 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
751
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
752 minx = dstrect->x;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
753 miny = dstrect->y;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
754 maxx = dstrect->x + dstrect->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
755 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
756
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
757 minu = (GLfloat) srcrect->x / texture->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
758 minu *= texturedata->texw;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
759 maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
760 maxu *= texturedata->texw;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
761 minv = (GLfloat) srcrect->y / texture->h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
762 minv *= texturedata->texh;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
763 maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
764 maxv *= texturedata->texh;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
765
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
766 GLshort vertices[8];
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
767 GLfloat texCoords[8];
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
768
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
769 vertices[0] = minx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
770 vertices[1] = miny;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
771 vertices[2] = maxx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
772 vertices[3] = miny;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
773 vertices[4] = minx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
774 vertices[5] = maxy;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
775 vertices[6] = maxx;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
776 vertices[7] = maxy;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
777
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
778 texCoords[0] = minu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
779 texCoords[1] = minv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
780 texCoords[2] = maxu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
781 texCoords[3] = minv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
782 texCoords[4] = minu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
783 texCoords[5] = maxv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
784 texCoords[6] = maxu;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
785 texCoords[7] = maxv;
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
786
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
787 data->glVertexPointer(2, GL_SHORT, 0, vertices);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
788 data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
789 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
790 }
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
791
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
792 data->glDisable(GL_TEXTURE_2D);
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
793
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
794 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
795 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
796
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
797 static void
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3122
diff changeset
798 GLES_RenderPresent(SDL_Renderer * renderer)
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
799 {
5150
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: 5145
diff changeset
800 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: 5145
diff changeset
801
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
802 SDL_GL_SwapWindow(renderer->window);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
803 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
804
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
805 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
806 GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
807 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
808 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
809
5150
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: 5145
diff changeset
810 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: 5145
diff changeset
811
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
812 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
813 return;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
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 if (data->texture) {
2753
Sam Lantinga <slouken@libsdl.org>
parents: 2739
diff changeset
816 glDeleteTextures(1, &data->texture);
2739
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
817 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 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
819 SDL_free(data->pixels);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
820 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
821 SDL_FreeDirtyRects(&data->dirty);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 SDL_free(data);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
823 texture->driverdata = NULL;
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
824 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
825
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
826 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
827 GLES_DestroyRenderer(SDL_Renderer * renderer)
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
828 {
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
829 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
830
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
831 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
832 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
833 SDL_GL_DeleteContext(data->context);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
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 SDL_free(data);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
836 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.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 SDL_free(renderer);
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
838 }
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
839
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2964
diff changeset
840 #endif /* SDL_VIDEO_RENDER_OGL_ES */
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
841
68862734a5fd These files are similar in purpose and structure as SDL_renderer_gl.c and SDL_renderer_gl.h, except they use OpenGL ES 1.1 for rendering.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
842 /* vi: set ts=4 sw=4 expandtab: */