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.3 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(sptr<GraphicsDevice> const& device) : Texture2D(device) {
impl2 = unew<PlatformImplementation>();
}
2024-05-23 14:38:16 -03:00
void 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
auto& swapChain = m_device->impl->_swapChain;
2024-03-18 15:41:46 -03:00
if (!swapChain->impl->GetBackBuffer(impl->dxTexture2D))
{
Exception::Throw(Exception::FAILED_TO_CREATE);
}
impl->dxTexture2D->GetDesc(&impl->dxDescription);
2024-05-24 22:26:10 -03:00
auto& dxdevice = m_device->impl->_device;
2024-04-07 14:06:12 -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
impl2->_renderTargetView->GetDesc(&impl2->_renderTargetDesc);
//depthStencilFormat = DepthFormat::None;
multiSampleCount = impl->dxDescription.SampleDesc.Count;
//targetUsage = RenderTargetUsage::DiscardContent;
2024-03-18 15:41:46 -03:00
}
2024-04-22 11:22:18 -03:00
void 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
}
if (!impl2->_renderTargetView)
2024-08-02 17:17:33 -03:00
{
Initialize();
}
2024-05-24 22:26:10 -03:00
auto& context = m_device->impl->_context;
context->OMSetRenderTargets(1, impl2->_renderTargetView.GetAddressOf(), nullptr);
2024-04-22 11:22:18 -03:00
}
2024-03-18 15:41:46 -03:00
}