Pretty print shaders for debugging purposes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index e882577..306b518 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -521,6 +521,22 @@ GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type, GLenum shader_t
SDL_assert(num_src <= SDL_arraysize(shader_src_list));
+#ifdef DEBUG_PRINT_SHADERS
+ {
+ int i;
+ char *message = NULL;
+
+ SDL_asprintf(&message, "Compiling shader:\n");
+ for (i = 0; i < num_src; ++i) {
+ char *last_message = message;
+ SDL_asprintf(&message, "%s%s", last_message, shader_src_list[i]);
+ SDL_free(last_message);
+ }
+ SDL_Log("%s\n", message);
+ SDL_free(message);
+ }
+#endif
+
/* Compile */
id = data->glCreateShader(shader_type);
data->glShaderSource(id, num_src, shader_src_list, NULL);
@@ -541,10 +557,10 @@ GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type, GLenum shader_t
}
}
if (info) {
- SDL_SetError("Failed to load the shader: %s", info);
+ SDL_SetError("Failed to load the shader %d: %s", type, info);
SDL_small_free(info, isstack);
} else {
- SDL_SetError("Failed to load the shader");
+ SDL_SetError("Failed to load the shader %d", type);
}
data->glDeleteShader(id);
return 0;
diff --git a/src/render/opengles2/SDL_shaders_gles2.c b/src/render/opengles2/SDL_shaders_gles2.c
index 54a5896..cd7f6f1 100644
--- a/src/render/opengles2/SDL_shaders_gles2.c
+++ b/src/render/opengles2/SDL_shaders_gles2.c
@@ -32,117 +32,122 @@
* Vertex/fragment shader source *
*************************************************************************************************/
-static const char GLES2_Fragment_Include_Best_Texture_Precision[] = "\n\
- #ifdef GL_FRAGMENT_PRECISION_HIGH\n\
- #define SDL_TEXCOORD_PRECISION highp\n\
- #else\n\
- #define SDL_TEXCOORD_PRECISION mediump\n\
- #endif\n\
- precision mediump float;\n\
-";
-
-static const char GLES2_Fragment_Include_Medium_Texture_Precision[] = "\n\
- #define SDL_TEXCOORD_PRECISION mediump\n\
- precision mediump float;\n\
-";
-
-static const char GLES2_Fragment_Include_High_Texture_Precision[] = "\n\
- #define SDL_TEXCOORD_PRECISION highp\n\
- precision mediump float;\n\
-";
-
-static const char GLES2_Fragment_Include_Undef_Precision[] = "\n\
- #define mediump\n\
- #define highp\n\
- #define lowp\n\
- #define SDL_TEXCOORD_PRECISION\n\
-";
-
-static const char GLES2_Vertex_Default[] = " \
- uniform mat4 u_projection; \
- attribute vec2 a_position; \
- attribute vec4 a_color; \
- attribute vec2 a_texCoord; \
- varying vec2 v_texCoord; \
- varying vec4 v_color; \
- \
- void main() \
- { \
- v_texCoord = a_texCoord; \
- gl_Position = u_projection * vec4(a_position, 0.0, 1.0);\
- gl_PointSize = 1.0; \
- v_color = a_color; \
- } \
-";
-
-static const char GLES2_Fragment_Solid[] = " \
- varying mediump vec4 v_color; \
- \
- void main() \
- { \
- gl_FragColor = v_color; \
- } \
-";
-
-static const char GLES2_Fragment_TextureABGR[] = " \
- uniform sampler2D u_texture; \
- varying mediump vec4 v_color;\n\
- varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n\
- \
- void main() \
- { \
- gl_FragColor = texture2D(u_texture, v_texCoord); \
- gl_FragColor *= v_color; \
- } \
-";
+static const char GLES2_Fragment_Include_Best_Texture_Precision[] = \
+"#ifdef GL_FRAGMENT_PRECISION_HIGH\n" \
+"#define SDL_TEXCOORD_PRECISION highp\n" \
+"#else\n" \
+"#define SDL_TEXCOORD_PRECISION mediump\n" \
+"#endif\n" \
+"\n" \
+"precision mediump float;\n" \
+"\n" \
+;
+
+static const char GLES2_Fragment_Include_Medium_Texture_Precision[] = \
+"#define SDL_TEXCOORD_PRECISION mediump\n" \
+"precision mediump float;\n" \
+"\n" \
+;
+
+static const char GLES2_Fragment_Include_High_Texture_Precision[] = \
+"#define SDL_TEXCOORD_PRECISION highp\n" \
+"precision mediump float;\n" \
+"\n" \
+;
+
+static const char GLES2_Fragment_Include_Undef_Precision[] = \
+"#define mediump\n" \
+"#define highp\n" \
+"#define lowp\n" \
+"#define SDL_TEXCOORD_PRECISION\n" \
+"\n" \
+;
+
+static const char GLES2_Vertex_Default[] = \
+"uniform mat4 u_projection;\n" \
+"attribute vec2 a_position;\n" \
+"attribute vec4 a_color;\n" \
+"attribute vec2 a_texCoord;\n" \
+"varying vec2 v_texCoord;\n" \
+"varying vec4 v_color;\n" \
+"\n" \
+"void main()\n" \
+"{\n" \
+" v_texCoord = a_texCoord;\n" \
+" gl_Position = u_projection * vec4(a_position, 0.0, 1.0);\n" \
+" gl_PointSize = 1.0;\n" \
+" v_color = a_color;\n" \
+"}\n" \
+;
+
+static const char GLES2_Fragment_Solid[] = \
+"varying mediump vec4 v_color;\n" \
+"\n" \
+"void main()\n" \
+"{\n" \
+" gl_FragColor = v_color;\n" \
+"}\n" \
+;
+
+static const char GLES2_Fragment_TextureABGR[] = \
+"uniform sampler2D u_texture;\n" \
+"varying mediump vec4 v_color;\n" \
+"varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n" \
+"\n" \
+"void main()\n" \
+"{\n" \
+" gl_FragColor = texture2D(u_texture, v_texCoord);\n" \
+" gl_FragColor *= v_color;\n" \
+"}\n" \
+;
/* ARGB to ABGR conversion */
-static const char GLES2_Fragment_TextureARGB[] = " \
- uniform sampler2D u_texture; \
- varying mediump vec4 v_color;\n\
- varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n\
- \
- void main() \
- { \
- mediump vec4 abgr = texture2D(u_texture, v_texCoord); \
- gl_FragColor = abgr; \
- gl_FragColor.r = abgr.b; \
- gl_FragColor.b = abgr.r; \
- gl_FragColor *= v_color; \
- } \
-";
+static const char GLES2_Fragment_TextureARGB[] = \
+"uniform sampler2D u_texture;\n" \
+"varying mediump vec4 v_color;\n" \
+"varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n" \
+"\n" \
+"void main()\n" \
+"{\n" \
+" mediump vec4 abgr = texture2D(u_texture, v_texCoord);\n" \
+" gl_FragColor = abgr;\n" \
+" gl_FragColor.r = abgr.b;\n" \
+" gl_FragColor.b = abgr.r;\n" \
+" gl_FragColor *= v_color;\n" \
+"}\n" \
+;
/* RGB to ABGR conversion */
-static const char GLES2_Fragment_TextureRGB[] = " \
- uniform sampler2D u_texture; \
- varying mediump vec4 v_color;\n\
- varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n\
- \
- void main() \
- { \
- mediump vec4 abgr = texture2D(u_texture, v_texCoord); \
- gl_FragColor = abgr; \
- gl_FragColor.r = abgr.b; \
- gl_FragColor.b = abgr.r; \
- gl_FragColor.a = 1.0; \
- gl_FragColor *= v_color; \
- } \
-";
+static const char GLES2_Fragment_TextureRGB[] = \
+"uniform sampler2D u_texture;\n" \
+"varying mediump vec4 v_color;\n" \
+"varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n" \
+"\n" \
+"void main()\n" \
+"{\n" \
+" mediump vec4 abgr = texture2D(u_texture, v_texCoord);\n" \
+" gl_FragColor = abgr;\n" \
+" gl_FragColor.r = abgr.b;\n" \
+" gl_FragColor.b = abgr.r;\n" \
+" gl_FragColor.a = 1.0;\n" \
+" gl_FragColor *= v_color;\n" \
+"}\n" \
+;
/* BGR to ABGR conversion */
-static const char GLES2_Fragment_TextureBGR[] = " \
- uniform sampler2D u_texture; \
- varying mediump vec4 v_color;\n\
- varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n\
- \
- void main() \
- { \
- mediump vec4 abgr = texture2D(u_texture, v_texCoord); \
- gl_FragColor = abgr; \
- gl_FragColor.a = 1.0; \
- gl_FragColor *= v_color; \
- } \
-";
+static const char GLES2_Fragment_TextureBGR[] = \
+"uniform sampler2D u_texture;\n" \
+"varying mediump vec4 v_color;\n" \
+"varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n" \
+"\n" \
+"void main()\n" \
+"{\n" \
+" mediump vec4 abgr = texture2D(u_texture, v_texCoord);\n" \
+" gl_FragColor = abgr;\n" \
+" gl_FragColor.a = 1.0;\n" \
+" gl_FragColor *= v_color;\n" \
+"}\n" \
+;
#if SDL_HAVE_YUV
@@ -154,6 +159,7 @@ static const char GLES2_Fragment_TextureBGR[] = " \
"const mat3 matrix = mat3( 1, 1, 1,\n" \
" 0, -0.3441, 1.772,\n" \
" 1.402, -0.7141, 0);\n" \
+"\n" \
#define BT601_SHADER_CONSTANTS \
"// YUV offset \n" \
@@ -163,6 +169,7 @@ static const char GLES2_Fragment_TextureBGR[] = " \
"const mat3 matrix = mat3( 1.1644, 1.1644, 1.1644,\n" \
" 0, -0.3918, 2.0172,\n" \
" 1.596, -0.813, 0);\n" \
+"\n" \
#define BT709_SHADER_CONSTANTS \
"// YUV offset \n" \
@@ -172,6 +179,7 @@ static const char GLES2_Fragment_TextureBGR[] = " \
"const mat3 matrix = mat3( 1.1644, 1.1644, 1.1644,\n" \
" 0, -0.2132, 2.1124,\n" \
" 1.7927, -0.5329, 0);\n" \
+"\n" \
#define YUV_SHADER_PROLOGUE \
@@ -183,7 +191,6 @@ static const char GLES2_Fragment_TextureBGR[] = " \
"\n" \
#define YUV_SHADER_BODY \
-"\n" \
"void main()\n" \
"{\n" \
" mediump vec3 yuv;\n" \
@@ -204,7 +211,6 @@ static const char GLES2_Fragment_TextureBGR[] = " \
"}" \
#define NV12_RA_SHADER_BODY \
-"\n" \
"void main()\n" \
"{\n" \
" mediump vec3 yuv;\n" \
@@ -224,7 +230,6 @@ static const char GLES2_Fragment_TextureBGR[] = " \
"}" \
#define NV12_RG_SHADER_BODY \
-"\n" \
"void main()\n" \
"{\n" \
" mediump vec3 yuv;\n" \
@@ -244,7 +249,6 @@ static const char GLES2_Fragment_TextureBGR[] = " \
"}" \
#define NV21_SHADER_BODY \
-"\n" \
"void main()\n" \
"{\n" \
" mediump vec3 yuv;\n" \
@@ -326,20 +330,21 @@ static const char GLES2_Fragment_TextureNV21BT709[] = \
#endif
/* Custom Android video format texture */
-static const char GLES2_Fragment_TextureExternalOES_Prologue[] = " \
- #extension GL_OES_EGL_image_external : require\n\
-";
-static const char GLES2_Fragment_TextureExternalOES[] = " \
- uniform samplerExternalOES u_texture; \
- varying mediump vec4 v_color; \
- varying SDL_TEXCOORD_PRECISION vec2 v_texCoord; \
- \
- void main() \
- { \
- gl_FragColor = texture2D(u_texture, v_texCoord); \
- gl_FragColor *= v_color; \
- } \
-";
+static const char GLES2_Fragment_TextureExternalOES_Prologue[] = \
+"#extension GL_OES_EGL_image_external : require\n" \
+"\n" \
+;
+static const char GLES2_Fragment_TextureExternalOES[] = \
+"uniform samplerExternalOES u_texture;\n" \
+"varying mediump vec4 v_color;\n" \
+"varying SDL_TEXCOORD_PRECISION vec2 v_texCoord;\n" \
+"\n" \
+"void main()\n" \
+"{\n" \
+" gl_FragColor = texture2D(u_texture, v_texCoord);\n" \
+" gl_FragColor *= v_color;\n" \
+"}\n" \
+;
/*************************************************************************************************