diff --git a/framework/platform-dx/device.cpp b/framework/platform-dx/device.cpp index 1e297d8..5f440ff 100644 --- a/framework/platform-dx/device.cpp +++ b/framework/platform-dx/device.cpp @@ -87,7 +87,7 @@ namespace xna { impl->_context->OMSetRenderTargets( 1, - impl->_renderTarget2D->render_impl->_renderTargetView.GetAddressOf(), + impl->_renderTarget2D->impl2->_renderTargetView.GetAddressOf(), nullptr); return result; @@ -104,7 +104,7 @@ namespace xna { impl->_backgroundColor[3] = v4.W; impl->_context->ClearRenderTargetView( - impl->_renderTarget2D->render_impl->_renderTargetView.Get(), + impl->_renderTarget2D->impl2->_renderTargetView.Get(), impl->_backgroundColor); } diff --git a/framework/platform-dx/rendertarget.cpp b/framework/platform-dx/rendertarget.cpp index d89678b..ddd6b4a 100644 --- a/framework/platform-dx/rendertarget.cpp +++ b/framework/platform-dx/rendertarget.cpp @@ -1,49 +1,49 @@ #include "xna/xna-dx.hpp" namespace xna { - RenderTarget2D::RenderTarget2D() : Texture2D() { - render_impl = unew(); - } - RenderTarget2D::RenderTarget2D(sptr const& device) : Texture2D(device) { - render_impl = unew(); - } + impl2 = unew(); + } - RenderTarget2D::~RenderTarget2D() { - render_impl = nullptr; - } - - bool RenderTarget2D::Initialize() { + void RenderTarget2D::Initialize() { if (!impl || !m_device || !m_device->impl->_device) { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); } - if (!m_device->impl->_swapChain->impl->GetBackBuffer(impl->dxTexture2D)) - return false; + auto& swapChain = m_device->impl->_swapChain; + if (!swapChain->impl->GetBackBuffer(impl->dxTexture2D)) + { + Exception::Throw(Exception::FAILED_TO_CREATE); + } + + impl->dxTexture2D->GetDesc(&impl->dxDescription); auto& dxdevice = m_device->impl->_device; - const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D.Get(), NULL, render_impl->_renderTargetView.ReleaseAndGetAddressOf()); + const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D.Get(), NULL, impl2->_renderTargetView.ReleaseAndGetAddressOf()); if (FAILED(hr)) { Exception::Throw(Exception::FAILED_TO_CREATE); } - return true; + impl2->_renderTargetView->GetDesc(&impl2->_renderTargetDesc); + + //depthStencilFormat = DepthFormat::None; + multiSampleCount = impl->dxDescription.SampleDesc.Count; + //targetUsage = RenderTargetUsage::DiscardContent; } - bool RenderTarget2D::Apply() { + void RenderTarget2D::Apply() { if (!m_device || !m_device->impl->_context) { Exception::Throw(Exception::FAILED_TO_APPLY); } - if (!render_impl->_renderTargetView) + if (!impl2->_renderTargetView) { Initialize(); } auto& context = m_device->impl->_context; - context->OMSetRenderTargets(1, render_impl->_renderTargetView.GetAddressOf(), nullptr); - return true; + context->OMSetRenderTargets(1, impl2->_renderTargetView.GetAddressOf(), nullptr); } } \ No newline at end of file diff --git a/framework/platform-dx/texture.cpp b/framework/platform-dx/texture.cpp index 08632cc..38219e1 100644 --- a/framework/platform-dx/texture.cpp +++ b/framework/platform-dx/texture.cpp @@ -31,6 +31,8 @@ namespace xna { surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format); levelCount = static_cast(impl->dxShaderDescription.Texture2D.MipLevels); + width = static_cast(impl->dxDescription.Width); + height = static_cast(impl->dxDescription.Height); } Texture2D::Texture2D() : Texture(nullptr) { @@ -236,23 +238,7 @@ namespace xna { texture2d->impl->dxDescription = desc; return texture2d; - } - - Int Texture2D::Width() const { - return static_cast(impl->dxDescription.Width); - } - - Int Texture2D::Height() const { - return static_cast(impl->dxDescription.Height); - } - - Rectangle Texture2D::Bounds() const { - return Rectangle( - 0, 0, - static_cast(impl->dxDescription.Width), - static_cast(impl->dxDescription.Height) - ); - } + } HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data) { diff --git a/inc/xna/graphics/rendertarget.hpp b/inc/xna/graphics/rendertarget.hpp index 5c4adc7..ae49df5 100644 --- a/inc/xna/graphics/rendertarget.hpp +++ b/inc/xna/graphics/rendertarget.hpp @@ -8,15 +8,25 @@ namespace xna { class RenderTarget2D : public Texture2D { public: RenderTarget2D(); - RenderTarget2D(sptr const& device); + RenderTarget2D(sptr const& device); + + //Gets the data format for the depth stencil data. + constexpr DepthFormat DepthStencilFormat() const { return depthStencilFormat; } + //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; } - ~RenderTarget2D() override; - bool Initialize(); - bool Apply(); + void Initialize(); + void Apply(); + private: + DepthFormat depthStencilFormat{ DepthFormat::None }; + Int multiSampleCount{ 0 }; + RenderTargetUsage targetUsage{ RenderTargetUsage::DiscardContents }; public: struct PlatformImplementation; - uptr render_impl = nullptr; + uptr impl2 = nullptr; }; } diff --git a/inc/xna/graphics/texture.hpp b/inc/xna/graphics/texture.hpp index 58796ae..a26059e 100644 --- a/inc/xna/graphics/texture.hpp +++ b/inc/xna/graphics/texture.hpp @@ -8,9 +8,7 @@ namespace xna { //Represents a texture resource. class Texture : public GraphicsResource { public: - Texture(P_GraphicsDevice const& graphicsDevice) : GraphicsResource(graphicsDevice) {} - - virtual ~Texture() {} + Texture(P_GraphicsDevice const& graphicsDevice) : GraphicsResource(graphicsDevice) {} //Gets the format of the texture data. virtual SurfaceFormat Format() const = 0; @@ -24,16 +22,14 @@ namespace xna { Texture2D(); Texture2D(P_GraphicsDevice const& device); Texture2D(P_GraphicsDevice const& device, size_t width, size_t height); - Texture2D(P_GraphicsDevice const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format); - - ~Texture2D() override {} + Texture2D(P_GraphicsDevice const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format); //Gets the width of this texture resource, in pixels. - Int Width() const; + constexpr Int Width() const { return width; } //Gets the height of this texture resource, in pixels. - Int Height() const; + constexpr Int Height() const { return height; } //Gets the size of this resource. - Rectangle Bounds() const; + constexpr Rectangle Bounds() const { return { 0, 0, width, height }; } //Gets the format of the texture data. constexpr SurfaceFormat Format() const override { return surfaceFormat; } //Gets the number of texture levels in a multilevel texture. @@ -57,9 +53,11 @@ namespace xna { void Initialize(); - private: + protected: SurfaceFormat surfaceFormat{ SurfaceFormat::Color }; Int levelCount{ 0 }; + int width{ 0 }; + int height{ 0 }; public: struct PlatformImplementation;