Skip to content

Commit

Permalink
Merge branch 'stop-disposing-d3d11-backbuffer-texture'
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Apr 2, 2023
2 parents 5d5c9fe + 59e0bb4 commit 4640e52
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/Veldrid/D3D11/D3D11Swapchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ private void recreateSwapchain()
Resize(_width, _height);
}

private ID3D11Texture2D backBufferTexture;

public override void Resize(uint width, uint height)
{
_width = width;
Expand All @@ -259,6 +261,7 @@ public override void Resize(uint width, uint height)
_depthTexture.Dispose();
}

backBufferTexture.Dispose();
_framebuffer.Dispose();
}

Expand All @@ -270,29 +273,28 @@ public override void Resize(uint width, uint height)
}

// Get the backbuffer from the swapchain
using (ID3D11Texture2D backBufferTexture = _dxgiSwapChain.GetBuffer<ID3D11Texture2D>(0))
backBufferTexture = _dxgiSwapChain.GetBuffer<ID3D11Texture2D>(0);

if (_depthFormat != null)
{
if (_depthFormat != null)
{
TextureDescription depthDesc = new TextureDescription(
actualWidth, actualHeight, 1, 1, 1,
_depthFormat.Value,
TextureUsage.DepthStencil,
TextureType.Texture2D);
_depthTexture = new D3D11Texture(_gd.Device, ref depthDesc);
}
TextureDescription depthDesc = new TextureDescription(
actualWidth, actualHeight, 1, 1, 1,
_depthFormat.Value,
TextureUsage.DepthStencil,
TextureType.Texture2D);
_depthTexture = new D3D11Texture(_gd.Device, ref depthDesc);
}

D3D11Texture backBufferVdTexture = new D3D11Texture(
backBufferTexture,
TextureType.Texture2D,
D3D11Formats.ToVdFormat(_colorFormat));
D3D11Texture backBufferVdTexture = new D3D11Texture(
backBufferTexture,
TextureType.Texture2D,
D3D11Formats.ToVdFormat(_colorFormat));

FramebufferDescription desc = new FramebufferDescription(_depthTexture, backBufferVdTexture);
_framebuffer = new D3D11Framebuffer(_gd.Device, ref desc)
{
Swapchain = this
};
}
FramebufferDescription desc = new FramebufferDescription(_depthTexture, backBufferVdTexture);
_framebuffer = new D3D11Framebuffer(_gd.Device, ref desc)
{
Swapchain = this
};
}

public void WaitForNextFrameReady()
Expand Down

0 comments on commit 4640e52

Please sign in to comment.