-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswapchain.cpp
More file actions
56 lines (43 loc) · 1.3 KB
/
swapchain.cpp
File metadata and controls
56 lines (43 loc) · 1.3 KB
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
54
55
56
#include "swapchain.hpp"
#include "graphicsengine.hpp"
bool SwapChain::init(HWND hwnd, UINT width, UINT height)
{
ID3D11Device* device = GraphicsEngine::get()->m_d3d_device;
DXGI_SWAP_CHAIN_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.BufferCount = 1; // front buffer et le back buffer (double buffering)
desc.BufferDesc.Width = width;
desc.BufferDesc.Height = height;
desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.BufferDesc.RefreshRate.Numerator = 60;
desc.BufferDesc.RefreshRate.Denominator = 1;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.OutputWindow = hwnd;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Windowed = TRUE;
// Création de la swap chain
HRESULT hr = GraphicsEngine::get()->m_dxgi_factory->CreateSwapChain(device, &desc, &m_swap_chain);
if (FAILED(hr))
return false;
ID3D11Texture2D* buffer = nullptr;
hr = m_swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&buffer));
if (FAILED(hr))
return false;
device->CreateRenderTargetView(buffer, nullptr, &m_rtv);
buffer->Release();
if (FAILED(hr))
return false;
return true;
}
bool SwapChain::present(bool vsync)
{
m_swap_chain->Present(vsync, 0);
return false;
}
bool SwapChain::release()
{
m_swap_chain->Release();
delete this;
return true;
}