From daf8703fc9964b0fb196476c741a791d3997d901 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 24 Jun 2018 21:26:32 +0200 Subject: [PATCH] - split up Win32's SystemGLFrameBuffer as well to get the shareable parts between OpenGL and Vulkan into a base class. --- src/CMakeLists.txt | 1 + src/gl/system/gl_framebuffer.cpp | 1 - src/win32/gl_sysfb.cpp | 321 +------------------------------ src/win32/gl_sysfb.h | 42 +--- src/win32/win32basevideo.cpp | 3 +- src/win32/win32basevideo.h | 1 + 6 files changed, 10 insertions(+), 359 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 78316fbfe4..0f578c4c56 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -496,6 +496,7 @@ set( PLAT_WIN32_SOURCES win32/i_specialpaths.cpp win32/st_start.cpp win32/gl_sysfb.cpp + win32/base_sysfb.cpp win32/win32basevideo.cpp win32/win32glvideo.cpp ) set( PLAT_POSIX_SOURCES diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index c30f22c63d..6f0171b0ce 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -114,7 +114,6 @@ void OpenGLFrameBuffer::InitializeState() } gl_LoadExtensions(); - Super::InitializeState(); if (first) { diff --git a/src/win32/gl_sysfb.cpp b/src/win32/gl_sysfb.cpp index 868ea19e58..5229408585 100644 --- a/src/win32/gl_sysfb.cpp +++ b/src/win32/gl_sysfb.cpp @@ -57,21 +57,8 @@ extern HWND Window; -extern "C" { - __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; - __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; -} - PFNWGLSWAPINTERVALEXTPROC myWglSwapIntervalExtProc; -CVAR(Int, vid_adapter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) - -CVAR(Int, win_x, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -CVAR(Int, win_y, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -CVAR(Int, win_w, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -CVAR(Int, win_h, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -CVAR(Bool, win_maximized, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) - // For broadest GL compatibility, require user to explicitly enable quad-buffered stereo mode. // Setting vr_enable_quadbuffered_stereo does not automatically invoke quad-buffered stereo, // but makes it possible for subsequent "vr_mode 7" to invoke quad-buffered stereo @@ -97,218 +84,14 @@ EXTERN_CVAR(Int, vid_defheight) // //========================================================================== - void SystemGLFrameBuffer::GetCenteredPos(int in_w, int in_h, int &winx, int &winy, int &winw, int &winh, int &scrwidth, int &scrheight) +SystemGLFrameBuffer::SystemGLFrameBuffer(void *hMonitor, bool fullscreen) : SystemBaseFrameBuffer(hMonitor, fullscreen) { - DEVMODE displaysettings; - RECT rect; - int cx, cy; - - memset(&displaysettings, 0, sizeof(displaysettings)); - displaysettings.dmSize = sizeof(displaysettings); - EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &displaysettings); - scrwidth = (int)displaysettings.dmPelsWidth; - scrheight = (int)displaysettings.dmPelsHeight; - GetWindowRect(Window, &rect); - cx = scrwidth / 2; - cy = scrheight / 2; - if (in_w > 0) winw = in_w; - else winw = rect.right - rect.left; - if (in_h > 0) winh = in_h; - else winh = rect.bottom - rect.top; - winx = cx - winw / 2; - winy = cy - winh / 2; -} - -//========================================================================== -// -// -// -//========================================================================== - -void SystemGLFrameBuffer::KeepWindowOnScreen(int &winx, int &winy, int winw, int winh, int scrwidth, int scrheight) -{ - // If the window is too large to fit entirely on the screen, at least - // keep its upperleft corner visible. - if (winx + winw > scrwidth) - { - winx = scrwidth - winw; - } - if (winx < 0) - { - winx = 0; - } - if (winy + winh > scrheight) - { - winy = scrheight - winh; - } - if (winy < 0) - { - winy = 0; - } -} - -//========================================================================== -// -// -// -//========================================================================== - -void SystemGLFrameBuffer::SaveWindowedPos() -{ - // Don't save if we were run with the -0 option. - if (Args->CheckParm("-0")) - { - return; - } - // Make sure we only save the window position if it's not fullscreen. - static const int WINDOW_STYLE = WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX; - if ((GetWindowLong(Window, GWL_STYLE) & WINDOW_STYLE) == WINDOW_STYLE) - { - RECT wrect; - - if (GetWindowRect(Window, &wrect)) - { - // If (win_x,win_y) specify to center the window, don't change them - // if the window is still centered. - if (win_x < 0 || win_y < 0 || win_w < 0 || win_h < 0) - { - int winx, winy, winw, winh, scrwidth, scrheight; - - GetCenteredPos(win_w, win_h, winx, winy, winw, winh, scrwidth, scrheight); - KeepWindowOnScreen(winx, winy, winw, winh, scrwidth, scrheight); - if (win_x < 0 && winx == wrect.left) - { - wrect.left = win_x; - } - if (win_y < 0 && winy == wrect.top) - { - wrect.top = win_y; - } - wrect.right = winw + wrect.left; - wrect.bottom = winh + wrect.top; - } - - win_x = wrect.left; - win_y = wrect.top; - win_w = wrect.right - wrect.left; - win_h = wrect.bottom - wrect.top; - } - - win_maximized = IsZoomed(Window) == TRUE; - } -} - -//========================================================================== -// -// -// -//========================================================================== - -void SystemGLFrameBuffer::RestoreWindowedPos() -{ - int winx, winy, winw, winh, scrwidth, scrheight; - - GetCenteredPos(win_w, win_h, winx, winy, winw, winh, scrwidth, scrheight); - - // Just move to (0,0) if we were run with the -0 option. - if (Args->CheckParm("-0")) - { - winx = winy = 0; - } - else - { - if (win_x >= 0) - { - winx = win_x; - } - if (win_y >= 0) - { - winy = win_y; - } - KeepWindowOnScreen(winx, winy, winw, winh, scrwidth, scrheight); - } - SetWindowPos(Window, nullptr, winx, winy, winw, winh, SWP_NOZORDER | SWP_FRAMECHANGED); - - if (win_maximized && !Args->CheckParm("-0")) - ShowWindow(Window, SW_MAXIMIZE); -} - -//========================================================================== -// -// -// -//========================================================================== - -void SystemGLFrameBuffer::PositionWindow(bool fullscreen) -{ - RECT r; - LONG style, exStyle; - - RECT monRect; - - if (!m_Fullscreen) SaveWindowedPos(); - if (m_Monitor) - { - MONITORINFOEX mi; - mi.cbSize = sizeof mi; - - if (GetMonitorInfo(HMONITOR(m_Monitor), &mi)) - { - strcpy(m_displayDeviceNameBuffer, mi.szDevice); - m_displayDeviceName = m_displayDeviceNameBuffer; - monRect = mi.rcMonitor; - } - } - - ShowWindow(Window, SW_SHOW); - - GetWindowRect(Window, &r); - style = WS_VISIBLE | WS_CLIPSIBLINGS; - exStyle = 0; - - if (fullscreen) - style |= WS_POPUP; - else - { - style |= WS_OVERLAPPEDWINDOW; - exStyle |= WS_EX_WINDOWEDGE; - } - - SetWindowLong(Window, GWL_STYLE, style); - SetWindowLong(Window, GWL_EXSTYLE, exStyle); - - m_Fullscreen = fullscreen; - if (fullscreen) - { - SetWindowPos(Window, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - MoveWindow(Window, monRect.left, monRect.top, monRect.right-monRect.left, monRect.bottom-monRect.top, FALSE); - - // And now, seriously, it IS in the right place. Promise. - } - else - { - RestoreWindowedPos(); - } - SetSize(GetClientWidth(), GetClientHeight()); -} - -//========================================================================== -// -// -// -//========================================================================== - -SystemGLFrameBuffer::SystemGLFrameBuffer(void *hMonitor, bool fullscreen) : DFrameBuffer(vid_defwidth, vid_defheight) -{ - m_Monitor = hMonitor; - m_displayDeviceName = 0; - PositionWindow(fullscreen); - if (!static_cast(Video)->InitHardware(Window, 0)) { I_FatalError("Unable to initialize OpenGL"); return; } + HDC hDC = GetDC(Window); const char *wglext = nullptr; @@ -334,91 +117,10 @@ SystemGLFrameBuffer::SystemGLFrameBuffer(void *hMonitor, bool fullscreen) : DFra SwapInterval = -1; } } - - m_supportsGamma = !!GetDeviceGammaRamp(hDC, (void *)m_origGamma); ReleaseDC(Window, hDC); enable_quadbuffered = vr_enable_quadbuffered; } -//========================================================================== -// -// -// -//========================================================================== - -SystemGLFrameBuffer::~SystemGLFrameBuffer() -{ - ResetGammaTable(); - SaveWindowedPos(); - - ShowWindow (Window, SW_SHOW); - SetWindowLong(Window, GWL_STYLE, WS_VISIBLE | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW); - SetWindowLong(Window, GWL_EXSTYLE, WS_EX_WINDOWEDGE); - SetWindowPos(Window, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - I_GetEvent(); - - static_cast(Video)->Shutdown(); -} - - -//========================================================================== -// -// -// -//========================================================================== - -void SystemGLFrameBuffer::InitializeState() -{ -} - -//========================================================================== -// -// -// -//========================================================================== - -void SystemGLFrameBuffer::ResetGammaTable() -{ - if (m_supportsGamma) - { - HDC hDC = GetDC(Window); - SetDeviceGammaRamp(hDC, (void *)m_origGamma); - ReleaseDC(Window, hDC); - } -} - -void SystemGLFrameBuffer::SetGammaTable(uint16_t *tbl) -{ - if (m_supportsGamma) - { - HDC hDC = GetDC(Window); - SetDeviceGammaRamp(hDC, (void *)tbl); - ReleaseDC(Window, hDC); - } -} - -//========================================================================== -// -// -// -//========================================================================== - -bool SystemGLFrameBuffer::IsFullscreen() -{ - return m_Fullscreen; -} - -//========================================================================== -// -// -// -//========================================================================== - -void SystemGLFrameBuffer::ToggleFullscreen(bool yes) -{ - PositionWindow(yes); -} - //========================================================================== // // @@ -442,22 +144,3 @@ void SystemGLFrameBuffer::SwapBuffers() ::SwapBuffers(static_cast(Video)->m_hDC); } -//========================================================================== -// -// -// -//========================================================================== - -int SystemGLFrameBuffer::GetClientWidth() -{ - RECT rect = { 0 }; - GetClientRect(Window, &rect); - return rect.right - rect.left; -} - -int SystemGLFrameBuffer::GetClientHeight() -{ - RECT rect = { 0 }; - GetClientRect(Window, &rect); - return rect.bottom - rect.top; -} diff --git a/src/win32/gl_sysfb.h b/src/win32/gl_sysfb.h index fe098fcbd9..52afbf040d 100644 --- a/src/win32/gl_sysfb.h +++ b/src/win32/gl_sysfb.h @@ -1,54 +1,20 @@ -#ifndef __WIN32_GL_SYSFB_H__ -#define __WIN32_GL_SYSFB_H__ +#pragma once -#include "v_video.h" +#include "base_sysfb.h" -class SystemGLFrameBuffer : public DFrameBuffer +class SystemGLFrameBuffer : public SystemBaseFrameBuffer { - typedef DFrameBuffer Super; - - void SaveWindowedPos(); - void RestoreWindowedPos(); + typedef SystemBaseFrameBuffer Super; public: SystemGLFrameBuffer() {} // Actually, hMonitor is a HMONITOR, but it's passed as a void * as there // look to be some cross-platform bits in the way. SystemGLFrameBuffer(void *hMonitor, bool fullscreen); - virtual ~SystemGLFrameBuffer(); void SetVSync (bool vsync); void SwapBuffers(); - int GetClientWidth() override; - int GetClientHeight() override; - - bool IsFullscreen() override; - void ToggleFullscreen(bool yes) override; - - void InitializeState(); - protected: - - void GetCenteredPos(int in_w, int in_h, int &winx, int &winy, int &winw, int &winh, int &scrwidth, int &scrheight); - void KeepWindowOnScreen(int &winx, int &winy, int winw, int winh, int scrwidth, int scrheight); - - void PositionWindow(bool fullscreen); - - void ResetGammaTable(); - void SetGammaTable(uint16_t * tbl); - - float m_Gamma, m_Brightness, m_Contrast; - uint16_t m_origGamma[768]; - bool m_supportsGamma; - bool m_Fullscreen; - char m_displayDeviceNameBuffer[32/*CCHDEVICENAME*/]; // do not use windows.h constants here! - char *m_displayDeviceName; - void *m_Monitor; int SwapInterval; - - friend class Win32GLVideo; - }; - -#endif // __WIN32_GL_SYSFB_H__ diff --git a/src/win32/win32basevideo.cpp b/src/win32/win32basevideo.cpp index 25a97811d8..a444b7da23 100644 --- a/src/win32/win32basevideo.cpp +++ b/src/win32/win32basevideo.cpp @@ -53,7 +53,8 @@ #include "gl/system/gl_framebuffer.h" -EXTERN_CVAR(Int, vid_adapter) +CVAR(Int, vid_adapter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) + EXTERN_CVAR(Bool, fullscreen) EXTERN_CVAR(Bool, vr_enable_quadbuffered) diff --git a/src/win32/win32basevideo.h b/src/win32/win32basevideo.h index 5897febe3a..258e564444 100644 --- a/src/win32/win32basevideo.h +++ b/src/win32/win32basevideo.h @@ -28,5 +28,6 @@ protected: void GetDisplayDeviceName(); public: + virtual void Shutdown() = 0; };