Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
swap_chain.h
1 #pragma once
2 
3 #include "util/assert.h"
4 #include "renderer/buffers/color_buffer.h"
5 
6 #define SWAP_CHAIN_MAX_BUFFER_COUNT 4
7 
8 namespace blowbox
9 {
10  class Device;
11 
19  class SwapChain
20  {
21  public:
22  SwapChain();
23  ~SwapChain();
24 
37  void Create(HWND output_window, UINT width, UINT height, DXGI_FORMAT format, UINT buffer_count, DXGI_SWAP_EFFECT swap_effect, UINT flags, bool disable_alt_enter = true, bool windowed = true);
38 
43  void Present(bool vsync = true);
44 
50  ColorBuffer& GetBuffer(UINT buffer_index) { BLOWBOX_ASSERT(buffer_index < buffer_count_); return buffers_[buffer_index]; }
51 
57  const ColorBuffer& GetBuffer(UINT buffer_index) const { BLOWBOX_ASSERT(buffer_index < buffer_count_); return buffers_[buffer_index]; }
58 
59 
62 
65 
67  const UINT& GetBufferCount() const { return buffer_count_; }
69  const UINT& GetBackBufferIndex() const { return back_buffer_index_; }
70 
72  const UINT& GetBufferWidth() const { return desc_.BufferDesc.Width; }
74  const UINT& GetBufferHeight() const { return desc_.BufferDesc.Height; }
75 
77  operator IDXGISwapChain*() { return swap_chain_; }
78 
80  IDXGISwapChain* operator->() { return swap_chain_; }
82  const IDXGISwapChain* operator->() const { return swap_chain_; }
83  protected:
95  DXGI_SWAP_CHAIN_DESC DescribeSwapChain(HWND output_window, UINT width, UINT height, DXGI_FORMAT format, UINT buffer_count, DXGI_SWAP_EFFECT swap_effect, UINT flags, bool windowed = true);
96 
97  private:
98  IDXGISwapChain* swap_chain_;
99  DXGI_SWAP_CHAIN_DESC desc_;
102  ColorBuffer buffers_[SWAP_CHAIN_MAX_BUFFER_COUNT];
103  };
104 }
ColorBuffer & GetBuffer(UINT buffer_index)
Retrieve a certain buffer from the SwapChain buffers.
Definition: swap_chain.h:50
DXGI_SWAP_CHAIN_DESC DescribeSwapChain(HWND output_window, UINT width, UINT height, DXGI_FORMAT format, UINT buffer_count, DXGI_SWAP_EFFECT swap_effect, UINT flags, bool windowed=true)
Creates a DXGI_SWAP_CHAIN_DESC based on input params.
Definition: swap_chain.cc:64
Buffer-type for buffers with color data in them.
Definition: color_buffer.h:14
const UINT & GetBackBufferIndex() const
Definition: swap_chain.h:69
Wraps the IDXGISwapChain.
Definition: swap_chain.h:19
IDXGISwapChain * operator->()
Overloads the pointer operator to return the underlying IDXGISwapChain.
Definition: swap_chain.h:80
ColorBuffer & GetBackBuffer()
Definition: swap_chain.h:61
const UINT & GetBufferHeight() const
Definition: swap_chain.h:74
void Create(HWND output_window, UINT width, UINT height, DXGI_FORMAT format, UINT buffer_count, DXGI_SWAP_EFFECT swap_effect, UINT flags, bool disable_alt_enter=true, bool windowed=true)
Creates the actual SwapChain.
Definition: swap_chain.cc:26
void Present(bool vsync=true)
Presents the back buffer to the screen.
Definition: swap_chain.cc:57
const ColorBuffer & GetBuffer(UINT buffer_index) const
Retrieve a certain buffer from the SwapChain buffers.
Definition: swap_chain.h:57
const UINT & GetBufferCount() const
Definition: swap_chain.h:67
IDXGISwapChain * swap_chain_
The underlying IDXGISwapChain.
Definition: swap_chain.h:98
The main Blowbox namespace.
Definition: image.cc:8
UINT back_buffer_index_
The current back buffer index.
Definition: swap_chain.h:100
UINT buffer_count_
The number of buffers in use by the SwapChain.
Definition: swap_chain.h:101
const IDXGISwapChain * operator->() const
Overloads the pointer operator to return the underlying IDXGISwapChain.
Definition: swap_chain.h:82
DXGI_SWAP_CHAIN_DESC desc_
The description of the IDXGISwapChain.
Definition: swap_chain.h:99
const UINT & GetBufferWidth() const
Definition: swap_chain.h:72
const ColorBuffer & GetBackBuffer() const
Definition: swap_chain.h:64
ColorBuffer buffers_[SWAP_CHAIN_MAX_BUFFER_COUNT]
All the different SwapChain buffers.
Definition: swap_chain.h:102