From 6698c81d0628e917beb75f71383e3b3108b0804c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 12 Dec 2021 16:07:41 +0000 Subject: Move program handle to its own files --- gfx/gl/programHandle.cpp | 14 ++++++++++++++ gfx/gl/programHandle.h | 16 ++++++++++++++++ gfx/gl/shader.cpp | 12 ------------ gfx/gl/shader.h | 10 +--------- 4 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 gfx/gl/programHandle.cpp create mode 100644 gfx/gl/programHandle.h diff --git a/gfx/gl/programHandle.cpp b/gfx/gl/programHandle.cpp new file mode 100644 index 0000000..bfe06f2 --- /dev/null +++ b/gfx/gl/programHandle.cpp @@ -0,0 +1,14 @@ +#include "programHandle.h" +#include "glSource.h" + +ProgramHandleBase::ProgramHandleBase(GLuint vs, GLuint fs) : viewProjection_uniform {}, model_uniform {} +{ + glAttachShader(m_program, vs); + glAttachShader(m_program, fs); + + glLinkProgram(m_program); + GLsource::CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program"); + + glValidateProgram(m_program); + GLsource::CheckShaderError(m_program, GL_VALIDATE_STATUS, true, "Invalid shader program"); +} diff --git a/gfx/gl/programHandle.h b/gfx/gl/programHandle.h new file mode 100644 index 0000000..6aa1084 --- /dev/null +++ b/gfx/gl/programHandle.h @@ -0,0 +1,16 @@ +#ifndef PROGRAM_HANDLE_H +#define PROGRAM_HANDLE_H + +#include +#include + +class ProgramHandleBase { +public: + ProgramHandleBase(GLuint, GLuint); + using ProgramRef = glRef; + + ProgramRef m_program; + GLint viewProjection_uniform, model_uniform; +}; + +#endif diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp index 12ab510..47e08c5 100644 --- a/gfx/gl/shader.cpp +++ b/gfx/gl/shader.cpp @@ -16,18 +16,6 @@ #include #include -ProgramHandleBase::ProgramHandleBase(GLuint vs, GLuint fs) : viewProjection_uniform {}, model_uniform {} -{ - glAttachShader(m_program, vs); - glAttachShader(m_program, fs); - - glLinkProgram(m_program); - GLsource::CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program"); - - glValidateProgram(m_program); - GLsource::CheckShaderError(m_program, GL_VALIDATE_STATUS, true, "Invalid shader program"); -} - Shader::ProgramHandle::ProgramHandle(GLuint vs, GLuint fs) : ProgramHandleBase {vs, fs} { glBindAttribLocation(m_program, 0, "position"); diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h index 5b3aab8..249b2f4 100644 --- a/gfx/gl/shader.h +++ b/gfx/gl/shader.h @@ -1,6 +1,7 @@ #ifndef SHADER_INCLUDED_H #define SHADER_INCLUDED_H +#include "programHandle.h" #include #include #include @@ -9,15 +10,6 @@ class Location; -class ProgramHandleBase { -public: - ProgramHandleBase(GLuint, GLuint); - using ProgramRef = glRef; - - ProgramRef m_program; - GLint viewProjection_uniform, model_uniform; -}; - class Shader { public: enum class Program { Basic = 0, Water = 1, LandMass = 2, StaticPos = 3 }; -- cgit v1.2.3