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

55 lines
1.4 KiB
C++
Raw Normal View History

2024-09-06 22:23:32 -03:00
#include "xna-dx/framework.hpp"
2024-03-18 15:41:46 -03:00
namespace xna {
RenderTarget2D::RenderTarget2D() : Texture2D(nullptr) {
impl2 = unew<PlatformImplementation>();
}
2024-05-23 14:38:16 -03:00
RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) {
impl2 = unew<PlatformImplementation>();
}
2024-05-23 14:38:16 -03:00
P_RenderTarget2D RenderTarget2D::FromBackBuffer(P_GraphicsDevice const& device) {
auto& swapChain = device->Implementation->SwapChain;
auto rt = snew<RenderTarget2D>(device);
auto& implementation = rt->impl;
auto& implementation2 = rt->impl2;
2024-03-18 15:41:46 -03:00
if (!swapChain->impl->GetBackBuffer(implementation->dxTexture2D))
{
Exception::Throw(Exception::FAILED_TO_CREATE);
}
rt->Initialize();
return rt;
}
void RenderTarget2D::Initialize() {
if (!impl || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
}
if (impl2->_renderTargetView)
return;
impl->dxDescription.Width = width;
impl->dxDescription.Height = height;
impl->dxDescription.BindFlags = D3D11_BIND_FLAG::D3D11_BIND_RENDER_TARGET;
Texture2D::Initialize();
auto& dxdevice = BaseGraphicsDevice->Implementation->Device;
2024-04-07 14:06:12 -03:00
const auto hr = dxdevice->CreateRenderTargetView(
impl->dxTexture2D.Get(),
NULL,
impl2->_renderTargetView.ReleaseAndGetAddressOf());
2024-03-18 15:41:46 -03:00
2024-05-04 21:07:39 -03:00
if (FAILED(hr)) {
2024-07-06 12:20:54 -03:00
Exception::Throw(Exception::FAILED_TO_CREATE);
2024-05-04 21:07:39 -03:00
}
2024-03-18 15:41:46 -03:00
impl2->_renderTargetView->GetDesc(&impl2->_renderTargetDesc);
2024-03-18 15:41:46 -03:00
}
}