Support SDL video on any platform. It is only enabled by default on Mac OS X though. So in practice nothing changes, but we have more flexibility in debugging.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@317 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Maarten ter Huurne 2008-08-26 00:57:16 +00:00
parent 6a426c1654
commit 8013f92863
2 changed files with 82 additions and 76 deletions

View File

@ -23,7 +23,10 @@
#endif #endif
#include "GLInit.h" #include "GLInit.h"
#if defined(__APPLE__) #ifndef USE_SDL
#define USE_SDL 0
#endif
#if USE_SDL
#include "SDL.h" #include "SDL.h"
#endif #endif
@ -46,33 +49,35 @@ extern HINSTANCE g_hInstance;
void OpenGL_SwapBuffers() void OpenGL_SwapBuffers()
{ {
#if defined(_WIN32) #if USE_SDL
SwapBuffers(hDC);
#elif defined(__linux__)
glXSwapBuffers(GLWin.dpy, GLWin.win);
#else //others
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();
#elif defined(_WIN32)
SwapBuffers(hDC);
#else // GLX
glXSwapBuffers(GLWin.dpy, GLWin.win);
#endif #endif
} }
void OpenGL_SetWindowText(const char *text) void OpenGL_SetWindowText(const char *text)
{ {
#if defined(_WIN32) #if USE_SDL
SDL_WM_SetCaption(text, NULL);
#elif defined(_WIN32)
SetWindowText(EmuWindow::GetWnd(), text); SetWindowText(EmuWindow::GetWnd(), text);
#elif defined(__linux__) #else // GLX
/** /**
* Tell X to ask the window manager to set the window title. (X * Tell X to ask the window manager to set the window title. (X
* itself doesn't provide window title functionality.) * itself doesn't provide window title functionality.)
*/ */
XStoreName(GLWin.dpy, GLWin.win, text); XStoreName(GLWin.dpy, GLWin.win, text);
#else
SDL_WM_SetCaption(text, NULL);
#endif #endif
} }
BOOL Callback_PeekMessages() BOOL Callback_PeekMessages()
{ {
#if defined(_WIN32) #if USE_SDL
//TODO
#elif defined(_WIN32)
//TODO: peekmessage //TODO: peekmessage
MSG msg; MSG msg;
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
@ -83,14 +88,12 @@ BOOL Callback_PeekMessages()
DispatchMessage(&msg); DispatchMessage(&msg);
} }
return TRUE; return TRUE;
#elif defined(__linux__) #else // GLX
XEvent event; XEvent event;
while (XPending(GLWin.dpy) > 0) { while (XPending(GLWin.dpy) > 0) {
XNextEvent(GLWin.dpy, &event); XNextEvent(GLWin.dpy, &event);
} }
return TRUE; return TRUE;
#else
//TODO
#endif #endif
} }
@ -124,7 +127,6 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
_twidth = _iwidth; _twidth = _iwidth;
_theight = _iheight; _theight = _iheight;
} }
} }
else // Going Windowed else // Going Windowed
{ {
@ -166,7 +168,18 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
g_VideoInitialize.pPeekMessages = &Callback_PeekMessages; g_VideoInitialize.pPeekMessages = &Callback_PeekMessages;
g_VideoInitialize.pUpdateFPSDisplay = &UpdateFPSDisplay; g_VideoInitialize.pUpdateFPSDisplay = &UpdateFPSDisplay;
#if defined(_WIN32) #if USE_SDL
//init sdl video
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
//TODO : Display an error message
SDL_Quit();
return false;
}
//setup ogl to use double buffering
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#elif defined(_WIN32)
// create the window // create the window
if (!g_Config.renderToMainframe || g_VideoInitialize.pWindowHandle == NULL) if (!g_Config.renderToMainframe || g_VideoInitialize.pWindowHandle == NULL)
{ {
@ -279,7 +292,7 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
return false; return false;
} }
#elif defined(__linux__) #else // GLX
XVisualInfo *vi; XVisualInfo *vi;
Colormap cmap; Colormap cmap;
int dpyWidth, dpyHeight; int dpyWidth, dpyHeight;
@ -405,32 +418,49 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
XSetStandardProperties(GLWin.dpy, GLWin.win, "GPU", XSetStandardProperties(GLWin.dpy, GLWin.win, "GPU",
"GPU", None, NULL, 0, NULL); "GPU", None, NULL, 0, NULL);
XMapRaised(GLWin.dpy, GLWin.win); XMapRaised(GLWin.dpy, GLWin.win);
} }
#else #endif
//SDL for other OS (osx, bsd, ...) return true;
}
//init sdl video bool OpenGL_MakeCurrent()
if (SDL_Init(SDL_INIT_VIDEO) < 0) { {
#if USE_SDL
// Note: The reason for having the call to SDL_SetVideoMode in here instead
// of in OpenGL_Create() is that "make current" is part of the video
// mode setting and is not available as a separate call in SDL. We
// have to do "make current" here because this method runs in the CPU
// thread while OpenGL_Create() runs in a diferent thread and "make
// current" has to be done in the same thread that will be making
// calls to OpenGL.
// Fetch video info.
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (!videoInfo) {
// TODO: Display an error message.
SDL_Quit();
return false;
}
// Compute video mode flags.
const int videoFlags = SDL_OPENGL
| ( videoInfo->hw_available ? SDL_HWSURFACE : SDL_SWSURFACE )
| ( g_Config.bFullscreen ? SDL_FULLSCREEN : 0);
// Set vide mode.
// TODO: Can we use this field or is a separate field needed?
int _twidth = nBackbufferWidth;
int _theight = nBackbufferHeight;
SDL_Surface *screen = SDL_SetVideoMode(_twidth, _theight, 0, videoFlags);
if (!screen) {
//TODO : Display an error message //TODO : Display an error message
SDL_Quit(); SDL_Quit();
return false; return false;
} }
#elif defined(_WIN32)
//setup ogl to use double buffering
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#endif
return true;
}
bool OpenGL_MakeCurrent()
{
#if defined(_WIN32)
if (!wglMakeCurrent(hDC,hRC)) { if (!wglMakeCurrent(hDC,hRC)) {
MessageBox(NULL,"(5) Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); MessageBox(NULL,"(5) Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; return false;
} }
#elif defined(__linux__) #else // GLX
Window winDummy; Window winDummy;
unsigned int borderDummy; unsigned int borderDummy;
// connect the glx-context to the window // connect the glx-context to the window
@ -447,44 +477,16 @@ bool OpenGL_MakeCurrent()
XSelectInput(GLWin.dpy, GLWin.win, ExposureMask | KeyPressMask | KeyReleaseMask | XSelectInput(GLWin.dpy, GLWin.win, ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPressMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask | ButtonPressMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask |
FocusChangeMask ); FocusChangeMask );
#else
// Note: The reason for having the call to SDL_SetVideoMode in here instead
// of in OpenGL_Create() is that "make current" is part of the video
// mode setting and is not available as a separate call in SDL. We
// have to do "make current" here because this method runs in the CPU
// thread while OpenGL_Create() runs in a diferent thread and "make
// current" has to be done in the same thread that will be making
// calls to OpenGL.
// Fetch video info.
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (!videoInfo) {
// TODO: Display an error message.
SDL_Quit();
return false;
}
// Compute video mode flags.
const int videoFlags = SDL_OPENGL
| ( videoInfo->hw_available ? SDL_HWSURFACE : SDL_SWSURFACE )
| ( g_Config.bFullscreen ? SDL_FULLSCREEN : 0);
// Set vide mode.
// TODO: Can we use this field or is a separate field needed?
int _twidth = nBackbufferWidth;
int _theight = nBackbufferHeight;
SDL_Surface *screen = SDL_SetVideoMode(_twidth, _theight, 0, videoFlags);
if (!screen) {
//TODO : Display an error message
SDL_Quit();
return false;
}
#endif #endif
return true; return true;
} }
void OpenGL_Update() void OpenGL_Update()
{ {
#if defined(_WIN32) #if USE_SDL
//TODO
#elif defined(_WIN32)
if (EmuWindow::GetParentWnd()) if (EmuWindow::GetParentWnd())
{ {
RECT rcWindow; RECT rcWindow;
@ -517,7 +519,7 @@ void OpenGL_Update()
} }
} }
#elif defined(__linux__) #else // GLX
Window winDummy; Window winDummy;
unsigned int borderDummy; unsigned int borderDummy;
XGetGeometry(GLWin.dpy, GLWin.win, &winDummy, &GLWin.x, &GLWin.y, XGetGeometry(GLWin.dpy, GLWin.win, &winDummy, &GLWin.x, &GLWin.y,
@ -543,15 +545,15 @@ void OpenGL_Update()
nXoff = (nBackbufferWidth - (640 * MValueX)) / 2; nXoff = (nBackbufferWidth - (640 * MValueX)) / 2;
nYoff = (nBackbufferHeight - (480 * MValueY)) / 2; nYoff = (nBackbufferHeight - (480 * MValueY)) / 2;
} }
#else
//SDL stuff
#endif #endif
} }
void OpenGL_Shutdown() void OpenGL_Shutdown()
{ {
#if defined(_WIN32) #if USE_SDL
SDL_Quit();
#elif defined(_WIN32)
if (hRC) // Do We Have A Rendering Context? if (hRC) // 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?
@ -571,7 +573,7 @@ void OpenGL_Shutdown()
MessageBox(NULL,"Release Device Context Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); MessageBox(NULL,"Release Device Context Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
hDC = NULL; // Set DC To NULL hDC = NULL; // Set DC To NULL
} }
#elif defined(__linux__) #else // GLX
if (GLWin.ctx) if (GLWin.ctx)
{ {
if (!glXMakeCurrent(GLWin.dpy, None, NULL)) if (!glXMakeCurrent(GLWin.dpy, None, NULL))
@ -590,7 +592,5 @@ void OpenGL_Shutdown()
XF86VidModeSetViewPort(GLWin.dpy, GLWin.screen, 0, 0); XF86VidModeSetViewPort(GLWin.dpy, GLWin.screen, 0, 0);
} }
} }
#else
SDL_Quit();
#endif #endif
} }

View File

@ -33,12 +33,11 @@ libs = [
] ]
if sys.platform == 'darwin': if sys.platform == 'darwin':
platform = 'mac' platform = 'mac'
# SDL is currently the only way to get video on Mac OS X.
useSDL = True
# Use libraries from MacPorts. # Use libraries from MacPorts.
compileFlags.append('-I/opt/local/include') compileFlags.append('-I/opt/local/include')
linkFlags.append('-L/opt/local/lib') linkFlags.append('-L/opt/local/lib')
# Use SDL.
compileFlags.append('`sdl-config --cflags`')
linkFlags.append('`sdl-config --libs`')
# Use frameworks instead of plain libs, when possible. # Use frameworks instead of plain libs, when possible.
linkFlags += [ linkFlags += [
'-framework %s' % framework '-framework %s' % framework
@ -46,12 +45,19 @@ if sys.platform == 'darwin':
] ]
else: else:
platform = 'linux' platform = 'linux'
# By default, GLX is used on Linux to setup OpenGL, but you can select SDL
# instead if you like, by changing the line below.
useSDL = False
# Libraries with pkg-config support. # Libraries with pkg-config support.
compileFlags.append('`pkg-config --cflags xxf86vm`') compileFlags.append('`pkg-config --cflags xxf86vm`')
linkFlags.append('`pkg-config --libs xxf86vm`') linkFlags.append('`pkg-config --libs xxf86vm`')
# Libraries without pkg-config support. # Libraries without pkg-config support.
libs += [ 'GL', 'Cg', 'CgGL', 'X11' ] libs += [ 'GL', 'Cg', 'CgGL', 'X11' ]
if useSDL:
compileFlags += [ '`sdl-config --cflags`', '-DUSE_SDL=1' ]
linkFlags += [ '`sdl-config --libs`' ]
gfxenv = env.Copy( gfxenv = env.Copy(
CXXFLAGS = ' '.join(compileFlags), CXXFLAGS = ' '.join(compileFlags),
LINKFLAGS = ' '.join(linkFlags), LINKFLAGS = ' '.join(linkFlags),