Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Don't validate/delete shaders #2147

Merged
merged 2 commits into from
Sep 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 6 additions & 33 deletions src/mbgl/shader/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -67,37 +65,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<GLchar[]>(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));
MBGL_CHECK_ERROR(glDetachShader(program, fragShader));
MBGL_CHECK_ERROR(glDeleteShader(fragShader));

a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos"));
}

Expand Down Expand Up @@ -140,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;
}
}
3 changes: 3 additions & 0 deletions src/mbgl/shader/shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

}
Expand Down