aboutsummaryrefslogtreecommitdiff
path: root/src/shader/wrap/compute_shader.h
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-25 23:47:27 +0200
committerAdrian Kummerlaender2018-05-25 23:48:59 +0200
commitf728e4c8d202de241673a13ce61570b6acb4bba7 (patch)
treea7e29c4319f0e6d667b98f359ddf089c0565c15a /src/shader/wrap/compute_shader.h
parent5157658ec0cc07d2c56c978ca010cbb78236439f (diff)
downloadcomputicle-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/wrap/compute_shader.h')
-rw-r--r--src/shader/wrap/compute_shader.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/shader/wrap/compute_shader.h b/src/shader/wrap/compute_shader.h
new file mode 100644
index 0000000..9f5c5cb
--- /dev/null
+++ b/src/shader/wrap/compute_shader.h
@@ -0,0 +1,47 @@
+#pragma once
+
+#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() const {
+ 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) 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);
+ }
+};