2023-10-03 20:37:00 +02:00
|
|
|
// Copyright (C) 2013 Christian Stehno
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in Irrlicht.h
|
|
|
|
|
|
|
|
#include "CGLXManager.h"
|
|
|
|
|
|
|
|
#ifdef _IRR_COMPILE_WITH_GLX_MANAGER_
|
|
|
|
|
|
|
|
#include "os.h"
|
|
|
|
|
2024-01-16 20:59:36 +01:00
|
|
|
#define GL_GLEXT_LEGACY 1
|
|
|
|
#define GLX_GLXEXT_LEGACY 1
|
2023-10-03 20:37:00 +02:00
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glx.h>
|
|
|
|
#include <GL/glext.h>
|
|
|
|
#include <GL/glxext.h>
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace video
|
|
|
|
{
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
CGLXManager::CGLXManager(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &videodata, int screennr) :
|
|
|
|
Params(params), PrimaryContext(videodata), VisualInfo(0), glxFBConfig(0), GlxWin(0)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
#ifdef _DEBUG
|
2023-10-03 20:37:00 +02:00
|
|
|
setDebugName("CGLXManager");
|
2024-03-20 19:35:52 +01:00
|
|
|
#endif
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
CurrentContext.OpenGLLinux.X11Display = PrimaryContext.OpenGLLinux.X11Display;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
int major, minor;
|
2024-03-20 19:35:52 +01:00
|
|
|
Display *display = (Display *)PrimaryContext.OpenGLLinux.X11Display;
|
|
|
|
const bool isAvailableGLX = glXQueryExtension(display, &major, &minor);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (isAvailableGLX && glXQueryVersion(display, &major, &minor)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GLX_VERSION_1_3)
|
2024-03-20 19:35:52 +01:00
|
|
|
typedef GLXFBConfig *(*PFNGLXCHOOSEFBCONFIGPROC)(Display *dpy, int screen, const int *attrib_list, int *nelements);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
PFNGLXCHOOSEFBCONFIGPROC glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC)glXGetProcAddress(reinterpret_cast<const GLubyte *>("glXChooseFBConfig"));
|
|
|
|
if (major == 1 && minor > 2 && glxChooseFBConfig) {
|
|
|
|
os::Printer::log("GLX >= 1.3", ELL_DEBUG);
|
2023-10-03 20:37:00 +02:00
|
|
|
// attribute array for the draw buffer
|
|
|
|
int visualAttrBuffer[] =
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
GLX_RENDER_TYPE,
|
|
|
|
GLX_RGBA_BIT,
|
|
|
|
GLX_RED_SIZE,
|
|
|
|
4,
|
|
|
|
GLX_GREEN_SIZE,
|
|
|
|
4,
|
|
|
|
GLX_BLUE_SIZE,
|
|
|
|
4,
|
|
|
|
GLX_ALPHA_SIZE,
|
|
|
|
Params.WithAlphaChannel ? 1 : 0,
|
|
|
|
GLX_DEPTH_SIZE,
|
|
|
|
Params.ZBufferBits, // 10,11
|
|
|
|
GLX_DOUBLEBUFFER,
|
|
|
|
Params.Doublebuffer ? True : False,
|
|
|
|
GLX_STENCIL_SIZE,
|
|
|
|
Params.Stencilbuffer ? 1 : 0,
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GLX_VERSION_1_4) && defined(GLX_SAMPLE_BUFFERS) // we need to check the extension string!
|
2024-03-20 19:35:52 +01:00
|
|
|
GLX_SAMPLE_BUFFERS,
|
|
|
|
1,
|
|
|
|
GLX_SAMPLES,
|
|
|
|
Params.AntiAlias, // 18,19
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GLX_ARB_multisample)
|
2024-03-20 19:35:52 +01:00
|
|
|
GLX_SAMPLE_BUFFERS_ARB,
|
|
|
|
1,
|
|
|
|
GLX_SAMPLES_ARB,
|
|
|
|
Params.AntiAlias, // 18,19
|
2023-10-03 20:37:00 +02:00
|
|
|
#elif defined(GLX_SGIS_multisample)
|
2024-03-20 19:35:52 +01:00
|
|
|
GLX_SAMPLE_BUFFERS_SGIS,
|
|
|
|
1,
|
|
|
|
GLX_SAMPLES_SGIS,
|
|
|
|
Params.AntiAlias, // 18,19
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
2024-03-20 19:35:52 +01:00
|
|
|
GLX_STEREO,
|
|
|
|
Params.Stereobuffer ? True : False,
|
2023-10-03 20:37:00 +02:00
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
GLXFBConfig *configList = 0;
|
|
|
|
int nitems = 0;
|
|
|
|
if (Params.AntiAlias < 2) {
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[17] = 0;
|
|
|
|
visualAttrBuffer[19] = 0;
|
|
|
|
}
|
|
|
|
// first round with unchanged values
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems);
|
|
|
|
if (!configList && Params.AntiAlias) {
|
|
|
|
while (!configList && (visualAttrBuffer[19] > 1)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[19] -= 1;
|
2024-03-20 19:35:52 +01:00
|
|
|
configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!configList) {
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[17] = 0;
|
|
|
|
visualAttrBuffer[19] = 0;
|
2024-03-20 19:35:52 +01:00
|
|
|
configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems);
|
|
|
|
if (configList) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("No FSAA available.", ELL_WARNING);
|
2024-03-20 19:35:52 +01:00
|
|
|
Params.AntiAlias = 0;
|
|
|
|
} else {
|
|
|
|
// reenable multisampling
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[17] = 1;
|
|
|
|
visualAttrBuffer[19] = Params.AntiAlias;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Next try with flipped stencil buffer value
|
|
|
|
// If the first round was with stencil flag it's now without
|
|
|
|
// Other way round also makes sense because some configs
|
|
|
|
// only have depth buffer combined with stencil buffer
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!configList) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (Params.Stencilbuffer)
|
|
|
|
os::Printer::log("No stencilbuffer available, disabling stencil shadows.", ELL_WARNING);
|
|
|
|
Params.Stencilbuffer = !Params.Stencilbuffer;
|
2024-03-20 19:35:52 +01:00
|
|
|
visualAttrBuffer[15] = Params.Stencilbuffer ? 1 : 0;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems);
|
|
|
|
if (!configList && Params.AntiAlias) {
|
|
|
|
while (!configList && (visualAttrBuffer[19] > 1)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[19] -= 1;
|
2024-03-20 19:35:52 +01:00
|
|
|
configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!configList) {
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[17] = 0;
|
|
|
|
visualAttrBuffer[19] = 0;
|
2024-03-20 19:35:52 +01:00
|
|
|
configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems);
|
|
|
|
if (configList) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("No FSAA available.", ELL_WARNING);
|
2024-03-20 19:35:52 +01:00
|
|
|
Params.AntiAlias = 0;
|
|
|
|
} else {
|
|
|
|
// reenable multisampling
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[17] = 1;
|
|
|
|
visualAttrBuffer[19] = Params.AntiAlias;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Next try without double buffer
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!configList && Params.Doublebuffer) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("No doublebuffering available.", ELL_WARNING);
|
2024-03-20 19:35:52 +01:00
|
|
|
Params.Doublebuffer = false;
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[13] = GLX_DONT_CARE;
|
|
|
|
Params.Stencilbuffer = false;
|
2024-03-20 19:35:52 +01:00
|
|
|
visualAttrBuffer[15] = 0;
|
|
|
|
configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems);
|
|
|
|
if (!configList && Params.AntiAlias) {
|
|
|
|
while (!configList && (visualAttrBuffer[19] > 1)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[19] -= 1;
|
2024-03-20 19:35:52 +01:00
|
|
|
configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!configList) {
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[17] = 0;
|
|
|
|
visualAttrBuffer[19] = 0;
|
2024-03-20 19:35:52 +01:00
|
|
|
configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems);
|
|
|
|
if (configList) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("No FSAA available.", ELL_WARNING);
|
2024-03-20 19:35:52 +01:00
|
|
|
Params.AntiAlias = 0;
|
|
|
|
} else {
|
|
|
|
// reenable multisampling
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[17] = 1;
|
|
|
|
visualAttrBuffer[19] = Params.AntiAlias;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
if (configList) {
|
|
|
|
glxFBConfig = configList[0];
|
2023-10-03 20:37:00 +02:00
|
|
|
XFree(configList);
|
2024-03-20 19:35:52 +01:00
|
|
|
typedef XVisualInfo *(*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display *dpy, GLXFBConfig config);
|
|
|
|
PFNGLXGETVISUALFROMFBCONFIGPROC glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGPROC)glXGetProcAddress(reinterpret_cast<const GLubyte *>("glXGetVisualFromFBConfig"));
|
2023-10-03 20:37:00 +02:00
|
|
|
if (glxGetVisualFromFBConfig)
|
2024-03-20 19:35:52 +01:00
|
|
|
VisualInfo = glxGetVisualFromFBConfig(display, (GLXFBConfig)glxFBConfig);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2023-10-03 20:37:00 +02:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// attribute array for the draw buffer
|
|
|
|
int visualAttrBuffer[] =
|
2024-03-20 19:35:52 +01:00
|
|
|
{
|
|
|
|
GLX_RGBA, GLX_USE_GL,
|
|
|
|
GLX_RED_SIZE, 4,
|
|
|
|
GLX_GREEN_SIZE, 4,
|
|
|
|
GLX_BLUE_SIZE, 4,
|
|
|
|
GLX_ALPHA_SIZE, Params.WithAlphaChannel ? 1 : 0,
|
|
|
|
GLX_DEPTH_SIZE, Params.ZBufferBits,
|
|
|
|
GLX_STENCIL_SIZE, Params.Stencilbuffer ? 1 : 0, // 12,13
|
|
|
|
// The following attributes have no flags, but are
|
|
|
|
// either present or not. As a no-op we use
|
|
|
|
// GLX_USE_GL, which is silently ignored by glXChooseVisual
|
|
|
|
Params.Doublebuffer ? GLX_DOUBLEBUFFER : GLX_USE_GL, // 14
|
|
|
|
Params.Stereobuffer ? GLX_STEREO : GLX_USE_GL, // 15
|
|
|
|
None};
|
|
|
|
|
|
|
|
VisualInfo = glXChooseVisual(display, screennr, visualAttrBuffer);
|
|
|
|
if (!VisualInfo) {
|
2023-10-03 20:37:00 +02:00
|
|
|
if (Params.Stencilbuffer)
|
|
|
|
os::Printer::log("No stencilbuffer available, disabling.", ELL_WARNING);
|
|
|
|
Params.Stencilbuffer = !Params.Stencilbuffer;
|
2024-03-20 19:35:52 +01:00
|
|
|
visualAttrBuffer[13] = Params.Stencilbuffer ? 1 : 0;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
VisualInfo = glXChooseVisual(display, screennr, visualAttrBuffer);
|
|
|
|
if (!VisualInfo && Params.Doublebuffer) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("No doublebuffering available.", ELL_WARNING);
|
2024-03-20 19:35:52 +01:00
|
|
|
Params.Doublebuffer = false;
|
2023-10-03 20:37:00 +02:00
|
|
|
visualAttrBuffer[14] = GLX_USE_GL;
|
2024-03-20 19:35:52 +01:00
|
|
|
VisualInfo = glXChooseVisual(display, screennr, visualAttrBuffer);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("No GLX support available. OpenGL driver will not work.", ELL_WARNING);
|
|
|
|
}
|
|
|
|
|
|
|
|
CGLXManager::~CGLXManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
bool CGLXManager::initialize(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &videodata)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
// store params
|
2024-03-20 19:35:52 +01:00
|
|
|
Params = params;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
// set display
|
2024-03-20 19:35:52 +01:00
|
|
|
CurrentContext.OpenGLLinux.X11Display = videodata.OpenGLLinux.X11Display;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
// now get new window
|
2024-03-20 19:35:52 +01:00
|
|
|
CurrentContext.OpenGLLinux.X11Window = videodata.OpenGLLinux.X11Window;
|
|
|
|
if (!PrimaryContext.OpenGLLinux.X11Window) {
|
|
|
|
PrimaryContext.OpenGLLinux.X11Window = CurrentContext.OpenGLLinux.X11Window;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGLXManager::terminate()
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
memset((void *)&CurrentContext, 0, sizeof(CurrentContext));
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGLXManager::generateSurface()
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
if (glxFBConfig) {
|
|
|
|
GlxWin = glXCreateWindow((Display *)CurrentContext.OpenGLLinux.X11Display, (GLXFBConfig)glxFBConfig, CurrentContext.OpenGLLinux.X11Window, NULL);
|
|
|
|
if (!GlxWin) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("Could not create GLX window.", ELL_WARNING);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
CurrentContext.OpenGLLinux.GLXWindow = GlxWin;
|
|
|
|
} else {
|
|
|
|
CurrentContext.OpenGLLinux.GLXWindow = CurrentContext.OpenGLLinux.X11Window;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGLXManager::destroySurface()
|
|
|
|
{
|
|
|
|
if (GlxWin)
|
2024-03-20 19:35:52 +01:00
|
|
|
glXDestroyWindow((Display *)CurrentContext.OpenGLLinux.X11Display, GlxWin);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(GLX_ARB_create_context)
|
|
|
|
static int IrrIgnoreError(Display *display, XErrorEvent *event)
|
|
|
|
{
|
|
|
|
char msg[256];
|
|
|
|
XGetErrorText(display, event->error_code, msg, 256);
|
|
|
|
os::Printer::log("Ignoring an X error", msg, ELL_DEBUG);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool CGLXManager::generateContext()
|
|
|
|
{
|
|
|
|
GLXContext context = 0;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (glxFBConfig) {
|
|
|
|
if (GlxWin) {
|
2023-10-03 20:37:00 +02:00
|
|
|
#if defined(GLX_ARB_create_context)
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
PFNGLXCREATECONTEXTATTRIBSARBPROC glxCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress(reinterpret_cast<const GLubyte *>("glXCreateContextAttribsARB"));
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (glxCreateContextAttribsARB) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("GLX with GLX_ARB_create_context", ELL_DEBUG);
|
|
|
|
int contextAttrBuffer[] = {
|
2024-03-20 19:35:52 +01:00
|
|
|
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
|
|
|
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
|
|
|
|
// GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
|
|
|
|
None};
|
2023-10-03 20:37:00 +02:00
|
|
|
XErrorHandler old = XSetErrorHandler(IrrIgnoreError);
|
2024-03-20 19:35:52 +01:00
|
|
|
context = glxCreateContextAttribsARB((Display *)CurrentContext.OpenGLLinux.X11Display, (GLXFBConfig)glxFBConfig, NULL, True, contextAttrBuffer);
|
2023-10-03 20:37:00 +02:00
|
|
|
XSetErrorHandler(old);
|
|
|
|
// transparently fall back to legacy call
|
|
|
|
}
|
|
|
|
if (!context)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// create glx context
|
2024-03-20 19:35:52 +01:00
|
|
|
context = glXCreateNewContext((Display *)CurrentContext.OpenGLLinux.X11Display, (GLXFBConfig)glxFBConfig, GLX_RGBA_TYPE, NULL, True);
|
|
|
|
if (!context) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("Could not create GLX rendering context.", ELL_WARNING);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("GLX window was not properly created.", ELL_WARNING);
|
|
|
|
return false;
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
|
|
|
context = glXCreateContext((Display *)CurrentContext.OpenGLLinux.X11Display, VisualInfo, NULL, True);
|
|
|
|
if (!context) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("Could not create GLX rendering context.", ELL_WARNING);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
CurrentContext.OpenGLLinux.X11Context = context;
|
2023-10-03 20:37:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
const SExposedVideoData &CGLXManager::getContext() const
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
return CurrentContext;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
bool CGLXManager::activateContext(const SExposedVideoData &videoData, bool restorePrimaryOnZero)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
// TODO: handle restorePrimaryOnZero
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (videoData.OpenGLLinux.X11Window) {
|
|
|
|
if (videoData.OpenGLLinux.X11Display && videoData.OpenGLLinux.X11Context) {
|
|
|
|
if (!glXMakeCurrent((Display *)videoData.OpenGLLinux.X11Display, videoData.OpenGLLinux.GLXWindow, (GLXContext)videoData.OpenGLLinux.X11Context)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("Context activation failed.");
|
|
|
|
return false;
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
CurrentContext.OpenGLLinux.GLXWindow = videoData.OpenGLLinux.GLXWindow;
|
|
|
|
CurrentContext.OpenGLLinux.X11Window = videoData.OpenGLLinux.X11Window;
|
|
|
|
CurrentContext.OpenGLLinux.X11Display = videoData.OpenGLLinux.X11Display;
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
// in case we only got a window ID, try with the existing values for display and context
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!glXMakeCurrent((Display *)PrimaryContext.OpenGLLinux.X11Display, videoData.OpenGLLinux.GLXWindow, (GLXContext)PrimaryContext.OpenGLLinux.X11Context)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("Context activation failed.");
|
|
|
|
return false;
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
CurrentContext.OpenGLLinux.GLXWindow = videoData.OpenGLLinux.GLXWindow;
|
|
|
|
CurrentContext.OpenGLLinux.X11Window = videoData.OpenGLLinux.X11Window;
|
|
|
|
CurrentContext.OpenGLLinux.X11Display = PrimaryContext.OpenGLLinux.X11Display;
|
|
|
|
}
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
} else if (!restorePrimaryOnZero && !videoData.OpenGLLinux.X11Window && !videoData.OpenGLLinux.X11Display) {
|
|
|
|
if (!glXMakeCurrent((Display *)PrimaryContext.OpenGLLinux.X11Display, None, NULL)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("Render Context reset failed.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
CurrentContext.OpenGLLinux.X11Window = 0;
|
|
|
|
CurrentContext.OpenGLLinux.X11Display = 0;
|
|
|
|
}
|
|
|
|
// set back to main context
|
2024-03-20 19:35:52 +01:00
|
|
|
else if (CurrentContext.OpenGLLinux.X11Display != PrimaryContext.OpenGLLinux.X11Display) {
|
|
|
|
if (!glXMakeCurrent((Display *)PrimaryContext.OpenGLLinux.X11Display, PrimaryContext.OpenGLLinux.X11Window, (GLXContext)PrimaryContext.OpenGLLinux.X11Context)) {
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("Context activation failed.");
|
|
|
|
return false;
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
2023-10-03 20:37:00 +02:00
|
|
|
CurrentContext = PrimaryContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGLXManager::destroyContext()
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
if (CurrentContext.OpenGLLinux.X11Context) {
|
|
|
|
if (GlxWin) {
|
|
|
|
if (!glXMakeContextCurrent((Display *)CurrentContext.OpenGLLinux.X11Display, None, None, NULL))
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("Could not release glx context.", ELL_WARNING);
|
2024-03-20 19:35:52 +01:00
|
|
|
} else {
|
|
|
|
if (!glXMakeCurrent((Display *)CurrentContext.OpenGLLinux.X11Display, None, NULL))
|
2023-10-03 20:37:00 +02:00
|
|
|
os::Printer::log("Could not release glx context.", ELL_WARNING);
|
|
|
|
}
|
2024-03-20 19:35:52 +01:00
|
|
|
glXDestroyContext((Display *)CurrentContext.OpenGLLinux.X11Display, (GLXContext)CurrentContext.OpenGLLinux.X11Context);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
void *CGLXManager::getProcAddress(const std::string &procName)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
return (void *)glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(procName.c_str()));
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGLXManager::swapBuffers()
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
glXSwapBuffers((Display *)CurrentContext.OpenGLLinux.X11Display, CurrentContext.OpenGLLinux.GLXWindow);
|
2023-10-03 20:37:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|