mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Manage all Assets with ContentManager
This commit is contained in:
@@ -18,7 +18,7 @@ namespace GlitchyEngine.Renderer
|
||||
protected internal ID3D11Texture2D* _nativeTexture ~ _?.Release();
|
||||
protected internal ID3D11RenderTargetView* _nativeRenderTargetView ~ _?.Release();
|
||||
|
||||
private void ReleaseAndNullify()
|
||||
internal void ReleaseAndNullifyD3DObjects()
|
||||
{
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
|
||||
@@ -29,15 +29,25 @@ namespace GlitchyEngine.Renderer
|
||||
ReleaseRefAndNullify!(_depthStenilTarget);
|
||||
}
|
||||
|
||||
public override void Resize(uint32 width, uint32 height)
|
||||
public override void Resize(uint32 width, uint32 height, Format? newPixelFormat, DepthStencilFormat? newDepthStencilFormat)
|
||||
{
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
|
||||
ReleaseAndNullify();
|
||||
ReleaseAndNullifyD3DObjects();
|
||||
|
||||
_description.Width = width;
|
||||
_description.Height = height;
|
||||
|
||||
if (newPixelFormat != null)
|
||||
{
|
||||
_description.PixelFormat = newPixelFormat.Value;
|
||||
}
|
||||
|
||||
if (newDepthStencilFormat != null)
|
||||
{
|
||||
_description.DepthStencilFormat = newDepthStencilFormat.Value;
|
||||
}
|
||||
|
||||
ApplyChanges();
|
||||
}
|
||||
|
||||
@@ -45,7 +55,7 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
|
||||
ReleaseAndNullify();
|
||||
ReleaseAndNullifyD3DObjects();
|
||||
|
||||
if(_description.IsSwapchainTarget)
|
||||
{
|
||||
@@ -123,7 +133,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
protected override TextureViewBinding PlatformGetViewBinding()
|
||||
{
|
||||
return new .(_nativeResourceView, _samplerState.nativeSamplerState);
|
||||
return new .(_nativeResourceView, _samplerState?.nativeSamplerState);
|
||||
}
|
||||
|
||||
protected override void PlatformSneakySwappyTexture(RenderTarget2D otherTexture)
|
||||
|
||||
@@ -72,14 +72,16 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
if(nativeSwapChain != null)
|
||||
{
|
||||
//nativeBackBufferTarget.Release();
|
||||
_backBuffer.ReleaseRef();
|
||||
// It's important to not delete the _backBuffer-Object, because we want others to be able to rely on this backbuffer-reference.
|
||||
_backBuffer.ReleaseAndNullifyD3DObjects();
|
||||
|
||||
var resizeResult = nativeSwapChain.ResizeBuffers(backBufferCount, _width, _height, backBufferFormat, .None);
|
||||
if(resizeResult.Failed)
|
||||
{
|
||||
Log.EngineLogger.Error($"Failed to resize swap chain. Message({(int)resizeResult}):{resizeResult}");
|
||||
}
|
||||
|
||||
_backBuffer.Resize(_width, _height, backBufferFormat, _depthStencilFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -108,15 +110,16 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
|
||||
factory.Release();
|
||||
|
||||
RenderTarget2DDescription desc = .(backBufferFormat, _width, _height);
|
||||
desc.DepthStencilFormat = _depthStencilFormat;
|
||||
desc.IsSwapchainTarget = true;
|
||||
|
||||
_backBuffer = new RenderTarget2D(desc);
|
||||
_backBuffer.Identifier = "Backbuffer";
|
||||
_backBuffer.SamplerState = SamplerStateManager.LinearClamp;
|
||||
}
|
||||
|
||||
RenderTarget2DDescription desc = .(backBufferFormat, _width, _height);
|
||||
desc.DepthStencilFormat = _depthStencilFormat;
|
||||
desc.IsSwapchainTarget = true;
|
||||
|
||||
// Todo: perhaps just update the render target
|
||||
_backBuffer = new RenderTarget2D(desc);
|
||||
|
||||
_backBufferViewport = GlitchyEngine.Renderer.Viewport(0, 0, _width, _height, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ namespace GlitchyEngine.Renderer
|
||||
internal this(ID3D11ShaderResourceView* shaderResourceView, ID3D11SamplerState* samplerState)
|
||||
{
|
||||
_nativeShaderResourceView = shaderResourceView;
|
||||
|
||||
|
||||
// TODO: What is the 200 check for?
|
||||
if ((uint)(void*)_nativeShaderResourceView != 0 && (uint)(void*)_nativeShaderResourceView < 200)
|
||||
{
|
||||
|
||||
@@ -23,6 +24,12 @@ namespace GlitchyEngine.Renderer
|
||||
_nativeSamplerState = samplerState;
|
||||
_nativeSamplerState?.AddRef();
|
||||
}
|
||||
|
||||
protected ~this()
|
||||
{
|
||||
_nativeShaderResourceView?.Release();
|
||||
_nativeSamplerState?.Release();
|
||||
}
|
||||
|
||||
public static override TextureViewBinding CreateDefault() => new .(null, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user