1
0
Fork 0

Platform/Unix: Rename X11SharedDisplay to Xlib, and remove Display member variable from all classes.

We now initialize/destroy the display in Xlib::init/shutdown that is called in UnixApplication::init/shutdown and
therefore is valid through the whole lifetime. So no need for classes to keep references.
This commit is contained in:
Henrik Hautakoski 2020-12-25 17:17:51 +01:00
parent 60dd9bacb0
commit 090646b61a
17 changed files with 137 additions and 201 deletions

View file

@ -4,7 +4,7 @@
#include <Spectre/System/Log.h>
#include "glad_glx.h"
#include "X11SharedDisplay.h"
#include "Xlib.h"
#include "GLXContext.h"
namespace sp {
@ -60,7 +60,6 @@ static bool ensureExtensionsLoaded(::Display* disp, int screen)
}
GLXContext::GLXContext() :
m_disp (NULL),
m_win (0),
m_ctx (NULL)
{
@ -76,13 +75,6 @@ bool GLXContext::create(const PlatformDisplay* display)
// Destroy any previous context first.
destroy();
m_disp = XGetDisplay();
if (m_disp == NULL) {
destroy();
Log::warn("X11: Could not open display");
return false;
}
m_win = (::Window) display->getHandle();
if (!createGLContext()) {
@ -95,6 +87,7 @@ bool GLXContext::create(const PlatformDisplay* display)
bool GLXContext::createGLContext()
{
::Display* disp = Xlib::getDisplay();
::GLXFBConfig *fbc;
::XVisualInfo *info;
int fbcount;
@ -117,31 +110,31 @@ bool GLXContext::createGLContext()
};
// Ensure glx extensions are loaded.
if (!ensureExtensionsLoaded(m_disp, DefaultScreen(m_disp))) {
if (!ensureExtensionsLoaded(disp, DefaultScreen(disp))) {
return false;
}
info = ::glXChooseVisual(m_disp, DefaultScreen(m_disp), vi_attr);
info = ::glXChooseVisual(disp, DefaultScreen(disp), vi_attr);
if (info == NULL) {
Log::warn("GLX: Could not find a valid VisualInfo.");
return false;
}
// Setup GL settings.
fbc = glXChooseFBConfig(m_disp, DefaultScreen(m_disp), (const int*) info->visual, &fbcount);
fbc = glXChooseFBConfig(disp, DefaultScreen(disp), (const int*) info->visual, &fbcount);
if (fbc == NULL) {
Log::warn("GLX: Could not find FB Config.");
return false;
}
// Create context.
m_ctx = glXCreateContextAttribsARB(m_disp, fbc[0], NULL, GL_TRUE, ctx_attr);
m_ctx = glXCreateContextAttribsARB(disp, fbc[0], NULL, GL_TRUE, ctx_attr);
if (m_ctx == NULL) {
Log::warn("GLX: Failed to create context.");
return false;
}
glXMakeCurrent(m_disp, m_win, m_ctx);
glXMakeCurrent(disp, m_win, m_ctx);
// Load OpenGL
if (!loadGL()) {
@ -155,29 +148,24 @@ bool GLXContext::createGLContext()
void GLXContext::destroy()
{
if (m_ctx) {
::glXDestroyContext(m_disp, m_ctx);
::glXDestroyContext(Xlib::getDisplay(), m_ctx);
m_ctx = NULL;
}
if (m_disp) {
XReleaseDisplay(m_disp);
m_disp = NULL;
}
m_win = None;
}
bool GLXContext::activate()
{
if (m_win && m_ctx) {
return ::glXMakeCurrent(m_disp, m_win, m_ctx);
return ::glXMakeCurrent(Xlib::getDisplay(), m_win, m_ctx);
}
return false;
}
bool GLXContext::deactivate()
{
return ::glXMakeCurrent(m_disp, None, NULL);
return ::glXMakeCurrent(Xlib::getDisplay(), None, NULL);
}
bool GLXContext::isActive() const
@ -187,7 +175,8 @@ bool GLXContext::isActive() const
bool GLXContext::setSwapInterval(int interval)
{
ensureExtensionsLoaded(m_disp, DefaultScreen(m_disp));
::Display *disp = Xlib::getDisplay();
ensureExtensionsLoaded(disp, DefaultScreen(disp));
if (GLAD_GLX_MESA_swap_control) {
return glXSwapIntervalMESA(interval);
@ -215,7 +204,7 @@ void GLXContext::setSize(const Vector2u size)
void GLXContext::swapBuffers()
{
glXSwapBuffers(m_disp, m_win);
glXSwapBuffers(Xlib::getDisplay(), m_win);
}
} // namespace sp