2024-07-13 22:55:36 -03:00
|
|
|
#include "xna/xna-dx.hpp"
|
2024-03-18 15:41:46 -03:00
|
|
|
|
|
|
|
namespace xna {
|
2024-08-05 15:42:56 -03:00
|
|
|
RenderTarget2D::RenderTarget2D() : Texture2D(nullptr) {
|
|
|
|
impl2 = unew<PlatformImplementation>();
|
|
|
|
}
|
|
|
|
|
2024-05-23 14:38:16 -03:00
|
|
|
RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) {
|
2024-08-03 22:45:19 -03:00
|
|
|
impl2 = unew<PlatformImplementation>();
|
|
|
|
}
|
2024-05-23 14:38:16 -03:00
|
|
|
|
2024-08-05 15:42:56 -03:00
|
|
|
P_RenderTarget2D RenderTarget2D::FromBackBuffer(P_GraphicsDevice const& device) {
|
|
|
|
auto& swapChain = device->impl->_swapChain;
|
|
|
|
auto rt = snew<RenderTarget2D>(device);
|
|
|
|
auto& implementation = rt->impl;
|
|
|
|
auto& implementation2 = rt->impl2;
|
2024-03-18 15:41:46 -03:00
|
|
|
|
2024-08-05 15:42:56 -03:00
|
|
|
if (!swapChain->impl->GetBackBuffer(implementation->dxTexture2D))
|
2024-08-03 22:45:19 -03:00
|
|
|
{
|
|
|
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
|
|
|
}
|
|
|
|
|
2024-08-05 15:42:56 -03:00
|
|
|
rt->Initialize();
|
|
|
|
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderTarget2D::Initialize() {
|
|
|
|
if (!impl || !m_device || !m_device->impl->_device) {
|
|
|
|
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
|
|
|
}
|
|
|
|
|
2024-08-05 17:32:28 -03:00
|
|
|
if (impl2->_renderTargetView)
|
|
|
|
return;
|
|
|
|
|
2024-08-05 15:42:56 -03:00
|
|
|
impl->dxDescription.Width = width;
|
|
|
|
impl->dxDescription.Height = height;
|
|
|
|
impl->dxDescription.BindFlags = D3D11_BIND_FLAG::D3D11_BIND_RENDER_TARGET;
|
|
|
|
|
|
|
|
Texture2D::Initialize();
|
|
|
|
|
2024-05-24 22:26:10 -03:00
|
|
|
auto& dxdevice = m_device->impl->_device;
|
2024-04-07 14:06:12 -03:00
|
|
|
|
2024-08-05 15:42:56 -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
|
|
|
|
2024-08-03 22:45:19 -03:00
|
|
|
impl2->_renderTargetView->GetDesc(&impl2->_renderTargetDesc);
|
2024-03-18 15:41:46 -03:00
|
|
|
}
|
|
|
|
}
|