- Made the loading of assembly types faster and more safe

- Started working on implementing all Texture baseclass methods
This commit is contained in:
SND\AstrorEnales_cp 2012-02-19 11:24:23 +00:00
parent 30499fac83
commit e1d3ca0575
11 changed files with 251 additions and 150 deletions

View File

@ -129,6 +129,14 @@
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
<Name>ANX.Framework</Name>
</ProjectReference>
<ProjectReference Include="..\InputSystems\ANX.InputDevices.Windows.XInput\ANX.InputDevices.Windows.XInput.csproj">
<Project>{60D08399-244F-46A3-91F1-4CFD26D961A3}</Project>
<Name>ANX.InputDevices.Windows.XInput</Name>
</ProjectReference>
<ProjectReference Include="..\InputSystems\ANX.InputSystem.Standard\ANX.InputSystem.Standard.csproj">
<Project>{49066074-3B7B-4A55-B122-6BD33AB73558}</Project>
<Name>ANX.InputSystem.Standard</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -63,8 +63,8 @@ namespace ANX.Framework.Graphics
public Texture(GraphicsDevice graphicsDevice)
: base(graphicsDevice)
{
base.GraphicsDevice.ResourceCreated += new EventHandler<ResourceCreatedEventArgs>(GraphicsDevice_ResourceCreated);
base.GraphicsDevice.ResourceDestroyed += new EventHandler<ResourceDestroyedEventArgs>(GraphicsDevice_ResourceDestroyed);
base.GraphicsDevice.ResourceCreated += GraphicsDevice_ResourceCreated;
base.GraphicsDevice.ResourceDestroyed += GraphicsDevice_ResourceDestroyed;
}
~Texture()

View File

@ -58,16 +58,43 @@ namespace ANX.Framework.Graphics
{
public class Texture2D : Texture, IGraphicsResource
{
#region Private Members
#region Private
protected internal int width;
protected internal int height;
#endregion // Private Members
private INativeTexture2D nativeTexture2D;
#endregion
internal Texture2D(GraphicsDevice graphicsDevice)
#region Public
public Rectangle Bounds
{
get
{
return new Rectangle(0, 0, this.width, this.height);
}
}
public int Width
{
get
{
return this.width;
}
}
public int Height
{
get
{
return this.height;
}
}
#endregion
#region Constructor
internal Texture2D(GraphicsDevice graphicsDevice)
: base(graphicsDevice)
{
}
public Texture2D(GraphicsDevice graphicsDevice, int width, int height)
@ -79,7 +106,7 @@ namespace ANX.Framework.Graphics
base.levelCount = 1;
base.format = SurfaceFormat.Color;
CreateNativeTextureSurface(graphicsDevice, SurfaceFormat.Color, width, height, levelCount);
CreateNativeTextureSurface();
}
public Texture2D(GraphicsDevice graphicsDevice, int width, int height, [MarshalAsAttribute(UnmanagedType.U1)] bool mipMap, SurfaceFormat format)
@ -91,10 +118,12 @@ namespace ANX.Framework.Graphics
base.levelCount = 1; //TODO: mipmap paramter?!?!?
base.format = format;
CreateNativeTextureSurface(graphicsDevice, format, width, height, levelCount);
CreateNativeTextureSurface();
}
#endregion
public static Texture2D FromStream(GraphicsDevice graphicsDevice, Stream stream)
#region FromStream (TODO)
public static Texture2D FromStream(GraphicsDevice graphicsDevice, Stream stream)
{
throw new NotImplementedException();
}
@ -103,8 +132,10 @@ namespace ANX.Framework.Graphics
{
throw new NotImplementedException();
}
#endregion
public void GetData<T>(int level, Nullable<Rectangle> rect, T[] data, int startIndex, int elementCount) where T : struct
#region GetData (TODO)
public void GetData<T>(int level, Nullable<Rectangle> rect, T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
@ -117,19 +148,11 @@ namespace ANX.Framework.Graphics
public void GetData<T>(T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
}
#endregion
public void SaveAsJpeg(Stream stream, int width, int height)
{
throw new NotImplementedException();
}
public void SaveAsPng(Stream stream, int width, int height)
{
throw new NotImplementedException();
}
public void SetData<T>(int level, Nullable<Rectangle> rect, T[] data, int startIndex, int elementCount) where T : struct
#region SetData (TODO)
public void SetData<T>(int level, Nullable<Rectangle> rect, T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
@ -142,50 +165,50 @@ namespace ANX.Framework.Graphics
public void SetData<T>(T[] data, int startIndex, int elementCount) where T : struct
{
NativeTexture.SetData<T>(GraphicsDevice, data, startIndex, elementCount);
}
}
#endregion
public override void Dispose()
#region SaveAsJpeg
public void SaveAsJpeg(Stream stream, int width, int height)
{
nativeTexture2D.SaveAsJpeg(stream, width, height);
}
#endregion
#region SaveAsPng
public void SaveAsPng(Stream stream, int width, int height)
{
nativeTexture2D.SaveAsPng(stream, width, height);
}
#endregion
#region Dispose
public override void Dispose()
{
base.Dispose(true);
}
protected override void Dispose([MarshalAs(UnmanagedType.U1)] bool disposeManaged)
protected override void Dispose(
[MarshalAs(UnmanagedType.U1)] bool disposeManaged)
{
base.Dispose(disposeManaged);
}
}
#endregion
public Rectangle Bounds
#region ReCreateNativeTextureSurface
internal override void ReCreateNativeTextureSurface()
{
get
{
return new Rectangle(0, 0, this.width, this.height);
}
}
CreateNativeTextureSurface();
}
#endregion
public int Width
#region CreateNativeTextureSurface
private void CreateNativeTextureSurface()
{
get
{
return this.width;
}
}
public int Height
{
get
{
return this.height;
}
}
internal override void ReCreateNativeTextureSurface()
{
CreateNativeTextureSurface(GraphicsDevice, base.format, this.width, this.height, this.levelCount);
}
internal void CreateNativeTextureSurface(GraphicsDevice device, SurfaceFormat format, int width, int height, int levelCount)
{
base.nativeTexture = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateTexture(device, format, width, height, levelCount);
}
nativeTexture2D =
AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateTexture(GraphicsDevice, format, width, height, levelCount);
base.nativeTexture = nativeTexture2D;
}
#endregion
}
}

View File

@ -1,10 +1,7 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.NonXNA;
using System.Runtime.InteropServices;
using ANX.Framework.NonXNA;
#endregion // Using Statements
@ -58,13 +55,57 @@ using System.Runtime.InteropServices;
namespace ANX.Framework.Graphics
{
public class VertexBuffer : GraphicsResource, IGraphicsResource
{
{
#region Private
private VertexDeclaration vertexDeclaration;
private int vertexCount;
private BufferUsage bufferUsage;
private INativeBuffer nativeVertexBuffer;
private INativeBuffer nativeVertexBuffer;
#endregion
public VertexBuffer(GraphicsDevice graphicsDevice, Type vertexType, int vertexCount, BufferUsage usage)
#region Constructor
// This is now internal because via befriending the assemblies
// it's usable in the modules but doesn't confuse the enduser.
internal INativeBuffer NativeVertexBuffer
{
get
{
if (this.nativeVertexBuffer == null)
{
CreateNativeBuffer();
}
return this.nativeVertexBuffer;
}
}
public BufferUsage BufferUsage
{
get
{
return this.bufferUsage;
}
}
public int VertexCount
{
get
{
return this.vertexCount;
}
}
public VertexDeclaration VertexDeclaration
{
get
{
return this.vertexDeclaration;
}
}
#endregion
#region Constructor
public VertexBuffer(GraphicsDevice graphicsDevice, Type vertexType, int vertexCount, BufferUsage usage)
: this(graphicsDevice, VertexBuffer.TypeToVertexDeclaration(vertexType), vertexCount, usage)
{
}
@ -87,18 +128,22 @@ namespace ANX.Framework.Graphics
Dispose();
base.GraphicsDevice.ResourceCreated -= GraphicsDevice_ResourceCreated;
base.GraphicsDevice.ResourceDestroyed -= GraphicsDevice_ResourceDestroyed;
}
}
#endregion
private void GraphicsDevice_ResourceDestroyed(object sender, ResourceDestroyedEventArgs e)
#region GraphicsDevice_ResourceDestroyed
private void GraphicsDevice_ResourceDestroyed(object sender, ResourceDestroyedEventArgs e)
{
if (nativeVertexBuffer != null)
{
nativeVertexBuffer.Dispose();
nativeVertexBuffer = null;
}
}
}
#endregion
private void GraphicsDevice_ResourceCreated(object sender, ResourceCreatedEventArgs e)
#region GraphicsDevice_ResourceCreated
private void GraphicsDevice_ResourceCreated(object sender, ResourceCreatedEventArgs e)
{
if (nativeVertexBuffer != null)
{
@ -107,39 +152,19 @@ namespace ANX.Framework.Graphics
}
CreateNativeBuffer();
}
}
#endregion
private void CreateNativeBuffer()
#region CreateNativeBuffer
private void CreateNativeBuffer()
{
this.nativeVertexBuffer =
AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateVertexBuffer(GraphicsDevice, this, vertexDeclaration, vertexCount, bufferUsage);
}
public BufferUsage BufferUsage
{
get
{
return this.bufferUsage;
}
}
}
#endregion
public int VertexCount
{
get
{
return this.vertexCount;
}
}
public VertexDeclaration VertexDeclaration
{
get
{
return this.vertexDeclaration;
}
}
public void GetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct
#region GetData
public void GetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct
{
throw new NotImplementedException();
}
@ -152,35 +177,29 @@ namespace ANX.Framework.Graphics
public void GetData<T>(T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
}
#endregion
public void SetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct
#region SetData
public void SetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct
{
//this.nativeVertexBuffer.SetData<T>(GraphicsDevice, offsetInBytes, data, startIndex, elementCount, vertexStride);
//NativeVertexBuffer.SetData(GraphicsDevice, offsetInBytes, data, startIndex, elementCount, vertexStride);
throw new NotImplementedException();
}
public void SetData<T>(T[] data) where T : struct
{
if (this.nativeVertexBuffer == null)
{
CreateNativeBuffer();
}
this.nativeVertexBuffer.SetData<T>(GraphicsDevice, data);
NativeVertexBuffer.SetData(GraphicsDevice, data);
}
public void SetData<T>(T[] data, int startIndex, int elementCount) where T : struct
{
if (this.nativeVertexBuffer == null)
{
CreateNativeBuffer();
}
this.nativeVertexBuffer.SetData<T>(GraphicsDevice, data, startIndex, elementCount);
NativeVertexBuffer.SetData(GraphicsDevice, data, startIndex, elementCount);
}
#endregion
private static VertexDeclaration TypeToVertexDeclaration(Type t)
#region TypeToVertexDeclaration
private static VertexDeclaration TypeToVertexDeclaration(Type t)
{
IVertexType vt = Activator.CreateInstance(t) as IVertexType;
if (vt != null)
@ -190,8 +209,10 @@ namespace ANX.Framework.Graphics
return null;
}
#endregion
public override void Dispose()
#region Dispose
public override void Dispose()
{
if (nativeVertexBuffer != null)
{
@ -204,27 +225,12 @@ namespace ANX.Framework.Graphics
// do not dispose the VertexDeclaration here, because it's only a reference
vertexDeclaration = null;
}
}
// This is now internal because via befriending the assemblies
// it's usable in the modules but doesn't confuse the enduser.
internal INativeBuffer NativeVertexBuffer
{
get
{
if (this.nativeVertexBuffer == null)
{
CreateNativeBuffer();
}
return this.nativeVertexBuffer;
}
}
}
protected override void Dispose([MarshalAs(UnmanagedType.U1)] bool disposeManaged)
{
throw new NotImplementedException();
}
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -97,7 +97,17 @@ namespace ANX.Framework.NonXNA
if (this.assembly != null)
{
foreach (Type t in this.assembly.GetTypes().Where(p =>
Type[] allTypes;
try
{
allTypes = this.assembly.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
allTypes = ex.Types;
}
foreach (Type t in allTypes.Where(p =>
typeof(IInputSystemCreator).IsAssignableFrom(p) ||
typeof(IRenderSystemCreator).IsAssignableFrom(p) ||
typeof(ISoundSystemCreator).IsAssignableFrom(p) ||
@ -121,26 +131,26 @@ namespace ANX.Framework.NonXNA
// Scan the addin for InputDeviceCreators and register them
//
foreach (Type t in this.assembly.GetTypes().Where(p =>
foreach (Type t in allTypes.Where(p =>
typeof(IGamePadCreator).IsAssignableFrom(p)))
{
InputDeviceFactory.Instance.AddCreator(Activator.CreateInstance(t) as IGamePadCreator);
}
foreach (Type t in this.assembly.GetTypes().Where(p =>
foreach (Type t in allTypes.Where(p =>
typeof(IKeyboardCreator).IsAssignableFrom(p)))
{
InputDeviceFactory.Instance.AddCreator(Activator.CreateInstance(t) as IKeyboardCreator);
}
foreach (Type t in this.assembly.GetTypes().Where(p =>
foreach (Type t in allTypes.Where(p =>
typeof(IMouseCreator).IsAssignableFrom(p)))
{
InputDeviceFactory.Instance.AddCreator(Activator.CreateInstance(t) as IMouseCreator);
}
#if XNAEXT
foreach (Type t in this.assembly.GetTypes().Where(p =>
foreach (Type t in allTypes.Where(p =>
typeof(IMotionSensingDeviceCreator).IsAssignableFrom(p)))
{
InputDeviceFactory.Instance.AddCreator(Activator.CreateInstance(t) as IMotionSensingDeviceCreator);

View File

@ -1,8 +1,4 @@
#region Using Statements
using System;
using ANX.Framework.Graphics;
#endregion // Using Statements
using System.IO;
#region License
@ -53,8 +49,9 @@ using ANX.Framework.Graphics;
namespace ANX.Framework.NonXNA.RenderSystem
{
public interface INativeTexture2D : INativeTexture
{
}
public interface INativeTexture2D : INativeTexture
{
void SaveAsJpeg(Stream stream, int width, int height);
void SaveAsPng(Stream stream, int width, int height);
}
}

View File

@ -57,7 +57,7 @@ using NLog;
#endregion // License
namespace ANX.InputDevices.Windows.XInput
namespace ANX.InputDevices.Standard
{
public class Creator : IInputSystemCreator
{

View File

@ -311,6 +311,20 @@ namespace ANX.Framework.Windows.DX10
this.nativeTexture.Dispose();
this.nativeTexture = null;
}
}
}
#region SaveAsJpeg (TODO)
public void SaveAsJpeg(Stream stream, int width, int height)
{
throw new NotImplementedException();
}
#endregion
#region SaveAsPng (TODO)
public void SaveAsPng(Stream stream, int width, int height)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA.RenderSystem;
@ -351,6 +352,20 @@ namespace ANX.Framework.Windows.GL3
}
#endregion
#region SaveAsJpeg (TODO)
public void SaveAsJpeg(Stream stream, int width, int height)
{
throw new NotImplementedException();
}
#endregion
#region SaveAsPng (TODO)
public void SaveAsPng(Stream stream, int width, int height)
{
throw new NotImplementedException();
}
#endregion
#region Dispose
/// <summary>
/// Dispose the native OpenGL texture handle.

View File

@ -311,6 +311,20 @@ namespace ANX.RenderSystem.Windows.DX11
this.nativeTexture.Dispose();
this.nativeTexture = null;
}
}
}
#region SaveAsJpeg (TODO)
public void SaveAsJpeg(Stream stream, int width, int height)
{
throw new NotImplementedException();
}
#endregion
#region SaveAsPng (TODO)
public void SaveAsPng(Stream stream, int width, int height)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -311,6 +311,20 @@ namespace ANX.Framework.Windows.DX10
this.nativeTexture.Dispose();
this.nativeTexture = null;
}
}
}
#region SaveAsJpeg (TODO)
public void SaveAsJpeg(Stream stream, int width, int height)
{
throw new NotImplementedException();
}
#endregion
#region SaveAsPng (TODO)
public void SaveAsPng(Stream stream, int width, int height)
{
throw new NotImplementedException();
}
#endregion
}
}