From c15439b7cbf0095960882b8c1480a837e35d5047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 9 Apr 2015 20:36:52 -0700 Subject: [PATCH] Added ability to continue when GL shader compilation fails. Issue #327. --- src/renderer_gl.cpp | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 1f5f3b6a..a619dd84 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -2853,32 +2853,40 @@ namespace bgfx { namespace gl void ProgramGL::create(const ShaderGL& _vsh, const ShaderGL& _fsh) { m_id = glCreateProgram(); - BX_TRACE("program create: %d: %d, %d", m_id, _vsh.m_id, _fsh.m_id); + BX_TRACE("Program create: GL%d: GL%d, GL%d", m_id, _vsh.m_id, _fsh.m_id); const uint64_t id = (uint64_t(_vsh.m_hash)<<32) | _fsh.m_hash; const bool cached = s_renderGL->programFetchFromCache(m_id, id); if (!cached) { - GL_CHECK(glAttachShader(m_id, _vsh.m_id) ); - - if (0 != _fsh.m_id) - { - GL_CHECK(glAttachShader(m_id, _fsh.m_id) ); - } - - GL_CHECK(glLinkProgram(m_id) ); - GLint linked = 0; - GL_CHECK(glGetProgramiv(m_id, GL_LINK_STATUS, &linked) ); + if (0 == _vsh.m_id) + { + GL_CHECK(glAttachShader(m_id, _vsh.m_id) ); + + if (0 != _fsh.m_id) + { + GL_CHECK(glAttachShader(m_id, _fsh.m_id) ); + } + + GL_CHECK(glLinkProgram(m_id) ); + GL_CHECK(glGetProgramiv(m_id, GL_LINK_STATUS, &linked) ); + + if (0 == linked) + { + char log[1024]; + GL_CHECK(glGetProgramInfoLog(m_id, sizeof(log), NULL, log) ); + BX_TRACE("%d: %s", linked, log); + } + } if (0 == linked) { - char log[1024]; - GL_CHECK(glGetProgramInfoLog(m_id, sizeof(log), NULL, log) ); - BX_TRACE("%d: %s", linked, log); - + BX_WARN(0 != _vsh.m_id, "Invalid vertex/compute shader."); GL_CHECK(glDeleteProgram(m_id) ); + m_used[0] = Attrib::Count; + m_id = 0; return; } @@ -4188,6 +4196,7 @@ namespace bgfx { namespace gl BX_TRACE("Failed to compile shader. %d: %s", compiled, log); GL_CHECK(glDeleteShader(m_id) ); + m_id = 0; BGFX_FATAL(false, bgfx::Fatal::InvalidShader, "Failed to compile shader."); } else if (BX_ENABLED(BGFX_CONFIG_DEBUG) @@ -5052,6 +5061,10 @@ namespace bgfx { namespace gl { programIdx = key.m_program; GLuint id = invalidHandle == programIdx ? 0 : m_program[programIdx].m_id; + + // Skip rendering if program index is valid, but program is invalid. + programIdx = 0 == id ? invalidHandle : programIdx; + GL_CHECK(glUseProgram(id) ); programChanged = constantsChanged =