SHARE
TWEET

Untitled

a guest Dec 15th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "SwapChain.h"
  2. #include "GraphicsEngine.h"
  3.  
  4. SwapChain::SwapChain()
  5. {
  6. }
  7.  
  8. bool SwapChain::init(HWND hwnd, UINT width, UINT height)
  9. {
  10.     ID3D11Device*device= GraphicsEngine::get()->m_d3d_device;
  11.  
  12.     DXGI_SWAP_CHAIN_DESC desc;
  13.     ZeroMemory(&desc, sizeof(desc));
  14.     desc.BufferCount = 1;
  15.     desc.BufferDesc.Width = width;
  16.     desc.BufferDesc.Height = height;
  17.     desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  18.     desc.BufferDesc.RefreshRate.Numerator = 60;
  19.     desc.BufferDesc.RefreshRate.Denominator = 1;
  20.     desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  21.     desc.OutputWindow = hwnd;
  22.     desc.SampleDesc.Count = 1;
  23.     desc.SampleDesc.Quality = 0;
  24.     desc.Windowed = TRUE;
  25.  
  26.     //Create the swap chain for the window indicated by HWND parameter
  27.     HRESULT hr=GraphicsEngine::get()->m_dxgi_factory->CreateSwapChain(device, &desc, &m_swap_chain);
  28.    
  29.     if (FAILED(hr))
  30.     {
  31.         return false;
  32.     }
  33.  
  34.     //Get the back buffer color and create its render target view
  35.     ID3D11Texture2D* buffer=NULL;
  36.     hr=m_swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&buffer);
  37.    
  38.     if (FAILED(hr))
  39.     {
  40.         return false;
  41.     }
  42.  
  43.     hr=device->CreateRenderTargetView(buffer, NULL, &m_rtv);
  44.     buffer->Release();
  45.  
  46.     if (FAILED(hr))
  47.     {
  48.         return false;
  49.     }
  50.  
  51.     return true;
  52. }
  53.  
  54. bool SwapChain::present(bool vsync)
  55. {
  56.     m_swap_chain->Present(vsync, NULL);
  57.  
  58.     return true;
  59. }
  60.  
  61. bool SwapChain::release()
  62. {
  63.     m_swap_chain->Release();
  64.     delete this;
  65.     return true;
  66. }
  67.  
  68. SwapChain::~SwapChain()
  69. {
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top