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:
parent
da53a0a272
commit
c6797f4d93
@ -6,11 +6,11 @@
|
||||
namespace xna {
|
||||
class GraphicsResource {
|
||||
public:
|
||||
GraphicsResource(GraphicsDevice* device) : m_device(device){}
|
||||
GraphicsResource(sptr<GraphicsDevice> const& device) : m_device(device){}
|
||||
|
||||
virtual ~GraphicsResource(){}
|
||||
|
||||
virtual bool Bind(GraphicsDevice* device) {
|
||||
virtual bool Bind(sptr<GraphicsDevice> const& device) {
|
||||
if (device == m_device)
|
||||
return false;
|
||||
|
||||
@ -20,7 +20,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
protected:
|
||||
GraphicsDevice* m_device = nullptr;
|
||||
sptr<GraphicsDevice> m_device = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ namespace xna {
|
||||
|
||||
class BlendState : public IBlendState, public GraphicsResource {
|
||||
public:
|
||||
BlendState(GraphicsDevice* device) : GraphicsResource(device) {};
|
||||
BlendState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {};
|
||||
|
||||
virtual ~BlendState() override {
|
||||
if (dxBlendState) {
|
||||
|
@ -20,7 +20,7 @@ namespace xna {
|
||||
auto a_device = ContentManager::Services()->GetService(*typeof<GraphicsDevice>());
|
||||
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) {
|
||||
auto elementCount = input.ReadInt32();
|
||||
|
@ -8,7 +8,7 @@
|
||||
namespace xna {
|
||||
class DepthStencilState : public IDepthStencilState, public GraphicsResource {
|
||||
public:
|
||||
DepthStencilState(GraphicsDevice* device) : GraphicsResource(device) {
|
||||
DepthStencilState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
||||
dxDescription = defaultDesc();
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,8 @@ namespace xna {
|
||||
bool GraphicsDevice::Initialize(GameWindow& gameWindow) {
|
||||
reset();
|
||||
|
||||
auto _this = shared_from_this();
|
||||
|
||||
if (!createDevice()) return false;
|
||||
|
||||
auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&_factory);
|
||||
@ -41,13 +43,13 @@ namespace xna {
|
||||
_backgroundColor[2] = GetBValue(color) / 255.0f;
|
||||
_backgroundColor[3] = 1.0f;
|
||||
|
||||
_swapChain = New<xna::SwapChain>(this);
|
||||
_swapChain = New<xna::SwapChain>(_this);
|
||||
_swapChain->Initialize();
|
||||
|
||||
hr = _factory->MakeWindowAssociation(gameWindow.WindowHandle(), DXGI_MWA_NO_ALT_ENTER);
|
||||
if (FAILED(hr)) return false;
|
||||
|
||||
_renderTarget2D = New<RenderTarget2D>(this);
|
||||
_renderTarget2D = New<RenderTarget2D>(_this);
|
||||
if (!_renderTarget2D->Initialize())
|
||||
return false;
|
||||
|
||||
@ -64,7 +66,7 @@ namespace xna {
|
||||
_context->RSSetViewports(1, &view);
|
||||
|
||||
_blendState = BlendState::NonPremultiplied();
|
||||
_blendState->Bind(this);
|
||||
_blendState->Bind(_this);
|
||||
_blendState->Apply();
|
||||
|
||||
return true;
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "presentparameters-dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
class GraphicsDevice : public IGraphicsDevice {
|
||||
class GraphicsDevice : public IGraphicsDevice, public std::enable_shared_from_this<GraphicsDevice> {
|
||||
public:
|
||||
GraphicsDevice();
|
||||
GraphicsDevice(GraphicsDeviceInformation const& info);
|
||||
|
@ -8,7 +8,7 @@
|
||||
namespace xna {
|
||||
class RasterizerState : public IRasterizerState, public GraphicsResource {
|
||||
public:
|
||||
RasterizerState(GraphicsDevice* device) : GraphicsResource(device){}
|
||||
RasterizerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device){}
|
||||
|
||||
virtual ~RasterizerState() override {
|
||||
if (dxRasterizerState) {
|
||||
|
@ -9,7 +9,7 @@
|
||||
namespace xna {
|
||||
class RenderTarget2D : public IRenderTarget2D, public Texture2D {
|
||||
public:
|
||||
RenderTarget2D(GraphicsDevice* device) : Texture2D(device){}
|
||||
RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device){}
|
||||
|
||||
virtual ~RenderTarget2D() override {
|
||||
if (_renderTargetView) {
|
||||
|
@ -8,7 +8,7 @@
|
||||
namespace xna {
|
||||
class SamplerState : public ISamplerState, public GraphicsResource {
|
||||
public:
|
||||
SamplerState(GraphicsDevice* device) : GraphicsResource(device) {
|
||||
SamplerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
||||
_description.MaxAnisotropy = 4;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
namespace xna {
|
||||
class Shader : public IShader, public GraphicsResource {
|
||||
public:
|
||||
Shader(GraphicsDevice* device) : GraphicsResource(device){}
|
||||
Shader(sptr<GraphicsDevice> const& device) : GraphicsResource(device){}
|
||||
|
||||
virtual ~Shader() override {}
|
||||
|
||||
@ -19,7 +19,7 @@ namespace xna {
|
||||
|
||||
class VertexShader : public Shader {
|
||||
public:
|
||||
VertexShader(GraphicsDevice* device) : Shader(device){}
|
||||
VertexShader(sptr<GraphicsDevice> const& device) : Shader(device){}
|
||||
|
||||
virtual ~VertexShader() override {
|
||||
if (_vertexShader) {
|
||||
@ -36,7 +36,7 @@ namespace xna {
|
||||
|
||||
class PixelShader : public Shader {
|
||||
public:
|
||||
PixelShader(GraphicsDevice* device) : Shader(device) {}
|
||||
PixelShader(sptr<GraphicsDevice> const& device) : Shader(device) {}
|
||||
|
||||
virtual ~PixelShader() override {
|
||||
if (_pixelShader) {
|
||||
|
@ -9,7 +9,7 @@
|
||||
namespace xna {
|
||||
class SwapChain : public ISwapChain, public GraphicsResource {
|
||||
public:
|
||||
SwapChain(GraphicsDevice* device): GraphicsResource(device){}
|
||||
SwapChain(sptr<GraphicsDevice> const& device): GraphicsResource(device){}
|
||||
|
||||
virtual ~SwapChain() override {
|
||||
if (dxSwapChain) {
|
||||
|
@ -5,7 +5,8 @@
|
||||
namespace xna {
|
||||
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;
|
||||
auto wstr = XnaHToWString(fileName);
|
||||
|
||||
@ -94,17 +95,17 @@ namespace xna {
|
||||
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();
|
||||
dxDescription.Width = static_cast<UINT>(width);
|
||||
dxDescription.Height = static_cast<UINT>(height);
|
||||
}
|
||||
|
||||
Texture2D::Texture2D(GraphicsDevice* device) : GraphicsResource(device) {
|
||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
||||
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();
|
||||
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)
|
||||
{
|
||||
auto texture2d = New<Texture2D>(&device);
|
||||
auto _this = device.shared_from_this();
|
||||
auto texture2d = New<Texture2D>(_this);
|
||||
ID3D11Resource* resource = nullptr;
|
||||
|
||||
auto hr = DirectX::CreateWICTextureFromMemory(
|
||||
|
@ -14,9 +14,9 @@ namespace xna {
|
||||
setDefaultDesc();
|
||||
}
|
||||
|
||||
Texture2D(GraphicsDevice* device);
|
||||
Texture2D(GraphicsDevice* 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);
|
||||
Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height);
|
||||
Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format);
|
||||
|
||||
virtual ~Texture2D() override {
|
||||
if (dxTexture2D) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user