diff options
| author | nakeee <nakeee@gmail.com> | 2009-09-09 19:52:45 +0000 |
|---|---|---|
| committer | nakeee <nakeee@gmail.com> | 2009-09-09 19:52:45 +0000 |
| commit | bc6323ea0e6b2186a64e8d65a0df2df1e61e95b6 (patch) | |
| tree | d719548236ebc6278100e0c138987ea3c8cf8b69 /Source/Plugins/Plugin_VideoOGL | |
| parent | c1665ec6cd8b02ae4936116ca4d1816e531fac0a (diff) | |
removed the failed gltest code
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4238 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Plugins/Plugin_VideoOGL')
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp | 17 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h | 5 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/SConscript | 31 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/SDLWindow.cpp | 77 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/SDLWindow.h | 29 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/Win32Window.cpp | 803 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/Win32Window.h | 70 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/X11Window.cpp | 392 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/X11Window.h | 49 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/main.cpp | 161 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/nGLUtil.cpp | 139 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/nGLUtil.h | 64 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_VideoOGL/Src/nmain.cpp | 300 |
13 files changed, 82 insertions, 2055 deletions
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index b152d3c1c3..f13d964c8e 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -124,18 +124,13 @@ void UpdateFPSDisplay(const char *text) sprintf(temp, "SVN R%s: GL: %s", SVN_REV_STR, text); OpenGL_SetWindowText(temp); } -// ========================= -// ======================================================================================= // Create rendering window. // Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() -// ------------------ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight) { - // -------------------------------------------- // Check for fullscreen mode - // --------------- int _twidth, _theight; if (g_Config.bFullscreen) { @@ -165,21 +160,14 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight #if defined(_WIN32) EmuWindow::SetSize(_twidth, _theight); #endif - // ---------------------------- - // --------------------------------------------------------------------------------------- // Control window size and picture scaling - // ------------------ s_backbuffer_width = _twidth; s_backbuffer_height = _theight; g_VideoInitialize.pPeekMessages = &Callback_PeekMessages; g_VideoInitialize.pUpdateFPSDisplay = &UpdateFPSDisplay; - //char buff[100]; - //sprintf(buff, "%i %i %d %d %d", s_backbuffer_width, s_backbuffer_height, Max, MValueX, MValueY); - //MessageBox(0, buff, "", 0); - #if USE_SDL //init sdl video if (SDL_Init(SDL_INIT_VIDEO) < 0) { @@ -223,15 +211,11 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight GLWin.glCanvas->SetCurrent(); #else GLWin.glCanvas->SetCurrent(*GLWin.glCtxt); - // GLWin.glCtxt->SetCurrent(*GLWin.glCanvas); #endif #elif defined(_WIN32) - // --------------------------------------------------------------------------------------- // Create rendering window in Windows - // ---------------------- - // Create a separate window if (!g_Config.RenderToMainframe || g_VideoInitialize.pWindowHandle == NULL) g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create(NULL, g_hInstance, _T("Please wait...")); @@ -783,3 +767,4 @@ bool OpenGL_ReportFBOError(const char *function, const char *file, int line) } return true; } + diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h index 5475662bfd..54e569fb81 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h @@ -18,9 +18,6 @@ #ifndef _GLINIT_H_ #define _GLINIT_H_ -#if defined GLTEST && GLTEST -#include "nGLUtil.h" -#else #include "Config.h" #include "MathUtil.h" #include "pluginspecs_video.h" @@ -148,8 +145,6 @@ bool OpenGL_ReportFBOError(const char *function, const char *file, int line); #define GL_REPORT_ERRORD() #endif -#endif // GLTEST ?? - #include <Cg/cg.h> #include <Cg/cgGL.h> diff --git a/Source/Plugins/Plugin_VideoOGL/Src/SConscript b/Source/Plugins/Plugin_VideoOGL/Src/SConscript index e75df3e93e..992c928bb4 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/SConscript +++ b/Source/Plugins/Plugin_VideoOGL/Src/SConscript @@ -37,17 +37,11 @@ libs = [ gfxenv = env.Clone() -if gfxenv['GLTEST']: - files += [ - 'nmain.cpp', - 'nGLUtil.cpp', - ] - libs += [ 'inputcommon' ] -else: - files += [ - 'main.cpp', - 'GLUtil.cpp', - ] +files += [ + 'main.cpp', + 'GLUtil.cpp', + ] + if gfxenv['HAVE_WX']: files += [ 'GUI/ConfigDlg.cpp', @@ -110,21 +104,6 @@ conf.Define('HAVE_XXF86VM', gfxenv['HAVE_XXF86VM']) conf.Finish() -if gfxenv['GLTEST']: - if gfxenv['HAVE_XXF86VM']: - files += [ - 'X11Window.cpp', - ] - - if gfxenv['HAVE_SDL']: - files += [ - 'SDLWindow.cpp', - ] - if gfxenv['USE_WX']: - files += [ - 'WXGLWindow.cpp', - ] - # Sanity check if gfxenv['USE_WX'] and not gfxenv['HAVE_WX']: print "Must have wx to use wxgl" diff --git a/Source/Plugins/Plugin_VideoOGL/Src/SDLWindow.cpp b/Source/Plugins/Plugin_VideoOGL/Src/SDLWindow.cpp deleted file mode 100644 index d6b709df5d..0000000000 --- a/Source/Plugins/Plugin_VideoOGL/Src/SDLWindow.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "SDLWindow.h" - -void SDLWindow::SwapBuffers() { - SDL_GL_SwapBuffers(); -} - -void SDLWindow::SetWindowText(const char *text) { - SDL_WM_SetCaption(text, NULL); -} - -bool SDLWindow::PeekMessages() { - // TODO implement - return false; -} - -void SDLWindow::Update() { - - SDL_Surface *surface = SDL_GetVideoSurface(); - if (!surface) { - PanicAlert("Can't get surface to update"); - return; - } - - //SetSize(surface->w, surface->h); - updateDim(); - -} - -bool SDLWindow::MakeCurrent() { - /* 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) { - PanicAlert("Couldn't get video info"); - 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? - SDL_Surface *screen = SDL_SetVideoMode(GetXwin(), GetYwin(), - 0, videoFlags); - if (!screen) { - PanicAlert("Couldn't set video mode"); - SDL_Quit(); - return false; - } - - return true; -} - -SDLWindow::~SDLWindow() { - SDL_Quit(); -} - -SDLWindow::SDLWindow() : GLWindow() { - - //init sdl video - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - PanicAlert("Failed to init SDL: %s", SDL_GetError()); - SDL_Quit(); - //return NULL; - } - - // Setup ogl to use double buffering - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); -} diff --git a/Source/Plugins/Plugin_VideoOGL/Src/SDLWindow.h b/Source/Plugins/Plugin_VideoOGL/Src/SDLWindow.h deleted file mode 100644 index f53f921b4b..0000000000 --- a/Source/Plugins/Plugin_VideoOGL/Src/SDLWindow.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _SDLWINDOW_H -#define _SDLWINDOW_H - -#include "GLWindow.h" -#if defined HAVE_SDL && HAVE_SDL -#include <SDL.h> - -class SDLWindow : public GLWindow -{ -public: - virtual void SwapBuffers(); - virtual void SetWindowText(const char *text); - virtual bool PeekMessages(); - virtual void Update(); - virtual bool MakeCurrent(); - - static bool valid() { return true; } - ~SDLWindow(); - SDLWindow(); - -}; -#else -class SDLWindow : public GLWindow -{ -public: - SDLWindow() {} -}; -#endif -#endif diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Win32Window.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Win32Window.cpp deleted file mode 100644 index b871b12e7d..0000000000 --- a/Source/Plugins/Plugin_VideoOGL/Src/Win32Window.cpp +++ /dev/null @@ -1,803 +0,0 @@ -#include "Win32Window.h" - -// Static member data -unsigned int Win32Window::ourWindowCount = 0; -const char* Win32Window::ourClassName = _T("DolphinEmuWnd"); -Win32Window* Win32Window::ourFullscreenWindow = NULL; - - -Win32Window::Win32Window() : GLWindow(), -myHandle (NULL), -myCallback (0), -myCursor (NULL), -myIcon (NULL), -myKeyRepeatEnabled (true), -myIsCursorIn (false) -{ - // Register the window class at first call - if (ourWindowCount == 0) - RegisterWindowClass(); - - // Use small dimensions - //SetWinSize(1, 1); - - // Create the rendering window - if (!(myHandle = CreateWindow(ourClassName, _T(""), WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, - GetXwin(), GetYwin(), NULL, NULL, myhInstance, this))) { - PanicAlert("Error creating GL Window"); - } - - ShowWindow(myHandle, SW_SHOW); - - // Create the rendering context - if (myHandle) - { - VideoMode Mode; - Mode.Width = GetXwin(); - Mode.Height = GetYwin(); - Mode.BitsPerPixel = 32; - Mode.DepthBits = 24; - Mode.StencilBits = 8; - Mode.AntialiasingLevel = 0; - CreateContext(Mode); - - // Don't activate by default - //SetNotActive(); - } -} - -Win32Window::~Win32Window() -{ - // Destroy the custom icon, if any - if (myIcon) - DestroyIcon(myIcon); - - if (!myCallback) - { - // Destroy the window - if (myHandle) - DestroyWindow(myHandle); - - // Decrement the window count - ourWindowCount--; - - // Unregister window class if we were the last window - if (ourWindowCount == 0) - UnregisterClass(ourClassName, GetModuleHandle(NULL)); - } - else - { - // The window is external : remove the hook on its message callback - SetWindowLongPtr(myHandle, GWLP_WNDPROC, myCallback); - } -} - -void Win32Window::SwapBuffers() -{ - if (myDeviceContext && myGLContext) - ::SwapBuffers(myDeviceContext); -} - -void Win32Window::SetWindowText(const char *text) -{ - ::SetWindowText(GetWnd(), text); -} - -void Win32Window::ShowMouseCursor(bool Show) -{ - if (Show) - myCursor = LoadCursor(NULL, IDC_ARROW); - else - myCursor = NULL; - - SetCursor(myCursor); -} - -bool Win32Window::PeekMessages() -{ - // We update the window only if we own it - if (!myCallback) - { - MSG Message; - while (PeekMessage(&Message, myHandle, 0, 0, PM_REMOVE)) - { - TranslateMessage(&Message); - DispatchMessage(&Message); - } - } - return true; // I don't know why this is bool... -} - -void Win32Window::Update() -{ - // We just check all of our events here - // TODO - PeekMessages(); - eventHandler->Update(); - updateDim(); -} - -bool Win32Window::MakeCurrent() -{ - if (myDeviceContext && myGLContext && (wglGetCurrentContext() != myGLContext)) - { - wglMakeCurrent(myDeviceContext, myGLContext); - return true; - } - else - return false; -} - -void Win32Window::RegisterWindowClass() -{ - WNDCLASS WindowClass; - myhInstance = GetModuleHandle(NULL); - WindowClass.style = CS_OWNDC; - WindowClass.lpfnWndProc = &Win32Window::GlobalOnEvent; - WindowClass.cbClsExtra = 0; - WindowClass.cbWndExtra = 0; - WindowClass.hInstance = myhInstance; - WindowClass.hIcon = NULL; - WindowClass.hCursor = 0; - WindowClass.hbrBackground = 0; - WindowClass.lpszMenuName = NULL; - WindowClass.lpszClassName = ourClassName; - if (!RegisterClass(&WindowClass)) - ERROR_LOG("Failed To Register The Window Class\n"); -} - -void Win32Window::SwitchToFullscreen(const VideoMode& Mode) -{ - DEVMODE DevMode; - DevMode.dmSize = sizeof(DEVMODE); - DevMode.dmPelsWidth = Mode.Width; - DevMode.dmPelsHeight = Mode.Height; - DevMode.dmBitsPerPel = Mode.BitsPerPixel; - DevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; - - // Apply fullscreen mode - if (ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) - { - ERROR_LOG("Failed to change display mode for fullscreen\n"); - return; - } - - // Change window style (no border, no titlebar, ...) - SetWindowLong(myHandle, GWL_STYLE, WS_POPUP); - SetWindowLong(myHandle, GWL_EXSTYLE, WS_EX_APPWINDOW); - - // And resize it so that it fits the entire screen - SetWindowPos(myHandle, HWND_TOP, 0, 0, Mode.Width, Mode.Height, SWP_FRAMECHANGED); - ShowWindow(myHandle, SW_SHOW); - - // Set "this" as the current fullscreen window - ourFullscreenWindow = this; - - // SetPixelFormat can fail (really ?) if window style doesn't contain these flags - long Style = GetWindowLong(myHandle, GWL_STYLE); - SetWindowLong(myHandle, GWL_STYLE, Style | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); -} - -//VideoMode Win32Window::GetSupportedVideoModes(std::vector<VideoMode>& Modes) -//{ -// // First, clear array to fill -// Modes.clear(); -// -// // Enumerate all available video modes for primary display adapter -// DEVMODE Win32Mode; -// Win32Mode.dmSize = sizeof(DEVMODE); -// for (int Count = 0; EnumDisplaySettings(NULL, Count, &Win32Mode); ++Count) -// { -// // Convert to sfVideoMode -// VideoMode Mode(Win32Mode.dmPelsWidth, Win32Mode.dmPelsHeight, Win32Mode.dmBitsPerPel); -// -// // Add it only if it is not already in the array -// if (std::find(Modes.begin(), Modes.end(), Mode) == Modes.end()) -// Modes.push_back(Mode); -// } -//} - -void Win32Window::CreateContext(VideoMode& Mode) -{ - // TESTING - Mode.DepthBits = 24; - Mode.StencilBits = 8; - //Mode.AntialiasingLevel = 4; - - // Get the device context attached to the window - myDeviceContext = GetDC(myHandle); - if (myDeviceContext == NULL) - { - ERROR_LOG("Failed to get device context of window -- cannot create OpenGL context\n"); - return; - } - - // Let's find a suitable pixel format -- first try with antialiasing - int BestFormat = 0; - if (Mode.AntialiasingLevel > 0) - { - // Get the wglChoosePixelFormatARB function (it is an extension) - PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = reinterpret_cast<PFNWGLCHOOSEPIXELFORMATARBPROC>(wglGetProcAddress("wglChoosePixelFormatARB")); - - // Define the basic attributes we want for our window - int IntAttributes[] = - { - WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, - WGL_SUPPORT_OPENGL_ARB, GL_TRUE, - WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, - WGL_DOUBLE_BUFFER_ARB, GL_TRUE, - WGL_SAMPLE_BUFFERS_ARB, (Mode.AntialiasingLevel ? GL_TRUE : GL_FALSE), - WGL_SAMPLES_ARB, Mode.AntialiasingLevel, - 0, 0 - }; - - // Let's check how many formats are supporting our requirements - int Formats[128]; - UINT NbFormats; - float FloatAttributes[] = {0, 0}; - bool IsValid = wglChoosePixelFormatARB(myDeviceContext, IntAttributes, FloatAttributes, sizeof(Formats) / sizeof(*Formats), Formats, &NbFormats) != 0; - if (!IsValid || (NbFormats == 0)) - { - if (Mode.AntialiasingLevel > 2) - { - // No format matching our needs : reduce the multisampling level - char errMsg[256]; - sprintf(errMsg, "Failed to find a pixel format supporting %u antialiasing levels ; trying with 2 levels\n", Mode.AntialiasingLevel); - ERROR_LOG(errMsg); - - Mode.AntialiasingLevel = IntAttributes[1] = 2; - IsValid = wglChoosePixelFormatARB(myDeviceContext, IntAttributes, FloatAttributes, sizeof(Formats) / sizeof(*Formats), Formats, &NbFormats) != 0; - } - - if (!IsValid || (NbFormats == 0)) - { - // Cannot find any pixel format supporting multisampling ; disabling antialiasing - ERROR_LOG("Failed to find a pixel format supporting antialiasing ; antialiasing will be disabled\n"); - Mode.AntialiasingLevel = 0; - } - } - - // Get the best format among the returned ones - if (IsValid && (NbFormats > 0)) - { - int BestScore = 0xFFFF; - for (UINT i = 0; i < NbFormats; ++i) - { - // Get the current format's attributes - PIXELFORMATDESCRIPTOR Attribs; - Attribs.nSize = sizeof(PIXELFORMATDESCRIPTOR); - Attribs.nVersion = 1; - DescribePixelFormat(myDeviceContext, Formats[i], sizeof(PIXELFORMATDESCRIPTOR), &Attribs); - - // Evaluate the current configuration - int Color = Attribs.cRedBits + Attribs.cGreenBits + Attribs.cBlueBits + Attribs.cAlphaBits; - int Score = abs(static_cast<int>(Mode.BitsPerPixel - Color)) + // The EvaluateConfig function - abs(static_cast<int>(Mode.DepthBits - Attribs.cDepthBits)) + - abs(static_cast<int>(Mode.StencilBits - Attribs.cStencilBits)); - - // Keep it if it's better than the current best - if (Score < BestScore) - { - BestScore = Score; - BestFormat = Formats[i]; - } - } - } - } - - // Find a pixel format with no antialiasing, if not needed or not supported - if (BestFormat == 0) - { - // Setup a pixel format descriptor from the rendering settings - PIXELFORMATDESCRIPTOR PixelDescriptor; - ZeroMemory(&PixelDescriptor, sizeof(PIXELFORMATDESCRIPTOR)); - PixelDescriptor.nSize = sizeof(PIXELFORMATDESCRIPTOR); - PixelDescriptor.nVersion = 1; - PixelDescriptor.iLayerType = PFD_MAIN_PLANE; - PixelDescriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; - PixelDescriptor.iPixelType = PFD_TYPE_RGBA; - PixelDescriptor.cColorBits = static_cast<BYTE>(Mode.BitsPerPixel); - PixelDescriptor.cDepthBits = static_cast<BYTE>(Mode.DepthBits); - PixelDescriptor.cStencilBits = static_cast<BYTE>(Mode.StencilBits); - - // Get the pixel format that best matches our requirements - BestFormat = ChoosePixelFormat(myDeviceContext, &PixelDescriptor); - if (BestFormat == 0) - { - ERROR_LOG("Failed to find a suitable pixel format for device context -- cannot create OpenGL context\n"); - return; - } - } - - // Extract the depth and stencil bits from the chosen format - PIXELFORMATDESCRIPTOR ActualFormat; - ActualFormat.nSize = sizeof(PIXELFORMATDESCRIPTOR); - ActualFormat.nVersion = 1; - DescribePixelFormat(myDeviceContext, BestFormat, sizeof(PIXELFORMATDESCRIPTOR), &ActualFormat); - Mode.DepthBits = ActualFormat.cDepthBits; - Mode.StencilBits = ActualFormat.cStencilBits; - - // Set the chosen pixel format - if (!SetPixelFormat(myDeviceContext, BestFormat, &ActualFormat)) - { - ERROR_LOG("Failed to set pixel format for device context -- cannot create OpenGL context\n"); - return; - } - - // Create the OpenGL context from the device context - myGLContext = wglCreateContext(myDeviceContext); - if (myGLContext == NULL) - { - ERROR_LOG("Failed to create an OpenGL context for this window\n"); - return; - } - - // Share display lists with other contexts - HGLRC CurrentContext = wglGetCurrentContext(); - if (CurrentContext) - wglShareLists(CurrentContext, myGLContext); - - // Activate the context - MakeCurrent(); - - // Enable multisampling - if (Mode.AntialiasingLevel > 0) - glEnable(GL_MULTISAMPLE_ARB); -} - -void Win32Window::Cleanup() -{ - // Restore the previous video mode (in case we were running in fullscreen) - if (ourFullscreenWindow == this) - { - ChangeDisplaySettings(NULL, 0); - ourFullscreenWindow = NULL; - } - - // Unhide the mouse cursor (in case it was hidden) - ShowMouseCursor(true); - //GetProperty(OGL_HIDECURSOR) - - // Destroy the OpenGL context - if (myGLContext) - { - // Unbind the context before destroying it - //SetNotActive(); - - wglDeleteContext(myGLContext); - myGLContext = NULL; - } - if (myDeviceContext) - { - ReleaseDC(myHandle, myDeviceContext); - myDeviceContext = NULL; - } -} - - -/// Process a Win32 Event - -void Win32Window::ProcessEvent(UINT Message, WPARAM WParam, LPARAM LParam) -{ - // Don't process any message until window is created - if (myHandle == NULL) - return; - - switch (Message) - { - // Destroy Event - case WM_DESTROY : - { - // Here we must cleanup resources ! - Cleanup(); - break; - } - - // Set cursor Event - case WM_SETCURSOR : - { - // The mouse has moved, if the cursor is in our window we must refresh the cursor - if (LOWORD(LParam) == HTCLIENT) - SetCursor(myCursor); - break; - } - case WM_CLOSE : - { - sf::Event Evt; - Evt.Type = sf::Event::Closed; - eventHandler->addEvent(&Evt); - break; - } - - // Resize Event - case WM_SIZE : - { - // Update window size - RECT Rect; - GetClientRect(myHandle, &Rect); - SetWinSize(Rect.right - Rect.left, Rect.bottom - Rect.top); - - sf::Event Evt; - Evt.Type = sf::Event::Resized; - Evt.Size.Width = GetXwin(); - Evt.Size.Height = GetYwin(); - eventHandler->addEvent(&Evt); - break; - } - // Gain focus Event - case WM_SETFOCUS : - { - sf::Event Evt; - Evt.Type = sf::Event::GainedFocus; - eventHandler->addEvent(&Evt); - break; - } - - // Lost focus Event - case WM_KILLFOCUS : - { - sf::Event Evt; - Evt.Type = sf::Event::LostFocus; - eventHandler->addEvent(&Evt); - break; - } - - // Text Event - case WM_CHAR : - { - sf::Event Evt; - Evt.Type = sf::Event::TextEntered; - Evt.Text.Unicode = static_cast<u32>(WParam); - eventHandler->addEvent(&Evt); - break; - } - // Keydown Event - case WM_KEYDOWN : - case WM_SYSKEYDOWN : - { - if (myKeyRepeatEnabled || ((LParam & (1 << 30)) == 0)) - { - sf::Event Evt; - Evt.Type = sf::Event::KeyPressed; - Evt.Key.Code = (WParam == VK_SHIFT) ? GetShiftState(true) : VirtualKeyCodeToSF(WParam, LParam); - Evt.Key.Alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0; - Evt.Key.Control = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0; - Evt.Key.Shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0; - eventHandler->addEvent(&Evt); - } - break; - } - - // Keyup Event - case WM_KEYUP : - case WM_SYSKEYUP : - { - sf::Event Evt; - Evt.Type = sf::Event::KeyReleased; - Evt.Key.Code = (WParam == VK_SHIFT) ? GetShiftState(false) : VirtualKeyCodeToSF(WParam, LParam); - Evt.Key.Alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0; - Evt.Key.Control = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0; - Evt.Key.Shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0; - eventHandler->addEvent(&Evt); - break; - } - - // Mouse wheel Event - case WM_MOUSEWHEEL : - { - sf::Event Evt; - Evt.Type = sf::Event::MouseWheelMoved; - Evt.MouseWheel.Delta = static_cast<s16>(HIWORD(WParam)) / 120; - eventHandler->addEvent(&Evt); - break; - } - - // Mouse left button down Event - case WM_LBUTTONDOWN : - { - sf::Event Evt; - Evt.Type = sf::Event::MouseButtonPressed; - Evt.MouseButton.Button = sf::Mouse::Left; - Evt.MouseButton.X = LOWORD(LParam); - Evt.MouseButton.Y = HIWORD(LParam); - eventHandler->addEvent(&Evt); - break; - } - - // Mouse left button up Event - case WM_LBUTTONUP : - { - sf::Event Evt; - Evt.Type = sf::Event::MouseButtonReleased; - Evt.MouseButton.Button = sf::Mouse::Left; - Evt.MouseButton.X = LOWORD(LParam); - Evt.MouseButton.Y = HIWORD(LParam); - eventHandler->addEvent(&Evt); - break; - } - - // Mouse right button down Event - case WM_RBUTTONDOWN : - { - sf::Event Evt; - Evt.Type = sf::Event::MouseButtonPressed; - Evt.MouseButton.Button = sf::Mouse::Right; - Evt.MouseButton.X = LOWORD(LParam); - Evt.MouseButton.Y = HIWORD(LParam); - eventHandler->addEvent(&Evt); - break; - } - - // Mouse right button up Event - case WM_RBUTTONUP : - { - sf::Event Evt; - Evt.Type = sf::Event::MouseButtonReleased; - Evt.MouseButton.Button = sf::Mouse::Right; - Evt.MouseButton.X = LOWORD(LParam); - Evt.MouseButton.Y = HIWORD(LParam); - eventHandler->addEvent(&Evt); - break; - } - - // Mouse wheel button down Event - case WM_MBUTTONDOWN : - { - sf::Event Evt; - Evt.Type = sf::Event::MouseButtonPressed; - Evt.MouseButton.Button = sf::Mouse::Middle; - Evt.MouseButton.X = LOWORD(LParam); - Evt.MouseButton.Y = HIWORD(LParam); - eventHandler->addEvent(&Evt); - break; - } - - // Mouse wheel button up Event - case WM_MBUTTONUP : - { - sf::Event Evt; - Evt.Type = sf::Event::MouseButtonReleased; - Evt.MouseButton.Button = sf::Mouse::Middle; - Evt.MouseButton.X = LOWORD(LParam); - Evt.MouseButton.Y = HIWORD(LParam); - eventHandler->addEvent(&Evt); - break; - } - - // Mouse X button down Event - case WM_XBUTTONDOWN : - { - sf::Event Evt; - Evt.Type = sf::Event::MouseButtonPressed; - Evt.MouseButton.Button = HIWORD(WParam) == XBUTTON1 ? sf::Mouse::XButton1 : sf::Mouse::XButton2; - Evt.MouseButton.X = LOWORD(LParam); - Evt.MouseButton.Y = HIWORD(LParam); - eventHandler->addEvent(&Evt); - break; - } - - // Mouse X button up Event - case WM_XBUTTONUP : - { - sf::Event Evt; - Evt.Type = sf::Event::MouseButtonReleased; - Evt.MouseButton.Button = HIWORD(WParam) == XBUTTON1 ? sf::Mouse::XButton1 : sf::Mouse::XButton2; - Evt.MouseButton.X = LOWORD(LParam); - eventHandler->addEvent(&Evt); - break; - } - - // Mouse move Event - case WM_MOUSEMOVE : - { - // Check if we need to generate a MouseEntered Event - if (!myIsCursorIn) - { - TRACKMOUSEEVENT MouseEvent; - MouseEvent.cbSize = sizeof(TRACKMOUSEEVENT); - MouseEvent.hwndTrack = myHandle; - MouseEvent.dwFlags = TME_LEAVE; - TrackMouseEvent(&MouseEvent); - - myIsCursorIn = true; - - sf::Event Evt; - Evt.Type = sf::Event::MouseEntered; - eventHandler->addEvent(&Evt); - } - - sf::Event Evt; - Evt.Type = sf::Event::MouseMoved; - Evt.MouseMove.X = LOWORD(LParam); - Evt.MouseMove.Y = HIWORD(LParam); // (shuffle2) Added this, check to see if it's good - eventHandler->addEvent(&Evt); - break; - } - - // Mouse leave Event - case WM_MOUSELEAVE : - { - myIsCursorIn = false; - - sf::Event Evt; - Evt.Type = sf::Event::MouseLeft; - eventHandler->addEvent(&Evt); - break; - } - } -} - - -/// Check the state of the shift keys on a key sf::Event, -/// and return the corresponding SF key code - -sf::Key::Code Win32Window::GetShiftState(bool KeyDown) -{ - static bool LShiftPrevDown = false; - static bool RShiftPrevDown = false; - - bool LShiftDown = (HIWORD(GetAsyncKeyState(VK_LSHIFT)) != 0); - bool RShiftDown = (HIWORD(GetAsyncKeyState(VK_RSHIFT)) != 0); - - sf::Key::Code Code = sf::Key::Code(0); - if (KeyDown) - { - if (!LShiftPrevDown && LShiftDown) Code = sf::Key::LShift; - else if (!RShiftPrevDown && RShiftDown) Code = sf::Key::RShift; - } - else - { - if (LShiftPrevDown && !LShiftDown) Code = sf::Key::LShift; - else if (RShiftPrevDown && !RShiftDown) Code = sf::Key::RShift; - } - - LShiftPrevDown = LShiftDown; - RShiftPrevDown = RShiftDown; - - return Code; -} - - -/// Convert a Win32 virtual key code to a SFML key code - -sf::Key::Code Win32Window::VirtualKeyCodeToSF(WPARAM VirtualKey, LPARAM Flags) -{ - switch (VirtualKey) - { - // VK_SHIFT is handled by the GetShiftState function - case VK_MENU : return (Flags & (1 << 24)) ? sf::Key::RAlt : sf::Key::LAlt; - case VK_CONTROL : return (Flags & (1 << 24)) ? sf::Key::RControl : sf::Key::LControl; - case VK_LWIN : return sf::Key::LSystem; - case VK_RWIN : return sf::Key::RSystem; - case VK_APPS : return sf::Key::Menu; - case VK_OEM_1 : return sf::Key::SemiColon; - case VK_OEM_2 : return sf::Key::Slash; - case VK_OEM_PLUS : return sf::Key::Equal; - case VK_OEM_MINUS : return sf::Key::Dash; - case VK_OEM_4 : return sf::Key::LBracket; - case VK_OEM_6 : return sf::Key::RBracket; - case VK_OEM_COMMA : return sf::Key::Comma; - case VK_OEM_PERIOD : return sf::Key::Period; - case VK_OEM_7 : return sf::Key::Quote; - case VK_OEM_5 : return sf::Key::BackSlash; - case VK_OEM_3 : return sf::Key::Tilde; - case VK_ESCAPE : return sf::Key::Escape; - case VK_SPACE : return sf::Key::Space; - case VK_RETURN : return sf::Key::Return; - case VK_BACK : return sf::Key::Back; - case VK_TAB : return sf::Key::Tab; - case VK_PRIOR : return sf::Key::PageUp; - case VK_NEXT : return sf::Key::PageDown; - case VK_END : return sf::Key::End; - case VK_HOME : return sf::Key::Home; - case VK_INSERT : return sf::Key::Insert; - case VK_DELETE : return sf::Key::Delete; - case VK_ADD : return sf::Key::Add; - case VK_SUBTRACT : return sf::Key::Subtract; - case VK_MULTIPLY : return sf::Key::Multiply; - case VK_DIVIDE : return sf::Key::Divide; - case VK_PAUSE : return sf::Key::Pause; - case VK_F1 : return sf::Key::F1; - case VK_F2 : return sf::Key::F2; - case VK_F3 : return sf::Key::F3; - case VK_F4 : return sf::Key::F4; - case VK_F5 : return sf::Key::F5; - case VK_F6 : return sf::Key::F6; - case VK_F7 : return sf::Key::F7; - case VK_F8 : return sf::Key::F8; - case VK_F9 : return sf::Key::F9; - case VK_F10 : return sf::Key::F10; - case VK_F11 : return sf::Key::F11; - case VK_F12 : return sf::Key::F12; - case VK_F13 : return sf::Key::F13; - case VK_F14 : return sf::Key::F14; - case VK_F15 : return sf::Key::F15; - case VK_LEFT : return sf::Key::Left; - case VK_RIGHT : return sf::Key::Right; - case VK_UP : return sf::Key::Up; - case VK_DOWN : return sf::Key::Down; - case VK_NUMPAD0 : return sf::Key::Numpad0; - case VK_NUMPAD1 : return sf::Key::Numpad1; - case VK_NUMPAD2 : return sf::Key::Numpad2; - case VK_NUMPAD3 : return sf::Key::Numpad3; - case VK_NUMPAD4 : return sf::Key::Numpad4; - case VK_NUMPAD5 : return sf::Key::Numpad5; - case VK_NUMPAD6 : return sf::Key::Numpad6; - case VK_NUMPAD7 : return sf::Key::Numpad7; - case VK_NUMPAD8 : return sf::Key::Numpad8; - case VK_NUMPAD9 : return sf::Key::Numpad9; - case 'A' : return sf::Key::A; - case 'Z' : return sf::Key::Z; - case 'E' : return sf::Key::E; - case 'R' : return sf::Key::R; - case 'T' : return sf::Key::T; - case 'Y' : return sf::Key::Y; - case 'U' : return sf::Key::U; - case 'I' : return sf::Key::I; - case 'O' : return sf::Key::O; - case 'P' : return sf::Key::P; - case 'Q' : return sf::Key::Q; - case 'S' : return sf::Key::S; - case 'D' : return sf::Key::D; - case 'F' : return sf::Key::F; - case 'G' : return sf::Key::G; - case 'H' : return sf::Key::H; - case 'J' : return sf::Key::J; - case 'K' : return sf::Key::K; - case 'L' : return sf::Key::L; - case 'M' : return sf::Key::M; - case 'W' : return sf::Key::W; - case 'X' : return sf::Key::X; - case 'C' : return sf::Key::C; - case 'V' : return sf::Key::V; - case 'B' : return sf::Key::B; - case 'N' : return sf::Key::N; - case '0' : return sf::Key::Num0; - case '1' : return sf::Key::Num1; - case '2' : return sf::Key::Num2; - case '3' : return sf::Key::Num3; - case '4' : return sf::Key::Num4; - case '5' : return sf::Key::Num5; - case '6' : return sf::Key::Num6; - case '7' : return sf::Key::Num7; - case '8' : return sf::Key::Num8; - case '9' : return sf::Key::Num9; - } - - return sf::Key::Code(0); -} - - -/// Win32 Callback for the window class - -LRESULT CALLBACK Win32Window::GlobalOnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam) -{ - // Associate handle and Window instance when the creation message is received - if (Message == WM_CREATE) - { - // Get Win32Window instance (it was passed as the last argument of CreateWindow) - long This = reinterpret_cast<long>(reinterpret_cast<CREATESTRUCT*>(LParam)->lpCreateParams); - - // Set as the "user data" parameter of the window - SetWindowLongPtr(Handle, GWLP_USERDATA, This); - } - - // Get the GLWindow instance corresponding to the window handle - Win32Window* Window = reinterpret_cast<Win32Window*>(GetWindowLongPtr(Handle, GWLP_USERDATA)); - - // Forward the event to the appropriate function - if (Window) - { - Window->ProcessEvent(Message, WParam, LParam); - - if (Window->myCallback) - return CallWindowProc(reinterpret_cast<WNDPROC>(Window->myCallback), Handle, Message, WParam, LParam); - } - - // We don't forward the WM_CLOSE message to prevent the OS from automatically destroying the window - if (Message == WM_CLOSE) - return 0; - - return DefWindowProc(Handle, Message, WParam, LParam); -} diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Win32Window.h b/Source/Plugins/Plugin_VideoOGL/Src/Win32Window.h deleted file mode 100644 index 423ffe34a7..0000000000 --- a/Source/Plugins/Plugin_VideoOGL/Src/Win32Window.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _WIN32WINDOW_H -#define _WIN32WINDOW_H - -#include "GLWindow.h" - -#ifdef _WIN32 -class Win32Window : public GLWindow -{ -public: - virtual void SwapBuffers(); - virtual void SetWindowText(const char *text); - virtual bool PeekMessages(); - virtual void Update(); - virtual bool MakeCurrent(); - HWND GetWnd(){return myHandle;}; - HWND GetParentWnd(){return myParent;}; - - static bool valid() { return true; } - ~Win32Window(); - Win32Window(); - static sf::Key::Code VirtualKeyCodeToSF(WPARAM VirtualKey, LPARAM Flags); - static sf::Key::Code GetShiftState(bool KeyDown); - -private: - struct VideoMode - { - unsigned int Width; - unsigned int Height; - unsigned int BitsPerPixel; - unsigned int DepthBits; - unsigned int StencilBits; - unsigned int AntialiasingLevel; - }; - - virtual void ShowMouseCursor(bool Show); - void RegisterWindowClass(); - void SwitchToFullscreen(const VideoMode& Mode); - void CreateContext(VideoMode& Mode); - void Cleanup(); - void ProcessEvent(UINT Message, WPARAM WParam, LPARAM LParam); - static LRESULT CALLBACK GlobalOnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam); - - // Static member data - static unsigned int ourWindowCount; - static const char* ourClassName; - static Win32Window* ourFullscreenWindow; - - // Member data - HWND myHandle; - HINSTANCE myhInstance; - HWND myParent; // Possibly not wanted here - long myCallback; - HCURSOR myCursor; - HICON myIcon; - bool myKeyRepeatEnabled; - bool myIsCursorIn; - HDC myDeviceContext; - HGLRC myGLContext; -}; - -#else - -class Win32Window : public GLWindow -{ -public: - Win32Window() {} -}; - -#endif //_WIN32 -#endif //_WIN32WINDOW_H diff --git a/Source/Plugins/Plugin_VideoOGL/Src/X11Window.cpp b/Source/Plugins/Plugin_VideoOGL/Src/X11Window.cpp deleted file mode 100644 index a44ecb884c..0000000000 --- a/Source/Plugins/Plugin_VideoOGL/Src/X11Window.cpp +++ /dev/null @@ -1,392 +0,0 @@ -#include "X11Window.h" - -X11Window::X11Window() : GLWindow() { - - XVisualInfo *vi; - Colormap cmap; - int dpyWidth, dpyHeight; - int glxMajorVersion, glxMinorVersion; - int vidModeMajorVersion, vidModeMinorVersion; - Atom wmDelete; - - // attributes for a single buffered visual in RGBA format with at least - // 8 bits per color and a 24 bit depth buffer - int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 8, - GLX_GREEN_SIZE, 8, - GLX_BLUE_SIZE, 8, - GLX_DEPTH_SIZE, 24, - None}; - - // attributes for a double buffered visual in RGBA format with at least - // 8 bits per color and a 24 bit depth buffer - int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER, - GLX_RED_SIZE, 8, - GLX_GREEN_SIZE, 8, - GLX_BLUE_SIZE, 8, - GLX_DEPTH_SIZE, 24, - GLX_SAMPLE_BUFFERS_ARB, - g_Config.iMultisampleMode, - GLX_SAMPLES_ARB, 1, None }; - dpy = XOpenDisplay(0); - g_VideoInitialize.pWindowHandle = (HWND)dpy; - screen = DefaultScreen(dpy); - - fs = g_Config.bFullscreen; //Set to setting in Options - - /* get an appropriate visual */ - vi = glXChooseVisual(dpy, screen, attrListDbl); - if (vi == NULL) { - vi = glXChooseVisual(dpy, screen, attrListSgl); - doubleBuffered = False; - ERROR_LOG("Only Singlebuffered Visual!\n"); - } else { - doubleBuffered = True; - NOTICE_LOG("Got Doublebuffered Visual!\n"); - } - - glXQueryVersion(dpy, &glxMajorVersion, &glxMinorVersion); - NOTICE_LOG("glX-Version %d.%d\n", glxMajorVersion, glxMinorVersion); - /* create a GLX context */ - ctx = glXCreateContext(dpy, vi, 0, GL_TRUE); - if(!ctx) { - ERROR_LOG("Couldn't Create GLX context.Quit"); - exit(0); // TODO: Don't bring down entire Emu - } - - /* create a color map */ - cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), - vi->visual, AllocNone); - attr.colormap = cmap; - attr.border_pixel = 0; - - XkbSetDetectableAutoRepeat(dpy, True, NULL); - - // get a connection - XF86VidModeQueryVersion(dpy, &vidModeMajorVersion, &vidModeMinorVersion); - - if (fs) { - - XF86VidModeModeInfo **modes = NULL; - int modeNum = 0; - int bestMode = 0; - - // set best mode to current - bestMode = 0; - NOTICE_LOG("XF86VidModeExtension-Version %d.%d\n", vidModeMajorVersion, vidModeMinorVersion); - XF86VidModeGetAllModeLines(dpy, screen, &modeNum, &modes); - - if (modeNum > 0 && modes != NULL) { - /* save desktop-resolution before switching modes */ - deskMode = *modes[0]; - /* look for mode with requested resolution */ - for (int i = 0; i < modeNum; i++) { - if ((modes[i]->hdisplay == GetXwin()) && - (modes[i]->vdisplay == GetYwin())) { - bestMode = i; - } - } - - XF86VidModeSwitchToMode(dpy, screen, modes[bestMode]); - XF86VidModeSetViewPort(dpy, screen, 0, 0); - dpyWidth = modes[bestMode]->hdisplay; - dpyHeight = modes[bestMode]->vdisplay; - NOTICE_LOG("Resolution %dx%d\n", dpyWidth, dpyHeight); - XFree(modes); - - /* create a fullscreen window */ - attr.override_redirect = True; - attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | - KeyReleaseMask | ButtonReleaseMask | StructureNotifyMask; - win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, - dpyWidth, dpyHeight, 0, vi->depth, InputOutput, - vi->visual, CWBorderPixel | CWColormap | - CWEventMask | CWOverrideRedirect, &attr); - XWarpPointer(dpy, None, win, 0, 0, 0, 0, 0, 0); - XMapRaised(dpy, win); - XGrabKeyboard(dpy, win, True, GrabModeAsync, - GrabModeAsync, CurrentTime); - XGrabPointer(dpy, win, True, ButtonPressMask, - GrabModeAsync, GrabModeAsync, win, None, CurrentTime); - } - else { - ERROR_LOG("Failed to start fullscreen. If you received the \n" - "\"XFree86-VidModeExtension\" extension is missing, add\n" - "Load \"extmod\"\n" - "to your X configuration file (under the Module Section)\n"); - fs = 0; - } - } - - if (!fs) { - - // create a window in window mode - attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | - KeyReleaseMask | ButtonReleaseMask | - StructureNotifyMask | ResizeRedirectMask; - win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, GetXwin(), - GetYwin(), 0, vi->depth, InputOutput, vi->visual, - CWBorderPixel | CWColormap | CWEventMask, &attr); - // only set window title and handle wm_delete_events if in windowed mode - wmDelete = XInternAtom(dpy, "WM_DELETE_WINDOW", True); - XSetWMProtocols(dpy, win, &wmDelete, 1); - XSetStandardProperties(dpy, win, "GPU", - "GPU", None, NULL, 0, NULL); - XMapRaised(dpy, win); - } -} - -X11Window::~X11Window() { - if (ctx) { - if (!glXMakeCurrent(dpy, None, NULL)) { - ERROR_LOG("Could not release drawing context.\n"); - } - XUnmapWindow(dpy, win); - glXDestroyContext(dpy, ctx); - XCloseDisplay(dpy); - ctx = NULL; - } - /* switch back to original desktop resolution if we were in fs */ - if (dpy != NULL) { - if (fs) { - XF86VidModeSwitchToMode(dpy, screen, &deskMode); - XF86VidModeSetViewPort(dpy, screen, 0, 0); - } - } -} - -void X11Window::SwapBuffers() { - glXSwapBuffers(dpy, win); -} - -void X11Window::SetWindowText(const char *text) { - /** - * Tell X to ask the window manager to set the window title. (X - * itself doesn't provide window title functionality.) - */ - XStoreName(dpy, win, text); -} - -bool X11Window::PeekMessages() { - // TODO: implement - return false; -} - -// Taken from sfml code -void X11Window::ProcessEvent(XEvent WinEvent) { - switch (WinEvent.type) { - - case KeyPress : - { - // Get the keysym of the key that has been pressed - static XComposeStatus KeyboardStatus; - char Buffer[32]; - KeySym Sym; - XLookupString(&WinEvent.xkey, Buffer, sizeof(Buffer), &Sym, &KeyboardStatus); - - // Fill the event parameters - sf::Event Evt; - Evt.Type = sf::Event::KeyPressed; - Evt.Key.Code = KeysymToSF(Sym); - Evt.Key.Alt = WinEvent.xkey.state & Mod1Mask; - Evt.Key.Control = WinEvent.xkey.state & ControlMask; - Evt.Key.Shift = WinEvent.xkey.state & ShiftMask; - eventHandler->addEvent(&Evt); - break; - } - // Key up event - case KeyRelease : - { - // Get the keysym of the key that has been pressed - char Buffer[32]; - KeySym Sym; - XLookupString(&WinEvent.xkey, Buffer, 32, &Sym, NULL); - - // Fill the event parameters - sf::Event Evt; - Evt.Type = sf::Event::KeyReleased; - Evt.Key.Code = KeysymToSF(Sym); - Evt.Key.Alt = WinEvent.xkey.state & Mod1Mask; - Evt.Key.Control = WinEvent.xkey.state & ControlMask; - Evt.Key.Shift = WinEvent.xkey.state & ShiftMask; - eventHandler->addEvent(&Evt); - break; - } - } -} - -void X11Window::Update() { - // We just check all of our events here - XEvent event; - // KeySym key; - // int x,y; - // u32 w,h,depth; - - int num_events; - for (num_events = XPending(dpy);num_events > 0;num_events--) { - XNextEvent(dpy, &event); - ProcessEvent(event); - /* case ButtonPress: - case ButtonRelease: - XPutBackEvent(dpy, &event); - break; - case ConfigureNotify: - Window winDummy; - unsigned int borderDummy; - XGetGeometry(dpy, win, &winDummy, &x, &y, - &w, &h, &borderDummy, &depth); - SetSize(w, h); - break; - case ClientMessage: //TODO: We aren't reading this correctly, It could be anything, highest chance is that it's a close event though - Video_Shutdown(); // Calling from here since returning false does nothing - return; - break; - default: - //TODO: Should we put the event back if we don't handle it? - // I think we handle all the needed ones, the rest shouldn't matter - // But to be safe, let's but them back anyway - //XPutBackEvent(dpy, &event); - break; - }*/ - } - - eventHandler->Update(); - updateDim(); -} - -bool X11Window::MakeCurrent() { - - Window winDummy; - unsigned int borderDummy; - int x,y; - u32 w,h,depth; - // connect the glx-context to the window - glXMakeCurrent(dpy, win, ctx); - XGetGeometry(dpy, win, &winDummy, &x, &y, - &w, &h, &borderDummy, &depth); - - NOTICE_LOG("GLWin Depth %d", depth); - if (glXIsDirect(dpy, ctx)) { - ERROR_LOG("you have Direct Rendering!"); - } else { - NOTICE_LOG("no Direct Rendering possible!"); - } - - // better for pad plugin key input (thc) - XSelectInput(dpy, win, ExposureMask | KeyPressMask | ButtonPressMask | - KeyReleaseMask | ButtonReleaseMask | StructureNotifyMask | - EnterWindowMask | LeaveWindowMask | FocusChangeMask); - - return true; -} - -// Taken from SF code -sf::Key::Code X11Window::KeysymToSF(KeySym Sym) { - // First convert to uppercase (to avoid dealing with two different keysyms for the same key) - KeySym Lower, Key; - XConvertCase(Sym, &Lower, &Key); - - switch (Key) - { - case XK_Shift_L : return sf::Key::LShift; - case XK_Shift_R : return sf::Key::RShift; - case XK_Control_L : return sf::Key::LControl; - case XK_Control_R : return sf::Key::RControl; - case XK_Alt_L : return sf::Key::LAlt; - case XK_Alt_R : return sf::Key::RAlt; - case XK_Super_L : return sf::Key::LSystem; - case XK_Super_R : return sf::Key::RSystem; - case XK_Menu : return sf::Key::Menu; - case XK_Escape : return sf::Key::Escape; - case XK_semicolon : return sf::Key::SemiColon; - case XK_slash : return sf::Key::Slash; - case XK_equal : return sf::Key::Equal; - case XK_minus : return sf::Key::Dash; - case XK_bracketleft : return sf::Key::LBracket; - case XK_bracketright : return sf::Key::RBracket; - case XK_comma : return sf::Key::Comma; - case XK_period : return sf::Key::Period; - case XK_dead_acute : return sf::Key::Quote; - case XK_backslash : return sf::Key::BackSlash; - case XK_dead_grave : return sf::Key::Tilde; - case XK_space : return sf::Key::Space; - case XK_Return : return sf::Key::Return; - case XK_KP_Enter : return sf::Key::Return; - case XK_BackSpace : return sf::Key::Back; - case XK_Tab : return sf::Key::Tab; - case XK_Prior : return sf::Key::PageUp; - case XK_Next : return sf::Key::PageDown; - case XK_End : return sf::Key::End; - case XK_Home : return sf::Key::Home; - case XK_Insert : return sf::Key::Insert; - case XK_Delete : return sf::Key::Delete; - case XK_KP_Add : return sf::Key::Add; - case XK_KP_Subtract : return sf::Key::Subtract; - case XK_KP_Multiply : return sf::Key::Multiply; - case XK_KP_Divide : return sf::Key::Divide; - case XK_Pause : return sf::Key::Pause; - case XK_F1 : return sf::Key::F1; - case XK_F2 : return sf::Key::F2; - case XK_F3 : return sf::Key::F3; - case XK_F4 : return sf::Key::F4; - case XK_F5 : return sf::Key::F5; - case XK_F6 : return sf::Key::F6; - case XK_F7 : return sf::Key::F7; - case XK_F8 : return sf::Key::F8; - case XK_F9 : return sf::Key::F9; - case XK_F10 : return sf::Key::F10; - case XK_F11 : return sf::Key::F11; - case XK_F12 : return sf::Key::F12; - case XK_F13 : return sf::Key::F13; - case XK_F14 : return sf::Key::F14; - case XK_F15 : return sf::Key::F15; - case XK_Left : return sf::Key::Left; - case XK_Right : return sf::Key::Right; - case XK_Up : return sf::Key::Up; - case XK_Down : return sf::Key::Down; - case XK_KP_0 : return sf::Key::Numpad0; - case XK_KP_1 : return sf::Key::Numpad1; - case XK_KP_2 : return sf::Key::Numpad2; - case XK_KP_3 : return sf::Key::Numpad3; - case XK_KP_4 : return sf::Key::Numpad4; - case XK_KP_5 : return sf::Key::Numpad5; - case XK_KP_6 : return sf::Key::Numpad6; - case XK_KP_7 : return sf::Key::Numpad7; - case XK_KP_8 : return sf::Key::Numpad8; - case XK_Z : return sf::Key::Z; - case XK_E : return sf::Key::E; - case XK_R : return sf::Key::R; - case XK_T : return sf::Key::T; - case XK_Y : return sf::Key::Y; - case XK_U : return sf::Key::U; - case XK_I : return sf::Key::I; - case XK_O : return sf::Key::O; - case XK_P : return sf::Key::P; - case XK_Q : return sf::Key::Q; - case XK_S : return sf::Key::S; - case XK_D : return sf::Key::D; - case XK_F : return sf::Key::F; - case XK_G : return sf::Key::G; - case XK_H : return sf::Key::H; - case XK_J : return sf::Key::J; - case XK_K : return sf::Key::K; - case XK_L : return sf::Key::L; - case XK_M : return sf::Key::M; - case XK_W : return sf::Key::W; - case XK_X : return sf::Key::X; - case XK_C : return sf::Key::C; - case XK_V : return sf::Key::V; - case XK_B : return sf::Key::B; - case XK_N : return sf::Key::N; - case XK_0 : return sf::Key::Num0; - case XK_1 : return sf::Key::Num1; - case XK_2 : return sf::Key::Num2; - case XK_3 : return sf::Key::Num3; - case XK_4 : return sf::Key::Num4; - case XK_5 : return sf::Key::Num5; - case XK_6 : return sf::Key::Num6; - case XK_7 : return sf::Key::Num7; - case XK_8 : return sf::Key::Num8; - case XK_9 : return sf::Key::Num9; - } - return sf::Key::Code(0); -} diff --git a/Source/Plugins/Plugin_VideoOGL/Src/X11Window.h b/Source/Plugins/Plugin_VideoOGL/Src/X11Window.h deleted file mode 100644 index 46c5bb8f79..0000000000 --- a/Source/Plugins/Plugin_VideoOGL/Src/X11Window.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef _X11WINDOW_H -#define _X11WINDOW_H - -#include "GLWindow.h" -#if defined HAVE_X11 && HAVE_X11 -#include <GL/glxew.h> -#include <GL/gl.h> - -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/keysym.h> - -#include <X11/extensions/xf86vmode.h> -#include <X11/XKBlib.h> - -class X11Window : public GLWindow -{ -public: - int screen; - Window win; - Display *dpy; - GLXContext ctx; - XSetWindowAttributes attr; - Bool fs; - Bool doubleBuffered; - XF86VidModeModeInfo deskMode; - - virtual void SwapBuffers(); - virtual void SetWindowText(const char *text); - virtual bool PeekMessages(); - virtual void Update(); - virtual bool MakeCurrent(); - - static bool valid() { return true; } - ~X11Window(); - X11Window(); - static sf::Key::Code KeysymToSF(KeySym Sym); -private: - void ProcessEvent(XEvent WinEvent); - -}; -#else -class X11Window : public GLWindow -{ -public: - X11Window() {} -}; -#endif -#endif diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index 486ba4a185..4c5cdfcf8b 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -22,29 +22,29 @@ 1.1 Display settings -Internal and fullscreen resolution: Since the only internal resolutions allowed are also -fullscreen resolution allowed by the system there is only need for one resolution setting -that applies to both the internal resolution and the fullscreen resolution. -- Apparently no, someone else doesn't agree +Internal and fullscreen resolution: Since the only internal resolutions allowed +are also fullscreen resolution allowed by the system there is only need for one +resolution setting that applies to both the internal resolution and the +fullscreen resolution. - Apparently no, someone else doesn't agree -Todo: Make the internal resolution option apply instantly, currently only the native and 2x option -applies instantly. To do this we need to be able to change the reinitialize FramebufferManager:Init() -while a game is running. +Todo: Make the internal resolution option apply instantly, currently only the +native and 2x option applies instantly. To do this we need to be able to change +the reinitialize FramebufferManager:Init() while a game is running. 1.2 Screenshots -The screenshots should be taken from the internal representation of the picture regardless of -what the current window size is. Since AA and wireframe is applied together with the picture resizing -this rule is not currently applied to AA or wireframe pictures, they are instead taken from whatever -the window size is. +The screenshots should be taken from the internal representation of the picture +regardless of what the current window size is. Since AA and wireframe is +applied together with the picture resizing this rule is not currently applied +to AA or wireframe pictures, they are instead taken from whatever the window +size is. -Todo: Render AA and wireframe to a separate picture used for the screenshot in addition to the one -for display. +Todo: Render AA and wireframe to a separate picture used for the screenshot in +addition to the one for display. 1.3 AA - Make AA apply instantly during gameplay if possible */ @@ -115,12 +115,10 @@ void GetDllInfo (PLUGIN_INFO* _PluginInfo) _PluginInfo->Type = PLUGIN_TYPE_VIDEO; #ifdef DEBUGFAST sprintf(_PluginInfo->Name, "Dolphin OpenGL (DebugFast)"); +#elif defined _DEBUG + sprintf(_PluginInfo->Name, "Dolphin OpenGL (Debug)"); #else -#ifndef _DEBUG sprintf(_PluginInfo->Name, "Dolphin OpenGL"); -#else - sprintf(_PluginInfo->Name, "Dolphin OpenGL (Debug)"); -#endif #endif } @@ -151,39 +149,21 @@ wxWindow* GetParentedWxWindow(HWND Parent) } #endif -#if defined(HAVE_WX) && HAVE_WX void DllDebugger(HWND _hParent, bool Show) { - if (Show) - { +#if defined(HAVE_WX) && HAVE_WX + if (Show) { if (!m_DebuggerFrame) m_DebuggerFrame = new GFXDebuggerOGL(NULL); - //m_DebuggerFrame = new GFXDebuggerOGL(GetParentedWxWindow(_hParent)); m_DebuggerFrame->Show(); - } - else - { + } else { if (m_DebuggerFrame) m_DebuggerFrame->Hide(); } -} -#else -void DllDebugger(HWND _hParent, bool Show) { } #endif +} -void DllConfig(HWND _hParent) -{ -#if defined(HAVE_WX) && HAVE_WX - //if (!m_ConfigFrame) -if (allowConfigShow) // Prevent user to show more than 1 config window at same time -{ - m_ConfigFrame = new GFXConfigDialogOGL(GetParentedWxWindow(_hParent)); - - //else if (!m_ConfigFrame->GetParent()->IsShown()) - // m_ConfigFrame->Close(true); - -#if defined(_WIN32) - - +#ifdef _WIN32 +void Win32AddResolutions() { // Search for avaliable resolutions DWORD iModeNum = 0; @@ -199,7 +179,8 @@ if (allowConfigShow) // Prevent user to show more than 1 config window at same t char szBuffer[100]; sprintf(szBuffer, "%dx%d", dmi.dmPelsWidth, dmi.dmPelsHeight); std::string strBuffer(szBuffer); - // Create a check loop to check every pointer of resolutions to see if the res is added or not + // Create a check loop to check every pointer of resolutions to see if + // the res is added or not int b = 0; bool resFound = false; while (b < i && !resFound) @@ -209,7 +190,8 @@ if (allowConfigShow) // Prevent user to show more than 1 config window at same t b++; } // Add the resolution - if (!resFound && i < 100) // don't want to overflow resos array. not likely to happen, but you never know. + if (!resFound && i < 100) // don't want to overflow resos array. not + // likely to happen, but you never know. { resos.push_back(strBuffer); i++; @@ -218,11 +200,11 @@ if (allowConfigShow) // Prevent user to show more than 1 config window at same t } ZeroMemory(&dmi, sizeof(dmi)); } - -#elif defined(HAVE_X11) && HAVE_X11 && defined(HAVE_XXF86VM) && HAVE_XXF86VM - - int glxMajorVersion, glxMinorVersion; - int vidModeMajorVersion, vidModeMinorVersion; +} +#elif defined(HAVE_X11) && HAVE_X11 && defined(HAVE_XXF86VM) && HAVE_XXF86VM +void X11AddResolutions() { + int glxMajorVersion, glxMinorVersion; + int vidModeMajorVersion, vidModeMinorVersion; GLWin.dpy = XOpenDisplay(0); glXQueryVersion(GLWin.dpy, &glxMajorVersion, &glxMinorVersion); XF86VidModeQueryVersion(GLWin.dpy, &vidModeMajorVersion, &vidModeMinorVersion); @@ -244,45 +226,47 @@ if (allowConfigShow) // Prevent user to show more than 1 config window at same t char temp[32]; sprintf(temp,"%dx%d", modes[i]->hdisplay, modes[i]->vdisplay); m_ConfigFrame->AddFSReso(temp); - m_ConfigFrame->AddWindowReso(temp);//Add same to Window ones, since they should be nearly all that's needed - px = modes[i]->hdisplay;//Used to remove repeating from different screen depths + m_ConfigFrame->AddWindowReso(temp);//Add same to Window ones, + //since they should be + //nearly all that's needed + px = modes[i]->hdisplay;//Used to remove repeating from + //different screen depths py = modes[i]->vdisplay; } } } XFree(modes); - +} #elif defined(HAVE_COCOA) && HAVE_COCOA - +void CocaAddResolutions() { + CFArrayRef modes; CFRange range; CFDictionaryRef modesDict; CFNumberRef modeValue; - + int modeWidth; int modeHeight; int modeBpp; int modeIndex; int px = 0, py = 0; - - + + modes = CGDisplayAvailableModes(CGMainDisplayID()); - + range.location = 0; range.length = CFArrayGetCount(modes); - - for (modeIndex=0; modeIndex<range.length; modeIndex++) - { + + for (modeIndex=0; modeIndex<range.length; modeIndex++) { modesDict = (CFDictionaryRef)CFArrayGetValueAtIndex(modes, modeIndex); modeValue = (CFNumberRef) CFDictionaryGetValue(modesDict, kCGDisplayWidth); - CFNumberGetValue(modeValue, kCFNumberLongType, &modeWidth); + CFNumberGetValue(modeValue, kCFNumberLongType, &modeWidth); modeValue = (CFNumberRef) CFDictionaryGetValue(modesDict, kCGDisplayHeight); - CFNumberGetValue(modeValue, kCFNumberLongType, &modeHeight); + CFNumberGetValue(modeValue, kCFNumberLongType, &modeHeight); modeValue = (CFNumberRef) CFDictionaryGetValue(modesDict, kCGDisplayBitsPerPixel); - CFNumberGetValue(modeValue, kCFNumberLongType, &modeBpp); - - if (px != modeWidth && py != modeHeight) - { + CFNumberGetValue(modeValue, kCFNumberLongType, &modeBpp); + + if (px != modeWidth && py != modeHeight) { char temp[32]; sprintf(temp,"%dx%d", modeWidth, modeHeight); m_ConfigFrame->AddFSReso(temp); @@ -291,27 +275,34 @@ if (allowConfigShow) // Prevent user to show more than 1 config window at same t py = modeHeight; } } +} +#endif + +void DllConfig(HWND _hParent) +{ +#if defined(HAVE_WX) && HAVE_WX +// Prevent user to show more than 1 config window at same time + if (allowConfigShow) { + m_ConfigFrame = new GFXConfigDialogOGL(GetParentedWxWindow(_hParent)); + +#if defined(_WIN32) + Win32AddResolutions(); +#elif defined(HAVE_X11) && HAVE_X11 && defined(HAVE_XXF86VM) && HAVE_XXF86VM + X11AddResolutions(); +#elif defined(HAVE_COCOA) && HAVE_COCOA + CocaAddResolutions(); #endif - // Check if at least one resolution was found. If we don't and the resolution array is empty // CreateGUIControls() will crash because the array is empty. - if (m_ConfigFrame->arrayStringFor_FullscreenCB.size() == 0) - { + if (m_ConfigFrame->arrayStringFor_FullscreenCB.size() == 0) { m_ConfigFrame->AddFSReso("<No resolutions found>"); m_ConfigFrame->AddWindowReso("<No resolutions found>"); } - - // Only allow one open at a time - //if (!m_ConfigFrame->IsShown()) - //{ - - allowConfigShow = false; - m_ConfigFrame->CreateGUIControls(); - allowConfigShow = m_ConfigFrame->ShowModal() == 1 ? true : false; -} - //} - //else - // m_ConfigFrame->Hide(); + + allowConfigShow = false; + m_ConfigFrame->CreateGUIControls(); + allowConfigShow = m_ConfigFrame->ShowModal() == 1 ? true : false; + } #endif } @@ -319,10 +310,11 @@ void Initialize(void *init) { frameCount = 0; SVideoInitialize *_pVideoInitialize = (SVideoInitialize*)init; - g_VideoInitialize = *(_pVideoInitialize); // Create a shortcut to _pVideoInitialize that can also update it + // Create a shortcut to _pVideoInitialize that can also update it + g_VideoInitialize = *(_pVideoInitialize); InitXFBConvTables(); + g_Config.Load(); - g_Config.GameIniLoad(); #if defined(HAVE_WX) && HAVE_WX @@ -331,8 +323,7 @@ void Initialize(void *init) wxImage::AddHandler( new wxPNGHandler ); #endif - if (!OpenGL_Create(g_VideoInitialize, 640, 480)) // 640x480 will be the default if all else fails - { + if (!OpenGL_Create(g_VideoInitialize, 640, 480)) { g_VideoInitialize.pLog("Renderer::Create failed\n", TRUE); return; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/nGLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/nGLUtil.cpp deleted file mode 100644 index 0cd9e15e04..0000000000 --- a/Source/Plugins/Plugin_VideoOGL/Src/nGLUtil.cpp +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (C) 2003 Dolphin Project. - -// 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, version 2.0. - -// 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 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official SVN repository and contact information can be found at -// http://code.google.com/p/dolphin-emu/ - -#include "Globals.h" -#include "IniFile.h" -#include "svnrev.h" -#include "Config.h" -#include "Render.h" -#include "nGLUtil.h" - -GLWindow *glWin = NULL; - -void OpenGL_SwapBuffers() -{ - glWin->SwapBuffers(); -} - -void OpenGL_SetWindowText(const char *text) -{ - glWin->SetWindowText(text); -} - -unsigned int Callback_PeekMessages() -{ - return glWin->PeekMessages(); -} - -void UpdateFPSDisplay(const char *text) -{ - char temp[512]; - sprintf(temp, "SVN R%s: GL: %s", SVN_REV_STR, text); - OpenGL_SetWindowText(temp); - -} - -// ======================================================================================= -// Create window. Called from main.cpp -bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int width, int height) -{ - g_VideoInitialize.pPeekMessages = &Callback_PeekMessages; - g_VideoInitialize.pUpdateFPSDisplay = &UpdateFPSDisplay; - - if (strncasecmp(g_Config.iBackend, "sdl", 10) == 0) - glWin = new SDLWindow(); - else if (strncasecmp(g_Config.iBackend, "x11", 10) == 0) - glWin = new X11Window(); - else if (strncasecmp(g_Config.iBackend, "wxgl", 10) == 0) - glWin = new WXGLWindow(); - else if (strncasecmp(g_Config.iBackend, "windows", 10) == 0) - glWin = new Win32Window(); - else - PanicAlert("Invalid backend %s", g_Config.iBackend); - - if (! glWin) - return false; - - glWin->SetEventHandler((EventHandler *)globals->eventHandler); - return true; -} - -bool OpenGL_MakeCurrent() -{ - return glWin->MakeCurrent(); -} - - -// ======================================================================================= -// Update window width, size and etc. Called from Render.cpp and XFB.cpp -// ---------------- -void OpenGL_Update() -{ - glWin->Update(); -} - - -// ======================================================================================= -// Close plugin -// ---------------- -void OpenGL_Shutdown() -{ - delete glWin; -} - -u32 OpenGL_GetWidth() { - return glWin->GetXwin(); -} - -u32 OpenGL_GetHeight() { - return glWin->GetYwin(); -} - -void OpenGL_SetSize(u32 width, u32 height) { - glWin->SetWinSize(width, height); -} - -int OpenGL_GetXoff() { - return glWin->GetXoff(); -} - -int OpenGL_GetYoff() { - return glWin->GetYoff(); -} - -float OpenGL_GetXmax() { - return glWin->GetXmax(); -} - -float OpenGL_GetYmax() { - return glWin->GetYmax(); -} - -void OpenGL_AddBackends(ConfigDialog *frame) { - if(SDLWindow::valid()) - frame->AddRenderBackend("SDL"); - if(X11Window::valid()) - frame->AddRenderBackend("X11"); - if(WXGLWindow::valid()) - frame->AddRenderBackend("WXGL"); - if(Win32Window::valid()) - frame->AddRenderBackend("Windows"); // Not "Win32" because retarded people will ask where "win64" is... -} - -void OpenGL_AddResolutions(ConfigDialog *frame) { - // TODO get resolution iter -} diff --git a/Source/Plugins/Plugin_VideoOGL/Src/nGLUtil.h b/Source/Plugins/Plugin_VideoOGL/Src/nGLUtil.h deleted file mode 100644 index 46ed6906ce..0000000000 --- a/Source/Plugins/Plugin_VideoOGL/Src/nGLUtil.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2003 Dolphin Project. - -// 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, version 2.0. - -// 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 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official SVN repository and contact information can be found at -// http://code.google.com/p/dolphin-emu/ - -#ifndef _NGLINIT_H -#define _NGLINIT_H - -#include "Config.h" -#include "pluginspecs_video.h" -#include "GUI/ConfigDlg.h" -#include "GLWindow.h" -// backends -#include "SDLWindow.h" -#include "X11Window.h" -#include "WXGLWindow.h" -#include "Win32Window.h" - -#ifndef GL_DEPTH24_STENCIL8_EXT // allows FBOs to support stencils -#define GL_DEPTH_STENCIL_EXT 0x84F9 -#define GL_UNSIGNED_INT_24_8_EXT 0x84FA -#define GL_DEPTH24_STENCIL8_EXT 0x88F0 -#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 -#endif - -#define GL_REPORT_ERROR() { err = glGetError(); if( err != GL_NO_ERROR ) { ERROR_LOG("%s:%d: gl error 0x%x\n", __FILE__, (int)__LINE__, err); HandleGLError(); } } - -#if defined(_DEBUG) || defined(DEBUGFAST) -#define GL_REPORT_ERRORD() { GLenum err = glGetError(); if( err != GL_NO_ERROR ) { ERROR_LOG("%s:%d: gl error 0x%x\n", __FILE__, (int)__LINE__, err); HandleGLError(); } } -#else -#define GL_REPORT_ERRORD() -#endif - -void OpenGL_AddBackends(ConfigDialog *frame); -void OpenGL_AddResolutions(ConfigDialog *frame); - -// TODO old interface removal -bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _width, int _height); -bool OpenGL_MakeCurrent(); -void OpenGL_SwapBuffers(); -void OpenGL_SetWindowText(const char *text); -void OpenGL_Shutdown(); -void OpenGL_Update(); -u32 OpenGL_GetWidth(); -u32 OpenGL_GetHeight(); -void OpenGL_SetSize(u32 width, u32 height); -int OpenGL_GetXoff(); -int OpenGL_GetYoff(); -float OpenGL_GetXmax(); -float OpenGL_GetYmax(); - -#endif diff --git a/Source/Plugins/Plugin_VideoOGL/Src/nmain.cpp b/Source/Plugins/Plugin_VideoOGL/Src/nmain.cpp deleted file mode 100644 index 2ce28acf0c..0000000000 --- a/Source/Plugins/Plugin_VideoOGL/Src/nmain.cpp +++ /dev/null @@ -1,300 +0,0 @@ -// Copyright (C) 2003 Dolphin Project. - -// 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, version 2.0. - -// 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 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official SVN repository and contact information can be found at -// http://code.google.com/p/dolphin-emu/ - -#include "Globals.h" - -#if defined(HAVE_WX) && HAVE_WX -#include "GUI/ConfigDlg.h" -#include "Debugger/Debugger.h" // for the CDebugger class -#endif - -#include "Config.h" -#include "LookUpTables.h" -#include "ImageWrite.h" -#include "Render.h" -#include "nGLUtil.h" -#include "Fifo.h" -#include "OpcodeDecoding.h" -#include "TextureMngr.h" -#include "BPStructs.h" -#include "VertexLoader.h" -#include "VertexLoaderManager.h" -#include "VertexManager.h" -#include "PixelShaderCache.h" -#include "PixelShaderManager.h" -#include "VertexShaderCache.h" -#include "VertexShaderManager.h" -#include "XFB.h" -#include "XFBConvert.h" -#include "TextureConverter.h" - -#include "VideoState.h" - -SVideoInitialize g_VideoInitialize; -PLUGIN_GLOBALS* globals; - - -// Nasty stuff which win32 needs for wxw - -#if defined(_WIN32) && defined(HAVE_WX) && HAVE_WX -HINSTANCE g_hInstance; - -class wxDLLApp : public wxApp -{ - bool OnInit() - { - return true; - } -}; -IMPLEMENT_APP_NO_MAIN(wxDLLApp) - -WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst); - -BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle - DWORD dwReason, // reason called - LPVOID lpvReserved) // reserved -{ - switch (dwReason) - { - case DLL_PROCESS_ATTACH: - { // Use wxInitialize() if you don't want GUI instead of the following 12 lines - wxSetInstance((HINSTANCE)hinstDLL); - int argc = 0; - char **argv = NULL; - wxEntryStart(argc, argv); - if ( !wxTheApp || !wxTheApp->CallOnInit() ) - return FALSE; - } - break; - - case DLL_PROCESS_DETACH: - wxEntryCleanup(); // Use wxUninitialize() if you don't want GUI - break; - default: - break; - } - - g_hInstance = hinstDLL; - return TRUE; -} -#endif - - -/* Create debugging window. There's currently a strange crash that occurs whe a game is loaded - if the OpenGL plugin was loaded before. I'll try to fix that. Currently you may have to - clsoe the window if it has auto started, and then restart it after the dll has loaded - for the purpose of the game. At that point there is no need to use the same dll instance - as the one that is rendering the game. However, that could be done. */ - -#if defined(HAVE_WX) && HAVE_WX -CDebugger *m_frame; -void DllDebugger(HWND _hParent, bool Show) -{ - if(!m_frame && Show) - { - m_frame = new CDebugger(NULL); - m_frame->Show(); - } - else if (m_frame && !Show) - { - if(m_frame->Close()) - m_frame = NULL; - } -} - -void DoDllDebugger(){} -#else -void DllDebugger(HWND _hParent, bool Show) { } -void DoDllDebugger() { } -#endif - - -void GetDllInfo (PLUGIN_INFO* _PluginInfo) -{ - _PluginInfo->Version = 0x0100; - _PluginInfo->Type = PLUGIN_TYPE_VIDEO; -#ifdef DEBUGFAST - sprintf(_PluginInfo->Name, "Dolphin OpenGL (DebugFast)"); -#elif defined _DEBUG - sprintf(_PluginInfo->Name, "Dolphin OpenGL (Debug)"); -#else - sprintf(_PluginInfo->Name, "Dolphin OpenGL"); -#endif -} - -void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals) { - globals = _pPluginGlobals; -} - -void DllConfig(HWND _hParent) -{ - wxWindow * win = new wxWindow(); -#ifdef _WIN32 - win->SetHWND((WXHWND)_hParent); - win->AdoptAttributesFromHWND(); -#endif - //win->Reparent(wxGetApp().GetTopWindow()); - ConfigDialog *frame = new ConfigDialog(win); - OpenGL_AddBackends(frame); - OpenGL_AddResolutions(frame); - frame->ShowModal(); -} - -void Initialize(void *init) -{ - frameCount = 0; - SVideoInitialize *_pVideoInitialize = (SVideoInitialize*)init; - g_VideoInitialize = *(_pVideoInitialize); // Create a shortcut to _pVideoInitialize that can also update it - - InitLUTs(); - InitXFBConvTables(); - g_Config.Load(); - - if (!OpenGL_Create(g_VideoInitialize, 640, 480)) { //640x480 will be the default if all else fails// - g_VideoInitialize.pLog("Renderer::Create failed\n", TRUE); - return; - } - _pVideoInitialize->pPeekMessages = g_VideoInitialize.pPeekMessages; - _pVideoInitialize->pUpdateFPSDisplay = g_VideoInitialize.pUpdateFPSDisplay; - _pVideoInitialize->pWindowHandle = g_VideoInitialize.pWindowHandle; - - Renderer::AddMessage("Dolphin OpenGL Video Plugin" ,5000); -} - -void DoState(unsigned char **ptr, int mode) { -#ifndef _WIN32 - OpenGL_MakeCurrent(); -#endif - // Clear all caches that touch RAM - TextureMngr::Invalidate(); - // DisplayListManager::Invalidate(); - - VertexLoaderManager::MarkAllDirty(); - - PointerWrap p(ptr, mode); - VideoCommon_DoState(p); - - // Refresh state. - if (mode == PointerWrap::MODE_READ) - BPReload(); -} - -// This is called after Video_Initialize() from the Core -void Video_Prepare(void) -{ - OpenGL_MakeCurrent(); - if (!Renderer::Init()) { - g_VideoInitialize.pLog("Renderer::Create failed\n", TRUE); - PanicAlert("Can't create opengl renderer. You might be missing some required opengl extensions, check the logs for more info"); - exit(1); - } - - TextureMngr::Init(); - - BPInit(); - VertexManager::Init(); - Fifo_Init(); // must be done before OpcodeDecoder_Init() - OpcodeDecoder_Init(); - VertexShaderCache::Init(); - VertexShaderManager::Init(); - PixelShaderCache::Init(); - PixelShaderManager::Init(); - GL_REPORT_ERRORD(); - VertexLoaderManager::Init(); - TextureConverter::Init(); -} - -void Shutdown(void) -{ - TextureConverter::Shutdown(); - VertexLoaderManager::Shutdown(); - VertexShaderCache::Shutdown(); - VertexShaderManager::Shutdown(); - PixelShaderManager::Shutdown(); - PixelShaderCache::Shutdown(); - Fifo_Shutdown(); - VertexManager::Shutdown(); - TextureMngr::Shutdown(); - OpcodeDecoder_Shutdown(); - Renderer::Shutdown(); - OpenGL_Shutdown(); -} - -void Video_Stop(void) -{ - Fifo_Stop(); -} - -void Video_EnterLoop() -{ - Fifo_EnterLoop(g_VideoInitialize); -} - -bool ScreenShot(TCHAR *File) -{ - char str[64]; - int left = 200, top = 15; - sprintf(str, "Dolphin OpenGL"); - - Renderer::ResetGLState(); - Renderer::RenderText(str, left+1, top+1, 0xff000000); - Renderer::RenderText(str, left, top, 0xffc0ffff); - Renderer::RestoreGLState(); - - if (Renderer::SaveRenderTarget(File, 0)) { - char msg[255]; - sprintf(msg, "saved %s\n", File); - Renderer::AddMessage(msg, 500); - return true; - } - return false; -} - -unsigned int Video_Screenshot(TCHAR* _szFilename) -{ - if (ScreenShot(_szFilename)) - return TRUE; - - return FALSE; -} - -void Video_AddMessage(const char* pstr, u32 milliseconds) -{ - Renderer::AddMessage(pstr,milliseconds); -} - -void Video_UpdateXFB(u8* _pXFB, u32 _dwWidth, u32 _dwHeight, s32 _dwYOffset, bool scheduling) -{ - if(g_Config.bUseXFB && XFB_isInit()) - { - if (scheduling) // from CPU in DC without fifo&CP (some 2D homebrews) - { - XFB_SetUpdateArgs(_pXFB, _dwWidth, _dwHeight, _dwYOffset); - g_XFBUpdateRequested = TRUE; - } - else - { - if (_pXFB) // from CPU in SC mode - XFB_Draw(_pXFB, _dwWidth, _dwHeight, _dwYOffset); - else // from GP in DC without fifo&CP (some 2D homebrews) - { - XFB_Draw(); - g_XFBUpdateRequested = FALSE; - } - } - } -} |
