summaryrefslogtreecommitdiff
path: root/gfx/gl/program.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-11-03 19:47:46 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-11-03 19:48:31 +0000
commitc3eea71370eb94cff1fd96185458643fab6eb2c5 (patch)
treecb331dd81d9cb36d69e1b659353796ec170a78e4 /gfx/gl/program.h
parentRename Shader to SceneShader (diff)
downloadilt-c3eea71370eb94cff1fd96185458643fab6eb2c5.tar.bz2
ilt-c3eea71370eb94cff1fd96185458643fab6eb2c5.tar.xz
ilt-c3eea71370eb94cff1fd96185458643fab6eb2c5.zip
Restructure how shaders are worked with
Needs a tidy-up
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;
+};