1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
xn65/framework/platform/swapchain-dx.cpp

49 lines
1.7 KiB
C++
Raw Normal View History

2024-03-18 15:41:46 -03:00
#include "swapchain-dx.hpp"
#include "../graphics/device.hpp"
#include "adapter-dx.hpp"
#include "device-dx.hpp"
namespace xna {
2024-03-21 16:01:47 -03:00
SwapChain::SwapChain(GraphicsDevice* device){
_device = device;
2024-03-18 15:41:46 -03:00
}
bool SwapChain::Initialize(GameWindow const& gameWindow) {
const auto bounds = gameWindow.ClientBounds();
2024-03-21 16:01:47 -03:00
_swapDescription.BufferDesc.Width = static_cast<UINT>(bounds.Width);
_swapDescription.BufferDesc.Height = static_cast<UINT>(bounds.Height);
_swapDescription.BufferDesc.RefreshRate.Numerator = 60;
_swapDescription.BufferDesc.RefreshRate.Denominator = 1;
_swapDescription.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
_swapDescription.SampleDesc.Count = 1;
_swapDescription.SampleDesc.Quality = 0;
_swapDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
_swapDescription.BufferCount = 2;
_swapDescription.OutputWindow = gameWindow.WindowHandle();
_swapDescription.Windowed = gameWindow.Mode() != GameWindowMode::Fullscreen;
_swapDescription.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
_swapDescription.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
2024-03-18 15:41:46 -03:00
return true;
}
2024-03-21 16:01:47 -03:00
bool SwapChain::Apply() {
2024-03-18 15:41:46 -03:00
auto adapter = _device->Adapter();
2024-03-21 16:01:47 -03:00
auto dxAdapter = adapter->_adapter;
2024-03-18 15:41:46 -03:00
IDXGIFactory* dxFactory = nullptr;
if FAILED(dxAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&dxFactory))
return false;
2024-03-21 16:01:47 -03:00
auto dxdevice = _device->_device;
2024-03-18 15:41:46 -03:00
2024-03-21 16:01:47 -03:00
if FAILED(dxFactory->CreateSwapChain(dxdevice, &_swapDescription, &_swapChain))
2024-03-18 15:41:46 -03:00
return false;
dxFactory->Release();
dxFactory = nullptr;
return true;
}
}