author | Sam Lantinga <slouken@libsdl.org> |
Sat, 26 Feb 2011 21:39:34 -0800 | |
changeset 5402 | 5d102cd8aef3 |
parent 5355 | cc2215cda170 |
child 5484 | e20c93bc9122 |
permissions | -rw-r--r-- |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
/* |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 |
SDL - Simple DirectMedia Layer |
5262 | 3 |
Copyright (C) 1997-2011 Sam Lantinga |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
Copyright (C) 2010 itsnotabigtruck. |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 |
|
5260
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
6 |
This library is free software; you can redistribute it and/or |
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
7 |
modify it under the terms of the GNU Lesser General Public |
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
8 |
License as published by the Free Software Foundation; either |
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
9 |
version 2.1 of the License, or (at your option) any later version. |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 |
|
5260
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
11 |
This library is distributed in the hope that it will be useful, |
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
14 |
Lesser General Public License for more details. |
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
15 |
|
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
16 |
You should have received a copy of the GNU Lesser General Public |
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
17 |
License along with this library; if not, write to the Free Software |
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
18 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
19 |
|
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
20 |
Sam Lantinga |
62d2bc792002
itsnotabigtruck has given me permission to replace the license for his contribution.
Sam Lantinga <slouken@libsdl.org>
parents:
5249
diff
changeset
|
21 |
slouken@libsdl.org |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
*/ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
#include "SDL_config.h" |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 |
|
5226
710d00cb3a6a
Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents:
5224
diff
changeset
|
25 |
#if SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
|
5204
daa5463466c5
Fixed building on Android, added SDL_opengles2.h, removed unnecessary SDL_glesfuncs.h
Sam Lantinga <slouken@libsdl.org>
parents:
5202
diff
changeset
|
27 |
#include "SDL_opengles2.h" |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
#include "../SDL_sysrender.h" |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
#include "SDL_shaders_gles2.h" |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
/************************************************************************************************* |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
* Bootstrap data * |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 |
*************************************************************************************************/ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, Uint32 flags); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 |
SDL_RenderDriver GLES2_RenderDriver = { |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 |
GLES2_CreateRenderer, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 |
"opengles2", |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC), |
5202
1f2b17f42fd0
Removed extra unneeded pixel formats, added support for VSYNC on other platforms besides Zune HD.
Sam Lantinga <slouken@libsdl.org>
parents:
5201
diff
changeset
|
42 |
1, |
1f2b17f42fd0
Removed extra unneeded pixel formats, added support for VSYNC on other platforms besides Zune HD.
Sam Lantinga <slouken@libsdl.org>
parents:
5201
diff
changeset
|
43 |
{SDL_PIXELFORMAT_ABGR8888}, |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
0, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
0 |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 |
}; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 |
/************************************************************************************************* |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 |
* Context structures * |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 |
*************************************************************************************************/ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 |
typedef struct GLES2_TextureData |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 |
GLenum texture; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 |
GLenum texture_type; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 |
GLenum pixel_format; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 |
GLenum pixel_type; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 |
void *pixel_data; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 |
size_t pitch; |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
61 |
GLenum scaleMode; |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
} GLES2_TextureData; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 |
typedef struct GLES2_ShaderCacheEntry |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
GLuint id; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 |
GLES2_ShaderType type; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 |
const GLES2_ShaderInstance *instance; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 |
int references; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
struct GLES2_ShaderCacheEntry *prev; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 |
struct GLES2_ShaderCacheEntry *next; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 |
} GLES2_ShaderCacheEntry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 |
typedef struct GLES2_ShaderCache |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 |
int count; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 |
GLES2_ShaderCacheEntry *head; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 |
} GLES2_ShaderCache; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 |
typedef struct GLES2_ProgramCacheEntry |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 |
GLuint id; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 |
SDL_BlendMode blend_mode; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
GLES2_ShaderCacheEntry *vertex_shader; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
GLES2_ShaderCacheEntry *fragment_shader; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 |
GLuint uniform_locations[16]; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 |
struct GLES2_ProgramCacheEntry *prev; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 |
struct GLES2_ProgramCacheEntry *next; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 |
} GLES2_ProgramCacheEntry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 |
typedef struct GLES2_ProgramCache |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 |
int count; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
GLES2_ProgramCacheEntry *head; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 |
GLES2_ProgramCacheEntry *tail; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 |
} GLES2_ProgramCache; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 |
typedef enum |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 |
GLES2_ATTRIBUTE_POSITION = 0, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 |
GLES2_ATTRIBUTE_TEXCOORD = 1 |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 |
} GLES2_Attribute; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 |
typedef enum |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 |
GLES2_UNIFORM_PROJECTION, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
GLES2_UNIFORM_TEXTURE, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 |
GLES2_UNIFORM_MODULATION, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 |
GLES2_UNIFORM_COLOR, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 |
GLES2_UNIFORM_COLORTABLE |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 |
} GLES2_Uniform; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 |
typedef enum |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 |
GLES2_IMAGESOURCE_SOLID, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 |
GLES2_IMAGESOURCE_TEXTURE |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 |
} GLES2_ImageSource; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 |
typedef struct GLES2_DriverContext |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 |
SDL_GLContext *context; |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
122 |
struct { |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
123 |
int blendMode; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
124 |
GLenum scaleMode; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
125 |
SDL_bool tex_coords; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
126 |
} current; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
127 |
|
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 |
int shader_format_count; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 |
GLenum *shader_formats; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 |
GLES2_ShaderCache shader_cache; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 |
GLES2_ProgramCache program_cache; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 |
GLES2_ProgramCacheEntry *current_program; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 |
} GLES2_DriverContext; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
#define GLES2_MAX_CACHED_PROGRAMS 8 |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
/************************************************************************************************* |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 |
* Renderer state APIs * |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 |
*************************************************************************************************/ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 |
|
5224
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
141 |
static int GLES2_ActivateRenderer(SDL_Renderer *renderer); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 |
static void GLES2_WindowEvent(SDL_Renderer * renderer, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 |
const SDL_WindowEvent *event); |
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
144 |
static int GLES2_UpdateViewport(SDL_Renderer * renderer); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 |
static void GLES2_DestroyRenderer(SDL_Renderer *renderer); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 |
static SDL_GLContext SDL_CurrentContext = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 |
static int |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 |
GLES2_ActivateRenderer(SDL_Renderer * renderer) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 |
if (SDL_CurrentContext != rdata->context) { |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 |
/* Null out the current program to ensure we set it again */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 |
rdata->current_program = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 |
|
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
158 |
if (SDL_GL_MakeCurrent(renderer->window, rdata->context) < 0) { |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 |
SDL_CurrentContext = rdata->context; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 |
|
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
163 |
GLES2_UpdateViewport(renderer); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 |
static void |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 |
GLES2_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 |
{ |
5276 | 171 |
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) { |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 |
/* Rebind the context to the window area */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 |
SDL_CurrentContext = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 |
|
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
177 |
static int |
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
178 |
GLES2_UpdateViewport(SDL_Renderer * renderer) |
5224
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
179 |
{ |
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
180 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
5224
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
181 |
|
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
182 |
if (SDL_CurrentContext != rdata->context) { |
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
183 |
/* We'll update the viewport after we rebind the context */ |
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
184 |
return 0; |
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
185 |
} |
5224
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
186 |
|
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
187 |
glViewport(renderer->viewport.x, renderer->viewport.y, |
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
188 |
renderer->viewport.w, renderer->viewport.h); |
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
189 |
return 0; |
5224
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
190 |
} |
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
191 |
|
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
192 |
static void |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 |
GLES2_DestroyRenderer(SDL_Renderer *renderer) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 |
GLES2_ProgramCacheEntry *entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 |
GLES2_ProgramCacheEntry *next; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 |
|
5209
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
199 |
/* Deallocate everything */ |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
200 |
if (rdata) { |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
201 |
GLES2_ActivateRenderer(renderer); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 |
|
5209
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
203 |
entry = rdata->program_cache.head; |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
204 |
while (entry) { |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
205 |
glDeleteShader(entry->vertex_shader->id); |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
206 |
glDeleteShader(entry->fragment_shader->id); |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
207 |
SDL_free(entry->vertex_shader); |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
208 |
SDL_free(entry->fragment_shader); |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
209 |
glDeleteProgram(entry->id); |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
210 |
next = entry->next; |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
211 |
SDL_free(entry); |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
212 |
entry = next; |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
213 |
} |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
214 |
if (rdata->context) { |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
215 |
SDL_GL_DeleteContext(rdata->context); |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
216 |
} |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
217 |
if (rdata->shader_formats) { |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
218 |
SDL_free(rdata->shader_formats); |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
219 |
} |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
220 |
SDL_free(rdata); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 |
SDL_free(renderer); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 |
/************************************************************************************************* |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 |
* Texture APIs * |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 |
*************************************************************************************************/ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 |
static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 |
static void GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 |
static int GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 |
void **pixels, int *pitch); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 |
static void GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 |
static int GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 |
const void *pixels, int pitch); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 |
static int |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 |
GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 |
GLES2_TextureData *tdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 |
GLenum format; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 |
GLenum type; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 |
GLES2_ActivateRenderer(renderer); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 |
/* Determine the corresponding GLES texture format params */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 |
switch (texture->format) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 |
case SDL_PIXELFORMAT_ABGR8888: |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 |
format = GL_RGBA; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 |
type = GL_UNSIGNED_BYTE; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 |
break; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 |
default: |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 |
SDL_SetError("Texture format not supported"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 |
/* Allocate a texture struct */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 |
tdata = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData)); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 |
if (!tdata) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 |
SDL_OutOfMemory(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 |
tdata->texture = 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 |
tdata->texture_type = GL_TEXTURE_2D; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 |
tdata->pixel_format = format; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 |
tdata->pixel_type = type; |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
269 |
tdata->scaleMode = GL_LINEAR; |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 |
/* Allocate a blob for image data */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 |
if (texture->access == SDL_TEXTUREACCESS_STREAMING) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 |
tdata->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); |
5402
5d102cd8aef3
Zero streaming textures at the driver level
Sam Lantinga <slouken@libsdl.org>
parents:
5355
diff
changeset
|
275 |
tdata->pixel_data = SDL_calloc(1, tdata->pitch * texture->h); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 |
if (!tdata->pixel_data) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 |
SDL_OutOfMemory(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 |
SDL_free(tdata); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 |
/* Allocate the texture */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 |
glGetError(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 |
glGenTextures(1, &tdata->texture); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 |
glActiveTexture(GL_TEXTURE0); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 |
glBindTexture(tdata->texture_type, tdata->texture); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 |
glTexParameteri(tdata->texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 |
glTexParameteri(tdata->texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 |
glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 |
glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 |
glTexImage2D(tdata->texture_type, 0, format, texture->w, texture->h, 0, format, type, NULL); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 |
if (glGetError() != GL_NO_ERROR) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 |
SDL_SetError("Texture creation failed"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 |
glDeleteTextures(1, &tdata->texture); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 |
SDL_free(tdata); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 |
texture->driverdata = tdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 |
static void |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 |
GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 |
GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 |
GLES2_ActivateRenderer(renderer); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 |
/* Destroy the texture */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 |
if (tdata) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 |
glDeleteTextures(1, &tdata->texture); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 |
SDL_free(tdata->pixel_data); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 |
SDL_free(tdata); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 |
texture->driverdata = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 |
static int |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 |
GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 |
void **pixels, int *pitch) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 |
GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 |
/* Retrieve the buffer/pitch for the specified region */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 |
*pixels = (Uint8 *)tdata->pixel_data + |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 |
(tdata->pitch * rect->y) + |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 |
(rect->x * SDL_BYTESPERPIXEL(texture->format)); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 |
*pitch = tdata->pitch; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 |
static void |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 |
GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 |
GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; |
5227
9c0c4d767ef6
Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents:
5226
diff
changeset
|
341 |
SDL_Rect rect; |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 |
|
5227
9c0c4d767ef6
Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents:
5226
diff
changeset
|
343 |
/* We do whole texture updates, at least for now */ |
9c0c4d767ef6
Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents:
5226
diff
changeset
|
344 |
rect.x = 0; |
9c0c4d767ef6
Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents:
5226
diff
changeset
|
345 |
rect.y = 0; |
9c0c4d767ef6
Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents:
5226
diff
changeset
|
346 |
rect.w = texture->w; |
9c0c4d767ef6
Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents:
5226
diff
changeset
|
347 |
rect.h = texture->h; |
9c0c4d767ef6
Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents:
5226
diff
changeset
|
348 |
GLES2_UpdateTexture(renderer, texture, &rect, tdata->pixel_data, tdata->pitch); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 |
static int |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 |
GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 |
const void *pixels, int pitch) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 |
GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 |
Uint8 *blob = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 |
Uint8 *src; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 |
int srcPitch; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 |
int y; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 |
GLES2_ActivateRenderer(renderer); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
362 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 |
/* Bail out if we're supposed to update an empty rectangle */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 |
if (rect->w <= 0 || rect->h <= 0) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
365 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
366 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
367 |
/* Reformat the texture data into a tightly packed array */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 |
srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 |
src = (Uint8 *)pixels; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 |
if (pitch != srcPitch) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 |
blob = (Uint8 *)SDL_malloc(srcPitch * rect->h); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 |
if (!blob) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 |
SDL_OutOfMemory(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
377 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 |
src = blob; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 |
for (y = 0; y < rect->h; ++y) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 |
SDL_memcpy(src, pixels, srcPitch); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
382 |
src += srcPitch; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 |
pixels = (Uint8 *)pixels + pitch; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 |
src = blob; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
386 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
387 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
388 |
/* Create a texture subimage with the supplied data */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
389 |
glGetError(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
390 |
glActiveTexture(GL_TEXTURE0); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
391 |
glBindTexture(tdata->texture_type, tdata->texture); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 |
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 |
glTexSubImage2D(tdata->texture_type, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
394 |
0, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
395 |
rect->x, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 |
rect->y, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 |
rect->w, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
398 |
rect->h, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 |
tdata->pixel_format, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
400 |
tdata->pixel_type, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
401 |
src); |
5227
9c0c4d767ef6
Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents:
5226
diff
changeset
|
402 |
if (blob) { |
9c0c4d767ef6
Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents:
5226
diff
changeset
|
403 |
SDL_free(blob); |
9c0c4d767ef6
Reduce duplicated code in the texture update code paths
Sam Lantinga <slouken@libsdl.org>
parents:
5226
diff
changeset
|
404 |
} |
5214
b0797947dd1c
You don't need to copy the pixels into the streaming texture's pixel data. This behavior is defined specifically to optimize the UpdateTexture path.
Sam Lantinga <slouken@libsdl.org>
parents:
5213
diff
changeset
|
405 |
|
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 |
if (glGetError() != GL_NO_ERROR) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 |
SDL_SetError("Failed to update texture"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
410 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
411 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
412 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
413 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
414 |
/************************************************************************************************* |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
415 |
* Shader management functions * |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 |
*************************************************************************************************/ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
417 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
418 |
static GLES2_ShaderCacheEntry *GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
419 |
SDL_BlendMode blendMode); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 |
static void GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
421 |
static GLES2_ProgramCacheEntry *GLES2_CacheProgram(SDL_Renderer *renderer, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 |
GLES2_ShaderCacheEntry *vertex, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
423 |
GLES2_ShaderCacheEntry *fragment, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
424 |
SDL_BlendMode blendMode); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
425 |
static int GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
426 |
SDL_BlendMode blendMode); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
427 |
static int GLES2_SetOrthographicProjection(SDL_Renderer *renderer); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
428 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
429 |
static GLES2_ProgramCacheEntry * |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
430 |
GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
431 |
GLES2_ShaderCacheEntry *fragment, SDL_BlendMode blendMode) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
432 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
434 |
GLES2_ProgramCacheEntry *entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
435 |
GLES2_ShaderCacheEntry *shaderEntry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
436 |
GLint linkSuccessful; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
437 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
438 |
/* Check if we've already cached this program */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
439 |
entry = rdata->program_cache.head; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
440 |
while (entry) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
441 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
442 |
if (entry->vertex_shader == vertex && entry->fragment_shader == fragment) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
443 |
break; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
444 |
entry = entry->next; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
445 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
446 |
if (entry) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
447 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
448 |
if (rdata->program_cache.count > 1) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
449 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
450 |
if (entry->next) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
451 |
entry->next->prev = entry->prev; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
452 |
if (entry->prev) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
453 |
entry->prev->next = entry->next; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
454 |
entry->prev = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
455 |
entry->next = rdata->program_cache.head; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
456 |
rdata->program_cache.head->prev = entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
457 |
rdata->program_cache.head = entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
458 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
459 |
return entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
460 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
461 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
462 |
/* Create a program cache entry */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
463 |
entry = (GLES2_ProgramCacheEntry *)SDL_calloc(1, sizeof(GLES2_ProgramCacheEntry)); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
464 |
if (!entry) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
465 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
466 |
SDL_OutOfMemory(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
467 |
return NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
468 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
469 |
entry->vertex_shader = vertex; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
470 |
entry->fragment_shader = fragment; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
471 |
entry->blend_mode = blendMode; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
472 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
473 |
/* Create the program and link it */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
474 |
glGetError(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
475 |
entry->id = glCreateProgram(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
476 |
glAttachShader(entry->id, vertex->id); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
477 |
glAttachShader(entry->id, fragment->id); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
478 |
glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_POSITION, "a_position"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
479 |
glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_TEXCOORD, "a_texCoord"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
480 |
glLinkProgram(entry->id); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
481 |
glGetProgramiv(entry->id, GL_LINK_STATUS, &linkSuccessful); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
482 |
if (glGetError() != GL_NO_ERROR || !linkSuccessful) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
483 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
484 |
SDL_SetError("Failed to link shader program"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
485 |
glDeleteProgram(entry->id); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
486 |
SDL_free(entry); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
487 |
return NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
488 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
489 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
490 |
/* Predetermine locations of uniform variables */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
491 |
entry->uniform_locations[GLES2_UNIFORM_PROJECTION] = |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
492 |
glGetUniformLocation(entry->id, "u_projection"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
493 |
entry->uniform_locations[GLES2_UNIFORM_TEXTURE] = |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
494 |
glGetUniformLocation(entry->id, "u_texture"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
495 |
entry->uniform_locations[GLES2_UNIFORM_MODULATION] = |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
496 |
glGetUniformLocation(entry->id, "u_modulation"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
497 |
entry->uniform_locations[GLES2_UNIFORM_COLOR] = |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
498 |
glGetUniformLocation(entry->id, "u_color"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
499 |
entry->uniform_locations[GLES2_UNIFORM_COLORTABLE] = |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
500 |
glGetUniformLocation(entry->id, "u_colorTable"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
501 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
502 |
/* Cache the linked program */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
503 |
if (rdata->program_cache.head) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
504 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
505 |
entry->next = rdata->program_cache.head; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
506 |
rdata->program_cache.head->prev = entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
507 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
508 |
else |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
509 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
510 |
rdata->program_cache.tail = entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
511 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
512 |
rdata->program_cache.head = entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
513 |
++rdata->program_cache.count; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
514 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
515 |
/* Increment the refcount of the shaders we're using */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
516 |
++vertex->references; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
517 |
++fragment->references; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
518 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
519 |
/* Evict the last entry from the cache if we exceed the limit */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
520 |
if (rdata->program_cache.count > GLES2_MAX_CACHED_PROGRAMS) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
521 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
522 |
shaderEntry = rdata->program_cache.tail->vertex_shader; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
523 |
if (--shaderEntry->references <= 0) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
524 |
GLES2_EvictShader(renderer, shaderEntry); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
525 |
shaderEntry = rdata->program_cache.tail->fragment_shader; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
526 |
if (--shaderEntry->references <= 0) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
527 |
GLES2_EvictShader(renderer, shaderEntry); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
528 |
glDeleteProgram(rdata->program_cache.tail->id); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
529 |
rdata->program_cache.tail = rdata->program_cache.tail->prev; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
530 |
SDL_free(rdata->program_cache.tail->next); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
531 |
rdata->program_cache.tail->next = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
532 |
--rdata->program_cache.count; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
533 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
534 |
return entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
535 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
536 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
537 |
static GLES2_ShaderCacheEntry * |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
538 |
GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, SDL_BlendMode blendMode) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
539 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
540 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
541 |
const GLES2_Shader *shader; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
542 |
const GLES2_ShaderInstance *instance = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
543 |
GLES2_ShaderCacheEntry *entry = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
544 |
GLint compileSuccessful = GL_FALSE; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
545 |
int i, j; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
546 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
547 |
/* Find the corresponding shader */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
548 |
shader = GLES2_GetShader(type, blendMode); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
549 |
if (!shader) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
550 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
551 |
SDL_SetError("No shader matching the requested characteristics was found"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
552 |
return NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
553 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
554 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
555 |
/* Find a matching shader instance that's supported on this hardware */ |
5206
7d64745f1363
Fixed crash when binary shaders are not available.
Sam Lantinga <slouken@libsdl.org>
parents:
5204
diff
changeset
|
556 |
for (i = 0; i < shader->instance_count && !instance; ++i) |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
557 |
{ |
5206
7d64745f1363
Fixed crash when binary shaders are not available.
Sam Lantinga <slouken@libsdl.org>
parents:
5204
diff
changeset
|
558 |
for (j = 0; j < rdata->shader_format_count && !instance; ++j) |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
559 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
560 |
if (!shader->instances) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
561 |
continue; |
5206
7d64745f1363
Fixed crash when binary shaders are not available.
Sam Lantinga <slouken@libsdl.org>
parents:
5204
diff
changeset
|
562 |
if (!shader->instances[i]) |
7d64745f1363
Fixed crash when binary shaders are not available.
Sam Lantinga <slouken@libsdl.org>
parents:
5204
diff
changeset
|
563 |
continue; |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
564 |
if (shader->instances[i]->format != rdata->shader_formats[j]) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
565 |
continue; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
566 |
instance = shader->instances[i]; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
567 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
568 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
569 |
if (!instance) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
570 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
571 |
SDL_SetError("The specified shader cannot be loaded on the current platform"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
572 |
return NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
573 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
574 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
575 |
/* Check if we've already cached this shader */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
576 |
entry = rdata->shader_cache.head; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
577 |
while (entry) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
578 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
579 |
if (entry->instance == instance) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
580 |
break; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
581 |
entry = entry->next; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
582 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
583 |
if (entry) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
584 |
return entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
585 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
586 |
/* Create a shader cache entry */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
587 |
entry = (GLES2_ShaderCacheEntry *)SDL_calloc(1, sizeof(GLES2_ShaderCacheEntry)); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
588 |
if (!entry) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
589 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
590 |
SDL_OutOfMemory(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
591 |
return NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
592 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
593 |
entry->type = type; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
594 |
entry->instance = instance; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
595 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
596 |
/* Compile or load the selected shader instance */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
597 |
glGetError(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
598 |
entry->id = glCreateShader(instance->type); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
599 |
if (instance->format == (GLenum)-1) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
600 |
{ |
5212
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
601 |
glShaderSource(entry->id, 1, (const char **)&instance->data, NULL); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
602 |
glCompileShader(entry->id); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
603 |
glGetShaderiv(entry->id, GL_COMPILE_STATUS, &compileSuccessful); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
604 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
605 |
else |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
606 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
607 |
glShaderBinary(1, &entry->id, instance->format, instance->data, instance->length); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
608 |
compileSuccessful = GL_TRUE; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
609 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
610 |
if (glGetError() != GL_NO_ERROR || !compileSuccessful) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
611 |
{ |
5212
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
612 |
char *info = NULL; |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
613 |
int length; |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
614 |
|
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
615 |
glGetShaderiv(entry->id, GL_INFO_LOG_LENGTH, &length); |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
616 |
if (length > 0) { |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
617 |
info = SDL_stack_alloc(char, length); |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
618 |
if (info) { |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
619 |
glGetShaderInfoLog(entry->id, length, &length, info); |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
620 |
} |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
621 |
} |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
622 |
if (info) { |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
623 |
SDL_SetError("Failed to load the shader: %s", info); |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
624 |
SDL_stack_free(info); |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
625 |
} else { |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
626 |
SDL_SetError("Failed to load the shader"); |
7b6101f3ea58
Fixed compiling source shaders
Sam Lantinga <slouken@libsdl.org>
parents:
5209
diff
changeset
|
627 |
} |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
628 |
glDeleteShader(entry->id); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
629 |
SDL_free(entry); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
630 |
return NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
631 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
632 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
633 |
/* Link the shader entry in at the front of the cache */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
634 |
if (rdata->shader_cache.head) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
635 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
636 |
entry->next = rdata->shader_cache.head; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
637 |
rdata->shader_cache.head->prev = entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
638 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
639 |
rdata->shader_cache.head = entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
640 |
++rdata->shader_cache.count; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
641 |
return entry; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
642 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
643 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
644 |
static void |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
645 |
GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
646 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
647 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
648 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
649 |
/* Unlink the shader from the cache */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
650 |
if (entry->next) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
651 |
entry->next->prev = entry->prev; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
652 |
if (entry->prev) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
653 |
entry->prev->next = entry->next; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
654 |
if (rdata->shader_cache.head == entry) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
655 |
rdata->shader_cache.head = entry->next; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
656 |
--rdata->shader_cache.count; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
657 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
658 |
/* Deallocate the shader */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
659 |
glDeleteShader(entry->id); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
660 |
SDL_free(entry); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
661 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
662 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
663 |
static int |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
664 |
GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, SDL_BlendMode blendMode) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
665 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
666 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
667 |
GLES2_ShaderCacheEntry *vertex = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
668 |
GLES2_ShaderCacheEntry *fragment = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
669 |
GLES2_ShaderType vtype, ftype; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
670 |
GLES2_ProgramCacheEntry *program; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
671 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
672 |
/* Select an appropriate shader pair for the specified modes */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
673 |
vtype = GLES2_SHADER_VERTEX_DEFAULT; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
674 |
switch (source) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
675 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
676 |
case GLES2_IMAGESOURCE_SOLID: |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
677 |
ftype = GLES2_SHADER_FRAGMENT_SOLID_SRC; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
678 |
break; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
679 |
case GLES2_IMAGESOURCE_TEXTURE: |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
680 |
ftype = GLES2_SHADER_FRAGMENT_TEXTURE_SRC; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
681 |
break; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
682 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
683 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
684 |
/* Load the requested shaders */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
685 |
vertex = GLES2_CacheShader(renderer, vtype, blendMode); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
686 |
if (!vertex) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
687 |
goto fault; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
688 |
fragment = GLES2_CacheShader(renderer, ftype, blendMode); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
689 |
if (!fragment) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
690 |
goto fault; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
691 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
692 |
/* Check if we need to change programs at all */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
693 |
if (rdata->current_program && |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
694 |
rdata->current_program->vertex_shader == vertex && |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
695 |
rdata->current_program->fragment_shader == fragment) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
696 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
697 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
698 |
/* Generate a matching program */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
699 |
program = GLES2_CacheProgram(renderer, vertex, fragment, blendMode); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
700 |
if (!program) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
701 |
goto fault; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
702 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
703 |
/* Select that program in OpenGL */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
704 |
glGetError(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
705 |
glUseProgram(program->id); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
706 |
if (glGetError() != GL_NO_ERROR) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
707 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
708 |
SDL_SetError("Failed to select program"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
709 |
goto fault; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
710 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
711 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
712 |
/* Set the current program */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
713 |
rdata->current_program = program; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
714 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
715 |
/* Activate an orthographic projection */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
716 |
if (GLES2_SetOrthographicProjection(renderer) < 0) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
717 |
goto fault; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
718 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
719 |
/* Clean up and return */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
720 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
721 |
fault: |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
722 |
if (vertex && vertex->references <= 0) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
723 |
GLES2_EvictShader(renderer, vertex); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
724 |
if (fragment && fragment->references <= 0) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
725 |
GLES2_EvictShader(renderer, fragment); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
726 |
rdata->current_program = NULL; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
727 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
728 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
729 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
730 |
static int |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
731 |
GLES2_SetOrthographicProjection(SDL_Renderer *renderer) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
732 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
733 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
734 |
GLfloat projection[4][4]; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
735 |
GLuint locProjection; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
736 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
737 |
/* Prepare an orthographic projection */ |
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
738 |
projection[0][0] = 2.0f / renderer->viewport.w; |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
739 |
projection[0][1] = 0.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
740 |
projection[0][2] = 0.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
741 |
projection[0][3] = 0.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
742 |
projection[1][0] = 0.0f; |
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
743 |
projection[1][1] = -2.0f / renderer->viewport.h; |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
744 |
projection[1][2] = 0.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
745 |
projection[1][3] = 0.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
746 |
projection[2][0] = 0.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
747 |
projection[2][1] = 0.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
748 |
projection[2][2] = 1.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
749 |
projection[2][3] = 0.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
750 |
projection[3][0] = -1.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
751 |
projection[3][1] = 1.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
752 |
projection[3][2] = 0.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
753 |
projection[3][3] = 1.0f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
754 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
755 |
/* Set the projection matrix */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
756 |
locProjection = rdata->current_program->uniform_locations[GLES2_UNIFORM_PROJECTION]; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
757 |
glGetError(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
758 |
glUniformMatrix4fv(locProjection, 1, GL_FALSE, (GLfloat *)projection); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
759 |
if (glGetError() != GL_NO_ERROR) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
760 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
761 |
SDL_SetError("Failed to set orthographic projection"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
762 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
763 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
764 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
765 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
766 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
767 |
/************************************************************************************************* |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
768 |
* Rendering functions * |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
769 |
*************************************************************************************************/ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
770 |
|
5224
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
771 |
static const float inv255f = 1.0f / 255.0f; |
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
772 |
|
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
773 |
static int GLES2_RenderClear(SDL_Renderer *renderer); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
774 |
static int GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
775 |
static int GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count); |
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
776 |
static int GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
777 |
static int GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
778 |
const SDL_Rect *dstrect); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
779 |
static void GLES2_RenderPresent(SDL_Renderer *renderer); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
780 |
|
5333
5d3a2cd4e8c9
Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents:
5332
diff
changeset
|
781 |
|
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
782 |
static int |
5333
5d3a2cd4e8c9
Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents:
5332
diff
changeset
|
783 |
GLES2_RenderClear(SDL_Renderer * renderer) |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
784 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
785 |
GLES2_ActivateRenderer(renderer); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
786 |
|
5333
5d3a2cd4e8c9
Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents:
5332
diff
changeset
|
787 |
glClearColor((GLfloat) renderer->r * inv255f, |
5d3a2cd4e8c9
Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents:
5332
diff
changeset
|
788 |
(GLfloat) renderer->g * inv255f, |
5d3a2cd4e8c9
Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents:
5332
diff
changeset
|
789 |
(GLfloat) renderer->b * inv255f, |
5d3a2cd4e8c9
Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents:
5332
diff
changeset
|
790 |
(GLfloat) renderer->a * inv255f); |
5d3a2cd4e8c9
Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents:
5332
diff
changeset
|
791 |
|
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
792 |
glClear(GL_COLOR_BUFFER_BIT); |
5333
5d3a2cd4e8c9
Implemented OpenGL ES RenderClear()
Sam Lantinga <slouken@libsdl.org>
parents:
5332
diff
changeset
|
793 |
|
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
794 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
795 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
796 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
797 |
static void |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
798 |
GLES2_SetBlendMode(GLES2_DriverContext *rdata, int blendMode) |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
799 |
{ |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
800 |
if (blendMode != rdata->current.blendMode) { |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
801 |
switch (blendMode) { |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
802 |
default: |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
803 |
case SDL_BLENDMODE_NONE: |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
804 |
glDisable(GL_BLEND); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
805 |
break; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
806 |
case SDL_BLENDMODE_BLEND: |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
807 |
glEnable(GL_BLEND); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
808 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
809 |
break; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
810 |
case SDL_BLENDMODE_ADD: |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
811 |
glEnable(GL_BLEND); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
812 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
813 |
break; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
814 |
case SDL_BLENDMODE_MOD: |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
815 |
glEnable(GL_BLEND); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
816 |
glBlendFunc(GL_ZERO, GL_SRC_COLOR); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
817 |
break; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
818 |
} |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
819 |
rdata->current.blendMode = blendMode; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
820 |
} |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
821 |
} |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
822 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
823 |
static void |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
824 |
GLES2_SetTexCoords(GLES2_DriverContext * rdata, SDL_bool enabled) |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
825 |
{ |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
826 |
if (enabled != rdata->current.tex_coords) { |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
827 |
if (enabled) { |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
828 |
glEnableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
829 |
} else { |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
830 |
glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
831 |
} |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
832 |
rdata->current.tex_coords = enabled; |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
833 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
834 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
835 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
836 |
static int |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
837 |
GLES2_SetDrawingState(SDL_Renderer * renderer) |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
838 |
{ |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
839 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
840 |
int blendMode = renderer->blendMode; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
841 |
GLuint locColor; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
842 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
843 |
glGetError(); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
844 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
845 |
GLES2_ActivateRenderer(renderer); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
846 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
847 |
GLES2_SetBlendMode(rdata, blendMode); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
848 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
849 |
GLES2_SetTexCoords(rdata, SDL_FALSE); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
850 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
851 |
/* Activate an appropriate shader and set the projection matrix */ |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
852 |
if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, blendMode) < 0) |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
853 |
return -1; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
854 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
855 |
/* Select the color to draw with */ |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
856 |
locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR]; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
857 |
glUniform4f(locColor, |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
858 |
renderer->r * inv255f, |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
859 |
renderer->g * inv255f, |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
860 |
renderer->b * inv255f, |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
861 |
renderer->a * inv255f); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
862 |
return 0; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
863 |
} |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
864 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
865 |
static int |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
866 |
GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
867 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
868 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
869 |
GLfloat *vertices; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
870 |
int idx; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
871 |
|
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
872 |
if (GLES2_SetDrawingState(renderer) < 0) { |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
873 |
return -1; |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
874 |
} |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
875 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
876 |
/* Emit the specified vertices as points */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
877 |
vertices = SDL_stack_alloc(GLfloat, count * 2); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
878 |
for (idx = 0; idx < count; ++idx) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
879 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
880 |
GLfloat x = (GLfloat)points[idx].x + 0.5f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
881 |
GLfloat y = (GLfloat)points[idx].y + 0.5f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
882 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
883 |
vertices[idx * 2] = x; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
884 |
vertices[(idx * 2) + 1] = y; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
885 |
} |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
886 |
glGetError(); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
887 |
glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
888 |
glDrawArrays(GL_POINTS, 0, count); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
889 |
SDL_stack_free(vertices); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
890 |
if (glGetError() != GL_NO_ERROR) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
891 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
892 |
SDL_SetError("Failed to render lines"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
893 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
894 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
895 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
896 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
897 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
898 |
static int |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
899 |
GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
900 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
901 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
902 |
GLfloat *vertices; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
903 |
int idx; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
904 |
|
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
905 |
if (GLES2_SetDrawingState(renderer) < 0) { |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
906 |
return -1; |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
907 |
} |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
908 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
909 |
/* Emit a line strip including the specified vertices */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
910 |
vertices = SDL_stack_alloc(GLfloat, count * 2); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
911 |
for (idx = 0; idx < count; ++idx) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
912 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
913 |
GLfloat x = (GLfloat)points[idx].x + 0.5f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
914 |
GLfloat y = (GLfloat)points[idx].y + 0.5f; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
915 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
916 |
vertices[idx * 2] = x; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
917 |
vertices[(idx * 2) + 1] = y; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
918 |
} |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
919 |
glGetError(); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
920 |
glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
921 |
glDrawArrays(GL_LINE_STRIP, 0, count); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
922 |
SDL_stack_free(vertices); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
923 |
if (glGetError() != GL_NO_ERROR) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
924 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
925 |
SDL_SetError("Failed to render lines"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
926 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
927 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
928 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
929 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
930 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
931 |
static int |
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
932 |
GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count) |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
933 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
934 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
935 |
GLfloat vertices[8]; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
936 |
int idx; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
937 |
|
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
938 |
if (GLES2_SetDrawingState(renderer) < 0) { |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
939 |
return -1; |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
940 |
} |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
941 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
942 |
/* Emit a line loop for each rectangle */ |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
943 |
glGetError(); |
5297
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
944 |
for (idx = 0; idx < count; ++idx) { |
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
945 |
const SDL_Rect *rect = &rects[idx]; |
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
946 |
|
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
947 |
GLfloat xMin = (GLfloat)rect->x; |
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
948 |
GLfloat xMax = (GLfloat)(rect->x + rect->w); |
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
949 |
GLfloat yMin = (GLfloat)rect->y; |
1800dc39b74c
Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents:
5276
diff
changeset
|
950 |
GLfloat yMax = (GLfloat)(rect->y + rect->h); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
951 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
952 |
vertices[0] = xMin; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
953 |
vertices[1] = yMin; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
954 |
vertices[2] = xMax; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
955 |
vertices[3] = yMin; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
956 |
vertices[4] = xMin; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
957 |
vertices[5] = yMax; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
958 |
vertices[6] = xMax; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
959 |
vertices[7] = yMax; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
960 |
glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
961 |
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
962 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
963 |
if (glGetError() != GL_NO_ERROR) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
964 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
965 |
SDL_SetError("Failed to render lines"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
966 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
967 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
968 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
969 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
970 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
971 |
static int |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
972 |
GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
973 |
const SDL_Rect *dstrect) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
974 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
975 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
976 |
GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
977 |
GLES2_ImageSource sourceType; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
978 |
SDL_BlendMode blendMode; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
979 |
GLfloat vertices[8]; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
980 |
GLfloat texCoords[8]; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
981 |
GLuint locTexture; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
982 |
GLuint locModulation; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
983 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
984 |
GLES2_ActivateRenderer(renderer); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
985 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
986 |
/* Activate an appropriate shader and set the projection matrix */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
987 |
blendMode = texture->blendMode; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
988 |
sourceType = GLES2_IMAGESOURCE_TEXTURE; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
989 |
if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
990 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
991 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
992 |
/* Select the target texture */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
993 |
locTexture = rdata->current_program->uniform_locations[GLES2_UNIFORM_TEXTURE]; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
994 |
glGetError(); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
995 |
glActiveTexture(GL_TEXTURE0); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
996 |
glBindTexture(tdata->texture_type, tdata->texture); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
997 |
glUniform1i(locTexture, 0); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
998 |
|
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
999 |
if (tdata->scaleMode != rdata->current.scaleMode) { |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1000 |
glTexParameteri(tdata->texture_type, GL_TEXTURE_MIN_FILTER, |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1001 |
tdata->scaleMode); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1002 |
glTexParameteri(tdata->texture_type, GL_TEXTURE_MAG_FILTER, |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1003 |
tdata->scaleMode); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1004 |
rdata->current.scaleMode = tdata->scaleMode; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1005 |
} |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1006 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1007 |
/* Configure color modulation */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1008 |
locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION]; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1009 |
glUniform4f(locModulation, |
5224
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
1010 |
texture->r * inv255f, |
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
1011 |
texture->g * inv255f, |
2178ffe17222
Added function SDL_RenderSetClipRect()
Sam Lantinga <slouken@libsdl.org>
parents:
5222
diff
changeset
|
1012 |
texture->b * inv255f, |
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1013 |
texture->a * inv255f); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1014 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1015 |
/* Configure texture blending */ |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1016 |
GLES2_SetBlendMode(rdata, blendMode); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1017 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1018 |
GLES2_SetTexCoords(rdata, SDL_TRUE); |
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1019 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1020 |
/* Emit the textured quad */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1021 |
vertices[0] = (GLfloat)dstrect->x; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1022 |
vertices[1] = (GLfloat)dstrect->y; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1023 |
vertices[2] = (GLfloat)(dstrect->x + dstrect->w); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1024 |
vertices[3] = (GLfloat)dstrect->y; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1025 |
vertices[4] = (GLfloat)dstrect->x; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1026 |
vertices[5] = (GLfloat)(dstrect->y + dstrect->h); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1027 |
vertices[6] = (GLfloat)(dstrect->x + dstrect->w); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1028 |
vertices[7] = (GLfloat)(dstrect->y + dstrect->h); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1029 |
glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1030 |
texCoords[0] = srcrect->x / (GLfloat)texture->w; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1031 |
texCoords[1] = srcrect->y / (GLfloat)texture->h; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1032 |
texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1033 |
texCoords[3] = srcrect->y / (GLfloat)texture->h; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1034 |
texCoords[4] = srcrect->x / (GLfloat)texture->w; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1035 |
texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1036 |
texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1037 |
texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1038 |
glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1039 |
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1040 |
if (glGetError() != GL_NO_ERROR) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1041 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1042 |
SDL_SetError("Failed to render texture"); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1043 |
return -1; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1044 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1045 |
return 0; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1046 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1047 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1048 |
static void |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1049 |
GLES2_RenderPresent(SDL_Renderer *renderer) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1050 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1051 |
GLES2_ActivateRenderer(renderer); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1052 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1053 |
/* Tell the video driver to swap buffers */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1054 |
SDL_GL_SwapWindow(renderer->window); |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1055 |
} |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1056 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1057 |
/************************************************************************************************* |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1058 |
* Renderer instantiation * |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1059 |
*************************************************************************************************/ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1060 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1061 |
#define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1062 |
|
5355
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1063 |
static void |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1064 |
GLES2_ResetState(SDL_Renderer *renderer) |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1065 |
{ |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1066 |
GLES2_DriverContext *rdata = (GLES2_DriverContext *) renderer->driverdata; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1067 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1068 |
if (SDL_CurrentContext == rdata->context) { |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1069 |
GLES2_UpdateViewport(renderer); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1070 |
} else { |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1071 |
GLES2_ActivateRenderer(renderer); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1072 |
} |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1073 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1074 |
rdata->current.blendMode = -1; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1075 |
rdata->current.scaleMode = 0; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1076 |
rdata->current.tex_coords = SDL_FALSE; |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1077 |
|
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1078 |
glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1079 |
glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD); |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1080 |
} |
cc2215cda170
Added OpenGL state caching for decent speed improvement.
Sam Lantinga <slouken@libsdl.org>
parents:
5333
diff
changeset
|
1081 |
|
5201
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1082 |
static SDL_Renderer * |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1083 |
GLES2_CreateRenderer(SDL_Window *window, Uint32 flags) |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1084 |
{ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1085 |
SDL_Renderer *renderer; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1086 |
GLES2_DriverContext *rdata; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1087 |
GLint nFormats; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1088 |
#ifndef ZUNE_HD |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1089 |
GLboolean hasCompiler; |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1090 |
#endif |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1091 |
|
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1092 |
/* Create the renderer struct */ |
523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1093 |
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer)); |
5209
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
1094 |
if (!renderer) { |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5206
diff
changeset
|
1095 |