- split Win32GLVideo in two so that the OpenGL independent part can be used for Vulkan as well.

This commit is contained in:
Christoph Oelckers 2018-06-24 20:47:00 +02:00
parent c2d24e1dd3
commit 1519514dd7
7 changed files with 251 additions and 179 deletions

View file

@ -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 )

View file

@ -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");

View file

@ -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 <windows.h>
#include <GL/gl.h>
#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<MonitorEnumState *>(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<DumpAdaptersState *>(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));
}

View file

@ -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:
};

View file

@ -461,8 +461,3 @@ int SystemGLFrameBuffer::GetClientHeight()
GetClientRect(Window, &rect);
return rect.bottom - rect.top;
}
IVideo *gl_CreateVideo()
{
return new Win32GLVideo(0);
}

View file

@ -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<MonitorEnumState *>(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<DumpAdaptersState *>(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);

View file

@ -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:
};