Files
XCEngine/engine/include/XCEngine/RHI/D3D12/D3D12SwapChain.h

49 lines
1.4 KiB
C++

#pragma once
#include <d3d12.h>
#include <dxgi1_4.h>
#include <wrl/client.h>
#include <vector>
#include "../RHISwapChain.h"
#include "D3D12Enums.h"
#include "D3D12Texture.h"
using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12SwapChain : public RHISwapChain {
public:
D3D12SwapChain();
~D3D12SwapChain() override;
bool Initialize(IDXGIFactory4* factory, ID3D12CommandQueue* commandQueue, HWND windowHandle, uint32_t width, uint32_t height, uint32_t bufferCount = 2);
bool Initialize(IDXGISwapChain* swapChain, uint32_t width, uint32_t height);
void Shutdown() override;
uint32_t GetCurrentBackBufferIndex() const override;
RHITexture* GetCurrentBackBuffer() override;
D3D12Texture& GetBackBuffer(uint32_t index);
const D3D12Texture& GetBackBuffer(uint32_t index) const;
ID3D12CommandQueue* GetNativeCommandQueue() const { return m_commandQueue.Get(); }
void Present(uint32_t syncInterval = 1, uint32_t flags = 0) override;
void Resize(uint32_t width, uint32_t height) override;
void* GetNativeHandle() override;
private:
bool RefreshBackBuffers();
void ReleaseBackBuffers();
ComPtr<IDXGISwapChain3> m_swapChain;
ComPtr<ID3D12CommandQueue> m_commandQueue;
uint32_t m_width;
uint32_t m_height;
uint32_t m_bufferCount;
std::vector<D3D12Texture> m_backBuffers;
};
} // namespace RHI
} // namespace XCEngine