optimize AcquireSwapchainTexture

moar-validation
cosmonaut 2022-12-13 00:52:35 -08:00
parent 916962da6c
commit 36e6c6f332
5 changed files with 18 additions and 11 deletions

View File

@ -1630,13 +1630,13 @@ namespace MoonWorks.Graphics
return null;
}
return new Texture(
Device,
texturePtr,
window.SwapchainFormat,
width,
height
);
// Override the texture properties to avoid allocating a new texture instance!
window.SwapchainTexture.Handle = texturePtr;
window.SwapchainTexture.Width = width;
window.SwapchainTexture.Height = height;
window.SwapchainTexture.Format = window.SwapchainFormat;
return window.SwapchainTexture;
}
/// <summary>

View File

@ -73,6 +73,10 @@ namespace MoonWorks.Graphics
{
window.Claimed = true;
window.SwapchainFormat = GetSwapchainFormat(window);
if (window.SwapchainTexture == null)
{
window.SwapchainTexture = new Texture(this, IntPtr.Zero, window.SwapchainFormat, 0, 0);
}
}
return success;

View File

@ -5,7 +5,7 @@ namespace MoonWorks.Graphics
public abstract class GraphicsResource : IDisposable
{
public GraphicsDevice Device { get; }
public IntPtr Handle { get; protected set; }
public IntPtr Handle { get; internal set; }
public bool IsDisposed { get; private set; }
protected abstract Action<IntPtr, IntPtr> QueueDestroyFunction { get; }

View File

@ -9,14 +9,15 @@ namespace MoonWorks.Graphics
/// </summary>
public class Texture : GraphicsResource
{
public uint Width { get; }
public uint Height { get; }
public uint Width { get; internal set; }
public uint Height { get; internal set; }
public uint Depth { get; }
public TextureFormat Format { get; }
public TextureFormat Format { get; internal set; }
public bool IsCube { get; }
public uint LevelCount { get; }
public TextureUsageFlags UsageFlags { get; }
// FIXME: this allocates a delegate instance
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture;
/// <summary>

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using MoonWorks.Graphics;
using SDL2;
namespace MoonWorks
@ -10,6 +11,7 @@ namespace MoonWorks
public ScreenMode ScreenMode { get; private set; }
public uint Width { get; private set; }
public uint Height { get; private set; }
internal Texture SwapchainTexture { get; set; } = null;
public bool Claimed { get; internal set; }
public MoonWorks.Graphics.TextureFormat SwapchainFormat { get; internal set; }