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

@ -21,13 +21,11 @@ Window::Window()
m_caption = CAPTION_DEFAULT;
m_fmode = WINDOWED;
m_context = GLContext::create();
m_impl = PlatformApplication::get()->createWindow(this);
}
Window::~Window()
{
delete m_context;
delete m_impl;
}
@ -39,10 +37,6 @@ bool Window::create(WindowDescription description)
return false;
}
if (!m_context->create(m_impl)) {
return false;
}
init();
m_description = description;
@ -56,16 +50,11 @@ void Window::init()
setIcon(ICON_DEFAULT);
activate(true);
enableVSync(false);
showCursor(true);
}
void Window::destroy()
{
m_context->destroy();
m_impl->destroy();
}
@ -166,34 +155,8 @@ void Window::grabCursor(bool value)
m_impl->grabCursor(value);
}
bool Window::activate(bool value)
{
if (value) {
return m_context->activate();
}
return m_context->deactivate();
}
bool Window::enableVSync(bool value)
{
return m_context->setSwapInterval(value ? 1 : 0);
}
void Window::swapBuffers()
{
if (activate(true)) {
m_context->swapBuffers();
}
}
void Window::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 sp