diff options
Diffstat (limited to 'src/compute_shader.h')
-rw-r--r-- | src/compute_shader.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/compute_shader.h b/src/compute_shader.h new file mode 100644 index 0000000..298a454 --- /dev/null +++ b/src/compute_shader.h @@ -0,0 +1,41 @@ +#include "util.h" + +class ComputeShader { +private: + const GLuint _id; + +public: + struct Guard { + const GLuint _id; + + Guard(GLuint id): _id(id) { + glUseProgram(_id); + } + ~Guard() { + glUseProgram(0); + } + }; + + Guard use() { + return Guard(_id); + } + + ComputeShader(const std::string& src): + _id(glCreateProgram()) { + glAttachShader(_id, util::compileShader(src, GL_COMPUTE_SHADER)); + glLinkProgram(_id); + }; + ~ComputeShader() { + glDeleteProgram(_id); + } + + GLuint setUniform(const std::string& name, float x, float y) { + GLuint id = util::getUniform(_id, name); + glUniform2f(id, x, y); + return id; + } + + void dispatch(std::size_t dimX) { + glDispatchCompute(dimX, 1, 1); + } +}; |