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.5 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) {
2024-11-16 14:28:29 -03:00
Implementation2 = unew<RenderTarget2DImplementation>();
}
2024-05-23 14:38:16 -03:00
RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) {
2024-11-16 14:28:29 -03:00
Implementation2 = unew<RenderTarget2DImplementation>();
}
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->Implementation;
2024-11-16 14:28:29 -03:00
auto& implementation2 = rt->Implementation2;
2024-03-18 15:41:46 -03:00
if (!swapChain->impl->GetBackBuffer(implementation->Texture2D))
{
throw csharp::InvalidOperationException();
}
rt->Initialize();
return rt;
}
void RenderTarget2D::Initialize() {
if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) {
throw csharp::InvalidOperationException();
}
2024-11-16 14:28:29 -03:00
if (Implementation2->RenderTargetView)
return;
Implementation->Description.Width = width;
Implementation->Description.Height = height;
Implementation->Description.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(
Implementation->Texture2D.Get(),
NULL,
2024-11-16 14:28:29 -03:00
Implementation2->RenderTargetView.ReleaseAndGetAddressOf());
2024-03-18 15:41:46 -03:00
2024-05-04 21:07:39 -03:00
if (FAILED(hr)) {
throw csharp::InvalidOperationException();
2024-05-04 21:07:39 -03:00
}
2024-03-18 15:41:46 -03:00
2024-11-16 14:28:29 -03:00
Implementation2->RenderTargetView->GetDesc(&Implementation2->Description);
2024-03-18 15:41:46 -03:00
}
}