-
-
Save anonymous/19b543855b53ccb0b217 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static Shader<type> createShaderFromFile(std::string filepath) | |
{ | |
Shader<type> shader; | |
std::string shaderSource(util::loadFileContent<std::string>(filepath)); | |
assert(!shaderSource.empty()); | |
GLint shaderLength = shaderSource.length(); | |
auto shaderString = shaderSource.c_str(); | |
gl::ShaderSource(shader.id_.get(), 1, &shaderString, &shaderLength); | |
gl::CompileShader(shader.id_.get()); | |
GLint compileError = gl::GetError(); | |
GLint isCompiled = 0; | |
gl::GetShaderiv(shader.id_.get(), gl::COMPILE_STATUS, &isCompiled); | |
if(compileError) | |
{ | |
std::cout << "Error: " << compileError << "." << std::endl; | |
} | |
else | |
{ | |
std::cout << "No errors." << std::endl; | |
} | |
GLint logLength = 0; | |
gl::GetShaderiv(shader.id_.get(), gl::INFO_LOG_LENGTH, &logLength); | |
if(logLength > 1) | |
{ | |
std::vector<char> infoLog(logLength); | |
gl::GetShaderInfoLog(shader.id_.get(), logLength, &logLength, infoLog.data()); | |
std::cout << "Shader compilation log for " << filepath <<": " << std::endl; | |
std::cout << infoLog.data() << std::endl; | |
} | |
assert(isCompiled == gl::TRUE_); | |
return shader; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment