2015-11-03 04:19:41 +00:00
|
|
|
#ifndef BOO_WIN32COMMON_HPP
|
|
|
|
#define BOO_WIN32COMMON_HPP
|
|
|
|
|
|
|
|
#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
|
|
|
|
#include <windows.h>
|
2015-11-04 00:27:32 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2015-11-05 00:00:29 +00:00
|
|
|
#include "boo/System.hpp"
|
|
|
|
|
2015-11-04 00:27:32 +00:00
|
|
|
namespace boo {class IWindow;}
|
2015-11-03 04:19:41 +00:00
|
|
|
|
|
|
|
#if _WIN32_WINNT_WIN10
|
|
|
|
#include <dxgi1_4.h>
|
|
|
|
#include <d3d12.h>
|
|
|
|
#include <d3d11_1.h>
|
|
|
|
|
|
|
|
struct D3D12Context
|
|
|
|
{
|
2015-11-05 00:00:29 +00:00
|
|
|
ComPtr<IDXGIFactory4> m_dxFactory;
|
2015-11-03 04:19:41 +00:00
|
|
|
ComPtr<ID3D12Device> m_dev;
|
2015-11-04 00:27:32 +00:00
|
|
|
ComPtr<ID3D12CommandAllocator> m_qalloc[2];
|
2015-11-03 04:19:41 +00:00
|
|
|
ComPtr<ID3D12CommandQueue> m_q;
|
|
|
|
ComPtr<ID3D12CommandAllocator> m_loadqalloc;
|
|
|
|
ComPtr<ID3D12CommandQueue> m_loadq;
|
2015-11-05 00:00:29 +00:00
|
|
|
ComPtr<ID3D12Fence> m_loadfence;
|
|
|
|
UINT64 m_loadfenceval = 0;
|
|
|
|
HANDLE m_loadfencehandle;
|
|
|
|
ComPtr<ID3D12GraphicsCommandList> m_loadlist;
|
2015-11-03 04:19:41 +00:00
|
|
|
ComPtr<ID3D12RootSignature> m_rs;
|
2015-11-04 00:27:32 +00:00
|
|
|
struct Window
|
|
|
|
{
|
|
|
|
ComPtr<IDXGISwapChain3> m_swapChain;
|
|
|
|
UINT m_backBuf = 0;
|
2015-11-05 04:57:48 +00:00
|
|
|
bool m_needsResize = false;
|
2015-11-04 00:27:32 +00:00
|
|
|
size_t width, height;
|
|
|
|
};
|
|
|
|
std::unordered_map<boo::IWindow*, Window> m_windows;
|
2015-11-03 04:19:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#elif _WIN32_WINNT_WIN7
|
|
|
|
#include <dxgi1_2.h>
|
|
|
|
#include <d3d11_1.h>
|
|
|
|
#else
|
|
|
|
#error Unsupported Windows target
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct D3D11Context
|
|
|
|
{
|
2015-11-05 00:00:29 +00:00
|
|
|
ComPtr<IDXGIFactory2> m_dxFactory;
|
2015-11-03 04:19:41 +00:00
|
|
|
ComPtr<ID3D11Device1> m_dev;
|
|
|
|
ComPtr<ID3D11DeviceContext1> m_devCtx;
|
2015-11-04 00:27:32 +00:00
|
|
|
struct Window
|
|
|
|
{
|
|
|
|
IDXGISwapChain1* m_swapChain;
|
2015-11-05 04:57:48 +00:00
|
|
|
bool m_needsResize = false;
|
2015-11-04 00:27:32 +00:00
|
|
|
size_t width, height;
|
|
|
|
};
|
|
|
|
std::unordered_map<boo::IWindow*, Window> m_windows;
|
2015-11-03 04:19:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct D3DAppContext
|
|
|
|
{
|
|
|
|
D3D11Context m_ctx11;
|
|
|
|
#if _WIN32_WINNT_WIN10
|
|
|
|
D3D12Context m_ctx12;
|
|
|
|
#endif
|
2015-11-05 04:57:48 +00:00
|
|
|
|
|
|
|
void resize(boo::IWindow* window, size_t width, size_t height)
|
|
|
|
{
|
|
|
|
#if _WIN32_WINNT_WIN10
|
|
|
|
if (m_ctx12.m_dev)
|
|
|
|
{
|
|
|
|
m_ctx12.m_windows[window].width = width;
|
|
|
|
m_ctx12.m_windows[window].height = height;
|
|
|
|
m_ctx12.m_windows[window].m_needsResize = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
m_ctx11.m_windows[window].width = width;
|
|
|
|
m_ctx11.m_windows[window].height = height;
|
|
|
|
m_ctx11.m_windows[window].m_needsResize = true;
|
|
|
|
}
|
|
|
|
}
|
2015-11-03 04:19:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct HWNDEvent
|
|
|
|
{
|
|
|
|
UINT uMsg;
|
|
|
|
WPARAM wParam;
|
|
|
|
LPARAM lParam;
|
|
|
|
HWNDEvent(UINT m, WPARAM w, LPARAM l)
|
|
|
|
: uMsg(m), wParam(w), lParam(l) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BOO_WIN32COMMON_HPP
|