diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index e19ed9d18..4b3b93dfe 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -54,7 +54,7 @@ void MainComponent::Initialize() { #ifdef WICKEDENGINE_BUILD_VULKAN wiRenderer::SetShaderPath(wiRenderer::GetShaderPath() + "spirv/"); - wiRenderer::SetDevice(new GraphicsDevice_Vulkan(window, fullscreen, debugdevice)); + wiRenderer::SetDevice(std::make_shared(window, fullscreen, debugdevice)); #else wiHelper::messageBox("Vulkan SDK not found during building the application! Vulkan API disabled!", "Error"); #endif @@ -65,13 +65,13 @@ void MainComponent::Initialize() { wiRenderer::SetShaderPath(wiRenderer::GetShaderPath() + "hlsl6/"); } - wiRenderer::SetDevice(new GraphicsDevice_DX12(window, fullscreen, debugdevice)); + wiRenderer::SetDevice(std::make_shared(window, fullscreen, debugdevice)); } // default graphics device: if (wiRenderer::GetDevice() == nullptr) { - wiRenderer::SetDevice(new GraphicsDevice_DX11(window, fullscreen, debugdevice)); + wiRenderer::SetDevice(std::make_shared(window, fullscreen, debugdevice)); } } diff --git a/WickedEngine/wiGraphicsDevice.h b/WickedEngine/wiGraphicsDevice.h index cd2e88947..3d7572f61 100644 --- a/WickedEngine/wiGraphicsDevice.h +++ b/WickedEngine/wiGraphicsDevice.h @@ -4,13 +4,14 @@ #include "wiGraphicsResource.h" #include +#include namespace wiGraphics { typedef uint8_t CommandList; static const CommandList COMMANDLIST_COUNT = 16; - class GraphicsDevice + class GraphicsDevice : public std::enable_shared_from_this { protected: uint64_t FRAMECOUNT = 0; diff --git a/WickedEngine/wiGraphicsDevice_DX11.cpp b/WickedEngine/wiGraphicsDevice_DX11.cpp index 2f63645d1..9182a136b 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.cpp +++ b/WickedEngine/wiGraphicsDevice_DX11.cpp @@ -1293,7 +1293,7 @@ bool GraphicsDevice_DX11::CreateBuffer(const GPUBufferDesc *pDesc, const Subreso DestroyBuffer(pBuffer); DestroyResource(pBuffer); pBuffer->type = GPUResource::GPU_RESOURCE_TYPE::BUFFER; - pBuffer->Register(this); + pBuffer->Register(shared_from_this()); D3D11_BUFFER_DESC desc; desc.ByteWidth = pDesc->ByteWidth; @@ -1403,7 +1403,7 @@ bool GraphicsDevice_DX11::CreateTexture(const TextureDesc* pDesc, const Subresou DestroyTexture(pTexture); DestroyResource(pTexture); pTexture->type = GPUResource::GPU_RESOURCE_TYPE::TEXTURE; - pTexture->Register(this); + pTexture->Register(shared_from_this()); pTexture->desc = *pDesc; @@ -1476,7 +1476,7 @@ bool GraphicsDevice_DX11::CreateTexture(const TextureDesc* pDesc, const Subresou bool GraphicsDevice_DX11::CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, uint32_t NumElements, const ShaderByteCode* shaderCode, VertexLayout *pInputLayout) { DestroyInputLayout(pInputLayout); - pInputLayout->Register(this); + pInputLayout->Register(shared_from_this()); pInputLayout->desc.reserve((size_t)NumElements); @@ -1505,7 +1505,7 @@ bool GraphicsDevice_DX11::CreateInputLayout(const VertexLayoutDesc *pInputElemen bool GraphicsDevice_DX11::CreateVertexShader(const void *pShaderBytecode, size_t BytecodeLength, VertexShader *pVertexShader) { DestroyVertexShader(pVertexShader); - pVertexShader->Register(this); + pVertexShader->Register(shared_from_this()); pVertexShader->code.data = new BYTE[BytecodeLength]; memcpy(pVertexShader->code.data, pShaderBytecode, BytecodeLength); @@ -1515,7 +1515,7 @@ bool GraphicsDevice_DX11::CreateVertexShader(const void *pShaderBytecode, size_t bool GraphicsDevice_DX11::CreatePixelShader(const void *pShaderBytecode, size_t BytecodeLength, PixelShader *pPixelShader) { DestroyPixelShader(pPixelShader); - pPixelShader->Register(this); + pPixelShader->Register(shared_from_this()); pPixelShader->code.data = new BYTE[BytecodeLength]; memcpy(pPixelShader->code.data, pShaderBytecode, BytecodeLength); @@ -1525,7 +1525,7 @@ bool GraphicsDevice_DX11::CreatePixelShader(const void *pShaderBytecode, size_t bool GraphicsDevice_DX11::CreateGeometryShader(const void *pShaderBytecode, size_t BytecodeLength, GeometryShader *pGeometryShader) { DestroyGeometryShader(pGeometryShader); - pGeometryShader->Register(this); + pGeometryShader->Register(shared_from_this()); pGeometryShader->code.data = new BYTE[BytecodeLength]; memcpy(pGeometryShader->code.data, pShaderBytecode, BytecodeLength); @@ -1535,7 +1535,7 @@ bool GraphicsDevice_DX11::CreateGeometryShader(const void *pShaderBytecode, size bool GraphicsDevice_DX11::CreateHullShader(const void *pShaderBytecode, size_t BytecodeLength, HullShader *pHullShader) { DestroyHullShader(pHullShader); - pHullShader->Register(this); + pHullShader->Register(shared_from_this()); pHullShader->code.data = new BYTE[BytecodeLength]; memcpy(pHullShader->code.data, pShaderBytecode, BytecodeLength); @@ -1545,7 +1545,7 @@ bool GraphicsDevice_DX11::CreateHullShader(const void *pShaderBytecode, size_t B bool GraphicsDevice_DX11::CreateDomainShader(const void *pShaderBytecode, size_t BytecodeLength, DomainShader *pDomainShader) { DestroyDomainShader(pDomainShader); - pDomainShader->Register(this); + pDomainShader->Register(shared_from_this()); pDomainShader->code.data = new BYTE[BytecodeLength]; memcpy(pDomainShader->code.data, pShaderBytecode, BytecodeLength); @@ -1555,7 +1555,7 @@ bool GraphicsDevice_DX11::CreateDomainShader(const void *pShaderBytecode, size_t bool GraphicsDevice_DX11::CreateComputeShader(const void *pShaderBytecode, size_t BytecodeLength, ComputeShader *pComputeShader) { DestroyComputeShader(pComputeShader); - pComputeShader->Register(this); + pComputeShader->Register(shared_from_this()); pComputeShader->code.data = new BYTE[BytecodeLength]; memcpy(pComputeShader->code.data, pShaderBytecode, BytecodeLength); @@ -1565,7 +1565,7 @@ bool GraphicsDevice_DX11::CreateComputeShader(const void *pShaderBytecode, size_ bool GraphicsDevice_DX11::CreateBlendState(const BlendStateDesc *pBlendStateDesc, BlendState *pBlendState) { DestroyBlendState(pBlendState); - pBlendState->Register(this); + pBlendState->Register(shared_from_this()); D3D11_BLEND_DESC desc; desc.AlphaToCoverageEnable = pBlendStateDesc->AlphaToCoverageEnable; @@ -1588,7 +1588,7 @@ bool GraphicsDevice_DX11::CreateBlendState(const BlendStateDesc *pBlendStateDesc bool GraphicsDevice_DX11::CreateDepthStencilState(const DepthStencilStateDesc *pDepthStencilStateDesc, DepthStencilState *pDepthStencilState) { DestroyDepthStencilState(pDepthStencilState); - pDepthStencilState->Register(this); + pDepthStencilState->Register(shared_from_this()); D3D11_DEPTH_STENCIL_DESC desc; desc.DepthEnable = pDepthStencilStateDesc->DepthEnable; @@ -1612,7 +1612,7 @@ bool GraphicsDevice_DX11::CreateDepthStencilState(const DepthStencilStateDesc *p bool GraphicsDevice_DX11::CreateRasterizerState(const RasterizerStateDesc *pRasterizerStateDesc, RasterizerState *pRasterizerState) { DestroyRasterizerState(pRasterizerState); - pRasterizerState->Register(this); + pRasterizerState->Register(shared_from_this()); pRasterizerState->desc = *pRasterizerStateDesc; @@ -1690,7 +1690,7 @@ bool GraphicsDevice_DX11::CreateRasterizerState(const RasterizerStateDesc *pRast bool GraphicsDevice_DX11::CreateSamplerState(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) { DestroySamplerState(pSamplerState); - pSamplerState->Register(this); + pSamplerState->Register(shared_from_this()); D3D11_SAMPLER_DESC desc; desc.Filter = _ConvertFilter(pSamplerDesc->Filter); @@ -1713,7 +1713,7 @@ bool GraphicsDevice_DX11::CreateSamplerState(const SamplerDesc *pSamplerDesc, Sa bool GraphicsDevice_DX11::CreateQuery(const GPUQueryDesc *pDesc, GPUQuery *pQuery) { DestroyQuery(pQuery); - pQuery->Register(this); + pQuery->Register(shared_from_this()); HRESULT hr = E_FAIL; @@ -1751,7 +1751,7 @@ bool GraphicsDevice_DX11::CreateQuery(const GPUQueryDesc *pDesc, GPUQuery *pQuer bool GraphicsDevice_DX11::CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) { DestroyPipelineState(pso); - pso->Register(this); + pso->Register(shared_from_this()); pso->desc = *pDesc; @@ -1760,7 +1760,7 @@ bool GraphicsDevice_DX11::CreatePipelineState(const PipelineStateDesc* pDesc, Pi bool GraphicsDevice_DX11::CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) { DestroyRenderPass(renderpass); - renderpass->Register(this); + renderpass->Register(shared_from_this()); renderpass->desc = *pDesc; diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index 2e870d23e..bd5c26579 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -1949,7 +1949,7 @@ namespace wiGraphics DestroyBuffer(pBuffer); DestroyResource(pBuffer); pBuffer->type = GPUResource::GPU_RESOURCE_TYPE::BUFFER; - pBuffer->Register(this); + pBuffer->Register(shared_from_this()); HRESULT hr = E_FAIL; @@ -2110,7 +2110,7 @@ namespace wiGraphics DestroyTexture(pTexture); DestroyResource(pTexture); pTexture->type = GPUResource::GPU_RESOURCE_TYPE::TEXTURE; - pTexture->Register(this); + pTexture->Register(shared_from_this()); pTexture->desc = *pDesc; @@ -2276,7 +2276,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateInputLayout(const VertexLayoutDesc* pInputElementDescs, uint32_t NumElements, const ShaderByteCode* shaderCode, VertexLayout* pInputLayout) { DestroyInputLayout(pInputLayout); - pInputLayout->Register(this); + pInputLayout->Register(shared_from_this()); pInputLayout->desc.clear(); pInputLayout->desc.reserve((size_t)NumElements); @@ -2290,7 +2290,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateVertexShader(const void* pShaderBytecode, size_t BytecodeLength, VertexShader* pVertexShader) { DestroyVertexShader(pVertexShader); - pVertexShader->Register(this); + pVertexShader->Register(shared_from_this()); pVertexShader->code.data = new BYTE[BytecodeLength]; memcpy(pVertexShader->code.data, pShaderBytecode, BytecodeLength); @@ -2301,7 +2301,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreatePixelShader(const void* pShaderBytecode, size_t BytecodeLength, PixelShader* pPixelShader) { DestroyPixelShader(pPixelShader); - pPixelShader->Register(this); + pPixelShader->Register(shared_from_this()); pPixelShader->code.data = new BYTE[BytecodeLength]; memcpy(pPixelShader->code.data, pShaderBytecode, BytecodeLength); @@ -2312,7 +2312,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateGeometryShader(const void* pShaderBytecode, size_t BytecodeLength, GeometryShader* pGeometryShader) { DestroyGeometryShader(pGeometryShader); - pGeometryShader->Register(this); + pGeometryShader->Register(shared_from_this()); pGeometryShader->code.data = new BYTE[BytecodeLength]; memcpy(pGeometryShader->code.data, pShaderBytecode, BytecodeLength); @@ -2323,7 +2323,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateHullShader(const void* pShaderBytecode, size_t BytecodeLength, HullShader* pHullShader) { DestroyHullShader(pHullShader); - pHullShader->Register(this); + pHullShader->Register(shared_from_this()); pHullShader->code.data = new BYTE[BytecodeLength]; memcpy(pHullShader->code.data, pShaderBytecode, BytecodeLength); @@ -2334,7 +2334,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateDomainShader(const void* pShaderBytecode, size_t BytecodeLength, DomainShader* pDomainShader) { DestroyDomainShader(pDomainShader); - pDomainShader->Register(this); + pDomainShader->Register(shared_from_this()); pDomainShader->code.data = new BYTE[BytecodeLength]; memcpy(pDomainShader->code.data, pShaderBytecode, BytecodeLength); @@ -2345,7 +2345,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateComputeShader(const void* pShaderBytecode, size_t BytecodeLength, ComputeShader* pComputeShader) { DestroyComputeShader(pComputeShader); - pComputeShader->Register(this); + pComputeShader->Register(shared_from_this()); pComputeShader->code.data = new BYTE[BytecodeLength]; memcpy(pComputeShader->code.data, pShaderBytecode, BytecodeLength); @@ -2364,7 +2364,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateBlendState(const BlendStateDesc* pBlendStateDesc, BlendState* pBlendState) { DestroyBlendState(pBlendState); - pBlendState->Register(this); + pBlendState->Register(shared_from_this()); pBlendState->desc = *pBlendStateDesc; return S_OK; @@ -2372,7 +2372,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateDepthStencilState(const DepthStencilStateDesc* pDepthStencilStateDesc, DepthStencilState* pDepthStencilState) { DestroyDepthStencilState(pDepthStencilState); - pDepthStencilState->Register(this); + pDepthStencilState->Register(shared_from_this()); pDepthStencilState->desc = *pDepthStencilStateDesc; return S_OK; @@ -2380,7 +2380,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateRasterizerState(const RasterizerStateDesc* pRasterizerStateDesc, RasterizerState* pRasterizerState) { DestroyRasterizerState(pRasterizerState); - pRasterizerState->Register(this); + pRasterizerState->Register(shared_from_this()); pRasterizerState->desc = *pRasterizerStateDesc; return S_OK; @@ -2388,7 +2388,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateSamplerState(const SamplerDesc* pSamplerDesc, Sampler* pSamplerState) { DestroySamplerState(pSamplerState); - pSamplerState->Register(this); + pSamplerState->Register(shared_from_this()); D3D12_SAMPLER_DESC desc; desc.Filter = _ConvertFilter(pSamplerDesc->Filter); @@ -2415,7 +2415,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateQuery(const GPUQueryDesc* pDesc, GPUQuery* pQuery) { DestroyQuery(pQuery); - pQuery->Register(this); + pQuery->Register(shared_from_this()); HRESULT hr = E_FAIL; @@ -2460,7 +2460,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) { DestroyPipelineState(pso); - pso->Register(this); + pso->Register(shared_from_this()); pso->desc = *pDesc; @@ -2482,7 +2482,7 @@ namespace wiGraphics bool GraphicsDevice_DX12::CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) { DestroyRenderPass(renderpass); - renderpass->Register(this); + renderpass->Register(shared_from_this()); renderpass->desc = *pDesc; diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index f88105ae4..19b625efb 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -2255,7 +2255,7 @@ namespace wiGraphics DestroyBuffer(pBuffer); DestroyResource(pBuffer); pBuffer->type = GPUResource::GPU_RESOURCE_TYPE::BUFFER; - pBuffer->Register(this); + pBuffer->Register(shared_from_this()); pBuffer->desc = *pDesc; @@ -2441,7 +2441,7 @@ namespace wiGraphics DestroyTexture(pTexture); DestroyResource(pTexture); pTexture->type = GPUResource::GPU_RESOURCE_TYPE::TEXTURE; - pTexture->Register(this); + pTexture->Register(shared_from_this()); pTexture->desc = *pDesc; @@ -2666,7 +2666,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, uint32_t NumElements, const ShaderByteCode* shaderCode, VertexLayout *pInputLayout) { DestroyInputLayout(pInputLayout); - pInputLayout->Register(this); + pInputLayout->Register(shared_from_this()); pInputLayout->desc.clear(); pInputLayout->desc.reserve((size_t)NumElements); @@ -2680,7 +2680,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateVertexShader(const void *pShaderBytecode, size_t BytecodeLength, VertexShader *pVertexShader) { DestroyVertexShader(pVertexShader); - pVertexShader->Register(this); + pVertexShader->Register(shared_from_this()); pVertexShader->code.data = new BYTE[BytecodeLength]; memcpy(pVertexShader->code.data, pShaderBytecode, BytecodeLength); @@ -2691,7 +2691,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreatePixelShader(const void *pShaderBytecode, size_t BytecodeLength, PixelShader *pPixelShader) { DestroyPixelShader(pPixelShader); - pPixelShader->Register(this); + pPixelShader->Register(shared_from_this()); pPixelShader->code.data = new BYTE[BytecodeLength]; memcpy(pPixelShader->code.data, pShaderBytecode, BytecodeLength); @@ -2702,7 +2702,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateGeometryShader(const void *pShaderBytecode, size_t BytecodeLength, GeometryShader *pGeometryShader) { DestroyGeometryShader(pGeometryShader); - pGeometryShader->Register(this); + pGeometryShader->Register(shared_from_this()); pGeometryShader->code.data = new BYTE[BytecodeLength]; memcpy(pGeometryShader->code.data, pShaderBytecode, BytecodeLength); @@ -2713,7 +2713,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateHullShader(const void *pShaderBytecode, size_t BytecodeLength, HullShader *pHullShader) { DestroyHullShader(pHullShader); - pHullShader->Register(this); + pHullShader->Register(shared_from_this()); pHullShader->code.data = new BYTE[BytecodeLength]; memcpy(pHullShader->code.data, pShaderBytecode, BytecodeLength); @@ -2724,7 +2724,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateDomainShader(const void *pShaderBytecode, size_t BytecodeLength, DomainShader *pDomainShader) { DestroyDomainShader(pDomainShader); - pDomainShader->Register(this); + pDomainShader->Register(shared_from_this()); pDomainShader->code.data = new BYTE[BytecodeLength]; memcpy(pDomainShader->code.data, pShaderBytecode, BytecodeLength); @@ -2735,7 +2735,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateComputeShader(const void *pShaderBytecode, size_t BytecodeLength, ComputeShader *pComputeShader) { DestroyComputeShader(pComputeShader); - pComputeShader->Register(this); + pComputeShader->Register(shared_from_this()); pComputeShader->code.data = new BYTE[BytecodeLength]; memcpy(pComputeShader->code.data, pShaderBytecode, BytecodeLength); @@ -2778,7 +2778,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateBlendState(const BlendStateDesc *pBlendStateDesc, BlendState *pBlendState) { DestroyBlendState(pBlendState); - pBlendState->Register(this); + pBlendState->Register(shared_from_this()); pBlendState->desc = *pBlendStateDesc; return true; @@ -2786,7 +2786,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateDepthStencilState(const DepthStencilStateDesc *pDepthStencilStateDesc, DepthStencilState *pDepthStencilState) { DestroyDepthStencilState(pDepthStencilState); - pDepthStencilState->Register(this); + pDepthStencilState->Register(shared_from_this()); pDepthStencilState->desc = *pDepthStencilStateDesc; return true; @@ -2794,7 +2794,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateRasterizerState(const RasterizerStateDesc *pRasterizerStateDesc, RasterizerState *pRasterizerState) { DestroyRasterizerState(pRasterizerState); - pRasterizerState->Register(this); + pRasterizerState->Register(shared_from_this()); pRasterizerState->desc = *pRasterizerStateDesc; return true; @@ -2802,7 +2802,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateSamplerState(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) { DestroySamplerState(pSamplerState); - pSamplerState->Register(this); + pSamplerState->Register(shared_from_this()); pSamplerState->desc = *pSamplerDesc; @@ -2986,7 +2986,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateQuery(const GPUQueryDesc *pDesc, GPUQuery *pQuery) { DestroyQuery(pQuery); - pQuery->Register(this); + pQuery->Register(shared_from_this()); bool hr = false; @@ -3031,7 +3031,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) { DestroyPipelineState(pso); - pso->Register(this); + pso->Register(shared_from_this()); pso->desc = *pDesc; @@ -3053,7 +3053,7 @@ namespace wiGraphics bool GraphicsDevice_Vulkan::CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) { DestroyRenderPass(renderpass); - renderpass->Register(this); + renderpass->Register(shared_from_this()); renderpass->desc = *pDesc; diff --git a/WickedEngine/wiGraphicsResource.h b/WickedEngine/wiGraphicsResource.h index de0986f0e..eddfd49bb 100644 --- a/WickedEngine/wiGraphicsResource.h +++ b/WickedEngine/wiGraphicsResource.h @@ -2,6 +2,7 @@ #include "CommonInclude.h" #include "wiGraphicsDescriptors.h" +#include #include namespace wiGraphics @@ -10,8 +11,8 @@ namespace wiGraphics struct GraphicsDeviceChild { - GraphicsDevice* device = nullptr; - inline void Register(GraphicsDevice* dev) { device = dev; } + std::shared_ptr device; + inline void Register(std::shared_ptr dev) { device = dev; } inline bool IsValid() const { return device != nullptr; } }; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index dd9b8f9dd..b6257d4b7 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -42,7 +42,7 @@ using namespace wiAllocators; namespace wiRenderer { -GraphicsDevice* graphicsDevice = nullptr; +std::shared_ptr graphicsDevice; VertexShader vertexShaders[VSTYPE_COUNT]; PixelShader pixelShaders[PSTYPE_COUNT]; @@ -178,13 +178,13 @@ unordered_map packedLightmaps; -void SetDevice(GraphicsDevice* newDevice) +void SetDevice(std::shared_ptr newDevice) { graphicsDevice = newDevice; } GraphicsDevice* GetDevice() { - return graphicsDevice; + return graphicsDevice.get(); } // Direct reference to a renderable instance: diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 5a6cb3851..36f2cc1f9 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -5,6 +5,8 @@ #include "wiScene_Decl.h" #include "wiECS.h" +#include + struct RAY; namespace wiRenderer @@ -37,7 +39,7 @@ namespace wiRenderer void ClearWorld(); // Set the main graphics device globally: - void SetDevice(wiGraphics::GraphicsDevice* newDevice); + void SetDevice(std::shared_ptr newDevice); // Retrieve the main graphics device: wiGraphics::GraphicsDevice* GetDevice(); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 02e6235b1..f3b9c0bde 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 36; // minor bug fixes, alterations, refactors, updates - const int revision = 3; + const int revision = 4; long GetVersion()