2024-03-18 15:41:46 -03:00
|
|
|
#include "rendertarget-dx.hpp"
|
|
|
|
#include "../graphics/device.hpp"
|
|
|
|
#include "swapchain-dx.hpp"
|
|
|
|
#include "device-dx.hpp"
|
|
|
|
|
|
|
|
namespace xna {
|
2024-05-04 21:07:39 -03:00
|
|
|
bool RenderTarget2D::Initialize(xna_error_ptr_arg) {
|
|
|
|
if (!m_device || !m_device->_device) {
|
|
|
|
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-04 21:07:39 -03:00
|
|
|
if (dxTexture2D) {
|
|
|
|
dxTexture2D->Release();
|
|
|
|
dxTexture2D = nullptr;
|
2024-03-18 15:41:46 -03:00
|
|
|
}
|
|
|
|
|
2024-05-04 21:07:39 -03:00
|
|
|
if (!m_device->_swapChain->GetBackBuffer(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-04 21:07:39 -03:00
|
|
|
const auto hr = dxdevice->CreateRenderTargetView(dxTexture2D, NULL, &_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-04-22 11:22:18 -03:00
|
|
|
context->OMSetRenderTargets(1, &_renderTargetView, nullptr);
|
|
|
|
return true;
|
|
|
|
}
|
2024-03-18 15:41:46 -03:00
|
|
|
}
|