Dispose of graphics resources deterministically.

Textures, FrameBuffers and VertexBuffers allocated by the Sdl2 Renderer were only being released via finalizers. This could lead to OpenGL out of memory errors since resources may not be cleaned up in a timely manner. To avoid this, IDisposable has been implemented and transitively applied to classes that use these resources.

As a side-effect some static state is no longer static, particularly in Renderer, in order to facilitate this change and just for nicer design in general.

Also dispose some bitmaps.
This commit is contained in:
RoosterDragon
2014-10-24 18:21:30 +01:00
committed by RoosterDragon
parent 38b579a081
commit f0f02dff5c
31 changed files with 371 additions and 128 deletions

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Renderer.Null
public void Render(Action a) { }
}
public class NullTexture : ITexture
public sealed class NullTexture : ITexture
{
public TextureScaleFilter ScaleFilter { get { return TextureScaleFilter.Nearest; } set { } }
public void SetData(Bitmap bitmap) { }
@@ -86,18 +86,21 @@ namespace OpenRA.Renderer.Null
public void SetData(byte[] colors, int width, int height) { }
public byte[] GetData() { return new byte[0]; }
public Size Size { get { return new Size(0, 0); } }
public void Dispose() { }
}
public class NullFrameBuffer : IFrameBuffer
public sealed class NullFrameBuffer : IFrameBuffer
{
public void Bind() { }
public void Unbind() { }
public ITexture Texture { get { return new NullTexture(); } }
public void Dispose() { }
}
class NullVertexBuffer<T> : IVertexBuffer<T>
sealed class NullVertexBuffer<T> : IVertexBuffer<T>
{
public void Bind() { }
public void SetData(T[] vertices, int length) { }
public void Dispose() { }
}
}