2024-06-05 21:28:53 -03:00
|
|
|
#include "xna/platform-dx/dx.hpp"
|
2024-03-18 15:41:46 -03:00
|
|
|
|
|
|
|
namespace xna {
|
2024-05-23 14:38:16 -03:00
|
|
|
RenderTarget2D::RenderTarget2D() : Texture2D() {
|
|
|
|
render_impl = unew<PlatformImplementation>();
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) {
|
|
|
|
render_impl = unew<PlatformImplementation>();
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderTarget2D::~RenderTarget2D() {
|
|
|
|
render_impl = nullptr;
|
|
|
|
}
|
|
|
|
|
2024-06-22 11:02:01 -03:00
|
|
|
bool RenderTarget2D::Initialize() {
|
2024-05-24 22:26:10 -03:00
|
|
|
if (!impl || !m_device || !m_device->impl->_device) {
|
2024-06-22 11:02:01 -03:00
|
|
|
Exception::Throw(ExMessage::InitializeComponent);
|
2024-06-25 17:06:37 -03:00
|
|
|
}
|
2024-03-18 15:41:46 -03:00
|
|
|
|
2024-05-24 22:26:10 -03:00
|
|
|
if (!m_device->impl->_swapChain->impl->GetBackBuffer(impl->dxTexture2D))
|
2024-03-18 15:41:46 -03:00
|
|
|
return false;
|
|
|
|
|
2024-05-24 22:26:10 -03:00
|
|
|
auto& dxdevice = m_device->impl->_device;
|
2024-04-07 14:06:12 -03:00
|
|
|
|
2024-06-25 17:06:37 -03:00
|
|
|
const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D.Get(), NULL, render_impl->_renderTargetView.ReleaseAndGetAddressOf());
|
2024-03-18 15:41:46 -03:00
|
|
|
|
2024-05-04 21:07:39 -03:00
|
|
|
if (FAILED(hr)) {
|
2024-06-22 11:02:01 -03:00
|
|
|
Exception::Throw(ExMessage::CreateComponent);
|
2024-05-04 21:07:39 -03:00
|
|
|
}
|
2024-03-18 15:41:46 -03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2024-04-22 11:22:18 -03:00
|
|
|
|
2024-06-22 11:02:01 -03:00
|
|
|
bool RenderTarget2D::Apply() {
|
2024-05-24 22:26:10 -03:00
|
|
|
if (!m_device || !m_device->impl->_context) {
|
2024-06-22 11:02:01 -03:00
|
|
|
Exception::Throw(ExMessage::ApplyComponent);
|
2024-05-04 21:07:39 -03:00
|
|
|
}
|
|
|
|
|
2024-06-22 11:02:01 -03:00
|
|
|
if(!render_impl->_renderTargetView)
|
|
|
|
Exception::Throw(ExMessage::UnintializedComponent);
|
|
|
|
|
2024-05-24 22:26:10 -03:00
|
|
|
auto& context = m_device->impl->_context;
|
2024-06-25 17:06:37 -03:00
|
|
|
context->OMSetRenderTargets(1, render_impl->_renderTargetView.GetAddressOf(), nullptr);
|
2024-04-22 11:22:18 -03:00
|
|
|
return true;
|
|
|
|
}
|
2024-03-18 15:41:46 -03:00
|
|
|
}
|