diff options
author | Adrian Kummerlaender | 2018-05-21 13:04:41 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2018-05-21 13:05:43 +0200 |
commit | ffa662ec5acdaae36f0ffeaf0cee78a4200d897b (patch) | |
tree | 9933f6a0781a54e146664fa75bd235ed1bd7c154 /src/util.h | |
parent | 3bc6622f4f339a9ab3c808d02c48c1c144bc4e10 (diff) | |
download | computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar.gz computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar.bz2 computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar.lz computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar.xz computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar.zst computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.zip |
Introduce basic shader, texture buffer abstraction
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..ce8d012 --- /dev/null +++ b/src/util.h @@ -0,0 +1,44 @@ +#pragma once + +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; +} + +} |