aboutsummaryrefslogtreecommitdiff
path: root/src/shader/wrap/graphic_shader.cc
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-26 13:20:47 +0200
committerAdrian Kummerlaender2018-05-26 13:21:40 +0200
commit34052b51e00c939a35294d7085cadb5111484dd3 (patch)
tree03a5b1e350e47e2aa8551393ef67b2124ad50ddb /src/shader/wrap/graphic_shader.cc
parentf728e4c8d202de241673a13ce61570b6acb4bba7 (diff)
downloadcomputicle-34052b51e00c939a35294d7085cadb5111484dd3.tar
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.gz
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.bz2
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.lz
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.xz
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.zst
computicle-34052b51e00c939a35294d7085cadb5111484dd3.zip
Separate headers into compilation units
Diffstat (limited to 'src/shader/wrap/graphic_shader.cc')
-rw-r--r--src/shader/wrap/graphic_shader.cc45
1 files changed, 45 insertions, 0 deletions
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;
+}