2019-12-22 19:55:47 +00:00
|
|
|
/*
|
|
|
|
** hardware.cpp
|
|
|
|
** Somewhat OS-independant interface to the screen, mouse, keyboard, and stick
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** 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.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <mmsystem.h>
|
|
|
|
|
|
|
|
#include "hardware.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "v_text.h"
|
|
|
|
#include "basics.h"
|
|
|
|
#include "m_argv.h"
|
|
|
|
#include "version.h"
|
|
|
|
#include "printf.h"
|
|
|
|
#include "win32glvideo.h"
|
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
#include "win32vulkanvideo.h"
|
|
|
|
#endif
|
2020-04-23 19:18:40 +00:00
|
|
|
#include "engineerrors.h"
|
2019-12-22 19:55:47 +00:00
|
|
|
#include "i_system.h"
|
2022-06-06 09:45:02 +00:00
|
|
|
#include "i_mainwindow.h"
|
2019-12-22 19:55:47 +00:00
|
|
|
|
|
|
|
IVideo *Video;
|
|
|
|
|
|
|
|
// do not include GL headers here, only declare the necessary functions.
|
|
|
|
IVideo *gl_CreateVideo();
|
|
|
|
|
|
|
|
void I_RestartRenderer();
|
|
|
|
int currentcanvas = -1;
|
|
|
|
bool changerenderer;
|
|
|
|
|
|
|
|
void I_ShutdownGraphics ()
|
|
|
|
{
|
|
|
|
if (screen)
|
|
|
|
{
|
|
|
|
DFrameBuffer *s = screen;
|
|
|
|
screen = NULL;
|
|
|
|
delete s;
|
|
|
|
}
|
|
|
|
if (Video)
|
|
|
|
delete Video, Video = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void I_InitGraphics ()
|
|
|
|
{
|
|
|
|
// If the focus window is destroyed, it doesn't go back to the active window.
|
|
|
|
// (e.g. because the net pane was up, and a button on it had focus)
|
2022-06-06 09:45:02 +00:00
|
|
|
if (GetFocus() == NULL && GetActiveWindow() == mainwindow.GetHandle())
|
2019-12-22 19:55:47 +00:00
|
|
|
{
|
|
|
|
// Make sure it's in the foreground and focused. (It probably is
|
|
|
|
// already foregrounded but may not be focused.)
|
2022-06-06 09:45:02 +00:00
|
|
|
SetForegroundWindow(mainwindow.GetHandle());
|
|
|
|
SetFocus(mainwindow.GetHandle());
|
2019-12-22 19:55:47 +00:00
|
|
|
// Note that when I start a 2-player game on the same machine, the
|
|
|
|
// window for the game that isn't focused, active, or foregrounded
|
|
|
|
// still receives a WM_ACTIVATEAPP message telling it that it's the
|
|
|
|
// active window. The window that is really the active window does
|
|
|
|
// not receive a WM_ACTIVATEAPP message, so both games think they
|
|
|
|
// are the active app. Huh?
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_VULKAN
|
2022-08-03 11:27:48 +00:00
|
|
|
if (V_GetBackend() == 1)
|
2019-12-22 19:55:47 +00:00
|
|
|
{
|
|
|
|
// first try Vulkan, if that fails OpenGL
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Video = new Win32VulkanVideo();
|
|
|
|
}
|
|
|
|
catch (CVulkanError &error)
|
|
|
|
{
|
|
|
|
Printf(TEXTCOLOR_RED "Initialization of Vulkan failed: %s\n", error.what());
|
|
|
|
Video = new Win32GLVideo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2020-04-23 19:18:40 +00:00
|
|
|
#endif
|
2019-12-22 19:55:47 +00:00
|
|
|
{
|
|
|
|
Video = new Win32GLVideo();
|
|
|
|
}
|
|
|
|
|
|
|
|
// we somehow STILL don't have a display!!
|
|
|
|
if (Video == NULL)
|
|
|
|
I_FatalError ("Failed to initialize display");
|
2021-12-30 09:30:21 +00:00
|
|
|
|
2019-12-22 19:55:47 +00:00
|
|
|
}
|