Creating OpenGL utility class, consolidating number of OpenGL function objects

This commit is contained in:
Dan Paulat 2021-07-23 21:30:51 -05:00
parent c6a323247d
commit 59be110c10
10 changed files with 124 additions and 73 deletions

View file

@ -0,0 +1,23 @@
#pragma once
#include <QOpenGLFunctions_3_3_Core>
#define SCWX_GL_CHECK_ERROR() \
{ \
GLenum err; \
while ((err = p->gl_.glGetError()) != GL_NO_ERROR) \
{ \
BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "GL Error: " << err \
<< ", " __FILE__ << ":" << __LINE__; \
} \
}
namespace scwx
{
namespace qt
{
using OpenGLFunctions = QOpenGLFunctions_3_3_Core;
} // namespace qt
} // namespace scwx

View file

@ -1,7 +1,6 @@
#include <scwx/qt/util/shader_program.hpp>
#include <QFile>
#include <QOpenGLFunctions_3_3_Core>
#include <boost/log/trivial.hpp>
@ -15,10 +14,9 @@ static const std::string logPrefix_ = "[scwx::qt::util::shader_program] ";
class ShaderProgramImpl
{
public:
explicit ShaderProgramImpl() : gl_(), id_ {GL_INVALID_INDEX}
explicit ShaderProgramImpl(OpenGLFunctions& gl) :
gl_(gl), id_ {GL_INVALID_INDEX}
{
gl_.initializeOpenGLFunctions();
// Create shader program
id_ = gl_.glCreateProgram();
}
@ -29,12 +27,15 @@ public:
gl_.glDeleteProgram(id_);
}
QOpenGLFunctions_3_3_Core gl_;
OpenGLFunctions& gl_;
GLuint id_;
};
ShaderProgram::ShaderProgram() : p(std::make_unique<ShaderProgramImpl>()) {}
ShaderProgram::ShaderProgram(OpenGLFunctions& gl) :
p(std::make_unique<ShaderProgramImpl>(gl))
{
}
ShaderProgram::~ShaderProgram() = default;
ShaderProgram::ShaderProgram(ShaderProgram&&) noexcept = default;
@ -50,7 +51,7 @@ bool ShaderProgram::Load(const std::string& vertexPath,
{
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Load()";
QOpenGLFunctions_3_3_Core& gl = p->gl_;
OpenGLFunctions& gl = p->gl_;
GLint glSuccess;
bool success = true;

View file

@ -1,14 +1,14 @@
#pragma once
#include <scwx/qt/util/gl.hpp>
#ifdef _WIN32
#include <Windows.h>
# include <Windows.h>
#endif
#include <memory>
#include <string>
#include <GL/gl.h>
namespace scwx
{
namespace qt
@ -19,7 +19,7 @@ class ShaderProgramImpl;
class ShaderProgram
{
public:
explicit ShaderProgram();
explicit ShaderProgram(OpenGLFunctions& gl);
~ShaderProgram();
ShaderProgram(const ShaderProgram&) = delete;