From c3eea71370eb94cff1fd96185458643fab6eb2c5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 3 Nov 2022 19:47:46 +0000 Subject: Restructure how shaders are worked with Needs a tidy-up --- gfx/gl/program.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 gfx/gl/program.h (limited to 'gfx/gl/program.h') 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 +#include +#include + +class Location; + +class Program { +public: + template 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; + void linkAndValidate() const; + ProgramRef m_program; +}; -- cgit v1.2.3