summaryrefslogtreecommitdiff
path: root/gfx/gl/program.h
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl/program.h')
-rw-r--r--gfx/gl/program.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/gfx/gl/program.h b/gfx/gl/program.h
new file mode 100644
index 0000000..711a26d
--- /dev/null
+++ b/gfx/gl/program.h
@@ -0,0 +1,46 @@
+#pragma once
+
+#include "shader.h"
+#include <GL/glew.h>
+#include <glRef.hpp>
+#include <glm/mat4x4.hpp>
+
+class Location;
+
+class Program {
+public:
+ template<typename... S> Program(const S &... srcs)
+ {
+ (glAttachShader(m_program, srcs), ...);
+ linkAndValidate();
+ }
+ virtual ~Program() = default;
+
+ class UniformLocation {
+ public:
+ UniformLocation(GLuint prog, const char * name);
+ operator auto() const
+ {
+ return location;
+ }
+
+ protected:
+ GLint location;
+ };
+
+ class RequiredUniformLocation : public UniformLocation {
+ public:
+ RequiredUniformLocation(GLuint prog, const char * name);
+ };
+
+ operator GLuint() const
+ {
+ return m_program;
+ }
+
+protected:
+ void use() const;
+ using ProgramRef = glRef<GLuint, &__glewCreateProgram, &__glewDeleteProgram>;
+ void linkAndValidate() const;
+ ProgramRef m_program;
+};