* move all remaining glx into the dedicated GLwin object
* rework a bit WGL to separate opengl context and window creation (like linux actually)

gsdx: Allow to control vsync. Not sure I used the good extension.

cmake: 
* check that EGL opengl context creation
* Shut up gcc warning when force inline might not work...



git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5437 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2012-10-21 18:10:13 +00:00
parent f53a062063
commit d5b318b990
17 changed files with 280 additions and 112 deletions

View File

@ -4,6 +4,37 @@ project(Pcsx2)
# Debian-based distributions require at least 2.8.5 due to multiarch. # Debian-based distributions require at least 2.8.5 due to multiarch.
cmake_minimum_required(VERSION 2.8.5) cmake_minimum_required(VERSION 2.8.5)
# Keep OLD policy. Code was updated to support the new one but wasn't tested
#
# cmake version 2.8.9
# CMP0018
# Ignore CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable.
#
# CMake 2.8.8 and lower compiled sources in SHARED and MODULE libraries
# using the value of the undocumented CMAKE_SHARED_LIBRARY_<Lang>_FLAGS
# platform variable. The variable contained platform-specific flags
# needed to compile objects for shared libraries. Typically it included
# a flag such as -fPIC for position independent code but also included
# other flags needed on certain platforms. CMake 2.8.9 and higher
# prefer instead to use the POSITION_INDEPENDENT_CODE target property to
# determine what targets should be position independent, and new
# undocumented platform variables to select flags while ignoring
# CMAKE_SHARED_LIBRARY_<Lang>_FLAGS completely.
#
# The default for either approach produces identical compilation flags,
# but if a project modifies CMAKE_SHARED_LIBRARY_<Lang>_FLAGS from its
# original value this policy determines which approach to use.
#
# The OLD behavior for this policy is to ignore the
# POSITION_INDEPENDENT_CODE property for all targets and use the
# modified value of CMAKE_SHARED_LIBRARY_<Lang>_FLAGS for SHARED and
# MODULE libraries.
#
# The NEW behavior for this policy is to ignore
# CMAKE_SHARED_LIBRARY_<Lang>_FLAGS whether it is modified or not and
# honor the POSITION_INDEPENDENT_CODE target property.
cmake_policy(SET CMP0018 OLD)
# Variable to check that people use the good file # Variable to check that people use the good file
set(TOP_CMAKE_WAS_SOURCED TRUE) set(TOP_CMAKE_WAS_SOURCED TRUE)

View File

@ -32,6 +32,10 @@ do
--glsl) --glsl)
flags="$flags -DGLSL_API=TRUE" flags="$flags -DGLSL_API=TRUE"
;; ;;
--egl)
echo "Warning EGL needs at lesat MESA 9.0"
flags="$flags -DEGL_API=TRUE"
;;
--clean) --clean)
clean_build=true clean_build=true
;; ;;
@ -43,6 +47,7 @@ do
echo "--release - Build PCSX2 as a Release build." echo "--release - Build PCSX2 as a Release build."
echo "--clean - Do a clean build." echo "--clean - Do a clean build."
echo "--glsl - Replace CG backend of ZZogl by GLSL" echo "--glsl - Replace CG backend of ZZogl by GLSL"
echo "--egl - Replace GLX by EGL (ZZogl plugins only)"
exit 1;; exit 1;;
esac esac
done done
@ -54,16 +59,18 @@ if [ "$flags" != "" ]; then
echo "Building pcsx2 with $flags" > install_log.txt echo "Building pcsx2 with $flags" > install_log.txt
fi fi
if [ ! -d "build" ]; then if [ "$clean_build" = true ]; then
mkdir build echo "Doing a clean build."
rm -fr build
# make clean 2>&1 | tee -a ../install_log.txt
fi fi
mkdir -p build
cd build cd build
cmake $flags .. 2>&1 | tee -a ../install_log.txt cmake $flags .. 2>&1 | tee -a ../install_log.txt
if [ "$clean_build" = true ]; then
echo "Doing a clean build."
make clean 2>&1 | tee -a ../install_log.txt
fi
CORE=`grep -w -c processor /proc/cpuinfo` CORE=`grep -w -c processor /proc/cpuinfo`
make -j $CORE 2>&1 | tee -a ../install_log.txt make -j $CORE 2>&1 | tee -a ../install_log.txt
make install 2>&1 | tee -a ../install_log.txt make install 2>&1 | tee -a ../install_log.txt

View File

@ -19,7 +19,7 @@
# Installation path : -DPACKAGE_MODE=TRUE(follow FHS)|FALSE(local bin/) # Installation path : -DPACKAGE_MODE=TRUE(follow FHS)|FALSE(local bin/)
# Plugin installation path : -DPLUGIN_DIR="/usr/lib/pcsx2" # Plugin installation path : -DPLUGIN_DIR="/usr/lib/pcsx2"
# GL Shader installation path : -DGLSL_SHADER_DIR="/usr/share/games/pcsx2" # GL Shader installation path : -DGLSL_SHADER_DIR="/usr/share/games/pcsx2"
# Game DB installation path : -DGAMEINDEX_DIR="/var/games/pcsx2" # Game DB installation path : -DGAMEINDEX_DIR="/usr/share/games/pcsx2"
# Follow XDG standard : -DXDG_STD=TRUE|FALSE # Follow XDG standard : -DXDG_STD=TRUE|FALSE
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@ -93,7 +93,7 @@ set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "")
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Set some default compiler flags # Set some default compiler flags
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
set(DEFAULT_WARNINGS "-Wno-write-strings -Wno-format -Wno-unused-parameter -Wno-unused-value -Wstrict-aliasing -Wno-unused-function") set(DEFAULT_WARNINGS "-Wno-write-strings -Wno-format -Wno-unused-parameter -Wno-unused-value -Wstrict-aliasing -Wno-unused-function -Wno-attributes")
set(DEFAULT_GCC_FLAG "-m32 -msse -msse2 -march=i686 -pthread ${DEFAULT_WARNINGS}") set(DEFAULT_GCC_FLAG "-m32 -msse -msse2 -march=i686 -pthread ${DEFAULT_WARNINGS}")
set(DEFAULT_CPP_FLAG "${DEFAULT_GCC_FLAG} -Wno-invalid-offsetof") set(DEFAULT_CPP_FLAG "${DEFAULT_GCC_FLAG} -Wno-invalid-offsetof")

View File

@ -9,8 +9,12 @@ if(EGL_INCLUDE_DIR AND EGL_LIBRARIES)
set(EGL_FIND_QUIETLY TRUE) set(EGL_FIND_QUIETLY TRUE)
endif(EGL_INCLUDE_DIR AND EGL_LIBRARIES) endif(EGL_INCLUDE_DIR AND EGL_LIBRARIES)
INCLUDE(CheckCXXSymbolExists)
# include dir # include dir
find_path(EGL_INCLUDE_DIR EGL/egl.h) find_path(EGL_INCLUDE_DIR EGL/eglext.h)
CHECK_CXX_SYMBOL_EXISTS(EGL_KHR_create_context "EGL/eglext.h" EGL_GL_CONTEXT_SUPPORT)
# finally the library itself # finally the library itself
find_library(libEGL NAMES EGL) find_library(libEGL NAMES EGL)

View File

@ -499,6 +499,11 @@ bool GSDeviceOGL::Reset(int w, int h)
return true; return true;
} }
void GSDeviceOGL::SetVSync(bool enable)
{
m_wnd->SetVSync(enable);
}
void GSDeviceOGL::Flip() void GSDeviceOGL::Flip()
{ {
// FIXME: disable it when code is working // FIXME: disable it when code is working
@ -1336,6 +1341,8 @@ void GSDeviceOGL::CompileShaderFromSource(const std::string& glsl_file, const st
myfile.close(); myfile.close();
} else { } else {
fprintf(stderr, "Error opening %s: ", shader_file.c_str()); fprintf(stderr, "Error opening %s: ", shader_file.c_str());
*program = 0;
return;
} }

View File

@ -593,6 +593,7 @@ class GSDeviceOGL : public GSDevice
bool Create(GSWnd* wnd); bool Create(GSWnd* wnd);
bool Reset(int w, int h); bool Reset(int w, int h);
void Flip(); void Flip();
void SetVSync(bool enable);
void DrawPrimitive(); void DrawPrimitive();
void DrawIndexedPrimitive(); void DrawIndexedPrimitive();

View File

@ -213,7 +213,7 @@ void GSWnd::HideFrame()
#else #else
GSWnd::GSWnd() GSWnd::GSWnd()
: m_window(NULL), m_Xwindow(0), m_XDisplay(NULL), m_ctx_attached(false) : m_window(NULL), m_Xwindow(0), m_XDisplay(NULL), m_ctx_attached(false), m_swapinterval(NULL)
{ {
} }
@ -277,7 +277,7 @@ bool GSWnd::CreateContext(int major, int minor)
void GSWnd::AttachContext() void GSWnd::AttachContext()
{ {
if (!IsContextAttached()) { if (!IsContextAttached()) {
fprintf(stderr, "Attach the context\n"); //fprintf(stderr, "Attach the context\n");
glXMakeCurrent(m_XDisplay, m_Xwindow, m_context); glXMakeCurrent(m_XDisplay, m_Xwindow, m_context);
m_ctx_attached = true; m_ctx_attached = true;
} }
@ -286,7 +286,7 @@ void GSWnd::AttachContext()
void GSWnd::DetachContext() void GSWnd::DetachContext()
{ {
if (IsContextAttached()) { if (IsContextAttached()) {
fprintf(stderr, "Detach the context\n"); //fprintf(stderr, "Detach the context\n");
glXMakeCurrent(m_XDisplay, None, NULL); glXMakeCurrent(m_XDisplay, None, NULL);
m_ctx_attached = false; m_ctx_attached = false;
} }
@ -299,7 +299,7 @@ void GSWnd::CheckContext()
if (glXIsDirect(m_XDisplay, m_context)) if (glXIsDirect(m_XDisplay, m_context))
fprintf(stderr, "glX-Version %d.%d with Direct Rendering\n", glxMajorVersion, glxMinorVersion); fprintf(stderr, "glX-Version %d.%d with Direct Rendering\n", glxMajorVersion, glxMinorVersion);
else else
fprintf(stderr, "glX-Version %d.%d with Indirect Rendering !!! It will be slow\n", glxMajorVersion, glxMinorVersion); fprintf(stderr, "glX-Version %d.%d with Indirect Rendering !!! It won't support properly opengl\n", glxMajorVersion, glxMinorVersion);
} }
bool GSWnd::Attach(void* handle, bool managed) bool GSWnd::Attach(void* handle, bool managed)
@ -319,6 +319,10 @@ bool GSWnd::Attach(void* handle, bool managed)
CheckContext(); CheckContext();
PFNGLXSWAPINTERVALMESAPROC m_swapinterval = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA");
//PFNGLXSWAPINTERVALMESAPROC m_swapinterval = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapInterval");
return true; return true;
} }
@ -427,6 +431,14 @@ bool GSWnd::SetWindowText(const char* title)
return true; return true;
} }
void GSWnd::SetVSync(bool enable)
{
// m_swapinterval uses an integer as parameter
// 0 -> disable vsync
// n -> wait n frame
if (m_swapinterval) m_swapinterval((int)enable);
}
void GSWnd::Flip() void GSWnd::Flip()
{ {
glXSwapBuffers(m_XDisplay, m_Xwindow); glXSwapBuffers(m_XDisplay, m_Xwindow);

View File

@ -69,6 +69,8 @@ class GSWnd
int m_renderer; int m_renderer;
GLXContext m_context; GLXContext m_context;
PFNGLXSWAPINTERVALMESAPROC m_swapinterval;
public: public:
GSWnd(); GSWnd();
virtual ~GSWnd(); virtual ~GSWnd();
@ -93,6 +95,7 @@ public:
void Hide(); void Hide();
void HideFrame(); void HideFrame();
void Flip(); void Flip();
void SetVSync(bool enable);
}; };
#endif #endif

View File

@ -54,8 +54,10 @@ else(GLSL_API)
endif(GLSL_API) endif(GLSL_API)
# Select the EGL API # Select the EGL API
if (EGL_API) if(EGL_API AND EGL_GL_CONTEXT_SUPPORT)
add_definitions(-DEGL_API) add_definitions(-DEGL_API)
else()
message(WARNING "Current EGL implementation doesn't support openGL context. Fallback to standard GLX.")
endif() endif()
@ -173,7 +175,7 @@ target_link_libraries(${Output} ${GLEW_LIBRARY})
# link target with opengl # link target with opengl
target_link_libraries(${Output} ${OPENGL_LIBRARIES}) target_link_libraries(${Output} ${OPENGL_LIBRARIES})
if(EGL_API) if (EGL_API AND EGL_GL_CONTEXT_SUPPORT)
target_link_libraries(${Output} ${EGL_LIBRARIES}) target_link_libraries(${Output} ${EGL_LIBRARIES})
endif() endif()
@ -237,7 +239,7 @@ if(BUILD_REPLAY_LOADERS)
endif(NOT GLSL_API) endif(NOT GLSL_API)
target_link_libraries(${Static} ${GLEW_LIBRARY}) target_link_libraries(${Static} ${GLEW_LIBRARY})
target_link_libraries(${Static} ${OPENGL_LIBRARIES}) target_link_libraries(${Static} ${OPENGL_LIBRARIES})
if(EGL_API) if (EGL_API AND EGL_GL_CONTEXT_SUPPORT)
target_link_libraries(${Static} ${EGL_LIBRARIES}) target_link_libraries(${Static} ${EGL_LIBRARIES})
endif() endif()
target_link_libraries(${Static} ${X11_LIBRARIES}) target_link_libraries(${Static} ${X11_LIBRARIES})

View File

@ -22,6 +22,7 @@
#ifdef _WIN32 #ifdef _WIN32
#define GL_WIN32_WINDOW #define GL_WIN32_WINDOW
#define WGL_API
#else #else
@ -44,6 +45,11 @@
#undef CreateWindow // Undo Windows.h global namespace pollution #undef CreateWindow // Undo Windows.h global namespace pollution
#ifdef GLX_API
typedef void (APIENTRYP _PFNSWAPINTERVAL)(int);
#endif
extern void SetDeviceSize(int nNewWidth, int nNewHeight); extern void SetDeviceSize(int nNewWidth, int nNewHeight);
extern void OnFKey(int key, int shift); extern void OnFKey(int key, int shift);
@ -53,16 +59,17 @@ class GLWindow
#if defined(GL_X11_WINDOW) #if defined(GL_X11_WINDOW)
void GetWindowSize(); void GetWindowSize();
void PrintProtocolVersion(); void PrintProtocolVersion();
#endif
bool CreateContextGL(int, int); bool CreateContextGL(int, int);
bool CreateContextGL(); bool CreateContextGL();
#endif
#ifdef GLX_API #ifdef GLX_API
Display *NativeDisplay; Display *NativeDisplay;
Window NativeWindow; Window NativeWindow;
GLXContext context; GLXContext glxContext;
_PFNSWAPINTERVAL swapinterval;
#endif #endif
#ifdef EGL_API #ifdef EGL_API
@ -78,6 +85,18 @@ class GLWindow
void CloseEGLDisplay(); void CloseEGLDisplay();
#endif #endif
#ifdef WGL_API
HWND NativeWindow;
HDC NativeDisplay; // hDC // Private GDI Device Context
HGLRC wglContext; // hRC // Permanent Rendering Context
bool OpenWGLDisplay();
void CloseWGLDisplay();
#endif
bool vsync_supported;
public: public:
char title[256]; char title[256];
Size backbuffer; Size backbuffer;
@ -91,6 +110,11 @@ class GLWindow
void SetTitle(char *strtitle); void SetTitle(char *strtitle);
void ProcessEvents(); void ProcessEvents();
void* GetProcAddress(const char* function);
void SetVsync(bool enable);
void InitVsync(bool extension); // dummy in EGL
void UpdateWindowSize(int nNewWidth, int nNewHeight) void UpdateWindowSize(int nNewWidth, int nNewHeight)
{ {
FUNCLOG FUNCLOG
@ -103,6 +127,14 @@ class GLWindow
conf.height = nNewHeight; conf.height = nNewHeight;
} }
} }
GLWindow() {
#ifdef WGL_API
NativeWindow = NULL;
NativeDisplay = NULL;
wglContext = NULL;
#endif
}
}; };
extern GLWindow GLWin; extern GLWindow GLWin;

View File

@ -22,10 +22,6 @@
#ifdef GL_WIN32_WINDOW #ifdef GL_WIN32_WINDOW
HWND GShwnd = NULL;
HDC hDC = NULL; // Private GDI Device Context
HGLRC hRC = NULL; // Permanent Rendering Context
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
static int nWindowWidth = 0, nWindowHeight = 0; static int nWindowWidth = 0, nWindowHeight = 0;
@ -109,7 +105,7 @@ bool GLWindow::CreateWindow(void *pDisplay)
GetWindowRect(GetDesktopWindow(), &rcdesktop); GetWindowRect(GetDesktopWindow(), &rcdesktop);
GShwnd = CreateWindowEx( dwExStyle, // Extended Style For The Window NativeWindow = CreateWindowEx( dwExStyle, // Extended Style For The Window
L"PS2EMU_ZEROGS", // Class Name L"PS2EMU_ZEROGS", // Class Name
L"ZZOgl", // Window Title L"ZZOgl", // Window Title
dwStyle, // Selected Window Style dwStyle, // Selected Window Style
@ -122,22 +118,22 @@ bool GLWindow::CreateWindow(void *pDisplay)
hInstance, // Instance hInstance, // Instance
NULL); // Don't Pass Anything To WM_CREATE NULL); // Don't Pass Anything To WM_CREATE
if (GShwnd == NULL) if (NativeWindow == NULL)
{ {
ZZLog::Error_Log("Failed to create window. Exiting..."); ZZLog::Error_Log("Failed to create window. Exiting...");
return false; return false;
} }
if (pDisplay != NULL) *(HWND*)pDisplay = GShwnd; if (pDisplay != NULL) *(HWND*)pDisplay = NativeWindow;
// set just in case // set just in case
SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)MsgProc); SetWindowLongPtr(NativeWindow, GWLP_WNDPROC, (LPARAM)(WNDPROC)MsgProc);
ShowWindow(GShwnd, SW_SHOWDEFAULT); ShowWindow(NativeWindow, SW_SHOWDEFAULT);
UpdateWindow(GShwnd); UpdateWindow(NativeWindow);
SetFocus(GShwnd); SetFocus(NativeWindow);
if (pDisplay == NULL) ZZLog::Error_Log("Failed to create window. Exiting..."); if (pDisplay == NULL) ZZLog::Error_Log("Failed to create window. Exiting...");
return (pDisplay != NULL); return (pDisplay != NULL);
@ -145,42 +141,37 @@ bool GLWindow::CreateWindow(void *pDisplay)
bool GLWindow::ReleaseContext() bool GLWindow::ReleaseContext()
{ {
if (hRC) // Do We Have A Rendering Context? if (wglContext) // Do We Have A Rendering Context?
{ {
if (!wglMakeCurrent(NULL, NULL)) // Are We Able To Release The DC And RC Contexts? if (!wglMakeCurrent(NULL, NULL)) // Are We Able To Release The DC And RC Contexts?
{ {
MessageBox(NULL, L"Release Of DC And RC Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); MessageBox(NULL, L"Release Of DC And RC Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
} }
if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC? if (!wglDeleteContext(wglContext)) // Are We Able To Delete The RC?
{ {
MessageBox(NULL, L"Release Rendering Context Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); MessageBox(NULL, L"Release Rendering Context Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
} }
hRC = NULL; // Set RC To NULL wglContext = NULL; // Set RC To NULL
} }
if (hDC && !ReleaseDC(GShwnd, hDC)) // Are We Able To Release The DC CloseWGLDisplay();
{
MessageBox(NULL, L"Release Device Context Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
hDC = NULL; // Set DC To NULL
}
return true; return true;
} }
void GLWindow::CloseWindow() void GLWindow::CloseWindow()
{ {
if (GShwnd != NULL) if (NativeWindow != NULL)
{ {
DestroyWindow(GShwnd); DestroyWindow(NativeWindow);
GShwnd = NULL; NativeWindow = NULL;
} }
} }
bool GLWindow::DisplayWindow(int _width, int _height) bool GLWindow::DisplayWindow(int _width, int _height)
{ {
GLuint PixelFormat; // Holds The Results After Searching For A Match
DWORD dwExStyle; // Window Extended Style DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style DWORD dwStyle; // Window Style
@ -215,10 +206,10 @@ bool GLWindow::DisplayWindow(int _width, int _height)
int X = (rcdesktop.right - rcdesktop.left) / 2 - (rc.right - rc.left) / 2; int X = (rcdesktop.right - rcdesktop.left) / 2 - (rc.right - rc.left) / 2;
int Y = (rcdesktop.bottom - rcdesktop.top) / 2 - (rc.bottom - rc.top) / 2; int Y = (rcdesktop.bottom - rcdesktop.top) / 2 - (rc.bottom - rc.top) / 2;
SetWindowLong(GShwnd, GWL_STYLE, dwStyle); SetWindowLong(NativeWindow, GWL_STYLE, dwStyle);
SetWindowLong(GShwnd, GWL_EXSTYLE, dwExStyle); SetWindowLong(NativeWindow, GWL_EXSTYLE, dwExStyle);
SetWindowPos(GShwnd, HWND_TOP, X, Y, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW); SetWindowPos(NativeWindow, HWND_TOP, X, Y, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW);
if (conf.fullscreen()) if (conf.fullscreen())
{ {
@ -249,6 +240,18 @@ bool GLWindow::DisplayWindow(int _width, int _height)
ChangeDisplaySettings(NULL, 0); ChangeDisplaySettings(NULL, 0);
} }
if (!OpenWGLDisplay()) return false;
if (!CreateContextGL()) return false;
UpdateWindow(NativeWindow);
return true;
}
bool GLWindow::OpenWGLDisplay()
{
GLuint PixelFormat; // Holds The Results After Searching For A Match
PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
{ {
@ -272,38 +275,60 @@ bool GLWindow::DisplayWindow(int _width, int _height)
0, 0, 0 // Layer Masks Ignored 0, 0, 0 // Layer Masks Ignored
}; };
if (!(hDC = GetDC(GShwnd))) if (!(NativeDisplay = GetDC(NativeWindow)))
{ {
MessageBox(NULL, L"(1) Can't Create A GL Device Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); MessageBox(NULL, L"(1) Can't Create A GL Device Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) if (!(PixelFormat = ChoosePixelFormat(NativeDisplay, &pfd)))
{ {
MessageBox(NULL, L"(2) Can't Find A Suitable PixelFormat.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); MessageBox(NULL, L"(2) Can't Find A Suitable PixelFormat.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
if (!SetPixelFormat(hDC, PixelFormat, &pfd)) if (!SetPixelFormat(NativeDisplay, PixelFormat, &pfd))
{ {
MessageBox(NULL, L"(3) Can't Set The PixelFormat.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); MessageBox(NULL, L"(3) Can't Set The PixelFormat.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
if (!(hRC = wglCreateContext(hDC))) return true;
}
void GLWindow::CloseWGLDisplay()
{
if (NativeDisplay && !ReleaseDC(NativeWindow, NativeDisplay)) // Are We Able To Release The DC
{ {
MessageBox(NULL, L"(4) Can't Create A GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); MessageBox(NULL, L"Release Device Context Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
NativeDisplay = NULL; // Set DC To NULL
}
}
bool GLWindow::CreateContextGL()
{
return CreateContextGL(2, 0);
}
bool GLWindow::CreateContextGL(int major, int minor)
{
if (major <= 2) {
if (!(wglContext = wglCreateContext(NativeDisplay)))
{
MessageBox(NULL, L"(4) Can't Create A GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (!wglMakeCurrent(NativeDisplay, wglContext))
{
MessageBox(NULL, L"(5) Can't Activate The GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return false;
}
} else {
// todo
return false; return false;
} }
if (!wglMakeCurrent(hDC, hRC))
{
MessageBox(NULL, L"(5) Can't Activate The GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return false;
}
UpdateWindow(GShwnd);
return true; return true;
} }
@ -313,13 +338,13 @@ void GLWindow::SwapGLBuffers()
if (glGetError() != GL_NO_ERROR) ZZLog::Debug_Log("glError before swap!"); if (glGetError() != GL_NO_ERROR) ZZLog::Debug_Log("glError before swap!");
SwapBuffers(hDC); SwapBuffers(NativeDisplay);
lastswaptime = timeGetTime(); lastswaptime = timeGetTime();
} }
void GLWindow::SetTitle(char *strtitle) void GLWindow::SetTitle(char *strtitle)
{ {
if (!conf.fullscreen()) SetWindowText(GShwnd, wxString::FromUTF8(strtitle)); if (!conf.fullscreen()) SetWindowText(NativeWindow, wxString::FromUTF8(strtitle));
} }
extern void ChangeDeviceSize(int nNewWidth, int nNewHeight); extern void ChangeDeviceSize(int nNewWidth, int nNewHeight);
@ -356,12 +381,12 @@ void GLWindow::ProcessEvents()
// destroy that msg // destroy that msg
conf.setFullscreen(false); conf.setFullscreen(false);
ChangeDeviceSize(conf.width, conf.height); ChangeDeviceSize(conf.width, conf.height);
UpdateWindow(GShwnd); UpdateWindow(NativeWindow);
continue; // so that msg doesn't get sent continue; // so that msg doesn't get sent
} }
else else
{ {
SendMessage(GShwnd, WM_DESTROY, 0, 0); SendMessage(NativeWindow, WM_DESTROY, 0, 0);
return; return;
} }
@ -390,5 +415,21 @@ void GLWindow::ProcessEvents()
} }
} }
void* GLWindow::GetProcAddress(const char* function)
{
return (void*)wglGetProcAddress(function);
}
void GLWindow::InitVsync(bool extension)
{
vsync_supported = extension;
}
void GLWindow::SetVsync(bool enable)
{
if (vsync_supported) {
wglSwapIntervalEXT(0);
}
}
#endif #endif

View File

@ -42,7 +42,6 @@
#endif #endif
#endif #endif
#ifdef USE_GSOPEN2 #ifdef USE_GSOPEN2
bool GLWindow::CreateWindow(void *pDisplay) bool GLWindow::CreateWindow(void *pDisplay)
{ {
@ -119,15 +118,15 @@ bool GLWindow::ReleaseContext()
if (!NativeDisplay) return status; if (!NativeDisplay) return status;
// free the context // free the context
if (context) if (glxContext)
{ {
if (!glXMakeCurrent(NativeDisplay, None, NULL)) { if (!glXMakeCurrent(NativeDisplay, None, NULL)) {
ZZLog::Error_Log("Could not release drawing context."); ZZLog::Error_Log("Could not release drawing context.");
status = false; status = false;
} }
glXDestroyContext(NativeDisplay, context); glXDestroyContext(NativeDisplay, glxContext);
context = NULL; glxContext = NULL;
} }
#endif #endif
#ifdef EGL_API #ifdef EGL_API
@ -192,7 +191,7 @@ void GLWindow::PrintProtocolVersion()
glXQueryVersion(NativeDisplay, &glxMajorVersion, &glxMinorVersion); glXQueryVersion(NativeDisplay, &glxMajorVersion, &glxMinorVersion);
if (glXIsDirect(NativeDisplay, context)) if (glXIsDirect(NativeDisplay, glxContext))
ZZLog::Error_Log("glX-Version %d.%d with Direct Rendering", glxMajorVersion, glxMinorVersion); ZZLog::Error_Log("glX-Version %d.%d with Direct Rendering", glxMajorVersion, glxMinorVersion);
else else
ZZLog::Error_Log("glX-Version %d.%d with Indirect Rendering !!! It will be slow", glxMajorVersion, glxMinorVersion); ZZLog::Error_Log("glX-Version %d.%d with Indirect Rendering !!! It will be slow", glxMajorVersion, glxMinorVersion);
@ -227,21 +226,21 @@ bool GLWindow::CreateContextGL(int major, int minor)
XVisualInfo *vi = glXChooseVisual(NativeDisplay, DefaultScreen(NativeDisplay), attrListDbl); XVisualInfo *vi = glXChooseVisual(NativeDisplay, DefaultScreen(NativeDisplay), attrListDbl);
if (vi == NULL) return NULL; if (vi == NULL) return NULL;
context = glXCreateContext(NativeDisplay, vi, NULL, GL_TRUE); glxContext = glXCreateContext(NativeDisplay, vi, NULL, GL_TRUE);
XFree(vi); XFree(vi);
if (!context) return false; if (!glxContext) return false;
glXMakeCurrent(NativeDisplay, NativeWindow, context); glXMakeCurrent(NativeDisplay, NativeWindow, glxContext);
return true; return true;
} }
PFNGLXCHOOSEFBCONFIGPROC glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC) glXGetProcAddress((GLubyte *) "glXChooseFBConfig"); PFNGLXCHOOSEFBCONFIGPROC glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC)GetProcAddress("glXChooseFBConfig");
int fbcount = 0; int fbcount = 0;
GLXFBConfig *fbc = glXChooseFBConfig(NativeDisplay, DefaultScreen(NativeDisplay), attrListDbl, &fbcount); GLXFBConfig *fbc = glXChooseFBConfig(NativeDisplay, DefaultScreen(NativeDisplay), attrListDbl, &fbcount);
if (!fbc || fbcount < 1) return false; if (!fbc || fbcount < 1) return false;
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte*) "glXCreateContextAttribsARB"); PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)GetProcAddress("glXCreateContextAttribsARB");
if (!glXCreateContextAttribsARB) return false; if (!glXCreateContextAttribsARB) return false;
// Create a context // Create a context
@ -253,22 +252,23 @@ bool GLWindow::CreateContextGL(int major, int minor)
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
//GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, //GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
// FIXME : Request a debug context to ease opengl development // FIXME : Request a debug context to ease opengl development
#if defined(ZEROGS_DEVBUILD) || defined(_DEBUG)
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
#endif
None None
}; };
context = glXCreateContextAttribsARB(NativeDisplay, fbc[0], 0, true, context_attribs); glxContext = glXCreateContextAttribsARB(NativeDisplay, fbc[0], 0, true, context_attribs);
if (!context) return false; if (!glxContext) return false;
XSync( NativeDisplay, false); XSync( NativeDisplay, false);
glXMakeCurrent(NativeDisplay, NativeWindow, context); glXMakeCurrent(NativeDisplay, NativeWindow, glxContext);
return true; return true;
} }
#endif #endif
#if defined(GLX_API) || defined(EGL_API)
bool GLWindow::CreateContextGL() bool GLWindow::CreateContextGL()
{ {
bool ret; bool ret;
@ -290,10 +290,9 @@ bool GLWindow::CreateContextGL()
#endif #endif
return ret; return ret;
} }
#endif
#ifdef EGL_API #ifdef EGL_API
bool GLWindow::CreateContextGL( int major, int minor) bool GLWindow::CreateContextGL(int major, int minor)
{ {
EGLConfig eglConfig; EGLConfig eglConfig;
EGLint numConfigs; EGLint numConfigs;
@ -305,7 +304,9 @@ bool GLWindow::CreateContextGL( int major, int minor)
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR, 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, //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 // FIXME : Request a debug context to ease opengl development
#if defined(ZEROGS_DEVBUILD) || defined(_DEBUG)
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR,
#endif
EGL_NONE EGL_NONE
}; };
EGLint attrList[] = { EGLint attrList[] = {
@ -383,6 +384,16 @@ bool GLWindow::DisplayWindow(int _width, int _height)
} }
#endif #endif
void* GLWindow::GetProcAddress(const char *function)
{
#ifdef EGL_API
return (void*)eglGetProcAddress(function);
#endif
#ifdef GLX_API
return (void*)glXGetProcAddress((const GLubyte*)function);
#endif
}
void GLWindow::SwapGLBuffers() void GLWindow::SwapGLBuffers()
{ {
if (glGetError() != GL_NO_ERROR) ZZLog::Debug_Log("glError before swap!"); if (glGetError() != GL_NO_ERROR) ZZLog::Debug_Log("glError before swap!");
@ -397,6 +408,45 @@ void GLWindow::SwapGLBuffers()
// glClear(GL_COLOR_BUFFER_BIT); // glClear(GL_COLOR_BUFFER_BIT);
} }
void GLWindow::InitVsync(bool extension)
{
#ifdef GLX_API
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),");
vsync_supported = false;
}
} else {
vsync_supported = false;
}
#endif
}
void GLWindow::SetVsync(bool enable)
{
fprintf(stderr, "change vsync %d\n", enable);
#ifdef EGL_API
eglSwapInterval(eglDisplay, enable);
#endif
#ifdef GLX_API
if (vsync_supported) {
swapinterval(enable);
}
#endif
}
u32 THR_KeyEvent = 0; // Value for key event processing between threads u32 THR_KeyEvent = 0; // Value for key event processing between threads
bool THR_bShift = false; bool THR_bShift = false;
bool THR_bCtrl = false; bool THR_bCtrl = false;

View File

@ -488,6 +488,7 @@ EXPORT_C_(void) GSsetVsync(int enabled)
ZZLog::Debug_Log("Setting VSync to 0x%x.", enabled); ZZLog::Debug_Log("Setting VSync to 0x%x.", enabled);
gs.vsync = enabled; gs.vsync = enabled;
GLWin.SetVsync(enabled);
} }
EXPORT_C_(void) GSvsync(int current_interlace) EXPORT_C_(void) GSvsync(int current_interlace)

View File

@ -40,11 +40,6 @@
#include <GL/glext.h> #include <GL/glext.h>
#include <GL/glx.h> #include <GL/glx.h>
inline void* wglGetProcAddress(const char* x)
{
return (void*)glXGetProcAddress((const GLubyte*)x);
}
#endif #endif
#include "Mem.h" #include "Mem.h"

View File

@ -367,11 +367,14 @@ void Error_Log(const char *fmt, ...)
va_end(list); va_end(list);
} }
#ifdef _DEBUG
#define LOUD_DEBUGGING #define LOUD_DEBUGGING
#endif
#ifdef OGL4_LOG #ifdef OGL4_LOG
void Check_GL_Error() void Check_GL_Error()
{ {
#if defined(ZEROGS_DEVBUILD) || defined(_DEBUG)
unsigned int count = 64; // max. num. of messages that will be read from the log unsigned int count = 64; // max. num. of messages that will be read from the log
int bufsize = 2048; int bufsize = 2048;
unsigned int* sources = new unsigned int[count]; unsigned int* sources = new unsigned int[count];
@ -399,6 +402,7 @@ void Check_GL_Error()
delete [] severities; delete [] severities;
delete [] lengths; delete [] lengths;
delete [] messageLog; delete [] messageLog;
#endif
} }
void GL_Error_Log(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, const char* message) void GL_Error_Log(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, const char* message)

View File

@ -23,11 +23,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "targets.h" #include "targets.h"
#ifdef _WIN32
extern HDC hDC; // Private GDI Device Context
extern HGLRC hRC; // Permanent Rendering Context
#endif
extern int s_frameskipping; extern int s_frameskipping;
extern float fFPS; extern float fFPS;
extern unsigned char zgsrevision, zgsbuild, zgsminor; extern unsigned char zgsrevision, zgsbuild, zgsminor;

View File

@ -36,8 +36,6 @@
#endif #endif
// ----------------- Types // ----------------- Types
typedef void (APIENTRYP _PFNSWAPINTERVAL)(int);
map<string, GLbyte> mapGLExtensions; map<string, GLbyte> mapGLExtensions;
extern bool ZZshLoadExtraEffects(); extern bool ZZshLoadExtraEffects();
@ -198,9 +196,9 @@ inline void CreateOtherCheck()
} }
if (IsGLExt("GL_ARB_draw_buffers")) if (IsGLExt("GL_ARB_draw_buffers"))
glDrawBuffers = (PFNGLDRAWBUFFERSPROC)wglGetProcAddress("glDrawBuffers"); glDrawBuffers = (PFNGLDRAWBUFFERSPROC)GLWin.GetProcAddress("glDrawBuffers");
else if (IsGLExt("GL_ATI_draw_buffers")) else if (IsGLExt("GL_ATI_draw_buffers"))
glDrawBuffers = (PFNGLDRAWBUFFERSPROC)wglGetProcAddress("glDrawBuffersATI"); glDrawBuffers = (PFNGLDRAWBUFFERSPROC)GLWin.GetProcAddress("glDrawBuffersATI");
if (!IsGLExt("GL_ARB_multitexture")) if (!IsGLExt("GL_ARB_multitexture"))
@ -222,27 +220,12 @@ inline void CreateOtherCheck()
ZZLog::Error_Log("Could not properly make bitmasks, so some textures will be missed."); ZZLog::Error_Log("Could not properly make bitmasks, so some textures will be missed.");
#ifdef _WIN32 #ifdef _WIN32
if (IsGLExt("WGL_EXT_swap_control") || IsGLExt("EXT_swap_control")) GLWin.InitVsync(IsGLExt("WGL_EXT_swap_control") || IsGLExt("EXT_swap_control"));
wglSwapIntervalEXT(0);
#else #else
if (IsGLExt("GLX_SGI_swap_control")) GLWin.InitVsync(IsGLExt("GLX_SGI_swap_control"));
{
_PFNSWAPINTERVAL swapinterval = (_PFNSWAPINTERVAL)wglGetProcAddress("glXSwapInterval");
if (!swapinterval)
swapinterval = (_PFNSWAPINTERVAL)wglGetProcAddress("glXSwapIntervalSGI");
if (!swapinterval)
swapinterval = (_PFNSWAPINTERVAL)wglGetProcAddress("glXSwapIntervalEXT");
if (swapinterval)
swapinterval(0);
else
ZZLog::Error_Log("No support for SwapInterval (framerate clamped to monitor refresh rate),");
}
#endif #endif
GLWin.SetVsync(false);
} }
@ -358,7 +341,7 @@ inline bool CreateFillExtensionsMap()
string all_ext(""); string all_ext("");
PFNGLGETSTRINGIPROC glGetStringi = 0; PFNGLGETSTRINGIPROC glGetStringi = 0;
glGetStringi = (PFNGLGETSTRINGIPROC)wglGetProcAddress("glGetStringi"); glGetStringi = (PFNGLGETSTRINGIPROC)GLWin.GetProcAddress("glGetStringi");
glGetIntegerv(GL_NUM_EXTENSIONS, &max_ext); glGetIntegerv(GL_NUM_EXTENSIONS, &max_ext);
if (glGetStringi && max_ext) { if (glGetStringi && max_ext) {