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.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 gfx/gl/program.cpp (limited to 'gfx/gl/program.cpp') diff --git a/gfx/gl/program.cpp b/gfx/gl/program.cpp new file mode 100644 index 0000000..c36cc80 --- /dev/null +++ b/gfx/gl/program.cpp @@ -0,0 +1,35 @@ +#include "program.h" +#include "shader.h" +#include +#include +#include +#include + +void +Program::linkAndValidate() const +{ + glLinkProgram(m_program); + Shader::CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program"); + + glValidateProgram(m_program); + Shader::CheckShaderError(m_program, GL_VALIDATE_STATUS, true, "Invalid shader program"); +} + +void +Program::use() const +{ + glUseProgram(m_program); +} + +Program::UniformLocation::UniformLocation(GLuint program, const char * name) : + location {glGetUniformLocation(program, name)} +{ +} + +Program::RequiredUniformLocation::RequiredUniformLocation(GLuint program, const char * name) : + UniformLocation {program, name} +{ + if (location < 0) { + throw std::logic_error("Required uniform does not exist"); + } +} -- cgit v1.2.3