GSdx: Remove GLX in favor of EGL (#3562)

This commit is contained in:
Hamish 2020-08-09 15:39:56 +12:00 committed by GitHub
parent bf2904d380
commit 8816f4bf0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 9 additions and 368 deletions

View File

@ -240,7 +240,7 @@ for ARG in "$@"; do
echo
echo "** Developer option **"
echo "--glsl : Replace CG backend of ZZogl by GLSL"
echo "--egl : Replace GLX by EGL (ZZogl/GSdx plugins)"
echo "--egl : Replace GLX by EGL (ZZogl/GSdx_legacy plugins)"
echo "--cross-multilib: Build a 32bit PCSX2 on a 64bit machine using multilib."
echo "--opencl : Enable experimental OpenCL support"
echo

View File

@ -87,6 +87,8 @@ endif()
## Use CheckLib package to find module
include(CheckLib)
if(Linux)
check_lib(EGL EGL EGL/egl.h)
check_lib(X11_XCB X11-xcb X11/Xlib-xcb.h)
check_lib(AIO aio libaio.h)
# There are two udev pkg config files - udev.pc (wrong), libudev.pc (correct)
# When cross compiling, pkg-config will be skipped so we have to look for
@ -98,10 +100,6 @@ if(Linux)
check_lib(LIBUDEV libudev libudev.h)
endif()
endif()
if(EGL_API)
check_lib(EGL EGL EGL/egl.h)
check_lib(X11_XCB X11-xcb X11/Xlib-xcb.h)
endif()
if(OPENCL_API)
check_lib(OPENCL OpenCL CL/cl.hpp)
endif()

View File

@ -43,10 +43,6 @@ if(XDG_STD)
set(GSdxFinalFlags ${GSdxFinalFlags} -DXDG_STD)
endif()
if(EGL_API AND EGL_FOUND)
set(GSdxFinalFlags ${GSdxFinalFlags} -DEGL_SUPPORTED)
endif()
if(OPENCL_FOUND)
set(GSdxFinalFlags ${GSdxFinalFlags} -DENABLE_OPENCL)
@ -220,13 +216,11 @@ if(Windows)
else()
LIST(APPEND GSdxSources
Window/GSLinuxDialog.cpp
Window/GSWndOGL.cpp
Window/GSWndEGL.cpp
)
LIST(APPEND GSdxHeaders
Window/GSWndEGL.h
Window/GSWndOGL.h
)
endif()
@ -239,6 +233,8 @@ set(GSdxFinalSources
set(GSdxFinalLibs
${X11_LIBRARIES}
${OPENGL_LIBRARIES}
${EGL_LIBRARIES}
${X11_XCB_LIBRARIES}
${GTK2_LIBRARIES}
${LIBC_LIBRARIES}
${PNG_LIBRARIES}
@ -246,10 +242,6 @@ set(GSdxFinalLibs
${LIBLZMA_LIBRARIES}
)
if(EGL_API AND EGL_FOUND)
set(GSdxFinalLibs ${GSdxFinalLibs} ${EGL_LIBRARIES} ${X11_XCB_LIBRARIES})
endif()
if(USE_VTUNE)
set(GSdxFinalLibs ${GSdxFinalLibs} ${VTUNE_LIBRARIES})
endif()

View File

@ -42,7 +42,6 @@ static HRESULT s_hr = E_FAIL;
#else
#include "Window/GSWndOGL.h"
#include "Window/GSWndEGL.h"
extern bool RunLinuxDialog();
@ -236,7 +235,7 @@ static int _GSopen(void** dsp, const char* title, GSRendererType renderer, int t
#ifdef ENABLE_OPENCL
case GSRendererType::OGL_OpenCL:
#endif
#if defined(EGL_SUPPORTED) && defined(__unix__)
#if defined(__unix__)
// Note: EGL code use GLX otherwise maybe it could be also compatible with Windows
// Yes OpenGL code isn't complicated enough !
switch (GSWndEGL::SelectPlatform()) {
@ -253,9 +252,6 @@ static int _GSopen(void** dsp, const char* title, GSRendererType renderer, int t
default:
break;
}
#endif
#if defined(__unix__)
wnds.push_back(std::make_shared<GSWndOGL>());
#else
wnds.push_back(std::make_shared<GSWndWGL>());
#endif
@ -264,7 +260,7 @@ static int _GSopen(void** dsp, const char* title, GSRendererType renderer, int t
#ifdef _WIN32
wnds.push_back(std::make_shared<GSWndDX>());
#else
wnds.push_back(std::make_shared<GSWndOGL>());
wnds.push_back(std::make_shared<GSWndEGL_X11>());
#endif
break;
}

View File

@ -22,7 +22,7 @@
#include "stdafx.h"
#include "GSWndEGL.h"
#if defined(__unix__) && defined(EGL_SUPPORTED)
#if defined(__unix__)
// static method
int GSWndEGL::SelectPlatform()

View File

@ -21,7 +21,7 @@
#include "GSWnd.h"
#if defined(__unix__) && defined(EGL_SUPPORTED)
#if defined(__unix__)
#include <EGL/egl.h>
#include <EGL/eglext.h>

View File

@ -1,278 +0,0 @@
/*
* Copyright (C) 2007-2012 Gabest
* http://www.gabest.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "stdafx.h"
#include "GSWndOGL.h"
#if defined(__unix__)
GSWndOGL::GSWndOGL()
: m_NativeWindow(0), m_NativeDisplay(nullptr), m_context(0), m_has_late_vsync(false), m_swapinterval_ext(nullptr), m_swapinterval_mesa(nullptr)
{
}
static bool ctxError = false;
static int ctxErrorHandler(Display *dpy, XErrorEvent *ev)
{
ctxError = true;
return 0;
}
void GSWndOGL::CreateContext(int major, int minor)
{
if ( !m_NativeDisplay || !m_NativeWindow )
{
fprintf( stderr, "Wrong X11 display/window\n" );
throw GSDXRecoverableError();
}
// Get visual information
static int attrListDbl[] =
{
// GLX_X_RENDERABLE: If True is specified, then only frame buffer configurations that have associated X
// visuals (and can be used to render to Windows and/or GLX pixmaps) will be considered. The default value is GLX_DONT_CARE.
GLX_X_RENDERABLE , True,
GLX_RED_SIZE , 8,
GLX_GREEN_SIZE , 8,
GLX_BLUE_SIZE , 8,
GLX_DEPTH_SIZE , 0,
GLX_DOUBLEBUFFER , True,
None
};
PFNGLXCHOOSEFBCONFIGPROC glX_ChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC) glXGetProcAddress((GLubyte *) "glXChooseFBConfig");
int fbcount = 0;
GLXFBConfig *fbc = glX_ChooseFBConfig(m_NativeDisplay, DefaultScreen(m_NativeDisplay), attrListDbl, &fbcount);
if (!fbc || fbcount < 1) {
throw GSDXRecoverableError();
}
PFNGLXCREATECONTEXTATTRIBSARBPROC glX_CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte*) "glXCreateContextAttribsARB");
if (!glX_CreateContextAttribsARB) {
throw GSDXRecoverableError();
}
// Install a dummy handler to handle gracefully (aka not segfault) the support of GL version
int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler);
// Be sure the handler is installed
XSync( m_NativeDisplay, false);
// Create a context
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, major,
GLX_CONTEXT_MINOR_VERSION_ARB, minor,
#ifdef ENABLE_OGL_DEBUG
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
#else
// Open Source isn't happy with an unsupported flags...
//GLX_CONTEXT_FLAGS_ARB, GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR,
#endif
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
None
};
m_context = glX_CreateContextAttribsARB(m_NativeDisplay, fbc[0], 0, true, context_attribs);
XFree(fbc);
// Don't forget to reinstall the older Handler
XSetErrorHandler(oldHandler);
// Get latest error
XSync( m_NativeDisplay, false);
if (!m_context || ctxError) {
fprintf(stderr, "Failed to create the opengl context. Check your drivers support openGL %d.%d. Hint: opensource drivers don't\n", major, minor );
throw GSDXRecoverableError();
}
}
void GSWndOGL::AttachContext()
{
if (!IsContextAttached()) {
//fprintf(stderr, "Attach the context\n");
glXMakeCurrent(m_NativeDisplay, m_NativeWindow, m_context);
m_ctx_attached = true;
}
}
void GSWndOGL::DetachContext()
{
if (IsContextAttached()) {
//fprintf(stderr, "Detach the context\n");
glXMakeCurrent(m_NativeDisplay, None, NULL);
m_ctx_attached = false;
}
}
void GSWndOGL::PopulateWndGlFunction()
{
m_swapinterval_ext = (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddress((const GLubyte*) "glXSwapIntervalEXT");
m_swapinterval_mesa = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA");
const char* ext = glXQueryExtensionsString(m_NativeDisplay, DefaultScreen(m_NativeDisplay));
m_has_late_vsync = m_swapinterval_ext && ext && strstr(ext, "GLX_EXT_swap_control");
}
bool GSWndOGL::Attach(void* handle, bool managed)
{
m_NativeWindow = *(Window*)handle;
m_managed = managed;
m_NativeDisplay = XOpenDisplay(NULL);
FullContextInit();
return true;
}
void GSWndOGL::Detach()
{
// Actually the destructor is not called when there is only a GSclose/GSshutdown
// The window still need to be closed
DetachContext();
if (m_context) glXDestroyContext(m_NativeDisplay, m_context);
if (m_NativeDisplay) {
XCloseDisplay(m_NativeDisplay);
m_NativeDisplay = NULL;
}
}
bool GSWndOGL::Create(const std::string& title, int w, int h)
{
if(m_NativeWindow)
throw GSDXRecoverableError();
if(w <= 0 || h <= 0) {
w = theApp.GetConfigI("ModeWidth");
h = theApp.GetConfigI("ModeHeight");
}
m_managed = true;
// note this part must be only executed when replaying .gs debug file
m_NativeDisplay = XOpenDisplay(NULL);
m_NativeWindow = XCreateSimpleWindow(m_NativeDisplay, DefaultRootWindow(m_NativeDisplay), 0, 0, w, h, 0, 0, 0);
XMapWindow (m_NativeDisplay, m_NativeWindow);
if (m_NativeWindow == 0)
throw GSDXRecoverableError();
FullContextInit();
return true;
}
void* GSWndOGL::GetProcAddress(const char* name, bool opt)
{
void* ptr = (void*)glXGetProcAddress((const GLubyte*)name);
if (ptr == NULL) {
if (theApp.GetConfigB("debug_opengl"))
fprintf(stderr, "Failed to find %s\n", name);
if (!opt)
throw GSDXRecoverableError();
}
return ptr;
}
void* GSWndOGL::GetDisplay()
{
// note this part must be only executed when replaying .gs debug file
return (void*)m_NativeDisplay;
}
GSVector4i GSWndOGL::GetClientRect()
{
unsigned int h = 480;
unsigned int w = 640;
unsigned int borderDummy;
unsigned int depthDummy;
Window winDummy;
int xDummy;
int yDummy;
if (!m_NativeDisplay) m_NativeDisplay = XOpenDisplay(NULL);
XGetGeometry(m_NativeDisplay, m_NativeWindow, &winDummy, &xDummy, &yDummy, &w, &h, &borderDummy, &depthDummy);
return GSVector4i(0, 0, (int)w, (int)h);
}
// Returns FALSE if the window has no title, or if th window title is under the strict
// management of the emulator.
bool GSWndOGL::SetWindowText(const char* title)
{
if (!m_managed) return true;
XTextProperty prop;
memset(&prop, 0, sizeof(prop));
char* ptitle = (char*)title;
if (XStringListToTextProperty(&ptitle, 1, &prop)) {
XSetWMName(m_NativeDisplay, m_NativeWindow, &prop);
}
XFree(prop.value);
XFlush(m_NativeDisplay);
return true;
}
void GSWndOGL::SetSwapInterval()
{
// m_swapinterval uses an integer as parameter
// 0 -> disable vsync
// n -> wait n frame
if (m_swapinterval_ext) m_swapinterval_ext(m_NativeDisplay, m_NativeWindow, m_vsync);
else if (m_swapinterval_mesa) m_swapinterval_mesa(m_vsync);
else fprintf(stderr, "Failed to set VSync\n");
}
void GSWndOGL::Flip()
{
if (m_vsync_change_requested.exchange(false))
SetSwapInterval();
glXSwapBuffers(m_NativeDisplay, m_NativeWindow);
}
void GSWndOGL::Show()
{
XMapRaised(m_NativeDisplay, m_NativeWindow);
XFlush(m_NativeDisplay);
}
void GSWndOGL::Hide()
{
XUnmapWindow(m_NativeDisplay, m_NativeWindow);
XFlush(m_NativeDisplay);
}
void GSWndOGL::HideFrame()
{
// TODO
}
#endif

View File

@ -1,67 +0,0 @@
/*
* Copyright (C) 2007-2012 Gabest
* http://www.gabest.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "GSWnd.h"
#if defined(__unix__)
#include <X11/Xlib.h>
#include <GL/glx.h>
class GSWndOGL final : public GSWndGL
{
Window m_NativeWindow;
Display* m_NativeDisplay;
GLXContext m_context;
bool m_has_late_vsync;
PFNGLXSWAPINTERVALEXTPROC m_swapinterval_ext;
PFNGLXSWAPINTERVALMESAPROC m_swapinterval_mesa;
void PopulateWndGlFunction();
void CreateContext(int major, int minor);
void SetSwapInterval();
bool HasLateVsyncSupport() { return m_has_late_vsync; }
public:
GSWndOGL();
virtual ~GSWndOGL() {};
bool Create(const std::string& title, int w, int h);
bool Attach(void* handle, bool managed = true);
void Detach();
void* GetDisplay();
void* GetHandle() {return (void*)m_NativeWindow;}
GSVector4i GetClientRect();
bool SetWindowText(const char* title);
void AttachContext();
void DetachContext();
void* GetProcAddress(const char* name, bool opt = false);
void Show();
void Hide();
void HideFrame();
void Flip();
};
#endif