diff options
author | Adrian Kummerlaender | 2018-05-25 23:47:27 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2018-05-25 23:48:59 +0200 |
commit | f728e4c8d202de241673a13ce61570b6acb4bba7 (patch) | |
tree | a7e29c4319f0e6d667b98f359ddf089c0565c15a /src/shader/util.h | |
parent | 5157658ec0cc07d2c56c978ca010cbb78236439f (diff) | |
download | computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.gz computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.bz2 computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.lz computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.xz computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.zst computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.zip |
Restructure source directory
Diffstat (limited to 'src/shader/util.h')
-rw-r--r-- | src/shader/util.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/shader/util.h b/src/shader/util.h new file mode 100644 index 0000000..7aec674 --- /dev/null +++ b/src/shader/util.h @@ -0,0 +1,46 @@ +#pragma once + +#include <iostream> + +namespace util { + +GLint getUniform(GLuint program, const std::string& name) { + const GLint uniform = glGetUniformLocation(program, name.c_str()); + if ( uniform == -1 ) { + std::cerr << "Could not bind uniform " << name << std::endl; + } + return uniform; +} + +GLint compileShader(const std::string& source, GLenum type) { + GLint shader = glCreateShader(type); + + if ( !shader ) { + std::cerr << "Cannot create a shader of type " << type << std::endl; + exit(-1); + } + + const char* source_data = source.c_str(); + const int source_length = source.size(); + + glShaderSource(shader, 1, &source_data, &source_length); + glCompileShader(shader); + + GLint compiled; + glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); + if ( !compiled ) { + std::cerr << "Cannot compile shader" << std::endl; + GLint maxLength = 0; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); + std::vector<GLchar> errorLog(maxLength); + glGetShaderInfoLog(shader, maxLength, &maxLength, &errorLog[0]); + for( auto c : errorLog ) { + std::cerr << c; + } + std::cerr << std::endl; + } + + return shader; +} + +} |