- 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> <Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
<Name>ANX.Framework</Name> <Name>ANX.Framework</Name>
</ProjectReference> </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> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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) public Texture(GraphicsDevice graphicsDevice)
: base(graphicsDevice) : base(graphicsDevice)
{ {
base.GraphicsDevice.ResourceCreated += new EventHandler<ResourceCreatedEventArgs>(GraphicsDevice_ResourceCreated); base.GraphicsDevice.ResourceCreated += GraphicsDevice_ResourceCreated;
base.GraphicsDevice.ResourceDestroyed += new EventHandler<ResourceDestroyedEventArgs>(GraphicsDevice_ResourceDestroyed); base.GraphicsDevice.ResourceDestroyed += GraphicsDevice_ResourceDestroyed;
} }
~Texture() ~Texture()

View File

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

View File

@ -1,10 +1,7 @@
#region Using Statements #region Using Statements
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.NonXNA;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ANX.Framework.NonXNA;
#endregion // Using Statements #endregion // Using Statements
@ -58,13 +55,57 @@ using System.Runtime.InteropServices;
namespace ANX.Framework.Graphics namespace ANX.Framework.Graphics
{ {
public class VertexBuffer : GraphicsResource, IGraphicsResource public class VertexBuffer : GraphicsResource, IGraphicsResource
{ {
#region Private
private VertexDeclaration vertexDeclaration; private VertexDeclaration vertexDeclaration;
private int vertexCount; private int vertexCount;
private BufferUsage bufferUsage; 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) : this(graphicsDevice, VertexBuffer.TypeToVertexDeclaration(vertexType), vertexCount, usage)
{ {
} }
@ -87,18 +128,22 @@ namespace ANX.Framework.Graphics
Dispose(); Dispose();
base.GraphicsDevice.ResourceCreated -= GraphicsDevice_ResourceCreated; base.GraphicsDevice.ResourceCreated -= GraphicsDevice_ResourceCreated;
base.GraphicsDevice.ResourceDestroyed -= GraphicsDevice_ResourceDestroyed; 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) if (nativeVertexBuffer != null)
{ {
nativeVertexBuffer.Dispose(); nativeVertexBuffer.Dispose();
nativeVertexBuffer = null; 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) if (nativeVertexBuffer != null)
{ {
@ -107,39 +152,19 @@ namespace ANX.Framework.Graphics
} }
CreateNativeBuffer(); CreateNativeBuffer();
} }
#endregion
private void CreateNativeBuffer() #region CreateNativeBuffer
private void CreateNativeBuffer()
{ {
this.nativeVertexBuffer = this.nativeVertexBuffer =
AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateVertexBuffer(GraphicsDevice, this, vertexDeclaration, vertexCount, bufferUsage); AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateVertexBuffer(GraphicsDevice, this, vertexDeclaration, vertexCount, bufferUsage);
} }
#endregion
public BufferUsage BufferUsage
{
get
{
return this.bufferUsage;
}
}
public int VertexCount #region GetData
{ public void GetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct
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
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -152,35 +177,29 @@ namespace ANX.Framework.Graphics
public void GetData<T>(T[] data, int startIndex, int elementCount) where T : struct public void GetData<T>(T[] data, int startIndex, int elementCount) where T : struct
{ {
throw new NotImplementedException(); 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(); throw new NotImplementedException();
} }
public void SetData<T>(T[] data) where T : struct public void SetData<T>(T[] data) where T : struct
{ {
if (this.nativeVertexBuffer == null) NativeVertexBuffer.SetData(GraphicsDevice, data);
{
CreateNativeBuffer();
}
this.nativeVertexBuffer.SetData<T>(GraphicsDevice, data);
} }
public void SetData<T>(T[] data, int startIndex, int elementCount) where T : struct public void SetData<T>(T[] data, int startIndex, int elementCount) where T : struct
{ {
if (this.nativeVertexBuffer == null) NativeVertexBuffer.SetData(GraphicsDevice, data, startIndex, elementCount);
{
CreateNativeBuffer();
}
this.nativeVertexBuffer.SetData<T>(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; IVertexType vt = Activator.CreateInstance(t) as IVertexType;
if (vt != null) if (vt != null)
@ -190,8 +209,10 @@ namespace ANX.Framework.Graphics
return null; return null;
} }
#endregion
public override void Dispose() #region Dispose
public override void Dispose()
{ {
if (nativeVertexBuffer != null) if (nativeVertexBuffer != null)
{ {
@ -204,27 +225,12 @@ namespace ANX.Framework.Graphics
// do not dispose the VertexDeclaration here, because it's only a reference // do not dispose the VertexDeclaration here, because it's only a reference
vertexDeclaration = null; 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) 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) 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(IInputSystemCreator).IsAssignableFrom(p) ||
typeof(IRenderSystemCreator).IsAssignableFrom(p) || typeof(IRenderSystemCreator).IsAssignableFrom(p) ||
typeof(ISoundSystemCreator).IsAssignableFrom(p) || typeof(ISoundSystemCreator).IsAssignableFrom(p) ||
@ -121,26 +131,26 @@ namespace ANX.Framework.NonXNA
// Scan the addin for InputDeviceCreators and register them // 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))) typeof(IGamePadCreator).IsAssignableFrom(p)))
{ {
InputDeviceFactory.Instance.AddCreator(Activator.CreateInstance(t) as IGamePadCreator); 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))) typeof(IKeyboardCreator).IsAssignableFrom(p)))
{ {
InputDeviceFactory.Instance.AddCreator(Activator.CreateInstance(t) as IKeyboardCreator); 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))) typeof(IMouseCreator).IsAssignableFrom(p)))
{ {
InputDeviceFactory.Instance.AddCreator(Activator.CreateInstance(t) as IMouseCreator); InputDeviceFactory.Instance.AddCreator(Activator.CreateInstance(t) as IMouseCreator);
} }
#if XNAEXT #if XNAEXT
foreach (Type t in this.assembly.GetTypes().Where(p => foreach (Type t in allTypes.Where(p =>
typeof(IMotionSensingDeviceCreator).IsAssignableFrom(p))) typeof(IMotionSensingDeviceCreator).IsAssignableFrom(p)))
{ {
InputDeviceFactory.Instance.AddCreator(Activator.CreateInstance(t) as IMotionSensingDeviceCreator); InputDeviceFactory.Instance.AddCreator(Activator.CreateInstance(t) as IMotionSensingDeviceCreator);

View File

@ -1,8 +1,4 @@
#region Using Statements using System.IO;
using System;
using ANX.Framework.Graphics;
#endregion // Using Statements
#region License #region License
@ -53,8 +49,9 @@ using ANX.Framework.Graphics;
namespace ANX.Framework.NonXNA.RenderSystem 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 #endregion // License
namespace ANX.InputDevices.Windows.XInput namespace ANX.InputDevices.Standard
{ {
public class Creator : IInputSystemCreator public class Creator : IInputSystemCreator
{ {

View File

@ -311,6 +311,20 @@ namespace ANX.Framework.Windows.DX10
this.nativeTexture.Dispose(); this.nativeTexture.Dispose();
this.nativeTexture = null; 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;
using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ANX.Framework.Graphics; using ANX.Framework.Graphics;
using ANX.Framework.NonXNA.RenderSystem; using ANX.Framework.NonXNA.RenderSystem;
@ -351,6 +352,20 @@ namespace ANX.Framework.Windows.GL3
} }
#endregion #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 #region Dispose
/// <summary> /// <summary>
/// Dispose the native OpenGL texture handle. /// Dispose the native OpenGL texture handle.

View File

@ -311,6 +311,20 @@ namespace ANX.RenderSystem.Windows.DX11
this.nativeTexture.Dispose(); this.nativeTexture.Dispose();
this.nativeTexture = null; 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.Dispose();
this.nativeTexture = null; 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
} }
} }