aboutsummaryrefslogtreecommitdiff
path: root/src/shader/wrap
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader/wrap')
-rw-r--r--src/shader/wrap/compute_shader.cc40
-rw-r--r--src/shader/wrap/compute_shader.h45
-rw-r--r--src/shader/wrap/graphic_shader.cc45
-rw-r--r--src/shader/wrap/graphic_shader.h51
4 files changed, 113 insertions, 68 deletions
diff --git a/src/shader/wrap/compute_shader.cc b/src/shader/wrap/compute_shader.cc
new file mode 100644
index 0000000..97ce52a
--- /dev/null
+++ b/src/shader/wrap/compute_shader.cc
@@ -0,0 +1,40 @@
+#include "compute_shader.h"
+
+#include "shader/util.h"
+
+ComputeShader::Guard::Guard(GLuint id):
+ _id(id) {
+ glUseProgram(_id);
+}
+
+ComputeShader::Guard::~Guard() {
+ glUseProgram(0);
+}
+
+ComputeShader::Guard ComputeShader::use() const {
+ return Guard(_id);
+}
+
+ComputeShader::ComputeShader(const std::string& src):
+ _id(glCreateProgram()) {
+ glAttachShader(_id, util::compileShader(src, GL_COMPUTE_SHADER));
+ glLinkProgram(_id);
+}
+
+ComputeShader::~ComputeShader() {
+ glDeleteProgram(_id);
+}
+
+GLuint ComputeShader::setUniform(const std::string& name, float x, float y) const {
+ GLuint id = util::getUniform(_id, name);
+ glUniform2f(id, x, y);
+ return id;
+}
+
+void ComputeShader::workOn(GLuint buffer) const {
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffer);
+}
+
+void ComputeShader::dispatch(std::size_t dimX) const {
+ glDispatchCompute(dimX, 1, 1);
+}
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;
};
diff --git a/src/shader/wrap/graphic_shader.cc b/src/shader/wrap/graphic_shader.cc
new file mode 100644
index 0000000..0ed37ff
--- /dev/null
+++ b/src/shader/wrap/graphic_shader.cc
@@ -0,0 +1,45 @@
+#include "graphic_shader.h"
+
+#include "shader/util.h"
+
+GraphicShader::Guard::Guard(GLuint id):
+ _id(id) {
+ glUseProgram(_id);
+}
+
+GraphicShader::Guard::~Guard() {
+ glUseProgram(0);
+}
+
+GraphicShader::Guard GraphicShader::use() const {
+ return Guard(_id);
+}
+
+GraphicShader::GraphicShader(const std::string& vertex, const std::string fragment):
+ _id(glCreateProgram()) {
+ glAttachShader(_id, util::compileShader(vertex, GL_VERTEX_SHADER));
+ glAttachShader(_id, util::compileShader(fragment, GL_FRAGMENT_SHADER));
+ glLinkProgram(_id);
+}
+
+GraphicShader::~GraphicShader() {
+ glDeleteProgram(_id);
+}
+
+GLuint GraphicShader::setUniform(const std::string& name, int value) const {
+ GLuint id = util::getUniform(_id, name);
+ glUniform1i(id, value);
+ return id;
+}
+
+GLuint GraphicShader::setUniform(const std::string& name, const std::vector<GLuint>& v) const {
+ GLuint id = util::getUniform(_id, name);
+ glUniform1iv(id, v.size(), reinterpret_cast<const GLint*>(v.data()));
+ return id;
+}
+
+GLuint GraphicShader::setUniform(const std::string& name, glm::mat4& M) const {
+ GLuint id = util::getUniform(_id, name);
+ glUniformMatrix4fv(id, 1, GL_FALSE, &M[0][0]);
+ return id;
+}
diff --git a/src/shader/wrap/graphic_shader.h b/src/shader/wrap/graphic_shader.h
index 03249d5..82f7e7a 100644
--- a/src/shader/wrap/graphic_shader.h
+++ b/src/shader/wrap/graphic_shader.h
@@ -1,5 +1,11 @@
#pragma once
+#include <vector>
+#include <string>
+
+#include <GL/glew.h>
+#include <glm/glm.hpp>
+
#include "shader/util.h"
class GraphicShader {
@@ -10,43 +16,16 @@ 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;
- GraphicShader(const std::string& vertex, const std::string fragment):
- _id(glCreateProgram()) {
- glAttachShader(_id, util::compileShader(vertex, GL_VERTEX_SHADER));
- glAttachShader(_id, util::compileShader(fragment, GL_FRAGMENT_SHADER));
- glLinkProgram(_id);
- };
- ~GraphicShader() {
- glDeleteProgram(_id);
- }
-
- GLuint setUniform(const std::string& name, int value) const {
- GLuint id = util::getUniform(_id, name);
- glUniform1i(id, value);
- return id;
- }
-
- GLuint setUniform(const std::string& name, const std::vector<GLuint>& v) const {
- GLuint id = util::getUniform(_id, name);
- glUniform1iv(id, v.size(), reinterpret_cast<const GLint*>(v.data()));
- return id;
- }
-
- GLuint setUniform(const std::string& name, glm::mat4& M) const {
- GLuint id = util::getUniform(_id, name);
- glUniformMatrix4fv(id, 1, GL_FALSE, &M[0][0]);
- return id;
- }
+ GraphicShader(const std::string& vertex, const std::string fragment);
+ ~GraphicShader();
+
+ GLuint setUniform(const std::string& name, int value) const;
+ GLuint setUniform(const std::string& name, const std::vector<GLuint>& v) const;
+ GLuint setUniform(const std::string& name, glm::mat4& M) const;
};