diff --git a/src/mbgl/shader/shader.cpp b/src/mbgl/shader/shader.cpp index ed4cb729b..c69518c8c 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 9b150c37e..329022479 100644 --- a/src/mbgl/shader/shader.hpp +++ b/src/mbgl/shader/shader.hpp @@ -28,6 +28,9 @@ protected: private: bool compileShader(uint32_t *shader, uint32_t type, const char *source); + + uint32_t vertShader = 0; + uint32_t fragShader = 0; }; }