#ifndef BOO_WI2COMMON_HPP #define BOO_WINCOMMON_HPP #include #include "boo/IWindow.hpp" namespace boo {class IWindow;} #if _WIN32_WINNT_WIN10 #include #include #include #include #include #elif _WIN32_WINNT_WIN7 #include #include #include #include #else #error Unsupported Windows target #endif struct D3D12Context { ComPtr m_dxFactory; ComPtr m_dev; ComPtr m_qalloc[2]; ComPtr m_q; ComPtr m_loadqalloc; ComPtr m_loadq; ComPtr m_loadfence; UINT64 m_loadfenceval = 0; HANDLE m_loadfencehandle; ComPtr m_loadlist; ComPtr m_rs; struct Window { ComPtr m_swapChain; UINT m_backBuf = 0; bool m_needsResize = false; size_t width, height; }; std::unordered_map m_windows; uint32_t m_sampleCount = 1; uint32_t m_anisotropy = 1; struct RGBATex2DFBViewDesc : D3D12_SHADER_RESOURCE_VIEW_DESC { RGBATex2DFBViewDesc() { Format = DXGI_FORMAT_R8G8B8A8_UNORM; ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; Texture2D = {UINT(0), UINT(1), UINT(0), 0.0f}; } } RGBATex2DFBViewDesc; }; struct D3D11Context { ComPtr m_dxFactory; ComPtr m_dev; ComPtr m_devCtx; ComPtr m_ss[3]; struct Window { ComPtr m_swapChain; bool m_needsResize = false; size_t width, height; bool m_needsFSTransition = false; bool m_fs = false; DXGI_MODE_DESC m_fsdesc = {}; }; std::unordered_map m_windows; uint32_t m_sampleCount = 1; uint32_t m_anisotropy = 1; DXGI_FORMAT m_fbFormat = DXGI_FORMAT_R8G8B8A8_UNORM; }; struct Boo3DAppContext { D3D11Context m_ctx11; #if _WIN32_WINNT_WIN10 D3D12Context m_ctx12; #endif void resize(boo::IWindow* window, size_t width, size_t height) { #if _WIN32_WINNT_WIN10 if (m_ctx12.m_dev) { D3D12Context::Window& win = m_ctx12.m_windows[window]; win.width = width; win.height = height; win.m_needsResize = true; } else #endif { D3D11Context::Window& win = m_ctx11.m_windows[window]; win.width = width; win.height = height; win.m_needsResize = true; } } }; static inline std::string WCSTMBS(const wchar_t* wstr) { int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr) - 1; std::string strTo(sizeNeeded, 0); WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &strTo[0], sizeNeeded, nullptr, nullptr); return strTo; } #endif // BOO_WINCOMMON_HPP