Browse Source

Allow setting custom filename on shader, fix diagnostics for Mesa GLES2

rdb 9 years ago
parent
commit
d3172015d5
3 changed files with 42 additions and 2 deletions
  1. 11 2
      panda/src/glstuff/glShaderContext_src.cxx
  2. 30 0
      panda/src/gobj/shader.I
  3. 1 0
      panda/src/gobj/shader.h

+ 11 - 2
panda/src/glstuff/glShaderContext_src.cxx

@@ -2666,10 +2666,10 @@ glsl_report_shader_errors(GLuint shader, Shader::ShaderType type, bool fatal) {
   istringstream log(info_log);
   string line;
   while (getline(log, line)) {
-    int fileno, lineno;
+    int fileno, lineno, colno;
     int prefixlen = 0;
 
-    // First is AMDIntel driver syntax, second is NVIDIA syntax.
+    // This first format is used by the majority of compilers.
     if (sscanf(line.c_str(), "ERROR: %d:%d: %n", &fileno, &lineno, &prefixlen) == 2
         && prefixlen > 0) {
 
@@ -2688,10 +2688,19 @@ glsl_report_shader_errors(GLuint shader, Shader::ShaderType type, bool fatal) {
     } else if (sscanf(line.c_str(), "%d(%d) : %n", &fileno, &lineno, &prefixlen) == 2
                && prefixlen > 0) {
 
+      // This is the format NVIDIA uses.
       Filename fn = _shader->get_filename_from_index(fileno, type);
       GLCAT.error(false)
         << fn << "(" << lineno << ") : " << (line.c_str() + prefixlen) << "\n";
 
+    } else if (sscanf(line.c_str(), "%d:%d(%d): %n", &fileno, &lineno, &colno, &prefixlen) == 3
+               && prefixlen > 0) {
+
+      // This is the format for Mesa's OpenGL ES 2 implementation.
+      Filename fn = _shader->get_filename_from_index(fileno, type);
+      GLCAT.error(false)
+        << fn << ":" << lineno << "(" << colno << "): " << (line.c_str() + prefixlen) << "\n";
+
     } else if (!fatal) {
       GLCAT.warning(false) << line << "\n";
 

+ 30 - 0
panda/src/gobj/shader.I

@@ -50,6 +50,36 @@ get_filename(ShaderType type) const {
   }
 }
 
+/**
+ * Sets the Shader's filename for the given shader type.  Useful for
+ * associating a shader created with Shader.make with a name for diagnostics.
+ */
+INLINE void Shader::
+set_filename(ShaderType type, const Filename &filename) {
+  switch (type) {
+  case ST_vertex:
+    _filename._vertex = filename;
+    break;
+  case ST_fragment:
+    _filename._fragment = filename;
+    break;
+  case ST_geometry:
+    _filename._geometry = filename;
+    break;
+  case ST_tess_control:
+    _filename._tess_control = filename;
+    break;
+  case ST_tess_evaluation:
+    _filename._tess_evaluation = filename;
+    break;
+  case ST_compute:
+    _filename._compute = filename;
+    break;
+  default:
+    _filename._shared = filename;
+  }
+}
+
 /**
  * Return the Shader's text for the given shader type.
  */

+ 1 - 0
panda/src/gobj/shader.h

@@ -98,6 +98,7 @@ PUBLISHED:
   static PT(Shader) make_compute(ShaderLanguage lang, const string &body);
 
   INLINE Filename get_filename(ShaderType type = ST_none) const;
+  INLINE void set_filename(ShaderType type, const Filename &filename);
   INLINE const string &get_text(ShaderType type = ST_none) const;
   INLINE bool get_error_flag() const;
   INLINE ShaderLanguage get_language() const;