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

55 lines
1.4 KiB
C++
Raw Normal View History

#include "graphics/device.hpp"
#include "platform-dx/device-dx.hpp"
2024-05-22 20:05:52 -03:00
#include "platform-dx/implementations.hpp"
2024-05-23 14:38:16 -03:00
#include "graphics/rendertarget.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-05-04 21:07:39 -03:00
bool RenderTarget2D::Initialize(xna_error_ptr_arg) {
2024-05-23 14:38:16 -03:00
if (!impl || !m_device || !m_device->_device) {
2024-05-04 21:07:39 -03:00
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
2024-04-22 11:22:18 -03:00
return false;
2024-05-04 21:07:39 -03:00
}
2024-03-18 15:41:46 -03:00
2024-05-23 14:38:16 -03:00
if (impl->dxTexture2D) {
impl->dxTexture2D->Release();
impl->dxTexture2D = nullptr;
2024-03-18 15:41:46 -03:00
}
2024-05-23 14:38:16 -03:00
if (!m_device->_swapChain->impl->GetBackBuffer(impl->dxTexture2D))
2024-03-18 15:41:46 -03:00
return false;
2024-05-04 21:07:39 -03:00
auto& dxdevice = m_device->_device;
2024-04-07 14:06:12 -03:00
2024-05-23 14:38:16 -03:00
const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D, NULL, &render_impl->_renderTargetView);
2024-03-18 15:41:46 -03:00
2024-05-04 21:07:39 -03:00
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
2024-04-22 11:22:18 -03:00
return false;
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-05-04 21:07:39 -03:00
bool RenderTarget2D::Apply(xna_error_ptr_arg) {
if (!m_device || !m_device->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false;
}
auto& context = m_device->_context;
2024-05-23 14:38:16 -03:00
context->OMSetRenderTargets(1, &render_impl->_renderTargetView, nullptr);
2024-04-22 11:22:18 -03:00
return true;
}
2024-03-18 15:41:46 -03:00
}