Module: Mesa
Branch: master
Commit: b8b774c775b672c89f1f4007c7b9575052d85739
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=b8b774c775b672c89f1f4007c7b9575052d85739

Author: Brian Paul <[email protected]>
Date:   Mon Sep 14 17:24:25 2009 -0600

glsl: remove extra #version directives from concatenated shader sources

When we concatenate shaders to do our form of poor-man linking, if there's
multiple #version directives, preprocessing fails.  This change disables
the extra #version directives by changing the first two chars to //.

This should help with some Wine issues such as bug 23946.

---

 src/mesa/shader/slang/slang_link.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/mesa/shader/slang/slang_link.c 
b/src/mesa/shader/slang/slang_link.c
index 387659f..3617ce1 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -540,6 +540,32 @@ _slang_update_inputs_outputs(struct gl_program *prog)
 
 
 
+/**
+ * Remove extra #version directives from the concatenated source string.
+ * Disable the extra ones by converting first two chars to //, a comment.
+ * This is a bit of hack to work around a preprocessor bug that only
+ * allows one #version directive per source.
+ */
+static void
+remove_extra_version_directives(GLchar *source)
+{
+   GLuint verCount = 0;
+   while (1) {
+      char *ver = _mesa_strstr(source, "#version");
+      if (ver) {
+         verCount++;
+         if (verCount > 1) {
+            ver[0] = '/';
+            ver[1] = '/';
+         }
+         source += 8;
+      }
+      else {
+         break;
+      }
+   }
+}
+
 
 
 /**
@@ -587,6 +613,8 @@ concat_shaders(struct gl_shader_program *shProg, GLenum 
shaderType)
    _mesa_printf("---NEW CONCATENATED SHADER---:\n%s\n------------\n", source);
    */
 
+   remove_extra_version_directives(source);
+
    newShader = CALLOC_STRUCT(gl_shader);
    newShader->Type = shaderType;
    newShader->Source = source;

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to