summaryrefslogtreecommitdiffstats
path: root/graphics/Shader.hpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-05-10 15:44:51 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-05-10 15:44:51 +0200
commit469a84c10ba60fba4a513c1b1a0eea600cd7b22f (patch)
tree4de3514353341f68fd63d3c12fa0a162008d3209 /graphics/Shader.hpp
parent2017-04-23 (diff)
downloadAltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar
AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar.gz
AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar.bz2
AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar.lz
AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar.xz
AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar.zst
AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.zip
Diffstat (limited to 'graphics/Shader.hpp')
-rw-r--r--graphics/Shader.hpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/graphics/Shader.hpp b/graphics/Shader.hpp
new file mode 100644
index 0000000..83e06e1
--- /dev/null
+++ b/graphics/Shader.hpp
@@ -0,0 +1,60 @@
+#pragma once
+
+#include <string>
+
+class Shader {
+ std::string shaderSource;
+ GLuint shaderId;
+ bool isVertex = true;
+
+ Shader(const Shader &);
+
+public:
+ Shader(std::string fileName, bool vertex = true);
+
+ ~Shader();
+
+ void bind();
+
+ GLuint GetId() {
+ return shaderId;
+ }
+
+};
+
+class ShaderProgram {
+ GLuint shaderProgram;
+public:
+ ShaderProgram() {
+ shaderProgram = glCreateProgram();
+ }
+
+ ~ShaderProgram() {
+ glDeleteProgram(shaderProgram);
+ }
+
+ void Attach(Shader &shader) {
+ glAttachShader(shaderProgram, shader.GetId());
+ }
+
+ void Link() {
+ glLinkProgram(shaderProgram);
+ GLint success;
+ GLchar infoLog[512];
+ glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
+ if (!success) {
+ glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
+ std::cout << "Shader program linking failed: " << infoLog << std::endl;
+ }
+ glUseProgram(shaderProgram);
+ }
+
+ GLuint GetId() {
+ return shaderProgram;
+ }
+
+ explicit operator GLuint() const {
+ return shaderProgram;
+ }
+
+}; \ No newline at end of file