mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 16:40:05 +00:00
Namespace cleanup
This commit is contained in:
parent
c22db501b3
commit
5a97d99a34
20 changed files with 88 additions and 46 deletions
|
|
@ -191,7 +191,7 @@ float Font::TextLength(const std::string& text, float pointSize) const
|
|||
return x;
|
||||
}
|
||||
|
||||
GLuint Font::GenerateTexture(OpenGLFunctions& gl)
|
||||
GLuint Font::GenerateTexture(gl::OpenGLFunctions& gl)
|
||||
{
|
||||
gl.glGenTextures(1, &p->atlas_->id);
|
||||
gl.glBindTexture(GL_TEXTURE_2D, p->atlas_->id);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/qt/gl/gl.hpp>
|
||||
#include <scwx/qt/util/font_buffer.hpp>
|
||||
#include <scwx/qt/util/gl.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
|
@ -38,7 +38,7 @@ public:
|
|||
float Kerning(char c1, char c2) const;
|
||||
float TextLength(const std::string& text, float pointSize) const;
|
||||
|
||||
GLuint GenerateTexture(OpenGLFunctions& gl);
|
||||
GLuint GenerateTexture(gl::OpenGLFunctions& gl);
|
||||
|
||||
static std::shared_ptr<Font> Create(const std::string& resource);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public:
|
|||
|
||||
~FontBufferImpl() {}
|
||||
|
||||
void RenderSetup(OpenGLFunctions& gl)
|
||||
void RenderSetup(gl::OpenGLFunctions& gl)
|
||||
{
|
||||
// Generate and setup VAO
|
||||
gl.glGenVertexArrays(1, &vaoId_);
|
||||
|
|
@ -64,7 +64,7 @@ public:
|
|||
gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesId_);
|
||||
}
|
||||
|
||||
void Upload(OpenGLFunctions& gl)
|
||||
void Upload(gl::OpenGLFunctions& gl)
|
||||
{
|
||||
if (verticesId_ == GL_INVALID_INDEX)
|
||||
{
|
||||
|
|
@ -157,7 +157,7 @@ void FontBuffer::Push(std::initializer_list<GLuint> indices,
|
|||
p->vertices_.insert(p->vertices_.end(), vertices);
|
||||
}
|
||||
|
||||
void FontBuffer::Render(OpenGLFunctions& gl)
|
||||
void FontBuffer::Render(gl::OpenGLFunctions& gl)
|
||||
{
|
||||
std::scoped_lock lock(p->mutex_);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/qt/util/gl.hpp>
|
||||
#include <scwx/qt/gl/gl.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ public:
|
|||
void Clear();
|
||||
void Push(std::initializer_list<GLuint> indices,
|
||||
std::initializer_list<GLfloat> vertices);
|
||||
void Render(OpenGLFunctions& gl);
|
||||
void Render(gl::OpenGLFunctions& gl);
|
||||
|
||||
private:
|
||||
std::unique_ptr<FontBufferImpl> p;
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
#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
|
||||
|
|
@ -1,177 +0,0 @@
|
|||
#include <scwx/qt/util/shader_program.hpp>
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
|
||||
static const std::string logPrefix_ = "[scwx::qt::util::shader_program] ";
|
||||
|
||||
static constexpr GLsizei INFO_LOG_BUF_SIZE = 512;
|
||||
|
||||
class ShaderProgramImpl
|
||||
{
|
||||
public:
|
||||
explicit ShaderProgramImpl(OpenGLFunctions& gl) :
|
||||
gl_(gl), id_ {GL_INVALID_INDEX}
|
||||
{
|
||||
// Create shader program
|
||||
id_ = gl_.glCreateProgram();
|
||||
}
|
||||
|
||||
~ShaderProgramImpl()
|
||||
{
|
||||
// Delete shader program
|
||||
gl_.glDeleteProgram(id_);
|
||||
}
|
||||
|
||||
OpenGLFunctions& gl_;
|
||||
|
||||
GLuint id_;
|
||||
};
|
||||
|
||||
ShaderProgram::ShaderProgram(OpenGLFunctions& gl) :
|
||||
p(std::make_unique<ShaderProgramImpl>(gl))
|
||||
{
|
||||
}
|
||||
ShaderProgram::~ShaderProgram() = default;
|
||||
|
||||
ShaderProgram::ShaderProgram(ShaderProgram&&) noexcept = default;
|
||||
ShaderProgram& ShaderProgram::operator=(ShaderProgram&&) noexcept = default;
|
||||
|
||||
GLuint ShaderProgram::id() const
|
||||
{
|
||||
return p->id_;
|
||||
}
|
||||
|
||||
bool ShaderProgram::Load(const std::string& vertexPath,
|
||||
const std::string& fragmentPath)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Load(\"" << vertexPath << "\", \""
|
||||
<< fragmentPath << "\")";
|
||||
|
||||
OpenGLFunctions& gl = p->gl_;
|
||||
|
||||
GLint glSuccess;
|
||||
bool success = true;
|
||||
char infoLog[INFO_LOG_BUF_SIZE];
|
||||
GLsizei logLength;
|
||||
|
||||
QFile vertexFile(vertexPath.c_str());
|
||||
QFile fragmentFile(fragmentPath.c_str());
|
||||
|
||||
vertexFile.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
fragmentFile.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
|
||||
if (!vertexFile.isOpen())
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
<< logPrefix_ << "Could not load vertex shader: " << vertexPath;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!fragmentFile.isOpen())
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
<< logPrefix_ << "Could not load fragment shader: " << fragmentPath;
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream vertexShaderStream(&vertexFile);
|
||||
QTextStream fragmentShaderStream(&fragmentFile);
|
||||
|
||||
vertexShaderStream.setEncoding(QStringConverter::Utf8);
|
||||
fragmentShaderStream.setEncoding(QStringConverter::Utf8);
|
||||
|
||||
std::string vertexShaderSource = vertexShaderStream.readAll().toStdString();
|
||||
std::string fragmentShaderSource =
|
||||
fragmentShaderStream.readAll().toStdString();
|
||||
|
||||
const char* vertexShaderSourceC = vertexShaderSource.c_str();
|
||||
const char* fragmentShaderSourceC = fragmentShaderSource.c_str();
|
||||
|
||||
// Create a vertex shader
|
||||
GLuint vertexShader = gl.glCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
// Attach the shader source code and compile the shader
|
||||
gl.glShaderSource(vertexShader, 1, &vertexShaderSourceC, NULL);
|
||||
gl.glCompileShader(vertexShader);
|
||||
|
||||
// Check for errors
|
||||
gl.glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &glSuccess);
|
||||
gl.glGetShaderInfoLog(vertexShader, INFO_LOG_BUF_SIZE, &logLength, infoLog);
|
||||
if (!glSuccess)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
<< logPrefix_ << "Vertex shader compilation failed: " << infoLog;
|
||||
success = false;
|
||||
}
|
||||
else if (logLength > 0)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
<< logPrefix_ << "Vertex shader compiled with warnings: " << infoLog;
|
||||
}
|
||||
|
||||
// Create a fragment shader
|
||||
GLuint fragmentShader = gl.glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
// Attach the shader source and compile the shader
|
||||
gl.glShaderSource(fragmentShader, 1, &fragmentShaderSourceC, NULL);
|
||||
gl.glCompileShader(fragmentShader);
|
||||
|
||||
// Check for errors
|
||||
gl.glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &glSuccess);
|
||||
gl.glGetShaderInfoLog(
|
||||
fragmentShader, INFO_LOG_BUF_SIZE, &logLength, infoLog);
|
||||
if (!glSuccess)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
<< logPrefix_ << "Fragment shader compilation failed: " << infoLog;
|
||||
success = false;
|
||||
}
|
||||
else if (logLength > 0)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
<< logPrefix_ << "Fragment shader compiled with warnings: " << infoLog;
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
gl.glAttachShader(p->id_, vertexShader);
|
||||
gl.glAttachShader(p->id_, fragmentShader);
|
||||
gl.glLinkProgram(p->id_);
|
||||
|
||||
// Check for errors
|
||||
gl.glGetProgramiv(p->id_, GL_LINK_STATUS, &glSuccess);
|
||||
gl.glGetProgramInfoLog(p->id_, INFO_LOG_BUF_SIZE, &logLength, infoLog);
|
||||
if (!glSuccess)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
<< logPrefix_ << "Shader program link failed: " << infoLog;
|
||||
success = false;
|
||||
}
|
||||
else if (logLength > 0)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
<< logPrefix_ << "Shader program linked with warnings: " << infoLog;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete shaders
|
||||
gl.glDeleteShader(vertexShader);
|
||||
gl.glDeleteShader(fragmentShader);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void ShaderProgram::Use() const
|
||||
{
|
||||
p->gl_.glUseProgram(p->id_);
|
||||
}
|
||||
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/qt/util/gl.hpp>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
|
||||
class ShaderProgramImpl;
|
||||
|
||||
class ShaderProgram
|
||||
{
|
||||
public:
|
||||
explicit ShaderProgram(OpenGLFunctions& gl);
|
||||
virtual ~ShaderProgram();
|
||||
|
||||
ShaderProgram(const ShaderProgram&) = delete;
|
||||
ShaderProgram& operator=(const ShaderProgram&) = delete;
|
||||
|
||||
ShaderProgram(ShaderProgram&&) noexcept;
|
||||
ShaderProgram& operator=(ShaderProgram&&) noexcept;
|
||||
|
||||
GLuint id() const;
|
||||
|
||||
bool Load(const std::string& vertexPath, const std::string& fragmentPath);
|
||||
|
||||
void Use() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<ShaderProgramImpl> p;
|
||||
};
|
||||
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
Loading…
Add table
Add a link
Reference in a new issue