diff --git a/ANX.Framework/ANX.Framework.csproj b/ANX.Framework/ANX.Framework.csproj
index 4ab7c230..8a2a1b84 100644
--- a/ANX.Framework/ANX.Framework.csproj
+++ b/ANX.Framework/ANX.Framework.csproj
@@ -445,7 +445,7 @@
-
+
diff --git a/ANX.Framework/Graphics/Effect.cs b/ANX.Framework/Graphics/Effect.cs
index 48aa893e..449b1ac0 100644
--- a/ANX.Framework/Graphics/Effect.cs
+++ b/ANX.Framework/Graphics/Effect.cs
@@ -60,7 +60,7 @@ namespace ANX.Framework.Graphics
public class Effect : GraphicsResource, IGraphicsResource
{
#region Private Members
- private WeakReference nativeEffect;
+ private INativeEffect nativeEffect;
private EffectTechniqueCollection techniqueCollection;
private EffectTechnique currentTechnique;
private EffectParameterCollection parameterCollection;
@@ -96,9 +96,10 @@ namespace ANX.Framework.Graphics
private void GraphicsDevice_ResourceCreated(object sender, ResourceCreatedEventArgs e)
{
- if (nativeEffect.IsAlive)
+ if (nativeEffect != null)
{
- nativeEffect.Target.Dispose();
+ nativeEffect.Dispose();
+ nativeEffect = null;
}
CreateNativeEffect();
@@ -106,9 +107,10 @@ namespace ANX.Framework.Graphics
private void GraphicsDevice_ResourceDestroyed(object sender, ResourceDestroyedEventArgs e)
{
- if (nativeEffect.IsAlive)
+ if (nativeEffect != null)
{
- nativeEffect.Target.Dispose();
+ nativeEffect.Dispose();
+ nativeEffect = null;
}
}
@@ -121,12 +123,12 @@ namespace ANX.Framework.Graphics
{
get
{
- if (!nativeEffect.IsAlive)
+ if (nativeEffect == null)
{
CreateNativeEffect();
}
- return this.nativeEffect.Target;
+ return this.nativeEffect;
}
}
@@ -160,9 +162,10 @@ namespace ANX.Framework.Graphics
public override void Dispose()
{
- if (nativeEffect.IsAlive)
+ if (nativeEffect != null)
{
- nativeEffect.Target.Dispose();
+ nativeEffect.Dispose();
+ nativeEffect = null;
}
}
@@ -173,10 +176,10 @@ namespace ANX.Framework.Graphics
private void CreateNativeEffect()
{
- this.nativeEffect = new WeakReference(AddInSystemFactory.Instance.GetDefaultCreator().CreateEffect(GraphicsDevice, this, new MemoryStream(this.byteCode, false)));
+ this.nativeEffect = AddInSystemFactory.Instance.GetDefaultCreator().CreateEffect(GraphicsDevice, this, new MemoryStream(this.byteCode, false));
- this.techniqueCollection = new EffectTechniqueCollection(this, this.nativeEffect.Target);
- this.parameterCollection = new EffectParameterCollection(this, this.nativeEffect.Target);
+ this.techniqueCollection = new EffectTechniqueCollection(this, this.nativeEffect);
+ this.parameterCollection = new EffectParameterCollection(this, this.nativeEffect);
}
}
}
diff --git a/ANX.Framework/Graphics/IndexBuffer.cs b/ANX.Framework/Graphics/IndexBuffer.cs
index 3238dc6d..25ffd1bc 100644
--- a/ANX.Framework/Graphics/IndexBuffer.cs
+++ b/ANX.Framework/Graphics/IndexBuffer.cs
@@ -61,7 +61,7 @@ namespace ANX.Framework.Graphics
private int indexCount;
private BufferUsage bufferUsage;
private IndexElementSize indexElementSize;
- private WeakReference nativeIndexBuffer;
+ private INativeBuffer nativeIndexBuffer;
public IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage)
: base(graphicsDevice)
@@ -107,17 +107,19 @@ namespace ANX.Framework.Graphics
private void GraphicsDevice_ResourceDestroyed(object sender, ResourceDestroyedEventArgs e)
{
- if (this.nativeIndexBuffer.IsAlive)
+ if (this.nativeIndexBuffer != null)
{
- this.nativeIndexBuffer.Target.Dispose();
+ this.nativeIndexBuffer.Dispose();
+ this.nativeIndexBuffer = null;
}
}
private void GraphicsDevice_ResourceCreated(object sender, ResourceCreatedEventArgs e)
{
- if (nativeIndexBuffer.IsAlive)
+ if (nativeIndexBuffer != null)
{
- nativeIndexBuffer.Target.Dispose();
+ nativeIndexBuffer.Dispose();
+ nativeIndexBuffer = null;
}
CreateNativeBuffer();
@@ -125,7 +127,7 @@ namespace ANX.Framework.Graphics
private void CreateNativeBuffer()
{
- this.nativeIndexBuffer = new WeakReference(AddInSystemFactory.Instance.GetDefaultCreator().CreateIndexBuffer(GraphicsDevice, indexElementSize, indexCount, bufferUsage));
+ this.nativeIndexBuffer = AddInSystemFactory.Instance.GetDefaultCreator().CreateIndexBuffer(GraphicsDevice, indexElementSize, indexCount, bufferUsage);
}
public void GetData(int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct
@@ -145,22 +147,22 @@ namespace ANX.Framework.Graphics
public void SetData(int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct
{
- if (!nativeIndexBuffer.IsAlive)
+ if (nativeIndexBuffer == null)
{
CreateNativeBuffer();
}
- this.nativeIndexBuffer.Target.SetData(GraphicsDevice, offsetInBytes, data, startIndex, elementCount);
+ this.nativeIndexBuffer.SetData(GraphicsDevice, offsetInBytes, data, startIndex, elementCount);
}
public void SetData(T[] data) where T : struct
{
- if (!nativeIndexBuffer.IsAlive)
+ if (nativeIndexBuffer == null)
{
CreateNativeBuffer();
}
- this.nativeIndexBuffer.Target.SetData(GraphicsDevice, data);
+ this.nativeIndexBuffer.SetData(GraphicsDevice, data);
}
public void SetData(T[] data, int startIndex, int elementCount) where T : struct
@@ -170,9 +172,10 @@ namespace ANX.Framework.Graphics
public override void Dispose()
{
- if (this.nativeIndexBuffer.IsAlive)
+ if (this.nativeIndexBuffer != null)
{
- this.nativeIndexBuffer.Target.Dispose();
+ this.nativeIndexBuffer.Dispose();
+ this.nativeIndexBuffer = null;
}
}
@@ -182,12 +185,12 @@ namespace ANX.Framework.Graphics
{
get
{
- if (!nativeIndexBuffer.IsAlive)
+ if (nativeIndexBuffer == null)
{
CreateNativeBuffer();
}
- return this.nativeIndexBuffer.Target;
+ return this.nativeIndexBuffer;
}
}
diff --git a/ANX.Framework/Graphics/RenderTarget2D.cs b/ANX.Framework/Graphics/RenderTarget2D.cs
index 72d7fb01..d377f595 100644
--- a/ANX.Framework/Graphics/RenderTarget2D.cs
+++ b/ANX.Framework/Graphics/RenderTarget2D.cs
@@ -86,7 +86,7 @@ namespace ANX.Framework.Graphics
this.usage = RenderTargetUsage.DiscardContents;
this.nativeRenderTarget = AddInSystemFactory.Instance.GetDefaultCreator().CreateRenderTarget(graphicsDevice, width, height, false, SurfaceFormat.Color, this.depthStencilFormat, this.multiSampleCount, this.usage);
- base.nativeTexture = new WeakReference(this.nativeRenderTarget as INativeTexture2D);
+ base.nativeTexture = this.nativeRenderTarget as INativeTexture2D;
}
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat)
@@ -97,7 +97,7 @@ namespace ANX.Framework.Graphics
this.usage = RenderTargetUsage.DiscardContents;
this.nativeRenderTarget = AddInSystemFactory.Instance.GetDefaultCreator().CreateRenderTarget(graphicsDevice, width, height, false, SurfaceFormat.Color, this.depthStencilFormat, this.multiSampleCount, this.usage);
- base.nativeTexture = new WeakReference(this.nativeRenderTarget as INativeTexture2D);
+ base.nativeTexture = this.nativeRenderTarget as INativeTexture2D;
}
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
@@ -108,7 +108,7 @@ namespace ANX.Framework.Graphics
this.usage = usage;
this.nativeRenderTarget = AddInSystemFactory.Instance.GetDefaultCreator().CreateRenderTarget(graphicsDevice, width, height, false, SurfaceFormat.Color, this.depthStencilFormat, this.multiSampleCount, this.usage);
- base.nativeTexture = new WeakReference(this.nativeRenderTarget as INativeTexture2D);
+ base.nativeTexture = this.nativeRenderTarget as INativeTexture2D;
}
#endregion // Constructors
diff --git a/ANX.Framework/Graphics/Texture.cs b/ANX.Framework/Graphics/Texture.cs
index d9c38d73..19a0686f 100644
--- a/ANX.Framework/Graphics/Texture.cs
+++ b/ANX.Framework/Graphics/Texture.cs
@@ -58,7 +58,7 @@ namespace ANX.Framework.Graphics
{
protected internal int levelCount;
protected internal SurfaceFormat format;
- protected internal WeakReference nativeTexture;
+ protected internal INativeTexture nativeTexture;
public Texture(GraphicsDevice graphicsDevice)
: base(graphicsDevice)
@@ -93,12 +93,12 @@ namespace ANX.Framework.Graphics
{
get
{
- if (!this.nativeTexture.IsAlive)
+ if (this.nativeTexture == null)
{
ReCreateNativeTextureSurface();
}
- return this.nativeTexture.Target;
+ return this.nativeTexture;
}
}
@@ -109,9 +109,10 @@ namespace ANX.Framework.Graphics
protected override void Dispose(bool disposeManaged)
{
- if (disposeManaged && nativeTexture.IsAlive)
+ if (disposeManaged && nativeTexture != null)
{
- nativeTexture.Target.Dispose();
+ nativeTexture.Dispose();
+ nativeTexture = null;
}
}
@@ -119,17 +120,19 @@ namespace ANX.Framework.Graphics
private void GraphicsDevice_ResourceDestroyed(object sender, ResourceDestroyedEventArgs e)
{
- if (nativeTexture.IsAlive)
+ if (nativeTexture != null)
{
- nativeTexture.Target.Dispose();
+ nativeTexture.Dispose();
+ nativeTexture = null;
}
}
private void GraphicsDevice_ResourceCreated(object sender, ResourceCreatedEventArgs e)
{
- if (nativeTexture.IsAlive)
+ if (nativeTexture != null)
{
- nativeTexture.Target.Dispose();
+ nativeTexture.Dispose();
+ nativeTexture = null;
}
ReCreateNativeTextureSurface();
diff --git a/ANX.Framework/Graphics/Texture2D.cs b/ANX.Framework/Graphics/Texture2D.cs
index a3330012..f7e9aa0f 100644
--- a/ANX.Framework/Graphics/Texture2D.cs
+++ b/ANX.Framework/Graphics/Texture2D.cs
@@ -184,7 +184,7 @@ namespace ANX.Framework.Graphics
internal void CreateNativeTextureSurface(GraphicsDevice device, SurfaceFormat format, int width, int height, int levelCount)
{
- base.nativeTexture = new WeakReference(AddInSystemFactory.Instance.GetDefaultCreator().CreateTexture(device, format, width, height, levelCount));
+ base.nativeTexture = AddInSystemFactory.Instance.GetDefaultCreator().CreateTexture(device, format, width, height, levelCount);
}
}
}
diff --git a/ANX.Framework/Graphics/VertexBuffer.cs b/ANX.Framework/Graphics/VertexBuffer.cs
index 8dd99454..b5f97f4b 100644
--- a/ANX.Framework/Graphics/VertexBuffer.cs
+++ b/ANX.Framework/Graphics/VertexBuffer.cs
@@ -61,7 +61,7 @@ namespace ANX.Framework.Graphics
private VertexDeclaration vertexDeclaration;
private int vertexCount;
private BufferUsage bufferUsage;
- private WeakReference nativeVertexBuffer;
+ private INativeBuffer nativeVertexBuffer;
public VertexBuffer(GraphicsDevice graphicsDevice, Type vertexType, int vertexCount, BufferUsage usage)
: this(graphicsDevice, VertexBuffer.TypeToVertexDeclaration(vertexType), vertexCount, usage)
@@ -90,17 +90,19 @@ namespace ANX.Framework.Graphics
private void GraphicsDevice_ResourceDestroyed(object sender, ResourceDestroyedEventArgs e)
{
- if (nativeVertexBuffer.IsAlive)
+ if (nativeVertexBuffer != null)
{
- nativeVertexBuffer.Target.Dispose();
+ nativeVertexBuffer.Dispose();
+ nativeVertexBuffer = null;
}
}
private void GraphicsDevice_ResourceCreated(object sender, ResourceCreatedEventArgs e)
{
- if (nativeVertexBuffer.IsAlive)
+ if (nativeVertexBuffer != null)
{
- nativeVertexBuffer.Target.Dispose();
+ nativeVertexBuffer.Dispose();
+ nativeVertexBuffer = null;
}
CreateNativeBuffer();
@@ -108,7 +110,7 @@ namespace ANX.Framework.Graphics
private void CreateNativeBuffer()
{
- this.nativeVertexBuffer = new WeakReference(AddInSystemFactory.Instance.GetDefaultCreator().CreateVertexBuffer(GraphicsDevice, vertexDeclaration, vertexCount, bufferUsage));
+ this.nativeVertexBuffer = AddInSystemFactory.Instance.GetDefaultCreator().CreateVertexBuffer(GraphicsDevice, vertexDeclaration, vertexCount, bufferUsage);
}
public BufferUsage BufferUsage
@@ -158,22 +160,22 @@ namespace ANX.Framework.Graphics
public void SetData(T[] data) where T : struct
{
- if (!this.nativeVertexBuffer.IsAlive)
+ if (this.nativeVertexBuffer == null)
{
CreateNativeBuffer();
}
- this.nativeVertexBuffer.Target.SetData(GraphicsDevice, data);
+ this.nativeVertexBuffer.SetData(GraphicsDevice, data);
}
public void SetData(T[] data, int startIndex, int elementCount) where T : struct
{
- if (!this.nativeVertexBuffer.IsAlive)
+ if (this.nativeVertexBuffer == null)
{
CreateNativeBuffer();
}
- this.nativeVertexBuffer.Target.SetData(GraphicsDevice, data, startIndex, elementCount);
+ this.nativeVertexBuffer.SetData(GraphicsDevice, data, startIndex, elementCount);
}
private static VertexDeclaration TypeToVertexDeclaration(Type t)
@@ -189,9 +191,10 @@ namespace ANX.Framework.Graphics
public override void Dispose()
{
- if (nativeVertexBuffer.IsAlive)
+ if (nativeVertexBuffer != null)
{
- nativeVertexBuffer.Target.Dispose();
+ nativeVertexBuffer.Dispose();
+ nativeVertexBuffer = null;
}
if (vertexDeclaration != null)
@@ -207,12 +210,12 @@ namespace ANX.Framework.Graphics
{
get
{
- if (!this.nativeVertexBuffer.IsAlive)
+ if (this.nativeVertexBuffer == null)
{
CreateNativeBuffer();
}
- return this.nativeVertexBuffer.Target;
+ return this.nativeVertexBuffer;
}
}