#pragma once

#include <wrl.h>
#include <vector>

class DirectXDescriptors;
struct ID3D12Resource;
struct ID3D12Device;
struct IDXGISwapChain4;

class DirectXBuffers
{
public:
    DirectXBuffers(UINT frameCount);

    void clear();

    UINT getCurrentBackBufferIndex() const;

    ID3D12Resource* getCurrentBackBuffer() const;

    ID3D12Resource* getBackBuffer(UINT index) const;

    ID3D12Resource* getDepthStencilBuffer() const;

    bool isInitialized();

    void setupBackBuffers(ID3D12Device* device, IDXGISwapChain4* swapChain, DirectXDescriptors* descriptors);

    void setupDepthStencilHeap(ID3D12Device* device, unsigned width, unsigned height);

    void setupDepthStencilView(ID3D12Device* device, DirectXDescriptors* descriptors);

    void updateBackbufferIndex(UINT index);

private:
    bool mInitialized{ false };
    UINT mFrameCount{ 2 };
    UINT mBackBufferIndex{ 0 };
    std::vector<Microsoft::WRL::ComPtr<ID3D12Resource> > mBackBuffers;
    Microsoft::WRL::ComPtr<ID3D12Resource> mDepthStencilBuffer;
};