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

Corrige SwapChain

This commit is contained in:
Danilo 2024-05-22 20:05:52 -03:00
parent 522edf20a0
commit 4b3a55f760
9 changed files with 70 additions and 84 deletions

View File

@ -6,7 +6,6 @@
#include "platform-dx/gdevicemanager-dx.hpp"
#include "platform-dx/implementations.hpp"
#include "platform-dx/rendertarget-dx.hpp"
#include "platform-dx/swapchain-dx.hpp"
#include "platform-dx/window-dx.hpp"
namespace xna {

View File

@ -4,6 +4,8 @@
#include "platform-dx/window-dx.hpp"
#include "platform-dx/gdeviceinfo-dx.hpp"
#include "graphics/presentparams.hpp"
#include "graphics/swapchain.hpp"
#include "platform-dx/implementations.hpp"
namespace xna {
GraphicsDeviceManager::GraphicsDeviceManager(Game*& game) : _game(game) {
@ -38,11 +40,11 @@ namespace xna {
auto& swap = _game->graphicsDevice->_swapChain;
BOOL state = false;
auto hr = swap->dxSwapChain->GetFullscreenState(&state, nullptr);
auto hr = swap->impl->dxSwapChain->GetFullscreenState(&state, nullptr);
if (FAILED(hr)) return false;
hr = swap->dxSwapChain->SetFullscreenState(!state, nullptr);
hr = swap->impl->dxSwapChain->SetFullscreenState(!state, nullptr);
if (FAILED(hr)) return false;

View File

@ -1,7 +1,7 @@
#include "platform-dx/rendertarget-dx.hpp"
#include "graphics/device.hpp"
#include "platform-dx/swapchain-dx.hpp"
#include "platform-dx/device-dx.hpp"
#include "platform-dx/implementations.hpp"
namespace xna {
bool RenderTarget2D::Initialize(xna_error_ptr_arg) {
@ -15,7 +15,7 @@ namespace xna {
dxTexture2D = nullptr;
}
if (!m_device->_swapChain->GetBackBuffer(dxTexture2D))
if (!m_device->_swapChain->impl->GetBackBuffer(dxTexture2D))
return false;
auto& dxdevice = m_device->_device;

View File

@ -1,10 +1,22 @@
#include "platform-dx/swapchain-dx.hpp"
#include "platform-dx/device-dx.hpp"
#include "platform-dx/dxhelpers.hpp"
#include "graphics/adapter.hpp"
#include "graphics/swapchain.hpp"
#include "platform-dx/implementations.hpp"
namespace xna {
SwapChain::SwapChain() : GraphicsResource(nullptr) {
impl = unew<PlatformImplementation>();
}
SwapChain::SwapChain(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
impl = unew<PlatformImplementation>();
}
SwapChain::~SwapChain() {
impl = nullptr;
}
static bool internalInit(GraphicsDevice& device, HWND windowHandle, IDXGISwapChain1*& swapChain, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fdesc) {
if (!device._device || !windowHandle)
return false;
@ -40,59 +52,47 @@ namespace xna {
}
bool SwapChain::Initialize(xna_error_ptr_arg) {
if (!m_device || !m_device->_device) {
if (!impl || !m_device || !m_device->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false;
}
const auto parameters = m_device->_presentationParameters;
dxDescription.Width = static_cast<UINT>(parameters.BackBufferWidth);
dxDescription.Height = static_cast<UINT>(parameters.BackBufferHeight);
dxDescription.Format = DxHelpers::ConvertSurfaceToDXGIFORMAT(parameters.BackBufferFormat);
dxDescription.SampleDesc.Count = 1;
dxDescription.SampleDesc.Quality = 0;
dxDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
dxDescription.BufferCount = 2;
dxDescription.SwapEffect = static_cast<DXGI_SWAP_EFFECT>(parameters.PresentationSwapEffect);
dxDescription.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
dxDescription.AlphaMode = DXGI_ALPHA_MODE::DXGI_ALPHA_MODE_UNSPECIFIED;
dxFullScreenDescription.RefreshRate.Numerator = 60;
dxFullScreenDescription.RefreshRate.Denominator = 1;
dxFullScreenDescription.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
dxFullScreenDescription.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
dxFullScreenDescription.Windowed = !parameters.Fullscreen;
impl->dxDescription.Width = static_cast<UINT>(parameters.BackBufferWidth);
impl->dxDescription.Height = static_cast<UINT>(parameters.BackBufferHeight);
impl->dxDescription.Format = DxHelpers::ConvertSurfaceToDXGIFORMAT(parameters.BackBufferFormat);
impl->dxDescription.SampleDesc.Count = 1;
impl->dxDescription.SampleDesc.Quality = 0;
impl->dxDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
impl->dxDescription.BufferCount = 2;
impl->dxDescription.SwapEffect = static_cast<DXGI_SWAP_EFFECT>(parameters.PresentationSwapEffect);
impl->dxDescription.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
impl->dxDescription.AlphaMode = DXGI_ALPHA_MODE::DXGI_ALPHA_MODE_UNSPECIFIED;
impl->dxFullScreenDescription.RefreshRate.Numerator = 60;
impl->dxFullScreenDescription.RefreshRate.Denominator = 1;
impl->dxFullScreenDescription.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
impl->dxFullScreenDescription.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
impl->dxFullScreenDescription.Windowed = !parameters.Fullscreen;
HWND hwnd = reinterpret_cast<HWND>(parameters.DeviceWindowHandle);
return internalInit(*m_device, hwnd, dxSwapChain, dxDescription, dxFullScreenDescription);
}
return internalInit(*m_device, hwnd, impl->dxSwapChain, impl->dxDescription, impl->dxFullScreenDescription);
}
bool SwapChain::Initialize(GameWindow const& gameWindow, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fullScreenDesc, xna_error_ptr_arg)
{
if (!m_device || !m_device->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false;
}
dxDescription = desc;
dxFullScreenDescription = fullScreenDesc;
return internalInit(*m_device, gameWindow.WindowHandle(), dxSwapChain, dxDescription, dxFullScreenDescription);
}
bool SwapChain::GetBackBuffer(ID3D11Texture2D*& texture2D) {
if (!dxSwapChain)
bool SwapChain::GetBackBuffer(Texture2D& texture2D) {
if (!impl || !impl->dxSwapChain)
return false;
const auto hr = dxSwapChain->GetBuffer(0, __uuidof(texture2D), (void**)(&texture2D));
const auto hr = impl->dxSwapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)(&texture2D.dxTexture2D));
return !FAILED(hr);
}
bool SwapChain::Present(bool vsync) {
if (!dxSwapChain)
if (!impl || !impl->dxSwapChain)
return false;
const auto hr = dxSwapChain->Present(vsync, NULL);
const auto hr = impl->dxSwapChain->Present(vsync, NULL);
return !FAILED(hr);
}
}

View File

@ -2,14 +2,21 @@
#define XNA_GRAPHICS_SWAPCHAIN_HPP
#include "../default.hpp"
#include "../game/window.hpp"
#include "gresource.hpp"
namespace xna {
class ISwapChain {
class SwapChain : GraphicsResource {
public:
virtual ~ISwapChain() {}
virtual bool Initialize(xna_error_nullarg) = 0;
};
SwapChain();
SwapChain(sptr<GraphicsDevice> const& device);
~SwapChain();
bool Initialize(xna_error_nullarg);
bool Present(bool vsync);
bool GetBackBuffer(Texture2D& texture2D);
public:
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
};
}
#endif

View File

@ -7,7 +7,6 @@
#include "../graphics/viewport.hpp"
#include "dxheaders.hpp"
#include "gdeviceinfo-dx.hpp"
#include "swapchain-dx.hpp"
#include "window-dx.hpp"
#include "graphics/presentparams.hpp"

View File

@ -13,8 +13,8 @@
#include "graphics/rasterizerstate.hpp"
#include "graphics/presentparams.hpp"
#include "platform-dx/rendertarget-dx.hpp"
#include "platform-dx/swapchain-dx.hpp"
#include "graphics/shader.hpp"
#include "graphics/swapchain.hpp"
namespace xna {
struct SpriteFont::PlatformImplementation {
@ -250,4 +250,19 @@ namespace xna {
ID3D11PixelShader* _pixelShader = nullptr;
};
struct SwapChain::PlatformImplementation {
IDXGISwapChain1* dxSwapChain{ nullptr };
DXGI_SWAP_CHAIN_DESC1 dxDescription{};
DXGI_SWAP_CHAIN_FULLSCREEN_DESC dxFullScreenDescription{};
bool GetBackBuffer(ID3D11Texture2D*& texture2D) {
if (!dxSwapChain)
return false;
const auto hr = dxSwapChain->GetBuffer(0, __uuidof(texture2D), (void**)(&texture2D));
return !FAILED(hr);
}
};
}

View File

@ -1,35 +0,0 @@
#ifndef XNA_PLATFORM_SWAPCHAIN_DX_HPP
#define XNA_PLATFORM_SWAPCHAIN_DX_HPP
#include "../graphics/swapchain.hpp"
#include "window-dx.hpp"
#include "dxheaders.hpp"
#include "../graphics/gresource.hpp"
namespace xna {
class SwapChain : public ISwapChain, public GraphicsResource {
public:
SwapChain(sptr<GraphicsDevice> const& device): GraphicsResource(device){}
virtual ~SwapChain() override {
if (dxSwapChain) {
dxSwapChain->Release();
dxSwapChain = nullptr;
}
}
virtual bool Initialize(xna_error_nullarg) override;
bool Initialize(GameWindow const& gameWindow, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fullScreenDesc, xna_error_nullarg);
bool GetBackBuffer(ID3D11Texture2D*& texture2D);
bool Present(bool vsync);
public:
IDXGISwapChain1* dxSwapChain{ nullptr };
DXGI_SWAP_CHAIN_DESC1 dxDescription{};
DXGI_SWAP_CHAIN_FULLSCREEN_DESC dxFullScreenDescription{};
};
}
#endif

View File

@ -9,7 +9,6 @@
#include "init-dx.hpp"
#include "rendertarget-dx.hpp"
#include "soundeffect-dx.hpp"
#include "swapchain-dx.hpp"
#include "texture-dx.hpp"
#include "vertexbuffer-dx.hpp"
#include "vertexinput-dx.hpp"