Fixed RenderTargets leaking a texure when it's a Swapchain target

This commit is contained in:
Simon Lübeß
2022-01-15 17:49:36 +01:00
parent a7b2515cf4
commit 6a55108a37
@@ -46,8 +46,6 @@ namespace GlitchyEngine.Renderer
ReleaseAndNullify(); ReleaseAndNullify();
PlatformCreateTexture();
if(_description.IsSwapchainTarget) if(_description.IsSwapchainTarget)
{ {
// TODO: if the engine supports multiple windows it has to support multiple swap chains. // TODO: if the engine supports multiple windows it has to support multiple swap chains.
@@ -59,6 +57,10 @@ namespace GlitchyEngine.Renderer
CreateViews(); CreateViews();
} }
else
{
PlatformCreateTexture();
}
if(_description.DepthStencilFormat != .None) if(_description.DepthStencilFormat != .None)
{ {
@@ -97,11 +99,25 @@ namespace GlitchyEngine.Renderer
{ {
Debug.Profiler.ProfileResourceFunction!(); Debug.Profiler.ProfileResourceFunction!();
var result = NativeDevice.CreateShaderResourceView(_nativeTexture, null, &_nativeResourceView); if(_description.IsSwapchainTarget)
Log.EngineLogger.Assert(result.Succeeded, "Failed to create resource view"); {
var result = NativeDevice.CreateShaderResourceView(_nativeTexture, null, &_nativeResourceView);
Log.EngineLogger.Assert(result.Succeeded, "Failed to create resource view");
result = NativeDevice.CreateRenderTargetView(_nativeTexture, null, &_nativeRenderTargetView); // TODO: SRGB...
Log.EngineLogger.Assert(result.Succeeded, "Failed to create render target view"); //RenderTargetViewDescription rtvDesc = .(_nativeTexture, .Texture2D, .R8G8B8A8_UNorm_SRGB);
//result = NativeDevice.CreateRenderTargetView(_nativeTexture, &rtvDesc, &_nativeRenderTargetView);
result = NativeDevice.CreateRenderTargetView(_nativeTexture, null, &_nativeRenderTargetView);
Log.EngineLogger.Assert(result.Succeeded, "Failed to create render target view");
}
else
{
var result = NativeDevice.CreateShaderResourceView(_nativeTexture, null, &_nativeResourceView);
Log.EngineLogger.Assert(result.Succeeded, "Failed to create resource view");
result = NativeDevice.CreateRenderTargetView(_nativeTexture, null, &_nativeRenderTargetView);
Log.EngineLogger.Assert(result.Succeeded, "Failed to create render target view");
}
} }
} }
} }