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

55 lines
1.5 KiB
C++

#include "xna-dx/framework.hpp"
namespace xna {
RenderTarget2D::RenderTarget2D() : Texture2D(nullptr) {
Implementation2 = unew<RenderTarget2DImplementation>();
}
RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) {
Implementation2 = unew<RenderTarget2DImplementation>();
}
P_RenderTarget2D RenderTarget2D::FromBackBuffer(P_GraphicsDevice const& device) {
auto& swapChain = device->Implementation->SwapChain;
auto rt = snew<RenderTarget2D>(device);
auto& implementation = rt->Implementation;
auto& implementation2 = rt->Implementation2;
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();
}
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;
const auto hr = dxdevice->CreateRenderTargetView(
Implementation->Texture2D.Get(),
NULL,
Implementation2->RenderTargetView.ReleaseAndGetAddressOf());
if (FAILED(hr)) {
throw csharp::InvalidOperationException();
}
Implementation2->RenderTargetView->GetDesc(&Implementation2->Description);
}
}