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

49 lines
1.2 KiB
C++
Raw Normal View History

2024-07-13 22:55:36 -03:00
#include "xna/xna-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;
}
bool RenderTarget2D::Initialize() {
2024-05-24 22:26:10 -03:00
if (!impl || !m_device || !m_device->impl->_device) {
2024-07-06 12:20:54 -03:00
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
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-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
return true;
}
2024-04-22 11:22:18 -03:00
bool RenderTarget2D::Apply() {
2024-05-24 22:26:10 -03:00
if (!m_device || !m_device->impl->_context) {
2024-07-06 12:20:54 -03:00
Exception::Throw(Exception::FAILED_TO_APPLY);
2024-05-04 21:07:39 -03:00
}
2024-08-02 17:17:33 -03:00
if (!render_impl->_renderTargetView)
{
Initialize();
}
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
}