From 1519514dd7d06fa7262d818222033067d8e338be Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 24 Jun 2018 20:47:00 +0200 Subject: [PATCH] - split Win32GLVideo in two so that the OpenGL independent part can be used for Vulkan as well. --- src/CMakeLists.txt | 3 +- src/win32/hardware.cpp | 3 +- src/win32/win32basevideo.cpp | 210 +++++++++++++++++++++++++++++++++++ src/win32/win32basevideo.h | 32 ++++++ src/win32/win32gliface.cpp | 5 - src/win32/win32glvideo.cpp | 154 +------------------------ src/win32/win32glvideo.h | 23 +--- 7 files changed, 251 insertions(+), 179 deletions(-) create mode 100644 src/win32/win32basevideo.cpp create mode 100644 src/win32/win32basevideo.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d77e733e0..d7c3bd105 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -496,7 +496,8 @@ set( PLAT_WIN32_SOURCES win32/i_specialpaths.cpp win32/st_start.cpp win32/win32gliface.cpp - win32/win32video.cpp ) + win32/win32basevideo.cpp + win32/win32glvideo.cpp ) set( PLAT_POSIX_SOURCES posix/i_cd.cpp posix/i_steam.cpp ) diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index 5c665e781..6c4fd007b 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -43,6 +43,7 @@ #include "doomstat.h" #include "m_argv.h" #include "version.h" +#include "win32glvideo.h" #include "swrenderer/r_swrenderer.h" EXTERN_CVAR (Bool, fullscreen) @@ -124,7 +125,7 @@ void I_InitGraphics () // are the active app. Huh? } - Video = gl_CreateVideo(); + Video = new Win32GLVideo(); if (Video == NULL) I_FatalError ("Failed to initialize display"); diff --git a/src/win32/win32basevideo.cpp b/src/win32/win32basevideo.cpp new file mode 100644 index 000000000..25a97811d --- /dev/null +++ b/src/win32/win32basevideo.cpp @@ -0,0 +1,210 @@ +/* +** win32video.cpp +** Code to let ZDoom draw to the screen +** +**--------------------------------------------------------------------------- +** Copyright 1998-2006 Randy Heit +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ + +#include +#include +#include "wglext.h" + +#include "gl_sysfb.h" +#include "hardware.h" +#include "x86.h" +#include "templates.h" +#include "version.h" +#include "c_console.h" +#include "v_video.h" +#include "i_input.h" +#include "i_system.h" +#include "doomstat.h" +#include "v_text.h" +#include "m_argv.h" +#include "doomerrors.h" +#include "Win32BaseVideo.h" + +#include "gl/system/gl_framebuffer.h" + +EXTERN_CVAR(Int, vid_adapter) +EXTERN_CVAR(Bool, fullscreen) +EXTERN_CVAR(Bool, vr_enable_quadbuffered) + +//========================================================================== +// +// +// +//========================================================================== + +Win32BaseVideo::Win32BaseVideo() +{ + I_SetWndProc(); + + GetDisplayDeviceName(); +} + +//========================================================================== +// +// +// +//========================================================================== + +struct MonitorEnumState +{ + int curIdx; + HMONITOR hFoundMonitor; +}; + +static BOOL CALLBACK GetDisplayDeviceNameMonitorEnumProc(HMONITOR hMonitor, HDC, LPRECT, LPARAM dwData) +{ + MonitorEnumState *state = reinterpret_cast(dwData); + + MONITORINFOEX mi; + mi.cbSize = sizeof mi; + GetMonitorInfo(hMonitor, &mi); + + // This assumes the monitors are returned by EnumDisplayMonitors in the + // order they're found in the Direct3D9 adapters list. Fingers crossed... + if (state->curIdx == vid_adapter) + { + state->hFoundMonitor = hMonitor; + + // Don't stop enumeration; this makes EnumDisplayMonitors fail. I like + // proper fails. + } + + ++state->curIdx; + + return TRUE; +} + +//========================================================================== +// +// +// +//========================================================================== + +void Win32BaseVideo::GetDisplayDeviceName() +{ + // If anything goes wrong, anything at all, everything uses the primary + // monitor. + m_DisplayDeviceName = 0; + m_hMonitor = 0; + + MonitorEnumState mes; + + mes.curIdx = 1; + mes.hFoundMonitor = 0; + + // Could also use EnumDisplayDevices, I guess. That might work. + if (EnumDisplayMonitors(0, 0, &GetDisplayDeviceNameMonitorEnumProc, LPARAM(&mes))) + { + if (mes.hFoundMonitor) + { + MONITORINFOEX mi; + + mi.cbSize = sizeof mi; + + if (GetMonitorInfo(mes.hFoundMonitor, &mi)) + { + strcpy(m_DisplayDeviceBuffer, mi.szDevice); + m_DisplayDeviceName = m_DisplayDeviceBuffer; + + m_hMonitor = mes.hFoundMonitor; + } + } + } +} + +//========================================================================== +// +// +// +//========================================================================== + +struct DumpAdaptersState +{ + unsigned index; + char *displayDeviceName; +}; + +static BOOL CALLBACK DumpAdaptersMonitorEnumProc(HMONITOR hMonitor, HDC, LPRECT, LPARAM dwData) +{ + DumpAdaptersState *state = reinterpret_cast(dwData); + + MONITORINFOEX mi; + mi.cbSize = sizeof mi; + + char moreinfo[64] = ""; + + bool active = true; + + if (GetMonitorInfo(hMonitor, &mi)) + { + bool primary = !!(mi.dwFlags & MONITORINFOF_PRIMARY); + + mysnprintf(moreinfo, countof(moreinfo), " [%ldx%ld @ (%ld,%ld)]%s", + mi.rcMonitor.right - mi.rcMonitor.left, + mi.rcMonitor.bottom - mi.rcMonitor.top, + mi.rcMonitor.left, mi.rcMonitor.top, + primary ? " (Primary)" : ""); + + if (!state->displayDeviceName && !primary) + active = false;//primary selected, but this ain't primary + else if (state->displayDeviceName && strcmp(state->displayDeviceName, mi.szDevice) != 0) + active = false;//this isn't the selected one + } + + Printf("%s%u. %s\n", + active ? TEXTCOLOR_BOLD : "", + state->index, + moreinfo); + + ++state->index; + + return TRUE; +} + +//========================================================================== +// +// +// +//========================================================================== + +void Win32BaseVideo::DumpAdapters() +{ + DumpAdaptersState das; + + das.index = 1; + das.displayDeviceName = m_DisplayDeviceName; + + EnumDisplayMonitors(0, 0, DumpAdaptersMonitorEnumProc, LPARAM(&das)); +} + diff --git a/src/win32/win32basevideo.h b/src/win32/win32basevideo.h new file mode 100644 index 000000000..5897febe3 --- /dev/null +++ b/src/win32/win32basevideo.h @@ -0,0 +1,32 @@ +#pragma once + +#include "v_video.h" + +//========================================================================== +// +// +// +//========================================================================== + +class Win32BaseVideo : public IVideo +{ +public: + Win32BaseVideo(); + + void DumpAdapters(); + + HDC m_hDC; + +protected: + HMODULE hmRender; + + char m_DisplayDeviceBuffer[CCHDEVICENAME]; + char *m_DisplayDeviceName; + HMONITOR m_hMonitor; + + HWND m_Window; + + void GetDisplayDeviceName(); +public: + +}; diff --git a/src/win32/win32gliface.cpp b/src/win32/win32gliface.cpp index ff814f8d1..868ea19e5 100644 --- a/src/win32/win32gliface.cpp +++ b/src/win32/win32gliface.cpp @@ -461,8 +461,3 @@ int SystemGLFrameBuffer::GetClientHeight() GetClientRect(Window, &rect); return rect.bottom - rect.top; } - -IVideo *gl_CreateVideo() -{ - return new Win32GLVideo(0); -} diff --git a/src/win32/win32glvideo.cpp b/src/win32/win32glvideo.cpp index 6b3796a98..2da91f9e2 100644 --- a/src/win32/win32glvideo.cpp +++ b/src/win32/win32glvideo.cpp @@ -73,96 +73,9 @@ PFNWGLCREATECONTEXTATTRIBSARBPROC myWglCreateContextAttribsARB; // //========================================================================== -Win32GLVideo::Win32GLVideo(int parm) +Win32GLVideo::Win32GLVideo() { - I_SetWndProc(); - - GetDisplayDeviceName(); SetPixelFormat(); - -} - -//========================================================================== -// -// -// -//========================================================================== - -Win32GLVideo::~Win32GLVideo() -{ -} - -//========================================================================== -// -// -// -//========================================================================== - -struct MonitorEnumState -{ - int curIdx; - HMONITOR hFoundMonitor; -}; - -static BOOL CALLBACK GetDisplayDeviceNameMonitorEnumProc(HMONITOR hMonitor, HDC, LPRECT, LPARAM dwData) -{ - MonitorEnumState *state = reinterpret_cast(dwData); - - MONITORINFOEX mi; - mi.cbSize = sizeof mi; - GetMonitorInfo(hMonitor, &mi); - - // This assumes the monitors are returned by EnumDisplayMonitors in the - // order they're found in the Direct3D9 adapters list. Fingers crossed... - if (state->curIdx == vid_adapter) - { - state->hFoundMonitor = hMonitor; - - // Don't stop enumeration; this makes EnumDisplayMonitors fail. I like - // proper fails. - } - - ++state->curIdx; - - return TRUE; -} - -//========================================================================== -// -// -// -//========================================================================== - -void Win32GLVideo::GetDisplayDeviceName() -{ - // If anything goes wrong, anything at all, everything uses the primary - // monitor. - m_DisplayDeviceName = 0; - m_hMonitor = 0; - - MonitorEnumState mes; - - mes.curIdx = 1; - mes.hFoundMonitor = 0; - - // Could also use EnumDisplayDevices, I guess. That might work. - if (EnumDisplayMonitors(0, 0, &GetDisplayDeviceNameMonitorEnumProc, LPARAM(&mes))) - { - if (mes.hFoundMonitor) - { - MONITORINFOEX mi; - - mi.cbSize = sizeof mi; - - if (GetMonitorInfo(mes.hFoundMonitor, &mi)) - { - strcpy(m_DisplayDeviceBuffer, mi.szDevice); - m_DisplayDeviceName = m_DisplayDeviceBuffer; - - m_hMonitor = mes.hFoundMonitor; - } - } - } } //========================================================================== @@ -185,71 +98,6 @@ DFrameBuffer *Win32GLVideo::CreateFrameBuffer() // //========================================================================== -struct DumpAdaptersState -{ - unsigned index; - char *displayDeviceName; -}; - -static BOOL CALLBACK DumpAdaptersMonitorEnumProc(HMONITOR hMonitor, HDC, LPRECT, LPARAM dwData) -{ - DumpAdaptersState *state = reinterpret_cast(dwData); - - MONITORINFOEX mi; - mi.cbSize = sizeof mi; - - char moreinfo[64] = ""; - - bool active = true; - - if (GetMonitorInfo(hMonitor, &mi)) - { - bool primary = !!(mi.dwFlags & MONITORINFOF_PRIMARY); - - mysnprintf(moreinfo, countof(moreinfo), " [%ldx%ld @ (%ld,%ld)]%s", - mi.rcMonitor.right - mi.rcMonitor.left, - mi.rcMonitor.bottom - mi.rcMonitor.top, - mi.rcMonitor.left, mi.rcMonitor.top, - primary ? " (Primary)" : ""); - - if (!state->displayDeviceName && !primary) - active = false;//primary selected, but this ain't primary - else if (state->displayDeviceName && strcmp(state->displayDeviceName, mi.szDevice) != 0) - active = false;//this isn't the selected one - } - - Printf("%s%u. %s\n", - active ? TEXTCOLOR_BOLD : "", - state->index, - moreinfo); - - ++state->index; - - return TRUE; -} - -//========================================================================== -// -// -// -//========================================================================== - -void Win32GLVideo::DumpAdapters() -{ - DumpAdaptersState das; - - das.index = 1; - das.displayDeviceName = m_DisplayDeviceName; - - EnumDisplayMonitors(0, 0, DumpAdaptersMonitorEnumProc, LPARAM(&das)); -} - -//========================================================================== -// -// -// -//========================================================================== - HWND Win32GLVideo::InitDummy() { HMODULE g_hInst = GetModuleHandle(NULL); diff --git a/src/win32/win32glvideo.h b/src/win32/win32glvideo.h index cb54a1e22..84c2abd13 100644 --- a/src/win32/win32glvideo.h +++ b/src/win32/win32glvideo.h @@ -1,6 +1,6 @@ #pragma once -#include "v_video.h" +#include "win32basevideo.h" //========================================================================== // @@ -8,35 +8,20 @@ // //========================================================================== -class Win32GLVideo : public IVideo +class Win32GLVideo : public Win32BaseVideo { public: - Win32GLVideo(int parm); - virtual ~Win32GLVideo(); + Win32GLVideo(); - DFrameBuffer *CreateFrameBuffer(); - void DumpAdapters(); + DFrameBuffer *CreateFrameBuffer() override; bool InitHardware(HWND Window, int multisample); void Shutdown(); - HDC m_hDC; - protected: - HMODULE hmRender; - - char m_DisplayDeviceBuffer[CCHDEVICENAME]; - char *m_DisplayDeviceName; - HMONITOR m_hMonitor; - - HWND m_Window; HGLRC m_hRC; HWND InitDummy(); void ShutdownDummy(HWND dummy); bool SetPixelFormat(); bool SetupPixelFormat(int multisample); - - void GetDisplayDeviceName(); -public: - };