From 059f67d1b5f764758a653c5db28cd8777b396343 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 4 Apr 2015 20:52:44 +0200 Subject: [PATCH] Improve GLSL error reporting, fix GLSL ES shader loading --- .../glstuff/glGraphicsStateGuardian_src.cxx | 10 ++++++- panda/src/glstuff/glShaderContext_src.cxx | 27 ++++++++++++------- panda/src/glstuff/glShaderContext_src.h | 4 +-- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 8e96089bfb..06fdd1eb4c 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -1382,7 +1382,7 @@ reset() { // if it failed to compile. This default shader just outputs // a red color, indicating that something went wrong. if (_default_shader == NULL) { - _default_shader = Shader::load(Shader::SL_GLSL, default_vshader, default_fshader); + _default_shader = Shader::make(Shader::SL_GLSL, default_vshader, default_fshader); } #endif @@ -2997,6 +2997,14 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader, } #endif // NDEBUG +#ifdef OPENGLES_2 + // We can't draw without a shader bound in OpenGL ES 2. This shouldn't + // happen anyway unless the default shader failed to compile somehow. + if (_current_shader_context == NULL) { + return false; + } +#endif + if (!GraphicsStateGuardian::begin_draw_primitives(geom_reader, munger, data_reader, force)) { return false; } diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index eb67ce51d5..1b66f6172a 100755 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -1593,7 +1593,7 @@ update_shader_texture_bindings(ShaderContext *prev) { // Description: This subroutine prints the infolog for a shader. //////////////////////////////////////////////////////////////////// void CLP(ShaderContext):: -glsl_report_shader_errors(GLuint shader, Shader::ShaderType type) { +glsl_report_shader_errors(GLuint shader, Shader::ShaderType type, bool fatal) { char *info_log; GLint length = 0; GLint num_chars = 0; @@ -1642,6 +1642,9 @@ glsl_report_shader_errors(GLuint shader, Shader::ShaderType type) { GLCAT.error(false) << fn << "(" << lineno << ") : " << (line.c_str() + prefixlen) << "\n"; + } else if (!fatal) { + GLCAT.warning(false) << line << "\n"; + } else { GLCAT.error(false) << line << "\n"; } @@ -1654,7 +1657,7 @@ glsl_report_shader_errors(GLuint shader, Shader::ShaderType type) { // Description: This subroutine prints the infolog for a program. //////////////////////////////////////////////////////////////////// void CLP(ShaderContext):: -glsl_report_program_errors(GLuint program) { +glsl_report_program_errors(GLuint program, bool fatal) { char *info_log; GLint length = 0; GLint num_chars = 0; @@ -1664,8 +1667,13 @@ glsl_report_program_errors(GLuint program) { if (length > 1) { info_log = (char *) alloca(length); _glgsg->_glGetProgramInfoLog(program, length, &num_chars, info_log); + if (strcmp(info_log, "Success.\n") != 0 && strcmp(info_log, "No errors.\n") != 0) { - GLCAT.error(false) << info_log << "\n"; + if (!fatal) { + GLCAT.warning(false) << info_log << "\n"; + } else { + GLCAT.error(false) << info_log << "\n"; + } } } } @@ -1733,7 +1741,7 @@ glsl_compile_shader(Shader::ShaderType type) { GLCAT.error() << "An error occurred while compiling GLSL shader " << _shader->get_filename(type) << ":\n"; - glsl_report_shader_errors(handle, type); + glsl_report_shader_errors(handle, type, true); _glgsg->_glDeleteShader(handle); _glgsg->report_my_gl_errors(); return false; @@ -1743,7 +1751,7 @@ glsl_compile_shader(Shader::ShaderType type) { _glsl_shaders.push_back(handle); // There might be warnings, so report those. - glsl_report_shader_errors(handle, type); + glsl_report_shader_errors(handle, type, false); return true; } @@ -1776,9 +1784,8 @@ glsl_compile_and_link() { valid &= glsl_compile_shader(Shader::ST_fragment); } -#ifdef OPENGLES - nassertr(false, false); // OpenGL ES has no geometry shaders. -#else + // OpenGL ES has no geometry shaders. +#ifndef OPENGLES if (!_shader->get_text(Shader::ST_geometry).empty()) { valid &= glsl_compile_shader(Shader::ST_geometry); @@ -1823,12 +1830,12 @@ glsl_compile_and_link() { _glgsg->_glGetProgramiv(_glsl_program, GL_LINK_STATUS, &status); if (status != GL_TRUE) { GLCAT.error() << "An error occurred while linking GLSL shader program!\n"; - glsl_report_program_errors(_glsl_program); + glsl_report_program_errors(_glsl_program, true); return false; } // Report any warnings. - glsl_report_program_errors(_glsl_program); + glsl_report_program_errors(_glsl_program, false); // Dump the binary if requested. #if !defined(NDEBUG) && !defined(OPENGLES) diff --git a/panda/src/glstuff/glShaderContext_src.h b/panda/src/glstuff/glShaderContext_src.h index 7def61d924..19c7190bcd 100755 --- a/panda/src/glstuff/glShaderContext_src.h +++ b/panda/src/glstuff/glShaderContext_src.h @@ -73,8 +73,8 @@ private: bool _uses_standard_vertex_arrays; - void glsl_report_shader_errors(GLuint shader, Shader::ShaderType type); - void glsl_report_program_errors(GLuint program); + void glsl_report_shader_errors(GLuint shader, Shader::ShaderType type, bool fatal); + void glsl_report_program_errors(GLuint program, bool fatal); bool glsl_compile_shader(Shader::ShaderType type); bool glsl_compile_and_link(); bool parse_and_set_short_hand_shader_vars(Shader::ShaderArgId &arg_id, Shader *s);