2010-07-10 08:20:50 +00:00
|
|
|
/* ZZ Open GL graphics plugin
|
|
|
|
* Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
|
|
|
|
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
|
2010-03-19 02:04:55 +00:00
|
|
|
*
|
|
|
|
* 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 of the License, 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 this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2010-03-19 02:04:55 +00:00
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
#include "Util.h"
|
|
|
|
#include "GLWin.h"
|
2010-03-19 02:04:55 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
#if defined(GL_X11_WINDOW)
|
|
|
|
|
|
|
|
#ifdef EGL_API
|
|
|
|
// Need at least MESA 9.0 (plan for october/november 2012)
|
|
|
|
// So force the destiny to at least check the compilation
|
|
|
|
#ifndef EGL_KHR_create_context
|
|
|
|
#define EGL_KHR_create_context 1
|
|
|
|
#define EGL_CONTEXT_MAJOR_VERSION_KHR EGL_CONTEXT_CLIENT_VERSION
|
|
|
|
#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB
|
|
|
|
#define EGL_CONTEXT_FLAGS_KHR 0x30FC
|
|
|
|
#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD
|
|
|
|
#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31BD
|
|
|
|
#define EGL_NO_RESET_NOTIFICATION_KHR 0x31BE
|
|
|
|
#define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31BF
|
|
|
|
#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001
|
|
|
|
#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002
|
|
|
|
#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR 0x00000004
|
|
|
|
#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001
|
|
|
|
#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002
|
|
|
|
#endif
|
|
|
|
#endif
|
2010-03-19 02:04:55 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
#ifdef USE_GSOPEN2
|
|
|
|
bool GLWindow::CreateWindow(void *pDisplay)
|
|
|
|
{
|
2012-09-23 18:52:44 +00:00
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
NativeWindow = (Window)*((u32*)(pDisplay)+1);
|
2011-06-12 14:48:36 +00:00
|
|
|
// Do not take the display which come from pcsx2 neither change it.
|
|
|
|
// You need a new one to do the operation in the GS thread
|
2012-09-23 18:52:44 +00:00
|
|
|
NativeDisplay = XOpenDisplay(NULL);
|
|
|
|
if (!NativeDisplay) ret = false;
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
#ifdef EGL_API
|
|
|
|
if (!OpenEGLDisplay()) ret = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
2011-06-12 14:48:36 +00:00
|
|
|
}
|
|
|
|
#else
|
2010-03-19 02:04:55 +00:00
|
|
|
bool GLWindow::CreateWindow(void *pDisplay)
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2012-09-23 18:52:44 +00:00
|
|
|
bool ret = true;
|
|
|
|
|
2010-09-05 16:30:47 +00:00
|
|
|
// init support of multi thread
|
|
|
|
if (!XInitThreads())
|
|
|
|
ZZLog::Error_Log("Failed to init the xlib concurent threads");
|
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
NativeDisplay = XOpenDisplay(NULL);
|
|
|
|
if (!NativeDisplay) ret = false;
|
2010-03-19 02:04:55 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
if (pDisplay == NULL)
|
2010-11-10 11:15:48 +00:00
|
|
|
{
|
|
|
|
ZZLog::Error_Log("Failed to create window. Exiting...");
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
// Allow pad to use the display
|
2012-09-23 18:52:44 +00:00
|
|
|
*(Display**)pDisplay = NativeDisplay;
|
2011-06-12 14:48:36 +00:00
|
|
|
// Pad can use the window to grab the input. For the moment just set to 0 to avoid
|
|
|
|
// to grab an unknow window... Anyway GSopen1 might be dropped in the future
|
|
|
|
*((u32*)(pDisplay)+1) = 0;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
#ifdef EGL_API
|
|
|
|
if (!OpenEGLDisplay()) ret = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EGL_API
|
|
|
|
EGLBoolean GLWindow::OpenEGLDisplay()
|
|
|
|
{
|
|
|
|
// Create an EGL display from the native display
|
|
|
|
eglDisplay = eglGetDisplay((EGLNativeDisplayType)NativeDisplay);
|
|
|
|
if ( eglDisplay == EGL_NO_DISPLAY ) return EGL_FALSE;
|
|
|
|
|
|
|
|
if ( !eglInitialize(eglDisplay, NULL, NULL) ) return EGL_FALSE;
|
|
|
|
|
|
|
|
return EGL_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EGL_API
|
|
|
|
void GLWindow::CloseEGLDisplay()
|
|
|
|
{
|
|
|
|
eglTerminate(eglDisplay);
|
2010-03-19 02:04:55 +00:00
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
#endif
|
2010-03-19 02:04:55 +00:00
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
bool GLWindow::ReleaseContext()
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2010-09-06 22:21:07 +00:00
|
|
|
bool status = true;
|
2012-09-23 18:52:44 +00:00
|
|
|
#ifdef GLX_API
|
|
|
|
if (!NativeDisplay) return status;
|
2010-09-06 22:21:07 +00:00
|
|
|
|
|
|
|
// free the context
|
2012-10-21 18:10:13 +00:00
|
|
|
if (glxContext)
|
2010-03-19 06:38:44 +00:00
|
|
|
{
|
2012-09-23 18:52:44 +00:00
|
|
|
if (!glXMakeCurrent(NativeDisplay, None, NULL)) {
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Could not release drawing context.");
|
2010-09-06 22:21:07 +00:00
|
|
|
status = false;
|
|
|
|
}
|
2012-09-23 18:52:44 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
glXDestroyContext(NativeDisplay, glxContext);
|
|
|
|
glxContext = NULL;
|
2010-03-19 06:38:44 +00:00
|
|
|
}
|
2012-09-23 18:52:44 +00:00
|
|
|
#endif
|
|
|
|
#ifdef EGL_API
|
|
|
|
eglReleaseThread();
|
|
|
|
#endif
|
2010-09-06 22:21:07 +00:00
|
|
|
|
|
|
|
return status;
|
2010-09-01 10:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindow::CloseWindow()
|
|
|
|
{
|
|
|
|
SaveConfig();
|
2012-09-23 18:52:44 +00:00
|
|
|
if (!NativeDisplay) return;
|
2010-03-19 02:04:55 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
#ifdef EGL_API
|
|
|
|
CloseEGLDisplay();
|
|
|
|
#endif
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
XCloseDisplay(NativeDisplay);
|
|
|
|
NativeDisplay = NULL;
|
2010-09-01 10:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindow::GetWindowSize()
|
|
|
|
{
|
2012-09-23 18:52:44 +00:00
|
|
|
if (!NativeDisplay or !NativeWindow) return;
|
2010-09-05 15:47:09 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
u32 depth = 0;
|
|
|
|
#ifdef GLX_API
|
2010-09-01 10:28:37 +00:00
|
|
|
unsigned int borderDummy;
|
|
|
|
Window winDummy;
|
2010-09-05 15:47:09 +00:00
|
|
|
s32 xDummy;
|
|
|
|
s32 yDummy;
|
2012-09-23 18:52:44 +00:00
|
|
|
u32 width;
|
|
|
|
u32 height;
|
|
|
|
|
|
|
|
XLockDisplay(NativeDisplay);
|
|
|
|
XGetGeometry(NativeDisplay, NativeWindow, &winDummy, &xDummy, &yDummy, &width, &height, &borderDummy, &depth);
|
|
|
|
XUnlockDisplay(NativeDisplay);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// FIXME: Not sure it works but that could remove latest X11 bits.
|
|
|
|
#ifdef EGL_API
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
eglQuerySurface(eglDisplay, eglSurface, EGL_WIDTH, &width);
|
|
|
|
eglQuerySurface(eglDisplay, eglSurface, EGL_HEIGHT, &height);
|
|
|
|
#endif
|
2010-09-08 11:16:27 +00:00
|
|
|
|
|
|
|
// update the gl buffer size
|
2010-11-14 01:38:10 +00:00
|
|
|
UpdateWindowSize(width, height);
|
2010-09-08 11:16:27 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
#ifndef USE_GSOPEN2
|
|
|
|
// too verbose!
|
2010-10-21 11:13:49 +00:00
|
|
|
ZZLog::Dev_Log("Resolution %dx%d. Depth %d bpp. Position (%d,%d)", width, height, depth, conf.x, conf.y);
|
2011-06-12 14:48:36 +00:00
|
|
|
#endif
|
2010-09-01 10:28:37 +00:00
|
|
|
}
|
2010-03-19 02:04:55 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
void GLWindow::PrintProtocolVersion()
|
2010-09-01 10:28:37 +00:00
|
|
|
{
|
2012-09-23 18:52:44 +00:00
|
|
|
#ifdef GLX_API
|
2010-09-01 10:28:37 +00:00
|
|
|
int glxMajorVersion, glxMinorVersion;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
glXQueryVersion(NativeDisplay, &glxMajorVersion, &glxMinorVersion);
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
if (glXIsDirect(NativeDisplay, glxContext))
|
2011-06-12 14:48:36 +00:00
|
|
|
ZZLog::Error_Log("glX-Version %d.%d with Direct Rendering", glxMajorVersion, glxMinorVersion);
|
|
|
|
else
|
|
|
|
ZZLog::Error_Log("glX-Version %d.%d with Indirect Rendering !!! It will be slow", glxMajorVersion, glxMinorVersion);
|
2012-09-23 18:52:44 +00:00
|
|
|
#endif
|
|
|
|
#ifdef EGL_API
|
|
|
|
ZZLog::Error_Log("Egl: %s : %s", eglQueryString(eglDisplay, EGL_VENDOR) , eglQueryString(eglDisplay, EGL_VERSION) );
|
|
|
|
ZZLog::Error_Log("Egl: extensions supported: %s", eglQueryString(eglDisplay, EGL_EXTENSIONS));
|
|
|
|
#endif
|
2010-09-01 10:28:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
#ifdef GLX_API
|
2012-04-29 18:50:07 +00:00
|
|
|
bool GLWindow::CreateContextGL(int major, int minor)
|
2010-09-08 11:16:27 +00:00
|
|
|
{
|
2012-09-23 18:52:44 +00:00
|
|
|
if (!NativeDisplay) return false;
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2012-04-29 18:50:07 +00:00
|
|
|
// Get visual information
|
2012-10-27 16:52:51 +00:00
|
|
|
int attrListDbl[] =
|
2012-04-29 18:50:07 +00:00
|
|
|
{
|
|
|
|
GLX_X_RENDERABLE , True,
|
|
|
|
GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
|
|
|
|
GLX_RENDER_TYPE , GLX_RGBA_BIT,
|
|
|
|
GLX_RED_SIZE , 8,
|
|
|
|
GLX_GREEN_SIZE , 8,
|
|
|
|
GLX_BLUE_SIZE , 8,
|
|
|
|
GLX_DEPTH_SIZE , 24,
|
|
|
|
GLX_DOUBLEBUFFER , True,
|
|
|
|
None
|
|
|
|
};
|
2011-07-01 09:01:50 +00:00
|
|
|
|
2012-10-27 16:52:51 +00:00
|
|
|
// Attribute are very sensible to the various implementation (intel, nvidia, amd)
|
|
|
|
// Nvidia and Intel doesn't support previous attributes for opengl2.0
|
|
|
|
int attrListDbl_2_0[] =
|
|
|
|
{
|
|
|
|
GLX_RGBA,
|
|
|
|
GLX_DOUBLEBUFFER,
|
|
|
|
GLX_RED_SIZE, 8,
|
|
|
|
GLX_GREEN_SIZE, 8,
|
|
|
|
GLX_BLUE_SIZE, 8,
|
|
|
|
GLX_DEPTH_SIZE, 24,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
// Only keep for older card but NVIDIA and AMD both drop the support of those cards
|
|
|
|
if (major <= 2) {
|
2012-10-27 16:52:51 +00:00
|
|
|
XVisualInfo *vi = glXChooseVisual(NativeDisplay, DefaultScreen(NativeDisplay), attrListDbl_2_0);
|
2012-09-23 18:52:44 +00:00
|
|
|
if (vi == NULL) return NULL;
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
glxContext = glXCreateContext(NativeDisplay, vi, NULL, GL_TRUE);
|
2012-09-23 18:52:44 +00:00
|
|
|
XFree(vi);
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
if (!glxContext) return false;
|
2012-09-23 18:52:44 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
glXMakeCurrent(NativeDisplay, NativeWindow, glxContext);
|
2012-09-23 18:52:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
PFNGLXCHOOSEFBCONFIGPROC glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC)GetProcAddress("glXChooseFBConfig");
|
2011-06-12 14:48:36 +00:00
|
|
|
int fbcount = 0;
|
2012-09-23 18:52:44 +00:00
|
|
|
GLXFBConfig *fbc = glXChooseFBConfig(NativeDisplay, DefaultScreen(NativeDisplay), attrListDbl, &fbcount);
|
2012-04-29 18:50:07 +00:00
|
|
|
if (!fbc || fbcount < 1) return false;
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)GetProcAddress("glXCreateContextAttribsARB");
|
2012-04-29 18:50:07 +00:00
|
|
|
if (!glXCreateContextAttribsARB) return false;
|
|
|
|
|
|
|
|
// Create a context
|
|
|
|
int context_attribs[] =
|
|
|
|
{
|
|
|
|
GLX_CONTEXT_MAJOR_VERSION_ARB, major,
|
|
|
|
GLX_CONTEXT_MINOR_VERSION_ARB, minor,
|
|
|
|
// Keep compatibility for old cruft
|
2011-06-12 14:48:36 +00:00
|
|
|
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
|
2012-04-29 18:50:07 +00:00
|
|
|
//GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
|
|
|
|
// FIXME : Request a debug context to ease opengl development
|
2012-10-21 18:10:13 +00:00
|
|
|
#if defined(ZEROGS_DEVBUILD) || defined(_DEBUG)
|
2012-04-29 18:50:07 +00:00
|
|
|
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
|
2012-10-21 18:10:13 +00:00
|
|
|
#endif
|
2012-04-29 18:50:07 +00:00
|
|
|
None
|
2011-06-12 14:48:36 +00:00
|
|
|
};
|
2012-04-29 18:50:07 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
glxContext = glXCreateContextAttribsARB(NativeDisplay, fbc[0], 0, true, context_attribs);
|
|
|
|
if (!glxContext) return false;
|
2012-04-29 18:50:07 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
XSync( NativeDisplay, false);
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
glXMakeCurrent(NativeDisplay, NativeWindow, glxContext);
|
2012-04-29 18:50:07 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-09-23 18:52:44 +00:00
|
|
|
#endif
|
2012-04-29 18:50:07 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
bool GLWindow::CreateContextGL()
|
2012-04-29 18:50:07 +00:00
|
|
|
{
|
2012-09-23 18:52:44 +00:00
|
|
|
bool ret;
|
2012-05-07 19:51:58 +00:00
|
|
|
#if defined(OGL4_LOG) || defined(GLSL4_API)
|
|
|
|
// We need to define a debug context. So we need at a 3.0 context (if not 3.2 actually)
|
2012-09-23 18:52:44 +00:00
|
|
|
ret = CreateContextGL(3, 3);
|
2012-04-19 21:22:08 +00:00
|
|
|
#else
|
2012-04-29 18:50:07 +00:00
|
|
|
// FIXME there was some issue with previous context creation on Geforce7. Code was rewritten
|
|
|
|
// for GSdx unfortunately it was not tested on Geforce7 so keep the 2.0 context for now.
|
2012-09-23 18:52:44 +00:00
|
|
|
// Note: Geforce 6&7 was dropped from nvidia driver (2012)
|
2012-04-29 18:50:07 +00:00
|
|
|
#if 0
|
2012-09-23 18:52:44 +00:00
|
|
|
ret = CreateContextGL(3, 0)
|
|
|
|
if (! ret )
|
|
|
|
ret = CreateContextGL(2, 0);
|
2012-04-29 18:50:07 +00:00
|
|
|
#else
|
2012-09-23 18:52:44 +00:00
|
|
|
ret = CreateContextGL(2, 0);
|
2012-04-29 18:50:07 +00:00
|
|
|
#endif
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
#endif
|
2012-09-23 18:52:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef EGL_API
|
2012-10-21 18:10:13 +00:00
|
|
|
bool GLWindow::CreateContextGL(int major, int minor)
|
2012-09-23 18:52:44 +00:00
|
|
|
{
|
|
|
|
EGLConfig eglConfig;
|
|
|
|
EGLint numConfigs;
|
|
|
|
EGLint contextAttribs[] =
|
|
|
|
{
|
|
|
|
EGL_CONTEXT_MAJOR_VERSION_KHR, major,
|
|
|
|
EGL_CONTEXT_MINOR_VERSION_KHR, minor,
|
|
|
|
// Keep compatibility for old cruft
|
|
|
|
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR,
|
|
|
|
//EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR | EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
|
|
|
|
// FIXME : Request a debug context to ease opengl development
|
2012-10-21 18:10:13 +00:00
|
|
|
#if defined(ZEROGS_DEVBUILD) || defined(_DEBUG)
|
2012-09-23 18:52:44 +00:00
|
|
|
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR,
|
2012-10-21 18:10:13 +00:00
|
|
|
#endif
|
2012-09-23 18:52:44 +00:00
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
EGLint attrList[] = {
|
|
|
|
EGL_RED_SIZE, 8,
|
|
|
|
EGL_GREEN_SIZE, 8,
|
|
|
|
EGL_BLUE_SIZE, 8,
|
|
|
|
EGL_DEPTH_SIZE, 24,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
eglBindAPI(EGL_OPENGL_API);
|
|
|
|
|
|
|
|
if ( !eglChooseConfig(eglDisplay, attrList, &eglConfig, 1, &numConfigs) )
|
|
|
|
{
|
|
|
|
ZZLog::Error_Log("Failed to get a frame buffer config!");
|
|
|
|
return EGL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, NativeWindow, NULL);
|
|
|
|
if ( eglSurface == EGL_NO_SURFACE )
|
|
|
|
{
|
|
|
|
ZZLog::Error_Log("Failed to get a window surface");
|
|
|
|
return EGL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
eglContext = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, contextAttribs );
|
|
|
|
if ( eglContext == EGL_NO_CONTEXT )
|
|
|
|
{
|
|
|
|
ZZLog::Error_Log("Failed to create the context");
|
|
|
|
ZZLog::Error_Log("EGL STATUS: %x", eglGetError());
|
|
|
|
return EGL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) )
|
|
|
|
{
|
|
|
|
return EGL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EGL_TRUE;
|
2011-06-12 14:48:36 +00:00
|
|
|
}
|
2012-09-23 18:52:44 +00:00
|
|
|
#endif
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
#ifdef USE_GSOPEN2
|
|
|
|
bool GLWindow::DisplayWindow(int _width, int _height)
|
|
|
|
{
|
|
|
|
GetWindowSize();
|
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
if ( !CreateContextGL() ) return false;
|
2012-04-29 18:50:07 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
PrintProtocolVersion();
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
bool GLWindow::DisplayWindow(int _width, int _height)
|
|
|
|
{
|
|
|
|
backbuffer.w = _width;
|
|
|
|
backbuffer.h = _height;
|
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
NativeWindow = XCreateSimpleWindow(NativeDisplay, DefaultRootWindow(NativeDisplay), conf.x, conf.y, backbuffer.w, backbuffer.h, 0, 0, 0);
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
// Draw the window
|
2012-09-23 18:52:44 +00:00
|
|
|
XMapRaised(NativeDisplay, NativeWindow);
|
|
|
|
XSync(NativeDisplay, false);
|
|
|
|
|
|
|
|
if ( !CreateContextGL() ) return false;
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
PrintProtocolVersion();
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
GetWindowSize();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
void* GLWindow::GetProcAddress(const char *function)
|
|
|
|
{
|
|
|
|
#ifdef EGL_API
|
|
|
|
return (void*)eglGetProcAddress(function);
|
|
|
|
#endif
|
|
|
|
#ifdef GLX_API
|
|
|
|
return (void*)glXGetProcAddress((const GLubyte*)function);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
void GLWindow::SwapGLBuffers()
|
|
|
|
{
|
|
|
|
if (glGetError() != GL_NO_ERROR) ZZLog::Debug_Log("glError before swap!");
|
2012-04-29 18:50:07 +00:00
|
|
|
ZZLog::Check_GL_Error();
|
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
#ifdef GLX_API
|
|
|
|
glXSwapBuffers(NativeDisplay, NativeWindow);
|
|
|
|
#endif
|
|
|
|
#ifdef EGL_API
|
|
|
|
eglSwapBuffers(eglDisplay, eglSurface);
|
|
|
|
#endif
|
2011-06-12 14:48:36 +00:00
|
|
|
// glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
void GLWindow::InitVsync(bool extension)
|
|
|
|
{
|
|
|
|
#ifdef GLX_API
|
2012-10-27 16:52:51 +00:00
|
|
|
vsync_supported = false;
|
2012-10-21 18:10:13 +00:00
|
|
|
if (extension) {
|
|
|
|
swapinterval = (_PFNSWAPINTERVAL)GetProcAddress("glXSwapInterval");
|
|
|
|
|
|
|
|
if (!swapinterval)
|
|
|
|
swapinterval = (_PFNSWAPINTERVAL)GetProcAddress("glXSwapIntervalSGI");
|
|
|
|
|
|
|
|
if (!swapinterval)
|
|
|
|
swapinterval = (_PFNSWAPINTERVAL)GetProcAddress("glXSwapIntervalEXT");
|
|
|
|
|
|
|
|
if (swapinterval) {
|
|
|
|
swapinterval(0);
|
|
|
|
vsync_supported = true;
|
|
|
|
} else {
|
|
|
|
ZZLog::Error_Log("No support for SwapInterval (framerate clamped to monitor refresh rate),");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindow::SetVsync(bool enable)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "change vsync %d\n", enable);
|
|
|
|
#ifdef EGL_API
|
|
|
|
eglSwapInterval(eglDisplay, enable);
|
|
|
|
#endif
|
|
|
|
#ifdef GLX_API
|
2012-10-27 16:52:51 +00:00
|
|
|
if (vsync_supported && swapinterval) {
|
2012-10-21 18:10:13 +00:00
|
|
|
swapinterval(enable);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
u32 THR_KeyEvent = 0; // Value for key event processing between threads
|
|
|
|
bool THR_bShift = false;
|
|
|
|
bool THR_bCtrl = false;
|
|
|
|
|
|
|
|
void GLWindow::ProcessEvents()
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
#ifdef USE_GSOPEN2
|
|
|
|
GetWindowSize();
|
2010-09-06 22:21:07 +00:00
|
|
|
#endif
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
if (THR_KeyEvent) // This value was passed from GSKeyEvents which could be in another thread
|
|
|
|
{
|
|
|
|
int my_KeyEvent = THR_KeyEvent;
|
|
|
|
bool my_bShift = THR_bShift;
|
|
|
|
bool my_bCtrl = THR_bCtrl;
|
|
|
|
THR_KeyEvent = 0;
|
|
|
|
|
|
|
|
switch (my_KeyEvent)
|
|
|
|
{
|
|
|
|
case XK_F5:
|
|
|
|
case XK_F6:
|
|
|
|
case XK_F7:
|
|
|
|
case XK_F9:
|
|
|
|
// Note: to avoid some clash with PCSX2 shortcut in GSOpen2.
|
|
|
|
// GS shortcut will only be activated when ctrl is press
|
|
|
|
if (my_bCtrl)
|
|
|
|
OnFKey(my_KeyEvent - XK_F1 + 1, my_bShift);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-05 15:47:09 +00:00
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2012-09-23 18:52:44 +00:00
|
|
|
// ************************** Function that are useless in GSopen2 (GSopen 1 is only used with the debug replayer)
|
|
|
|
void GLWindow::SetTitle(char *strtitle) { }
|
2010-11-09 12:04:07 +00:00
|
|
|
|
2010-03-19 02:04:55 +00:00
|
|
|
#endif
|