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

Implementações em Texture2D e RenderTarget

This commit is contained in:
Danilo 2024-08-03 22:45:19 -03:00
parent 576503d2be
commit 6d20f38b48
5 changed files with 47 additions and 53 deletions

View File

@ -87,7 +87,7 @@ namespace xna {
impl->_context->OMSetRenderTargets( impl->_context->OMSetRenderTargets(
1, 1,
impl->_renderTarget2D->render_impl->_renderTargetView.GetAddressOf(), impl->_renderTarget2D->impl2->_renderTargetView.GetAddressOf(),
nullptr); nullptr);
return result; return result;
@ -104,7 +104,7 @@ namespace xna {
impl->_backgroundColor[3] = v4.W; impl->_backgroundColor[3] = v4.W;
impl->_context->ClearRenderTargetView( impl->_context->ClearRenderTargetView(
impl->_renderTarget2D->render_impl->_renderTargetView.Get(), impl->_renderTarget2D->impl2->_renderTargetView.Get(),
impl->_backgroundColor); impl->_backgroundColor);
} }

View File

@ -1,49 +1,49 @@
#include "xna/xna-dx.hpp" #include "xna/xna-dx.hpp"
namespace xna { namespace xna {
RenderTarget2D::RenderTarget2D() : Texture2D() {
render_impl = unew<PlatformImplementation>();
}
RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) { RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) {
render_impl = unew<PlatformImplementation>(); impl2 = unew<PlatformImplementation>();
} }
RenderTarget2D::~RenderTarget2D() { void RenderTarget2D::Initialize() {
render_impl = nullptr;
}
bool RenderTarget2D::Initialize() {
if (!impl || !m_device || !m_device->impl->_device) { if (!impl || !m_device || !m_device->impl->_device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
} }
if (!m_device->impl->_swapChain->impl->GetBackBuffer(impl->dxTexture2D)) auto& swapChain = m_device->impl->_swapChain;
return false;
if (!swapChain->impl->GetBackBuffer(impl->dxTexture2D))
{
Exception::Throw(Exception::FAILED_TO_CREATE);
}
impl->dxTexture2D->GetDesc(&impl->dxDescription);
auto& dxdevice = m_device->impl->_device; 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)) { if (FAILED(hr)) {
Exception::Throw(Exception::FAILED_TO_CREATE); 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) { if (!m_device || !m_device->impl->_context) {
Exception::Throw(Exception::FAILED_TO_APPLY); Exception::Throw(Exception::FAILED_TO_APPLY);
} }
if (!render_impl->_renderTargetView) if (!impl2->_renderTargetView)
{ {
Initialize(); Initialize();
} }
auto& context = m_device->impl->_context; auto& context = m_device->impl->_context;
context->OMSetRenderTargets(1, render_impl->_renderTargetView.GetAddressOf(), nullptr); context->OMSetRenderTargets(1, impl2->_renderTargetView.GetAddressOf(), nullptr);
return true;
} }
} }

View File

@ -31,6 +31,8 @@ namespace xna {
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);
height = static_cast<Int>(impl->dxDescription.Height);
} }
Texture2D::Texture2D() : Texture(nullptr) { Texture2D::Texture2D() : Texture(nullptr) {
@ -236,23 +238,7 @@ namespace xna {
texture2d->impl->dxDescription = desc; texture2d->impl->dxDescription = desc;
return texture2d; return texture2d;
} }
Int Texture2D::Width() const {
return static_cast<Int>(impl->dxDescription.Width);
}
Int Texture2D::Height() const {
return static_cast<Int>(impl->dxDescription.Height);
}
Rectangle Texture2D::Bounds() const {
return Rectangle(
0, 0,
static_cast<Int>(impl->dxDescription.Width),
static_cast<Int>(impl->dxDescription.Height)
);
}
HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data) HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data)
{ {

View File

@ -8,15 +8,25 @@ 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; }
//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; void Initialize();
bool Initialize(); void Apply();
bool Apply(); private:
DepthFormat depthStencilFormat{ DepthFormat::None };
Int multiSampleCount{ 0 };
RenderTargetUsage targetUsage{ RenderTargetUsage::DiscardContents };
public: public:
struct PlatformImplementation; struct PlatformImplementation;
uptr<PlatformImplementation> render_impl = nullptr; uptr<PlatformImplementation> impl2 = nullptr;
}; };
} }

View File

@ -8,9 +8,7 @@ namespace xna {
//Represents a texture resource. //Represents a texture resource.
class Texture : public GraphicsResource { class Texture : public GraphicsResource {
public: public:
Texture(P_GraphicsDevice const& graphicsDevice) : GraphicsResource(graphicsDevice) {} Texture(P_GraphicsDevice const& graphicsDevice) : GraphicsResource(graphicsDevice) {}
virtual ~Texture() {}
//Gets the format of the texture data. //Gets the format of the texture data.
virtual SurfaceFormat Format() const = 0; virtual SurfaceFormat Format() const = 0;
@ -24,16 +22,14 @@ namespace xna {
Texture2D(); Texture2D();
Texture2D(P_GraphicsDevice const& device); 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);
Texture2D(P_GraphicsDevice const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format); Texture2D(P_GraphicsDevice const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format);
~Texture2D() override {}
//Gets the width of this texture resource, in pixels. //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. //Gets the height of this texture resource, in pixels.
Int Height() const; constexpr Int Height() const { return height; }
//Gets the size of this resource. //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. //Gets the format of the texture data.
constexpr SurfaceFormat Format() const override { return surfaceFormat; } constexpr SurfaceFormat Format() const override { return surfaceFormat; }
//Gets the number of texture levels in a multilevel texture. //Gets the number of texture levels in a multilevel texture.
@ -57,9 +53,11 @@ namespace xna {
void Initialize(); void Initialize();
private: protected:
SurfaceFormat surfaceFormat{ SurfaceFormat::Color }; SurfaceFormat surfaceFormat{ SurfaceFormat::Color };
Int levelCount{ 0 }; Int levelCount{ 0 };
int width{ 0 };
int height{ 0 };
public: public:
struct PlatformImplementation; struct PlatformImplementation;