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
#include "GLInit.h"
#if defined(__APPLE__)
#ifndef USE_SDL
#define USE_SDL 0
#endif
#if USE_SDL
#include "SDL.h"
#endif
@ -46,33 +49,35 @@ extern HINSTANCE g_hInstance;
void OpenGL_SwapBuffers()
{
#if defined(_WIN32)
SwapBuffers(hDC);
#elif defined(__linux__)
glXSwapBuffers(GLWin.dpy, GLWin.win);
#else //others
#if USE_SDL
SDL_GL_SwapBuffers();
#elif defined(_WIN32)
SwapBuffers(hDC);
#else // GLX
glXSwapBuffers(GLWin.dpy, GLWin.win);
#endif
}
void OpenGL_SetWindowText(const char *text)
{
#if defined(_WIN32)
#if USE_SDL
SDL_WM_SetCaption(text, NULL);
#elif defined(_WIN32)
SetWindowText(EmuWindow::GetWnd(), text);
#elif defined(__linux__)
#else // GLX
/**
* Tell X to ask the window manager to set the window title. (X
* itself doesn't provide window title functionality.)
*/
XStoreName(GLWin.dpy, GLWin.win, text);
#else
SDL_WM_SetCaption(text, NULL);
#endif
}
BOOL Callback_PeekMessages()
{
#if defined(_WIN32)
#if USE_SDL
//TODO
#elif defined(_WIN32)
//TODO: peekmessage
MSG msg;
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
@ -83,14 +88,12 @@ BOOL Callback_PeekMessages()
DispatchMessage(&msg);
}
return TRUE;
#elif defined(__linux__)
#else // GLX
XEvent event;
while (XPending(GLWin.dpy) > 0) {
XNextEvent(GLWin.dpy, &event);
}
return TRUE;
#else
//TODO
#endif
}
@ -124,7 +127,6 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
_twidth = _iwidth;
_theight = _iheight;
}
}
else // Going Windowed
{
@ -166,7 +168,18 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
g_VideoInitialize.pPeekMessages = &Callback_PeekMessages;
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
if (!g_Config.renderToMainframe || g_VideoInitialize.pWindowHandle == NULL)
{
@ -279,7 +292,7 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
return false;
}
#elif defined(__linux__)
#else // GLX
XVisualInfo *vi;
Colormap cmap;
int dpyWidth, dpyHeight;
@ -405,32 +418,49 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
XSetStandardProperties(GLWin.dpy, GLWin.win, "GPU",
"GPU", None, NULL, 0, NULL);
XMapRaised(GLWin.dpy, GLWin.win);
}
#else
//SDL for other OS (osx, bsd, ...)
}
#endif
return true;
}
//init sdl video
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
bool OpenGL_MakeCurrent()
{
#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
SDL_Quit();
return false;
}
//setup ogl to use double buffering
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#endif
return true;
}
bool OpenGL_MakeCurrent()
{
#if defined(_WIN32)
#elif defined(_WIN32)
if (!wglMakeCurrent(hDC,hRC)) {
MessageBox(NULL,"(5) Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
#elif defined(__linux__)
#else // GLX
Window winDummy;
unsigned int borderDummy;
// connect the glx-context to the window
@ -447,44 +477,16 @@ bool OpenGL_MakeCurrent()
XSelectInput(GLWin.dpy, GLWin.win, ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPressMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask |
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
return true;
}
void OpenGL_Update()
{
#if defined(_WIN32)
#if USE_SDL
//TODO
#elif defined(_WIN32)
if (EmuWindow::GetParentWnd())
{
RECT rcWindow;
@ -517,7 +519,7 @@ void OpenGL_Update()
}
}
#elif defined(__linux__)
#else // GLX
Window winDummy;
unsigned int borderDummy;
XGetGeometry(GLWin.dpy, GLWin.win, &winDummy, &GLWin.x, &GLWin.y,
@ -543,15 +545,15 @@ void OpenGL_Update()
nXoff = (nBackbufferWidth - (640 * MValueX)) / 2;
nYoff = (nBackbufferHeight - (480 * MValueY)) / 2;
}
#else
//SDL stuff
#endif
}
void OpenGL_Shutdown()
{
#if defined(_WIN32)
#if USE_SDL
SDL_Quit();
#elif defined(_WIN32)
if (hRC) // Do We Have A Rendering Context?
{
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);
hDC = NULL; // Set DC To NULL
}
#elif defined(__linux__)
#else // GLX
if (GLWin.ctx)
{
if (!glXMakeCurrent(GLWin.dpy, None, NULL))
@ -590,7 +592,5 @@ void OpenGL_Shutdown()
XF86VidModeSetViewPort(GLWin.dpy, GLWin.screen, 0, 0);
}
}
#else
SDL_Quit();
#endif
}

View File

@ -33,12 +33,11 @@ libs = [
]
if sys.platform == 'darwin':
platform = 'mac'
# SDL is currently the only way to get video on Mac OS X.
useSDL = True
# Use libraries from MacPorts.
compileFlags.append('-I/opt/local/include')
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.
linkFlags += [
'-framework %s' % framework
@ -46,12 +45,19 @@ if sys.platform == 'darwin':
]
else:
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.
compileFlags.append('`pkg-config --cflags xxf86vm`')
linkFlags.append('`pkg-config --libs xxf86vm`')
# Libraries without pkg-config support.
libs += [ 'GL', 'Cg', 'CgGL', 'X11' ]
if useSDL:
compileFlags += [ '`sdl-config --cflags`', '-DUSE_SDL=1' ]
linkFlags += [ '`sdl-config --libs`' ]
gfxenv = env.Copy(
CXXFLAGS = ' '.join(compileFlags),
LINKFLAGS = ' '.join(linkFlags),