Browse Source

shader: warn if GLSL shader does not contain #version line

Shaders without #version line (which are supposed to indicate GLSL 1.10) will be interpreted differently by different drivers, so this is almost certainly a mistake.  In the future, we can forbid this altogether or insert #version 110 automatically.
rdb 7 years ago
parent
commit
65a86d1b3f
1 changed files with 9 additions and 0 deletions
  1. 9 0
      panda/src/gobj/shader.cxx

+ 9 - 0
panda/src/gobj/shader.cxx

@@ -2750,6 +2750,7 @@ r_preprocess_source(ostream &out, istream &in, const Filename &fn,
   int ext_google_include = 0; // 1 = warn, 2 = enable
   int ext_google_line = 0;
   bool had_include = false;
+  bool had_version = false;
   int lineno = 0;
   bool write_line_directive = (fileno != 0);
 
@@ -2920,6 +2921,9 @@ r_preprocess_source(ostream &out, istream &in, const Filename &fn,
         write_line_directive = true;
       }
 
+    } else if (strcmp(directive, "version") == 0) {
+      had_version = true;
+
     } else if (strcmp(directive, "extension") == 0) {
       // Check for special preprocessing extensions.
       char extension[256];
@@ -3047,6 +3051,11 @@ r_preprocess_source(ostream &out, istream &in, const Filename &fn,
     out << line << "\n";
   }
 
+  if (fileno == 0 && !had_version) {
+    shader_cat.warning()
+      << "GLSL shader " << fn << " does not contain a #version line!\n";
+  }
+
   return true;
 }