optimize AcquireSwapchainTexture

pull/37/head
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 null;
} }
return new Texture( // Override the texture properties to avoid allocating a new texture instance!
Device, window.SwapchainTexture.Handle = texturePtr;
texturePtr, window.SwapchainTexture.Width = width;
window.SwapchainFormat, window.SwapchainTexture.Height = height;
width, window.SwapchainTexture.Format = window.SwapchainFormat;
height
); return window.SwapchainTexture;
} }
/// <summary> /// <summary>

View File

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

View File

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

View File

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

View File

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