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(
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);
}

View File

@ -1,49 +1,49 @@
#include "xna/xna-dx.hpp"
namespace xna {
RenderTarget2D::RenderTarget2D() : Texture2D() {
render_impl = unew<PlatformImplementation>();
}
RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) {
render_impl = unew<PlatformImplementation>();
}
impl2 = unew<PlatformImplementation>();
}
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);
}
}

View File

@ -31,6 +31,8 @@ namespace xna {
surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format);
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) {
@ -236,23 +238,7 @@ namespace xna {
texture2d->impl->dxDescription = desc;
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)
{

View File

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

View File

@ -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;