aboutsummaryrefslogtreecommitdiff
path: root/src/graphic_shader.h
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-21 13:04:41 +0200
committerAdrian Kummerlaender2018-05-21 13:05:43 +0200
commitffa662ec5acdaae36f0ffeaf0cee78a4200d897b (patch)
tree9933f6a0781a54e146664fa75bd235ed1bd7c154 /src/graphic_shader.h
parent3bc6622f4f339a9ab3c808d02c48c1c144bc4e10 (diff)
downloadcomputicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar
computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar.gz
computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar.bz2
computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar.lz
computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar.xz
computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.tar.zst
computicle-ffa662ec5acdaae36f0ffeaf0cee78a4200d897b.zip
Introduce basic shader, texture buffer abstraction
Diffstat (limited to 'src/graphic_shader.h')
-rw-r--r--src/graphic_shader.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/graphic_shader.h b/src/graphic_shader.h
new file mode 100644
index 0000000..2dd8c41
--- /dev/null
+++ b/src/graphic_shader.h
@@ -0,0 +1,44 @@
+#include "util.h"
+
+class GraphicShader {
+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);
+ }
+
+ 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) {
+ GLuint id = util::getUniform(_id, name);
+ glUniform1i(id, value);
+ return id;
+ }
+
+ GLuint setUniform(const std::string& name, glm::mat4& M) {
+ GLuint id = util::getUniform(_id, name);
+ glUniformMatrix4fv(id, 1, GL_FALSE, &M[0][0]);
+ return id;
+ }
+};