changeset 5236:e82908c86c9c

Made the shaders easier to debug when they don't compile
author Sam Lantinga <slouken@libsdl.org>
date Tue, 08 Feb 2011 20:31:39 -0800
parents 8efa43b915be
children 74bc160186a8
files src/render/opengl/SDL_shaders_gl.c
diffstat 1 files changed, 37 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/render/opengl/SDL_shaders_gl.c	Tue Feb 08 20:23:52 2011 -0800
+++ b/src/render/opengl/SDL_shaders_gl.c	Tue Feb 08 20:31:39 2011 -0800
@@ -31,6 +31,8 @@
 
 /* OpenGL shader implementation */
 
+/*#define DEBUG_SHADERS*/
+
 typedef struct
 {
     GLenum program;
@@ -74,51 +76,43 @@
     /* SHADER_SOLID */
     {
         /* vertex shader */
-        " \
-varying vec4 v_color; \
- \
-void main() \
-{ \
-    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \
-    v_color = gl_Color; \
-} \
-",
+"varying vec4 v_color;\n"
+"\n"
+"void main()\n"
+"{\n"
+"    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+"    v_color = gl_Color;\n"
+"}",
         /* fragment shader */
-        " \
-varying vec4 v_color; \
- \
-void main() \
-{ \
-    gl_FragColor = v_color; \
-} \
-"
+"varying vec4 v_color;\n"
+"\n"
+"void main()\n"
+"{\n"
+"    gl_FragColor = v_color;\n"
+"}"
     },
 
     /* SHADER_RGB */
     {
         /* vertex shader */
-        " \
-varying vec4 v_color; \
-varying vec2 v_texCoord; \
- \
-void main() \
-{ \
-    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \
-    v_color = gl_Color; \
-    v_texCoord = vec2(gl_MultiTexCoord0); \
-} \
-",
+"varying vec4 v_color;\n"
+"varying vec2 v_texCoord;\n"
+"\n"
+"void main()\n"
+"{\n"
+"    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+"    v_color = gl_Color;\n"
+"    v_texCoord = vec2(gl_MultiTexCoord0);\n"
+"}",
         /* fragment shader */
-        " \
-varying vec4 v_color; \
-varying vec2 v_texCoord; \
-uniform sampler2D tex0; \
- \
-void main() \
-{ \
-    gl_FragColor = texture2D(tex0, v_texCoord) * v_color; \
-} \
-"
+"varying vec4 v_color;\n"
+"varying vec2 v_texCoord;\n"
+"uniform sampler2D tex0;\n"
+"\n"
+"void main()\n"
+"{\n"
+"    gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
+"}"
     },
 };
 
@@ -142,8 +136,11 @@
         info = SDL_stack_alloc(char, length+1);
         ctx->glGetInfoLogARB(shader, length, NULL, info);
         SDL_LogError(SDL_LOG_CATEGORY_RENDER,
-            "Failed to compile shader:\n%s\n%s", source, info);
-fprintf(stderr, "Failed to compile shader:\n%s\n%s", source, info);
+            "Failed to compile shader:\n%s%s\n%s", defines, source, info);
+#ifdef DEBUG_SHADERS
+        fprintf(stderr,
+            "Failed to compile shader:\n%s%s\n%s", defines, source, info);
+#endif
         SDL_stack_free(info);
 
         return SDL_FALSE;