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

Implementa RenderTarget::FromBackBuffer

This commit is contained in:
Danilo 2024-08-05 15:42:56 -03:00
parent 6d20f38b48
commit fedb773b31
6 changed files with 81 additions and 64 deletions

View File

@ -54,8 +54,7 @@ namespace xna {
if (FAILED(hr)) if (FAILED(hr))
Exception::Throw(Exception::FAILED_TO_MAKE_WINDOW_ASSOCIATION); Exception::Throw(Exception::FAILED_TO_MAKE_WINDOW_ASSOCIATION);
impl->_renderTarget2D = snew<RenderTarget2D>(_this); impl->_renderTarget2D = RenderTarget2D::FromBackBuffer(_this);
impl->_renderTarget2D->Initialize();
impl->_renderTarget2D->Apply(); impl->_renderTarget2D->Apply();
D3D11_VIEWPORT view = DxHelpers::ViewportToDx(viewport); D3D11_VIEWPORT view = DxHelpers::ViewportToDx(viewport);

View File

@ -1,36 +1,53 @@
#include "xna/xna-dx.hpp" #include "xna/xna-dx.hpp"
namespace xna { namespace xna {
RenderTarget2D::RenderTarget2D() : Texture2D(nullptr) {
impl2 = unew<PlatformImplementation>();
}
RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) { RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) {
impl2 = unew<PlatformImplementation>(); impl2 = unew<PlatformImplementation>();
} }
void RenderTarget2D::Initialize() { P_RenderTarget2D RenderTarget2D::FromBackBuffer(P_GraphicsDevice const& device) {
if (!impl || !m_device || !m_device->impl->_device) { auto& swapChain = device->impl->_swapChain;
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); auto rt = snew<RenderTarget2D>(device);
} auto& implementation = rt->impl;
auto& implementation2 = rt->impl2;
auto& swapChain = m_device->impl->_swapChain; if (!swapChain->impl->GetBackBuffer(implementation->dxTexture2D))
if (!swapChain->impl->GetBackBuffer(impl->dxTexture2D))
{ {
Exception::Throw(Exception::FAILED_TO_CREATE); Exception::Throw(Exception::FAILED_TO_CREATE);
} }
impl->dxTexture2D->GetDesc(&impl->dxDescription); rt->Initialize();
return rt;
}
void RenderTarget2D::Initialize() {
if (!impl || !m_device || !m_device->impl->_device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
}
impl->dxDescription.Width = width;
impl->dxDescription.Height = height;
impl->dxDescription.BindFlags = D3D11_BIND_FLAG::D3D11_BIND_RENDER_TARGET;
Texture2D::Initialize();
auto& dxdevice = m_device->impl->_device; auto& dxdevice = m_device->impl->_device;
const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D.Get(), NULL, impl2->_renderTargetView.ReleaseAndGetAddressOf()); const auto hr = dxdevice->CreateRenderTargetView(
impl->dxTexture2D.Get(),
NULL,
impl2->_renderTargetView.ReleaseAndGetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(Exception::FAILED_TO_CREATE); Exception::Throw(Exception::FAILED_TO_CREATE);
} }
impl2->_renderTargetView->GetDesc(&impl2->_renderTargetDesc); impl2->_renderTargetView->GetDesc(&impl2->_renderTargetDesc);
//depthStencilFormat = DepthFormat::None;
multiSampleCount = impl->dxDescription.SampleDesc.Count;
//targetUsage = RenderTargetUsage::DiscardContent;
} }
void RenderTarget2D::Apply() { void RenderTarget2D::Apply() {

View File

@ -4,16 +4,50 @@ namespace xna {
static void setDefaultTexture2DDesc(Texture2D::PlatformImplementation& impl); static void setDefaultTexture2DDesc(Texture2D::PlatformImplementation& impl);
static HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data); static HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data);
Texture2D::Texture2D() : Texture(nullptr) {
impl = unew<PlatformImplementation>();
setDefaultTexture2DDesc(*impl);
}
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height) : Texture(device), width(width), height(height) {
impl = unew<PlatformImplementation>();
setDefaultTexture2DDesc(*impl);
impl->dxDescription.Width = static_cast<UINT>(this->width);
impl->dxDescription.Height = static_cast<UINT>(this->height);
}
Texture2D::Texture2D(sptr<GraphicsDevice> const& device) : Texture(device) {
impl = unew<PlatformImplementation>();
setDefaultTexture2DDesc(*impl);
}
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format)
: Texture(device), width(width), height(height), levelCount(mipMap) {
impl = unew<PlatformImplementation>();
setDefaultTexture2DDesc(*impl);
impl->dxDescription.Width = static_cast<UINT>(this->width);
impl->dxDescription.Height = static_cast<UINT>(this->height);
impl->dxDescription.MipLevels = static_cast<UINT>(this->levelCount);
impl->dxDescription.Format = DxHelpers::SurfaceFormatToDx(format);
}
void Texture2D::Initialize() void Texture2D::Initialize()
{ {
if (!m_device || !m_device->impl->_device) { if (!m_device || !m_device->impl->_device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
} }
auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, impl->dxTexture2D.ReleaseAndGetAddressOf()); HRESULT hr = 0;
if (FAILED(hr)) { if (!impl->dxTexture2D) {
Exception::Throw(Exception::FAILED_TO_CREATE); hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, impl->dxTexture2D.ReleaseAndGetAddressOf());
if (FAILED(hr)) {
Exception::Throw(Exception::FAILED_TO_CREATE);
}
}
else {
impl->dxTexture2D->GetDesc(&impl->dxDescription);
} }
comptr<ID3D11Resource> resource = nullptr; comptr<ID3D11Resource> resource = nullptr;
@ -22,45 +56,20 @@ namespace xna {
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(Exception::INVALID_OPERATION); Exception::Throw(Exception::INVALID_OPERATION);
} }
if (impl->dxDescription.BindFlags & D3D11_BIND_SHADER_RESOURCE) {
hr = m_device->impl->_device->CreateShaderResourceView(resource.Get(), &impl->dxShaderDescription, impl->dxShaderResource.ReleaseAndGetAddressOf());
hr = m_device->impl->_device->CreateShaderResourceView(resource.Get(), &impl->dxShaderDescription, &impl->dxShaderResource); if (FAILED(hr)) {
Exception::Throw(Exception::FAILED_TO_CREATE);
if (FAILED(hr)) { }
Exception::Throw(Exception::FAILED_TO_CREATE); }
}
surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format); surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format);
levelCount = static_cast<Int>(impl->dxShaderDescription.Texture2D.MipLevels); levelCount = static_cast<Int>(impl->dxShaderDescription.Texture2D.MipLevels);
width = static_cast<Int>(impl->dxDescription.Width); width = static_cast<Int>(impl->dxDescription.Width);
height = static_cast<Int>(impl->dxDescription.Height); height = static_cast<Int>(impl->dxDescription.Height);
} }
Texture2D::Texture2D() : Texture(nullptr) {
impl = unew<PlatformImplementation>();
setDefaultTexture2DDesc(*impl);
}
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height) : Texture(device) {
impl = unew<PlatformImplementation>();
setDefaultTexture2DDesc(*impl);
impl->dxDescription.Width = static_cast<UINT>(width);
impl->dxDescription.Height = static_cast<UINT>(height);
}
Texture2D::Texture2D(sptr<GraphicsDevice> const& device) : Texture(device) {
impl = unew<PlatformImplementation>();
setDefaultTexture2DDesc(*impl);
}
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : Texture(device)
{
impl = unew<PlatformImplementation>();
setDefaultTexture2DDesc(*impl);
impl->dxDescription.Width = static_cast<UINT>(width);
impl->dxDescription.Height = static_cast<UINT>(height);
impl->dxDescription.MipLevels = static_cast<UINT>(mipMap);
impl->dxDescription.Format = DxHelpers::SurfaceFormatToDx(format);
}
void Texture2D::SetData(std::vector<Uint> const& data, size_t startIndex, size_t elementCount) void Texture2D::SetData(std::vector<Uint> const& data, size_t startIndex, size_t elementCount)
{ {

View File

@ -207,6 +207,7 @@ namespace xna {
using P_FileStream = sptr<FileStream>; using P_FileStream = sptr<FileStream>;
using P_Texture = sptr<Texture>; using P_Texture = sptr<Texture>;
using P_Texture2D = sptr<Texture2D>; using P_Texture2D = sptr<Texture2D>;
using P_RenderTarget2D = sptr<RenderTarget2D>;
} }

View File

@ -8,22 +8,13 @@ namespace xna {
class RenderTarget2D : public Texture2D { class RenderTarget2D : public Texture2D {
public: public:
RenderTarget2D(); RenderTarget2D();
RenderTarget2D(sptr<GraphicsDevice> const& device); RenderTarget2D(sptr<GraphicsDevice> const& device);
//Gets the data format for the depth stencil data.
constexpr DepthFormat DepthStencilFormat() const { return depthStencilFormat; } static P_RenderTarget2D FromBackBuffer(P_GraphicsDevice const& device);
//Gets the number of sample locations during multisampling.
constexpr Int MultiSampleCount() const { return multiSampleCount; }
//Gets or sets the render target usage.
constexpr RenderTargetUsage TargetUsage() const { return targetUsage; }
void Initialize(); void Initialize();
void Apply(); void Apply();
private:
DepthFormat depthStencilFormat{ DepthFormat::None };
Int multiSampleCount{ 0 };
RenderTargetUsage targetUsage{ RenderTargetUsage::DiscardContents };
public: public:
struct PlatformImplementation; struct PlatformImplementation;
uptr<PlatformImplementation> impl2 = nullptr; uptr<PlatformImplementation> impl2 = nullptr;

View File

@ -4,4 +4,4 @@
# Add source to this project's executable. # Add source to this project's executable.
add_subdirectory ("01_blank") add_subdirectory ("01_blank")
#add_subdirectory ("02_PlatfformerStarterKit") add_subdirectory ("02_PlatfformerStarterKit")