1
0
Fork 0

Spectre/Window/Window: refactor out GLContext specific code to its own class (GLWindow)

This commit is contained in:
Henrik Hautakoski 2023-08-23 19:28:24 +02:00
parent 2de3bd93f7
commit b1ccea1397
7 changed files with 120 additions and 55 deletions

View file

@ -0,0 +1,70 @@
#include <Spectre/Window/GLContext.h>
#include <Spectre/Window/GLWindow.h>
#include <Graphics/GL/gl.h>
namespace sp {
GLWindow::GLWindow()
{
m_context = GLContext::create();
}
GLWindow::~GLWindow()
{
delete m_context;
}
bool GLWindow::create(WindowDescription description)
{
if (!Window::create(description)) {
return false;
}
if (!m_context->create(m_impl)) {
return false;
}
enableVSync(false);
return activate(true);
}
void GLWindow::destroy()
{
m_context->destroy();
Window::destroy();
}
bool GLWindow::activate(bool value)
{
if (value) {
return m_context->activate();
}
return m_context->deactivate();
}
bool GLWindow::enableVSync(bool value)
{
return m_context->setSwapInterval(value ? 1 : 0);
}
void GLWindow::swapBuffers()
{
if (activate(true)) {
m_context->swapBuffers();
}
}
void GLWindow::onReshape(int width, int height)
{
// TODO: This should even not be here.
// Generic Display should not have any GL calls.
// But it's better to have it here then in the platform specific GLContext
if (activate(true)) {
glViewport(0, 0, width, height);
}
}
} // namespace