diff options
Diffstat (limited to 'src/shader/wrap/compute_shader.h')
-rw-r--r-- | src/shader/wrap/compute_shader.h | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/src/shader/wrap/compute_shader.h b/src/shader/wrap/compute_shader.h index 9f5c5cb..e9e88ca 100644 --- a/src/shader/wrap/compute_shader.h +++ b/src/shader/wrap/compute_shader.h @@ -1,6 +1,8 @@ #pragma once -#include "util.h" +#include <string> + +#include <GL/glew.h> class ComputeShader { private: @@ -10,38 +12,17 @@ public: struct Guard { const GLuint _id; - Guard(GLuint id): _id(id) { - glUseProgram(_id); - } - ~Guard() { - glUseProgram(0); - } + Guard(GLuint id); + ~Guard(); }; - Guard use() const { - return Guard(_id); - } + Guard use() const; - 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) const { - GLuint id = util::getUniform(_id, name); - glUniform2f(id, x, y); - return id; - } - - void workOn(GLuint buffer) const { - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffer); - } - - void dispatch(std::size_t dimX) const { - glDispatchCompute(dimX, 1, 1); - } + ComputeShader(const std::string& src); + ~ComputeShader(); + + GLuint setUniform(const std::string& name, float x, float y) const; + + void workOn(GLuint buffer) const; + void dispatch(std::size_t dimX) const; }; |