#pragma once #include #include #include #include class Win32DxInterface; namespace mt { class Window; } struct ID3D12CommandQueue; struct ID3D12CommandAllocator; struct ID3D12GraphicsCommandList; struct IDXGISwapChain4; struct ID3D12DescriptorHeap; struct ID3D12Resource; struct ID3D12Fence; struct ID3D12RootSignature; struct ID3D12PipelineState; struct ID3D11Resource; struct ID2D1Bitmap1; struct D2D1_BITMAP_PROPERTIES1; struct CD3DX12_CPU_DESCRIPTOR_HANDLE; class Win32DxWindowInterface { public: Win32DxWindowInterface(mt::Window* window, Win32DxInterface* dxInterface); ~Win32DxWindowInterface(); bool initialize(); void onRender(); private: bool loadPipeline(); bool loadAssets(); void populateCommandList(); void waitForPreviousFrame(); void destroyWindow(); void renderD2d(); bool setupSwapChain(); void setupDescriptorHeaps(); void setupFrameResources(); void setupFrameResource(UINT idx, CD3DX12_CPU_DESCRIPTOR_HANDLE& descriptorHandle, const D2D1_BITMAP_PROPERTIES1& bitmapProps); void setupFrameD2DResource(UINT idx, const D2D1_BITMAP_PROPERTIES1& bitmapProps); void createSyncObjects(); static const UINT FrameCount = 2; Win32DxInterface* mDxInterface{ nullptr }; bool mInitialized{ false }; bool mIsValid{ false }; mt::Window* mWindow{ nullptr }; CD3DX12_VIEWPORT mViewport; CD3DX12_RECT mScissorRect; Microsoft::WRL::ComPtr mCommandAllocator; Microsoft::WRL::ComPtr mCommandList; Microsoft::WRL::ComPtr mSwapChain; Microsoft::WRL::ComPtr mRtvHeap; Microsoft::WRL::ComPtr mSrvHeap; Microsoft::WRL::ComPtr mCbvHeap; UINT mRtvDescriptorSize{ 0 }; Microsoft::WRL::ComPtr mRenderTargets[FrameCount]; Microsoft::WRL::ComPtr mWrappedBackBuffers[FrameCount]; Microsoft::WRL::ComPtr mD2dRenderTargets[FrameCount]; Microsoft::WRL::ComPtr mFence; uint64_t mFenceValue = 0; uint64_t mFrameFenceValues[FrameCount] = {}; HANDLE mFenceEvent{}; uint64_t mFrameIndex{ 0 }; }; using XcbGlWindowInterfacePtr = std::unique_ptr;