diff --git a/src/Graphics/CommandBuffer.cs b/src/Graphics/CommandBuffer.cs
index 5f9432d4..90a3a6be 100644
--- a/src/Graphics/CommandBuffer.cs
+++ b/src/Graphics/CommandBuffer.cs
@@ -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;
}
///
diff --git a/src/Graphics/GraphicsDevice.cs b/src/Graphics/GraphicsDevice.cs
index e79cae4b..2e134dff 100644
--- a/src/Graphics/GraphicsDevice.cs
+++ b/src/Graphics/GraphicsDevice.cs
@@ -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;
diff --git a/src/Graphics/GraphicsResource.cs b/src/Graphics/GraphicsResource.cs
index 27343df3..2e685461 100644
--- a/src/Graphics/GraphicsResource.cs
+++ b/src/Graphics/GraphicsResource.cs
@@ -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 QueueDestroyFunction { get; }
diff --git a/src/Graphics/Resources/Texture.cs b/src/Graphics/Resources/Texture.cs
index 124eaeff..190ac531 100644
--- a/src/Graphics/Resources/Texture.cs
+++ b/src/Graphics/Resources/Texture.cs
@@ -9,14 +9,15 @@ namespace MoonWorks.Graphics
///
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 QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture;
///
diff --git a/src/Window.cs b/src/Window.cs
index 65175d03..194f7d0a 100644
--- a/src/Window.cs
+++ b/src/Window.cs
@@ -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; }