summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/D3D12/D3D12SwapChain.h
blob: d7db3e7909247dcafffaabea0580f11c0b2cfb85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2019 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <d3d12.h>
#include <memory>
#include <vector>

#include "Common/CommonTypes.h"
#include "Common/WindowSystemInfo.h"
#include "VideoBackends/D3D12/Common.h"
#include "VideoBackends/D3DCommon/SwapChain.h"
#include "VideoCommon/TextureConfig.h"

namespace DX12
{
class DXTexture;
class DXFramebuffer;

class SwapChain : public D3DCommon::SwapChain
{
public:
  SwapChain(const WindowSystemInfo& wsi, IDXGIFactory* dxgi_factory,
            ID3D12CommandQueue* d3d_command_queue);
  ~SwapChain() override;

  static std::unique_ptr<SwapChain> Create(const WindowSystemInfo& wsi);

  bool Present() override;

  DXTexture* GetCurrentTexture() const { return m_buffers[m_current_buffer].texture.get(); }
  DXFramebuffer* GetCurrentFramebuffer() const
  {
    return m_buffers[m_current_buffer].framebuffer.get();
  }

protected:
  bool CreateSwapChainBuffers() override;
  void DestroySwapChainBuffers() override;

private:
  struct BufferResources
  {
    std::unique_ptr<DXTexture> texture;
    std::unique_ptr<DXFramebuffer> framebuffer;
  };

  std::vector<BufferResources> m_buffers;
  u32 m_current_buffer = 0;
};

}  // namespace DX12