2018-10-07 03:36:44 +00:00
|
|
|
#pragma once
|
2015-11-03 04:19:41 +00:00
|
|
|
|
|
|
|
#ifndef _CRT_SECURE_NO_WARNINGS
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS 1 /* STFU MSVC */
|
|
|
|
#endif
|
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN 1
|
|
|
|
#endif
|
2017-10-24 03:09:50 +00:00
|
|
|
#include "WinCommon.hpp"
|
2015-11-03 04:19:41 +00:00
|
|
|
#include <windows.h>
|
2015-11-04 00:27:32 +00:00
|
|
|
|
2017-11-25 02:49:20 +00:00
|
|
|
#if BOO_HAS_VULKAN
|
|
|
|
#include "boo/graphicsdev/Vulkan.hpp"
|
|
|
|
#endif
|
2018-01-10 06:15:18 +00:00
|
|
|
#include "boo/graphicsdev/GL.hpp"
|
2017-11-25 02:49:20 +00:00
|
|
|
|
2019-08-17 17:39:39 +00:00
|
|
|
#include <condition_variable>
|
|
|
|
#include <mutex>
|
|
|
|
|
2015-11-07 01:43:12 +00:00
|
|
|
extern DWORD g_mainThreadId;
|
2018-05-29 03:40:44 +00:00
|
|
|
extern std::mutex g_nwmt;
|
|
|
|
extern std::condition_variable g_nwcv;
|
2015-11-07 01:43:12 +00:00
|
|
|
|
2017-12-06 03:20:59 +00:00
|
|
|
#if _WIN32_WINNT_WINBLUE && !WINDOWS_STORE
|
2016-12-11 01:50:26 +00:00
|
|
|
#include <ShellScalingApi.h>
|
2019-08-16 08:11:27 +00:00
|
|
|
using PFN_GetScaleFactorForMonitor = HRESULT(WINAPI*)(_In_ HMONITOR, _Out_ DEVICE_SCALE_FACTOR*);
|
2016-12-11 01:50:26 +00:00
|
|
|
extern PFN_GetScaleFactorForMonitor MyGetScaleFactorForMonitor;
|
|
|
|
#endif
|
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
struct OGLContext {
|
|
|
|
ComPtr<IDXGIFactory1> m_dxFactory;
|
2019-08-16 07:47:57 +00:00
|
|
|
HGLRC m_lastContext = nullptr;
|
2018-12-08 05:17:51 +00:00
|
|
|
struct Window {
|
|
|
|
HWND m_hwnd;
|
|
|
|
HDC m_deviceContext;
|
|
|
|
HGLRC m_mainContext;
|
|
|
|
HGLRC m_renderContext;
|
|
|
|
bool m_needsResize = false;
|
|
|
|
size_t width, height;
|
|
|
|
|
|
|
|
bool m_fs = false;
|
2019-09-06 11:04:57 +00:00
|
|
|
LONG_PTR m_fsStyle;
|
|
|
|
LONG_PTR m_fsExStyle;
|
2018-12-08 05:17:51 +00:00
|
|
|
RECT m_fsRect;
|
|
|
|
int m_fsCountDown = 0;
|
|
|
|
};
|
|
|
|
std::unordered_map<const boo::IWindow*, Window> m_windows;
|
2020-04-18 00:25:01 +00:00
|
|
|
#if BOO_HAS_GL
|
2018-12-08 05:17:51 +00:00
|
|
|
boo::GLContext m_glCtx;
|
2020-04-18 00:25:01 +00:00
|
|
|
#endif
|
2015-11-07 01:43:12 +00:00
|
|
|
};
|
|
|
|
|
2018-05-29 03:40:44 +00:00
|
|
|
#if !WINDOWS_STORE
|
2018-12-08 05:17:51 +00:00
|
|
|
static inline void SetFullscreen(OGLContext::Window& win, bool fs) {
|
|
|
|
std::unique_lock<std::mutex> lk(g_nwmt);
|
|
|
|
PostThreadMessageW(g_mainThreadId, WM_USER + 5, WPARAM(&win), LPARAM(fs));
|
|
|
|
g_nwcv.wait(lk);
|
2018-05-29 03:40:44 +00:00
|
|
|
}
|
2017-11-25 02:49:20 +00:00
|
|
|
|
2018-06-02 00:01:47 +00:00
|
|
|
#if BOO_HAS_VULKAN
|
2018-12-08 05:17:51 +00:00
|
|
|
static inline void SetFullscreen(boo::VulkanContext::Window& win, bool fs) {
|
|
|
|
std::unique_lock<std::mutex> lk(g_nwmt);
|
|
|
|
PostThreadMessageW(g_mainThreadId, WM_USER + 6, WPARAM(&win), LPARAM(fs));
|
|
|
|
g_nwcv.wait(lk);
|
2017-11-25 02:49:20 +00:00
|
|
|
}
|
2018-05-29 03:40:44 +00:00
|
|
|
#endif
|
2018-06-02 00:01:47 +00:00
|
|
|
#endif
|
2017-11-25 02:49:20 +00:00
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
struct Boo3DAppContextWin32 : Boo3DAppContext {
|
|
|
|
OGLContext m_ctxOgl;
|
|
|
|
ComPtr<IDXGIFactory1> m_vulkanDxFactory;
|
2015-11-05 04:57:48 +00:00
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
bool isFullscreen(const boo::IWindow* window) {
|
2017-11-25 02:49:20 +00:00
|
|
|
#if BOO_HAS_VULKAN
|
2018-12-08 05:17:51 +00:00
|
|
|
if (m_vulkanDxFactory) {
|
|
|
|
boo::VulkanContext::Window& win = *boo::g_VulkanContext.m_windows[window];
|
|
|
|
return win.m_fs;
|
|
|
|
}
|
2017-11-25 02:49:20 +00:00
|
|
|
#endif
|
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
if (m_ctx11.m_dev) {
|
|
|
|
D3D11Context::Window& win = m_ctx11.m_windows[window];
|
|
|
|
BOOL isFScr;
|
|
|
|
win.m_swapChain->GetFullscreenState(&isFScr, nullptr);
|
|
|
|
return isFScr != 0;
|
2015-11-06 03:20:58 +00:00
|
|
|
}
|
2018-12-08 05:17:51 +00:00
|
|
|
OGLContext::Window& win = m_ctxOgl.m_windows[window];
|
|
|
|
return win.m_fs;
|
|
|
|
}
|
2015-11-06 03:20:58 +00:00
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
bool setFullscreen(boo::IWindow* window, bool fs) {
|
2017-11-25 02:49:20 +00:00
|
|
|
#if BOO_HAS_VULKAN
|
2018-12-08 05:17:51 +00:00
|
|
|
if (m_vulkanDxFactory) {
|
|
|
|
boo::VulkanContext::Window& win = *boo::g_VulkanContext.m_windows[window];
|
|
|
|
if (fs && win.m_fs)
|
|
|
|
return false;
|
|
|
|
else if (!fs && !win.m_fs)
|
|
|
|
return false;
|
|
|
|
SetFullscreen(win, fs);
|
|
|
|
return true;
|
|
|
|
}
|
2017-11-25 02:49:20 +00:00
|
|
|
#endif
|
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
if (m_ctx11.m_dev) {
|
|
|
|
D3D11Context::Window& win = m_ctx11.m_windows[window];
|
|
|
|
BOOL isFScr;
|
|
|
|
win.m_swapChain->GetFullscreenState(&isFScr, nullptr);
|
|
|
|
if (fs && isFScr)
|
|
|
|
return false;
|
|
|
|
else if (!fs && !isFScr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (fs) {
|
|
|
|
ComPtr<IDXGIOutput> out;
|
|
|
|
win.m_swapChain->GetContainingOutput(&out);
|
|
|
|
DXGI_OUTPUT_DESC outDesc;
|
|
|
|
out->GetDesc(&outDesc);
|
|
|
|
|
|
|
|
win.m_fsdesc.Width = outDesc.DesktopCoordinates.right;
|
|
|
|
win.m_fsdesc.Height = outDesc.DesktopCoordinates.bottom;
|
|
|
|
}
|
|
|
|
win.m_fs = fs;
|
|
|
|
win.m_needsFSTransition = true;
|
|
|
|
return true;
|
|
|
|
}
|
2015-11-07 01:43:12 +00:00
|
|
|
|
2017-12-06 03:20:59 +00:00
|
|
|
#if !WINDOWS_STORE
|
2018-12-08 05:17:51 +00:00
|
|
|
OGLContext::Window& win = m_ctxOgl.m_windows[window];
|
|
|
|
if (fs && win.m_fs)
|
|
|
|
return false;
|
|
|
|
else if (!fs && !win.m_fs)
|
|
|
|
return false;
|
|
|
|
SetFullscreen(win, fs);
|
2017-12-06 03:20:59 +00:00
|
|
|
#endif
|
2018-12-08 05:17:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-03 04:19:41 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
struct HWNDEvent {
|
|
|
|
UINT uMsg;
|
|
|
|
WPARAM wParam;
|
|
|
|
LPARAM lParam;
|
|
|
|
HWNDEvent(UINT m, WPARAM w, LPARAM l) : uMsg(m), wParam(w), lParam(l) {}
|
2015-11-03 04:19:41 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
struct Win32Cursors {
|
|
|
|
HCURSOR m_arrow;
|
|
|
|
HCURSOR m_hResize;
|
|
|
|
HCURSOR m_vResize;
|
|
|
|
HCURSOR m_ibeam;
|
|
|
|
HCURSOR m_crosshairs;
|
|
|
|
HCURSOR m_wait;
|
2015-12-01 00:33:14 +00:00
|
|
|
};
|
2018-12-08 05:17:51 +00:00
|
|
|
namespace boo {
|
2015-12-01 00:33:14 +00:00
|
|
|
extern Win32Cursors WIN32_CURSORS;
|
|
|
|
}
|