From 6db8e65394838e3269351cf393a8820cea1326a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 21 Aug 2015 14:33:17 -0400 Subject: [PATCH 1/2] don't validate the program it's not in a state where validation always succeeds with all drivers, e.g. because textures might not be attached yet --- src/mbgl/shader/shader.cpp | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/mbgl/shader/shader.cpp b/src/mbgl/shader/shader.cpp index 1e3df1bbc22..ed4cb729b3f 100644 --- a/src/mbgl/shader/shader.cpp +++ b/src/mbgl/shader/shader.cpp @@ -67,31 +67,6 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo } } - { - // Validate program - GLint status; - MBGL_CHECK_ERROR(glValidateProgram(program)); - - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_VALIDATE_STATUS, &status)); - if (status == 0) { - GLint logLength; - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); - const auto log = std::make_unique(logLength); - if (logLength > 0) { - MBGL_CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); - Log::Error(Event::Shader, "Program failed to validate: %s", log.get()); - } - - MBGL_CHECK_ERROR(glDeleteShader(vertShader)); - vertShader = 0; - MBGL_CHECK_ERROR(glDeleteShader(fragShader)); - fragShader = 0; - MBGL_CHECK_ERROR(glDeleteProgram(program)); - program = 0; - throw util::ShaderException(std::string { "Program " } + name + " failed to link: " + log.get()); - } - } - // Remove the compiled shaders; they are now part of the program. MBGL_CHECK_ERROR(glDetachShader(program, vertShader)); MBGL_CHECK_ERROR(glDeleteShader(vertShader)); From 5ef7011089e761dda0a26782c04dad9f61e65d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 21 Aug 2015 14:34:06 -0400 Subject: [PATCH 2/2] don't delete the shaders before the program some GPU drivers have issues with deleting shader objects that are attached to programs. while this is allowed by the spec, it seems that some drivers are crashing nonetheless. --- src/mbgl/shader/shader.cpp | 14 ++++++-------- src/mbgl/shader/shader.hpp | 3 +++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/mbgl/shader/shader.cpp b/src/mbgl/shader/shader.cpp index ed4cb729b3f..c69518c8c8f 100644 --- a/src/mbgl/shader/shader.cpp +++ b/src/mbgl/shader/shader.cpp @@ -20,8 +20,6 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo program = MBGL_CHECK_ERROR(glCreateProgram()); - GLuint vertShader = 0; - GLuint fragShader = 0; if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); MBGL_CHECK_ERROR(glDeleteProgram(program)); @@ -67,12 +65,6 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo } } - // Remove the compiled shaders; they are now part of the program. - MBGL_CHECK_ERROR(glDetachShader(program, vertShader)); - MBGL_CHECK_ERROR(glDeleteShader(vertShader)); - MBGL_CHECK_ERROR(glDetachShader(program, fragShader)); - MBGL_CHECK_ERROR(glDeleteShader(fragShader)); - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } @@ -115,7 +107,13 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { Shader::~Shader() { if (program) { + MBGL_CHECK_ERROR(glDetachShader(program, vertShader)); + MBGL_CHECK_ERROR(glDetachShader(program, fragShader)); MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; + MBGL_CHECK_ERROR(glDeleteShader(vertShader)); + vertShader = 0; + MBGL_CHECK_ERROR(glDeleteShader(fragShader)); + fragShader = 0; } } diff --git a/src/mbgl/shader/shader.hpp b/src/mbgl/shader/shader.hpp index 9b150c37edf..32902247963 100644 --- a/src/mbgl/shader/shader.hpp +++ b/src/mbgl/shader/shader.hpp @@ -28,6 +28,9 @@ class Shader : private util::noncopyable { private: bool compileShader(uint32_t *shader, uint32_t type, const char *source); + + uint32_t vertShader = 0; + uint32_t fragShader = 0; }; }