From 8fc78364e9396a571e86cc466884c42c97d5388d Mon Sep 17 00:00:00 2001 From: LoganDooley <56769909+LoganDooley@users.noreply.github.com> Date: Mon, 12 Sep 2022 21:09:57 -0400 Subject: [PATCH] shaderloader update --- src/shaderloader.h | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/shaderloader.h b/src/shaderloader.h index d5d07db..09acc26 100644 --- a/src/shaderloader.h +++ b/src/shaderloader.h @@ -4,46 +4,36 @@ #include #include #include - class ShaderLoader{ public: static GLuint createShaderProgram(const char * vertex_file_path, const char * fragment_file_path){ // Create and compile the shaders. GLuint vertexShaderID = createShader(GL_VERTEX_SHADER, vertex_file_path); GLuint fragmentShaderID = createShader(GL_FRAGMENT_SHADER, fragment_file_path); - // Link the shader program. GLuint programID = glCreateProgram(); glAttachShader(programID, vertexShaderID); glAttachShader(programID, fragmentShaderID); glLinkProgram(programID); - // Print the info log if error GLint status; glGetProgramiv(programID, GL_LINK_STATUS, &status); - if (status == GL_FALSE) { GLint length; glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &length); - std::string log(length, '\0'); glGetProgramInfoLog(programID, length, nullptr, &log[0]); - glDeleteProgram(programID); throw std::runtime_error(log); } - // Shaders no longer necessary, stored in program glDeleteShader(vertexShaderID); glDeleteShader(fragmentShaderID); - return programID; } - private: static GLuint createShader(GLenum shaderType, const char *filepath){ GLuint shaderID = glCreateShader(shaderType); - // Read shader file. std::string code; QString filepathStr = QString(filepath); @@ -54,27 +44,21 @@ class ShaderLoader{ }else{ throw std::runtime_error(std::string("Failed to open shader: ")+filepath); } - // Compile shader code. const char *codePtr = code.c_str(); glShaderSource(shaderID, 1, &codePtr, nullptr); // Assumes code is null terminated glCompileShader(shaderID); - // Print info log if shader fails to compile. GLint status; glGetShaderiv(shaderID, GL_COMPILE_STATUS, &status); - if (status == GL_FALSE) { GLint length; glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &length); - std::string log(length, '\0'); glGetShaderInfoLog(shaderID, length, nullptr, &log[0]); - - glDeleteProgram(shaderID); + glDeleteShader(shaderID); throw std::runtime_error(log); } - return shaderID; } };