diff options
author | Adrian Kummerlaender | 2018-06-08 14:15:59 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2018-06-08 14:15:59 +0200 |
commit | e9885141e4049a06b89000bf34959174fb2d4491 (patch) | |
tree | e35d057d7c9b92720d4584fed9c26f6eacfc5c60 /src | |
parent | 4fec98839385136f768c8ea1ee265fcaa50d8cc9 (diff) | |
download | computicle-e9885141e4049a06b89000bf34959174fb2d4491.tar computicle-e9885141e4049a06b89000bf34959174fb2d4491.tar.gz computicle-e9885141e4049a06b89000bf34959174fb2d4491.tar.bz2 computicle-e9885141e4049a06b89000bf34959174fb2d4491.tar.lz computicle-e9885141e4049a06b89000bf34959174fb2d4491.tar.xz computicle-e9885141e4049a06b89000bf34959174fb2d4491.tar.zst computicle-e9885141e4049a06b89000bf34959174fb2d4491.zip |
Expose compute shader state
Diffstat (limited to 'src')
-rw-r--r-- | src/shader/util.cc | 11 | ||||
-rw-r--r-- | src/shader/wrap/compute_shader.cc | 13 | ||||
-rw-r--r-- | src/shader/wrap/compute_shader.h | 4 | ||||
-rw-r--r-- | src/shader/wrap/graphic_shader.h | 2 |
4 files changed, 25 insertions, 5 deletions
diff --git a/src/shader/util.cc b/src/shader/util.cc index 07a1128..be59ac1 100644 --- a/src/shader/util.cc +++ b/src/shader/util.cc @@ -7,9 +7,12 @@ 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 -1; } + return uniform; } @@ -18,7 +21,7 @@ GLint compileShader(const std::string& source, GLenum type) { if ( !shader ) { std::cerr << "Cannot create a shader of type " << type << std::endl; - exit(-1); + return -1; } const char* source_data = source.c_str(); @@ -29,16 +32,22 @@ GLint compileShader(const std::string& source, GLenum type) { 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 -1; } return shader; diff --git a/src/shader/wrap/compute_shader.cc b/src/shader/wrap/compute_shader.cc index 97ce52a..e91ba77 100644 --- a/src/shader/wrap/compute_shader.cc +++ b/src/shader/wrap/compute_shader.cc @@ -17,14 +17,23 @@ ComputeShader::Guard ComputeShader::use() const { ComputeShader::ComputeShader(const std::string& src): _id(glCreateProgram()) { - glAttachShader(_id, util::compileShader(src, GL_COMPUTE_SHADER)); - glLinkProgram(_id); + GLint shader = util::compileShader(src, GL_COMPUTE_SHADER); + + if ( shader != -1 ) { + glAttachShader(_id, shader); + glLinkProgram(_id); + _good = true; + } } ComputeShader::~ComputeShader() { glDeleteProgram(_id); } +bool ComputeShader::isGood() const { + return _good; +} + GLuint ComputeShader::setUniform(const std::string& name, float x, float y) const { GLuint id = util::getUniform(_id, name); glUniform2f(id, x, y); diff --git a/src/shader/wrap/compute_shader.h b/src/shader/wrap/compute_shader.h index e9e88ca..ffdde59 100644 --- a/src/shader/wrap/compute_shader.h +++ b/src/shader/wrap/compute_shader.h @@ -8,6 +8,8 @@ class ComputeShader { private: const GLuint _id; + bool _good; + public: struct Guard { const GLuint _id; @@ -21,6 +23,8 @@ public: ComputeShader(const std::string& src); ~ComputeShader(); + bool isGood() const; + GLuint setUniform(const std::string& name, float x, float y) const; void workOn(GLuint buffer) const; diff --git a/src/shader/wrap/graphic_shader.h b/src/shader/wrap/graphic_shader.h index 82f7e7a..25a5efb 100644 --- a/src/shader/wrap/graphic_shader.h +++ b/src/shader/wrap/graphic_shader.h @@ -6,8 +6,6 @@ #include <GL/glew.h> #include <glm/glm.hpp> -#include "shader/util.h" - class GraphicShader { private: const GLuint _id; |