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

Correções em GraphicsResource

This commit is contained in:
Danilo 2024-05-06 15:57:09 -03:00
parent da53a0a272
commit c6797f4d93
13 changed files with 29 additions and 25 deletions

View File

@ -6,11 +6,11 @@
namespace xna { namespace xna {
class GraphicsResource { class GraphicsResource {
public: public:
GraphicsResource(GraphicsDevice* device) : m_device(device){} GraphicsResource(sptr<GraphicsDevice> const& device) : m_device(device){}
virtual ~GraphicsResource(){} virtual ~GraphicsResource(){}
virtual bool Bind(GraphicsDevice* device) { virtual bool Bind(sptr<GraphicsDevice> const& device) {
if (device == m_device) if (device == m_device)
return false; return false;
@ -20,7 +20,7 @@ namespace xna {
} }
protected: protected:
GraphicsDevice* m_device = nullptr; sptr<GraphicsDevice> m_device = nullptr;
}; };
} }

View File

@ -21,7 +21,7 @@ namespace xna {
class BlendState : public IBlendState, public GraphicsResource { class BlendState : public IBlendState, public GraphicsResource {
public: public:
BlendState(GraphicsDevice* device) : GraphicsResource(device) {}; BlendState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {};
virtual ~BlendState() override { virtual ~BlendState() override {
if (dxBlendState) { if (dxBlendState) {

View File

@ -20,7 +20,7 @@ namespace xna {
auto a_device = ContentManager::Services()->GetService(*typeof<GraphicsDevice>()); auto a_device = ContentManager::Services()->GetService(*typeof<GraphicsDevice>());
auto device = std::any_cast<sptr<GraphicsDevice>>(a_device); auto device = std::any_cast<sptr<GraphicsDevice>>(a_device);
auto texture2D = New<Texture2D>(device.get(), width, height, mipMaps, format); auto texture2D = New<Texture2D>(device, width, height, mipMaps, format);
for (size_t level = 0; level < mipMaps; ++level) { for (size_t level = 0; level < mipMaps; ++level) {
auto elementCount = input.ReadInt32(); auto elementCount = input.ReadInt32();

View File

@ -8,7 +8,7 @@
namespace xna { namespace xna {
class DepthStencilState : public IDepthStencilState, public GraphicsResource { class DepthStencilState : public IDepthStencilState, public GraphicsResource {
public: public:
DepthStencilState(GraphicsDevice* device) : GraphicsResource(device) { DepthStencilState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
dxDescription = defaultDesc(); dxDescription = defaultDesc();
} }

View File

@ -23,6 +23,8 @@ namespace xna {
bool GraphicsDevice::Initialize(GameWindow& gameWindow) { bool GraphicsDevice::Initialize(GameWindow& gameWindow) {
reset(); reset();
auto _this = shared_from_this();
if (!createDevice()) return false; if (!createDevice()) return false;
auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&_factory); auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&_factory);
@ -41,13 +43,13 @@ namespace xna {
_backgroundColor[2] = GetBValue(color) / 255.0f; _backgroundColor[2] = GetBValue(color) / 255.0f;
_backgroundColor[3] = 1.0f; _backgroundColor[3] = 1.0f;
_swapChain = New<xna::SwapChain>(this); _swapChain = New<xna::SwapChain>(_this);
_swapChain->Initialize(); _swapChain->Initialize();
hr = _factory->MakeWindowAssociation(gameWindow.WindowHandle(), DXGI_MWA_NO_ALT_ENTER); hr = _factory->MakeWindowAssociation(gameWindow.WindowHandle(), DXGI_MWA_NO_ALT_ENTER);
if (FAILED(hr)) return false; if (FAILED(hr)) return false;
_renderTarget2D = New<RenderTarget2D>(this); _renderTarget2D = New<RenderTarget2D>(_this);
if (!_renderTarget2D->Initialize()) if (!_renderTarget2D->Initialize())
return false; return false;
@ -64,7 +66,7 @@ namespace xna {
_context->RSSetViewports(1, &view); _context->RSSetViewports(1, &view);
_blendState = BlendState::NonPremultiplied(); _blendState = BlendState::NonPremultiplied();
_blendState->Bind(this); _blendState->Bind(_this);
_blendState->Apply(); _blendState->Apply();
return true; return true;

View File

@ -14,7 +14,7 @@
#include "presentparameters-dx.hpp" #include "presentparameters-dx.hpp"
namespace xna { namespace xna {
class GraphicsDevice : public IGraphicsDevice { class GraphicsDevice : public IGraphicsDevice, public std::enable_shared_from_this<GraphicsDevice> {
public: public:
GraphicsDevice(); GraphicsDevice();
GraphicsDevice(GraphicsDeviceInformation const& info); GraphicsDevice(GraphicsDeviceInformation const& info);

View File

@ -8,7 +8,7 @@
namespace xna { namespace xna {
class RasterizerState : public IRasterizerState, public GraphicsResource { class RasterizerState : public IRasterizerState, public GraphicsResource {
public: public:
RasterizerState(GraphicsDevice* device) : GraphicsResource(device){} RasterizerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device){}
virtual ~RasterizerState() override { virtual ~RasterizerState() override {
if (dxRasterizerState) { if (dxRasterizerState) {

View File

@ -9,7 +9,7 @@
namespace xna { namespace xna {
class RenderTarget2D : public IRenderTarget2D, public Texture2D { class RenderTarget2D : public IRenderTarget2D, public Texture2D {
public: public:
RenderTarget2D(GraphicsDevice* device) : Texture2D(device){} RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device){}
virtual ~RenderTarget2D() override { virtual ~RenderTarget2D() override {
if (_renderTargetView) { if (_renderTargetView) {

View File

@ -8,7 +8,7 @@
namespace xna { namespace xna {
class SamplerState : public ISamplerState, public GraphicsResource { class SamplerState : public ISamplerState, public GraphicsResource {
public: public:
SamplerState(GraphicsDevice* device) : GraphicsResource(device) { SamplerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
_description.MaxAnisotropy = 4; _description.MaxAnisotropy = 4;
} }

View File

@ -8,7 +8,7 @@
namespace xna { namespace xna {
class Shader : public IShader, public GraphicsResource { class Shader : public IShader, public GraphicsResource {
public: public:
Shader(GraphicsDevice* device) : GraphicsResource(device){} Shader(sptr<GraphicsDevice> const& device) : GraphicsResource(device){}
virtual ~Shader() override {} virtual ~Shader() override {}
@ -19,7 +19,7 @@ namespace xna {
class VertexShader : public Shader { class VertexShader : public Shader {
public: public:
VertexShader(GraphicsDevice* device) : Shader(device){} VertexShader(sptr<GraphicsDevice> const& device) : Shader(device){}
virtual ~VertexShader() override { virtual ~VertexShader() override {
if (_vertexShader) { if (_vertexShader) {
@ -36,7 +36,7 @@ namespace xna {
class PixelShader : public Shader { class PixelShader : public Shader {
public: public:
PixelShader(GraphicsDevice* device) : Shader(device) {} PixelShader(sptr<GraphicsDevice> const& device) : Shader(device) {}
virtual ~PixelShader() override { virtual ~PixelShader() override {
if (_pixelShader) { if (_pixelShader) {

View File

@ -9,7 +9,7 @@
namespace xna { namespace xna {
class SwapChain : public ISwapChain, public GraphicsResource { class SwapChain : public ISwapChain, public GraphicsResource {
public: public:
SwapChain(GraphicsDevice* device): GraphicsResource(device){} SwapChain(sptr<GraphicsDevice> const& device): GraphicsResource(device){}
virtual ~SwapChain() override { virtual ~SwapChain() override {
if (dxSwapChain) { if (dxSwapChain) {

View File

@ -5,7 +5,8 @@
namespace xna { namespace xna {
sptr<Texture2D> Texture2D::FromStream(GraphicsDevice& device, String const& fileName, xna_error_ptr_arg) sptr<Texture2D> Texture2D::FromStream(GraphicsDevice& device, String const& fileName, xna_error_ptr_arg)
{ {
auto texture2d = New<Texture2D>(&device); auto _this = device.shared_from_this();
auto texture2d = New<Texture2D>(_this);
ID3D11Resource* resource = nullptr; ID3D11Resource* resource = nullptr;
auto wstr = XnaHToWString(fileName); auto wstr = XnaHToWString(fileName);
@ -94,17 +95,17 @@ namespace xna {
return true; return true;
} }
Texture2D::Texture2D(GraphicsDevice* device, size_t width, size_t height) : GraphicsResource(device) { Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height) : GraphicsResource(device) {
setDefaultDesc(); setDefaultDesc();
dxDescription.Width = static_cast<UINT>(width); dxDescription.Width = static_cast<UINT>(width);
dxDescription.Height = static_cast<UINT>(height); dxDescription.Height = static_cast<UINT>(height);
} }
Texture2D::Texture2D(GraphicsDevice* device) : GraphicsResource(device) { Texture2D::Texture2D(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
setDefaultDesc(); setDefaultDesc();
} }
Texture2D::Texture2D(GraphicsDevice* device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : GraphicsResource(device) Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : GraphicsResource(device)
{ {
setDefaultDesc(); setDefaultDesc();
dxDescription.Width = static_cast<UINT>(width); dxDescription.Width = static_cast<UINT>(width);
@ -235,7 +236,8 @@ namespace xna {
sptr<Texture2D> Texture2D::FromMemory(GraphicsDevice& device, std::vector<Byte> const& data, xna_error_ptr_arg) sptr<Texture2D> Texture2D::FromMemory(GraphicsDevice& device, std::vector<Byte> const& data, xna_error_ptr_arg)
{ {
auto texture2d = New<Texture2D>(&device); auto _this = device.shared_from_this();
auto texture2d = New<Texture2D>(_this);
ID3D11Resource* resource = nullptr; ID3D11Resource* resource = nullptr;
auto hr = DirectX::CreateWICTextureFromMemory( auto hr = DirectX::CreateWICTextureFromMemory(

View File

@ -14,9 +14,9 @@ namespace xna {
setDefaultDesc(); setDefaultDesc();
} }
Texture2D(GraphicsDevice* device); Texture2D(sptr<GraphicsDevice> const& device);
Texture2D(GraphicsDevice* device, size_t width, size_t height); Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height);
Texture2D(GraphicsDevice* device, size_t width, size_t height, size_t mipMap, SurfaceFormat format); Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format);
virtual ~Texture2D() override { virtual ~Texture2D() override {
if (dxTexture2D) { if (dxTexture2D) {