aboutsummaryrefslogtreecommitdiffstats
path: root/yage/render/glslprogram.h
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-12-25 13:54:09 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-12-25 13:54:09 +0000
commitf949692714e72a0e2d45ebb6a5d698424ab71dee (patch)
treecfab638d8c4d35c297e981773cfee1a9af3490ee /yage/render/glslprogram.h
parent022a4bdd81332ce67d799be6a06afb42ae45ac2e (diff)
downloadYAGE-f949692714e72a0e2d45ebb6a5d698424ab71dee.tar.gz
YAGE-f949692714e72a0e2d45ebb6a5d698424ab71dee.zip
[Broken] Reorganising and fixing.
Diffstat (limited to 'yage/render/glslprogram.h')
-rw-r--r--yage/render/glslprogram.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/yage/render/glslprogram.h b/yage/render/glslprogram.h
new file mode 100644
index 00000000..0617bc1e
--- /dev/null
+++ b/yage/render/glslprogram.h
@@ -0,0 +1,58 @@
+/** ---------------------------------------------------------------------------
+ * @file: glslprogram.h
+ *
+ * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com>
+ * MIT License, see LICENSE file for more details.
+ * ----------------------------------------------------------------------------
+ */
+
+#ifndef GLSL_PROGRAM_H
+#define GLSL_PROGRAM_H
+
+#include <glad/glad.h>
+
+#include <string>
+
+namespace yage
+{
+
+class GlslProgram
+{
+public:
+ GlslProgram() = default;
+ GlslProgram(const GlslProgram &) = delete;
+ GlslProgram(GlslProgram &&) = delete;
+ ~GlslProgram();
+
+ GlslProgram &operator=(const GlslProgram &) = delete;
+ GlslProgram &operator=(GlslProgram &&) = delete;
+
+ /// compiles vertex and fragment shader
+ void compileShaders(const std::string &vertexShader,
+ const std::string fragmentShader);
+ void compileShadersFromFile(const std::string &vertex_shader_path,
+ const std::string &fragment_shader_path);
+ void linkShaders();
+ void addAttribute(const std::string &attribute_name);
+ GLint getUniformLocation(const std::string &uniform_name);
+ void use();
+ void unuse();
+
+ void defaultSetup();
+
+private:
+ /// compiled shader program id
+ GLuint program_id_ = 0;
+ GLuint vertex_shader_id_ = 0;
+ GLuint fragment_shader_id_ = 0;
+ int attribute_index_ = 0;
+
+ /// compiles one shader
+ void compileShader(GLuint shader, const std::string &shaderContent);
+ void compileShaderFromFile(GLuint shader, const std::string &file_path);
+ void initShaderId();
+};
+
+} // namespace yage
+
+#endif