[OpenTK] Add allocated resource registry

This commit is contained in:
thefiddler 2014-07-23 09:21:20 +02:00
parent 864cc84019
commit 77a44b2c8e

View file

@ -28,6 +28,7 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Input; using OpenTK.Input;
@ -42,12 +43,27 @@ namespace OpenTK.Platform
/// </summary> /// </summary>
abstract class PlatformFactoryBase : IPlatformFactory abstract class PlatformFactoryBase : IPlatformFactory
{ {
static readonly object sync = new object();
readonly List<IDisposable> Resources = new List<IDisposable>();
protected bool IsDisposed; protected bool IsDisposed;
public PlatformFactoryBase() public PlatformFactoryBase()
{ {
} }
#region Protected Members
protected void RegisterResource(IDisposable resource)
{
lock (sync)
{
Resources.Add(resource);
}
}
#endregion
#region IPlatformFactory Members #region IPlatformFactory Members
public abstract INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device); public abstract INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device);
@ -96,6 +112,13 @@ namespace OpenTK.Platform
{ {
if (manual) if (manual)
{ {
lock (sync)
{
foreach (var resource in Resources)
{
resource.Dispose();
}
}
} }
else else
{ {