From 3316d46dba72f5d73cd8b0f22c3769e6788b909e Mon Sep 17 00:00:00 2001 From: "SND\\AstrorEnales_cp" Date: Tue, 4 Sep 2012 21:36:46 +0000 Subject: [PATCH] - Implemented some GetData methods in the Vertex and Index Buffer implementations - Added developer, PercentageComplete and TestState attributes - Added Event to the FrameworkDispatcher which will be used by the components that need it (audio etc.) - Some more refactorings, regions, etc. --- ANX.Framework/ANX.Framework.csproj | 1 + ANX.Framework/ANX.Framework_Linux.csproj | 1 + ANX.Framework/ANX.Framework_PSVita.csproj | 1 + .../ANX.Framework_WindowsMetro.csproj | 1 + ANX.Framework/FrameworkDispatcher.cs | 9 +- .../GamerServices/IAvatarAnimation.cs | 14 +- ANX.Framework/Graphics/GraphicsDevice.cs | 154 ++--- ANX.Framework/Graphics/TextureCollection.cs | 37 +- ANX.Framework/Input/Touch/TouchCollection.cs | 8 +- .../RenderSystem/IRenderSystemCreator.cs | 2 + .../NonXNA/RenderSystem/VertexTypeHelper.cs | 20 + ANX.Framework/PlaneIntersectionType.cs | 5 - ANX.Framework/Quaternion.cs | 6 +- ANX.Framework/TitleContainer.cs | 4 + .../ANX.RenderSystem.Windows.DX10.csproj | 1 - ...ANX.RenderSystem.Windows.DX10_Linux.csproj | 1 - ...NX.RenderSystem.Windows.DX10_PSVita.csproj | 1 - ...derSystem.Windows.DX10_WindowsMetro.csproj | 1 - .../ANX.Framework.Windows.DX10/Creator.cs | 158 ++--- .../EffectPass_DX10.cs | 28 +- .../EffectTechnique_DX10.cs | 88 +-- .../IndexBuffer_DX10.cs | 247 ++++---- .../NativeMethods.cs | 71 --- .../Texture2D_DX10.cs | 588 +++++++++--------- .../VertexBuffer_DX10.cs | 265 ++++---- .../ANX.Framework.Windows.GL3/Creator.cs | 13 + .../EffectParameterGL3.cs | 2 +- .../ANX.RenderSystem.PsVita/Creator.cs | 7 + .../ANX.RenderSystem.Windows.DX11.csproj | 1 - ...ANX.RenderSystem.Windows.DX11_Linux.csproj | 1 - ...NX.RenderSystem.Windows.DX11_PSVita.csproj | 1 - ...derSystem.Windows.DX11_WindowsMetro.csproj | 1 - .../ANX.RenderSystem.Windows.DX11/Creator.cs | 7 + .../IndexBuffer_DX11.cs | 202 +++--- .../NativeMethods.cs | 69 -- .../VertexBuffer_DX11.cs | 35 +- .../ANX.RenderSystem.Windows.Metro/Creator.cs | 7 + .../ANXStatusComparer/Data/AssembliesData.cs | 6 - Tools/ANXStatusComparer/Data/BaseObject.cs | 35 +- 39 files changed, 963 insertions(+), 1136 deletions(-) create mode 100644 ANX.Framework/NonXNA/RenderSystem/VertexTypeHelper.cs delete mode 100644 RenderSystems/ANX.Framework.Windows.DX10/NativeMethods.cs delete mode 100644 RenderSystems/ANX.RenderSystem.Windows.DX11/NativeMethods.cs diff --git a/ANX.Framework/ANX.Framework.csproj b/ANX.Framework/ANX.Framework.csproj index fbe609bc..8df925d2 100644 --- a/ANX.Framework/ANX.Framework.csproj +++ b/ANX.Framework/ANX.Framework.csproj @@ -442,6 +442,7 @@ + diff --git a/ANX.Framework/ANX.Framework_Linux.csproj b/ANX.Framework/ANX.Framework_Linux.csproj index 88f3f685..4f5c2d60 100644 --- a/ANX.Framework/ANX.Framework_Linux.csproj +++ b/ANX.Framework/ANX.Framework_Linux.csproj @@ -442,6 +442,7 @@ + diff --git a/ANX.Framework/ANX.Framework_PSVita.csproj b/ANX.Framework/ANX.Framework_PSVita.csproj index 5c0ddec5..3803e3e6 100644 --- a/ANX.Framework/ANX.Framework_PSVita.csproj +++ b/ANX.Framework/ANX.Framework_PSVita.csproj @@ -444,6 +444,7 @@ + diff --git a/ANX.Framework/ANX.Framework_WindowsMetro.csproj b/ANX.Framework/ANX.Framework_WindowsMetro.csproj index 59746c94..dc38d73c 100644 --- a/ANX.Framework/ANX.Framework_WindowsMetro.csproj +++ b/ANX.Framework/ANX.Framework_WindowsMetro.csproj @@ -445,6 +445,7 @@ + diff --git a/ANX.Framework/FrameworkDispatcher.cs b/ANX.Framework/FrameworkDispatcher.cs index 313d977f..112b14fb 100644 --- a/ANX.Framework/FrameworkDispatcher.cs +++ b/ANX.Framework/FrameworkDispatcher.cs @@ -1,4 +1,5 @@ using System; +using ANX.Framework.NonXNA.Development; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -6,11 +7,17 @@ using System; namespace ANX.Framework { + [PercentageComplete(100)] + [TestState(TestStateAttribute.TestState.Tested)] + [Developer("AstrorEnales")] public static class FrameworkDispatcher { + internal static event Action OnUpdate; + public static void Update() { - throw new NotImplementedException(); + if (OnUpdate != null) + OnUpdate(); } } } diff --git a/ANX.Framework/GamerServices/IAvatarAnimation.cs b/ANX.Framework/GamerServices/IAvatarAnimation.cs index b52f3361..dcd2d07a 100644 --- a/ANX.Framework/GamerServices/IAvatarAnimation.cs +++ b/ANX.Framework/GamerServices/IAvatarAnimation.cs @@ -1,9 +1,6 @@ -#region Using Statements using System; -using ANX.Framework; using System.Collections.ObjectModel; - -#endregion // Using Statements +using ANX.Framework.NonXNA.Development; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -11,16 +8,15 @@ using System.Collections.ObjectModel; namespace ANX.Framework.GamerServices { + [PercentageComplete(100)] + [TestState(TestStateAttribute.TestState.Tested)] public interface IAvatarAnimation { ReadOnlyCollection BoneTransforms { get; } - TimeSpan CurrentPosition { get; set; } - AvatarExpression Expression { get; } - TimeSpan Length { get; } - - void Update(TimeSpan elapsedAnimationTime, bool loop); + + void Update(TimeSpan elapsedAnimationTime, bool loop); } } diff --git a/ANX.Framework/Graphics/GraphicsDevice.cs b/ANX.Framework/Graphics/GraphicsDevice.cs index 476a71ec..11bee07a 100644 --- a/ANX.Framework/Graphics/GraphicsDevice.cs +++ b/ANX.Framework/Graphics/GraphicsDevice.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using ANX.Framework.NonXNA; +using ANX.Framework.NonXNA.RenderSystem; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -11,7 +12,6 @@ namespace ANX.Framework.Graphics public class GraphicsDevice : IDisposable { #region Private Members - private INativeGraphicsDevice nativeDevice; private IndexBuffer indexBuffer; private SamplerStateCollection samplerStateCollection; private Viewport viewport; @@ -52,8 +52,8 @@ namespace ANX.Framework.Graphics // TODO: get maximum number of sampler states from capabilities this.samplerStateCollection = new SamplerStateCollection(this, 8); - this.textureCollection = new TextureCollection(); - this.vertexTextureCollection = new TextureCollection(); + this.textureCollection = new TextureCollection(16); + this.vertexTextureCollection = new TextureCollection(16); this.BlendState = BlendState.Opaque; this.DepthStencilState = DepthStencilState.Default; @@ -71,13 +71,9 @@ namespace ANX.Framework.Graphics { ClearOptions options = ClearOptions.Target; if (this.currentPresentationParameters.DepthStencilFormat != DepthFormat.None) - { options |= ClearOptions.DepthBuffer; - } if (this.currentPresentationParameters.DepthStencilFormat == DepthFormat.Depth24Stencil8) - { options |= ClearOptions.Stencil; - } Clear(options, color, 1, 0); // nativeDevice.Clear(ref color); @@ -93,17 +89,18 @@ namespace ANX.Framework.Graphics if ((options & ClearOptions.DepthBuffer) == ClearOptions.DepthBuffer && this.currentPresentationParameters.DepthStencilFormat == DepthFormat.None) { - throw new InvalidOperationException("The depth buffer can only be cleared if it exists. The current DepthStencilFormat is DepthFormat.None"); + throw new InvalidOperationException("The depth buffer can only be cleared if it exists. The current " + + "DepthStencilFormat is DepthFormat.None"); } if ((options & ClearOptions.Stencil) == ClearOptions.Stencil && this.currentPresentationParameters.DepthStencilFormat != DepthFormat.Depth24Stencil8) { - throw new InvalidOperationException("The stencil buffer can only be cleared if it exists. The current DepthStencilFormat is not DepthFormat.Depth24Stencil8"); + throw new InvalidOperationException("The stencil buffer can only be cleared if it exists. The current " + + "DepthStencilFormat is not DepthFormat.Depth24Stencil8"); } - - nativeDevice.Clear(options, color, depth, stencil); + NativeDevice.Clear(options, color, depth, stencil); } #endregion // Clear @@ -111,10 +108,11 @@ namespace ANX.Framework.Graphics #region Present public void Present() { - nativeDevice.Present(); + NativeDevice.Present(); } - public void Present(Nullable sourceRectangle, Nullable destinationRectangle, IntPtr overrideWindowHandle) + public void Present(Nullable sourceRectangle, Nullable destinationRectangle, + IntPtr overrideWindowHandle) { //TODO: implement throw new NotImplementedException(); @@ -126,13 +124,13 @@ namespace ANX.Framework.Graphics public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount) { - nativeDevice.DrawIndexedPrimitives(primitiveType, baseVertex, minVertexIndex, numVertices, startIndex, + NativeDevice.DrawIndexedPrimitives(primitiveType, baseVertex, minVertexIndex, numVertices, startIndex, primitiveCount); } public void DrawPrimitives(PrimitiveType primitiveType, int startVertex, int primitiveCount) { - nativeDevice.DrawPrimitives(primitiveType, startVertex, primitiveCount); + NativeDevice.DrawPrimitives(primitiveType, startVertex, primitiveCount); } #endregion @@ -140,7 +138,7 @@ namespace ANX.Framework.Graphics public void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, int instanceCount) { - nativeDevice.DrawInstancedPrimitives(primitiveType, baseVertex, minVertexIndex, numVertices, startIndex, + NativeDevice.DrawInstancedPrimitives(primitiveType, baseVertex, minVertexIndex, numVertices, startIndex, primitiveCount, instanceCount); } #endregion @@ -149,8 +147,8 @@ namespace ANX.Framework.Graphics public void DrawUserIndexedPrimitives(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, short[] indexData, int indexOffset, int primitiveCount) where T : struct, IVertexType { - VertexDeclaration vertexDeclaration = GetDeclarationForDraw(); - nativeDevice.DrawUserIndexedPrimitives(primitiveType, vertexData, vertexOffset, numVertices, indexData, + var vertexDeclaration = VertexTypeHelper.GetDeclaration(); + NativeDevice.DrawUserIndexedPrimitives(primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset, primitiveCount, vertexDeclaration, IndexElementSize.SixteenBits); } @@ -158,15 +156,15 @@ namespace ANX.Framework.Graphics short[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType { - nativeDevice.DrawUserIndexedPrimitives(primitiveType, vertexData, vertexOffset, numVertices, indexData, + NativeDevice.DrawUserIndexedPrimitives(primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset, primitiveCount, vertexDeclaration, IndexElementSize.SixteenBits); } public void DrawUserIndexedPrimitives(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount) where T : struct, IVertexType { - VertexDeclaration vertexDeclaration = GetDeclarationForDraw(); - nativeDevice.DrawUserIndexedPrimitives(primitiveType, vertexData, vertexOffset, numVertices, indexData, + var vertexDeclaration = VertexTypeHelper.GetDeclaration(); + NativeDevice.DrawUserIndexedPrimitives(primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset, primitiveCount, vertexDeclaration, IndexElementSize.ThirtyTwoBits); } @@ -174,7 +172,7 @@ namespace ANX.Framework.Graphics int[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType { - nativeDevice.DrawUserIndexedPrimitives(primitiveType, vertexData, vertexOffset, numVertices, indexData, + NativeDevice.DrawUserIndexedPrimitives(primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset, primitiveCount, vertexDeclaration, IndexElementSize.ThirtyTwoBits); } #endregion @@ -183,24 +181,17 @@ namespace ANX.Framework.Graphics public void DrawUserPrimitives(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount) where T : struct, IVertexType { - VertexDeclaration vertexDeclaration = GetDeclarationForDraw(); - nativeDevice.DrawUserPrimitives(primitiveType, vertexData, vertexOffset, primitiveCount, vertexDeclaration); + var vertexDeclaration = VertexTypeHelper.GetDeclaration(); + NativeDevice.DrawUserPrimitives(primitiveType, vertexData, vertexOffset, primitiveCount, vertexDeclaration); } public void DrawUserPrimitives(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType { - nativeDevice.DrawUserPrimitives(primitiveType, vertexData, vertexOffset, primitiveCount, vertexDeclaration); + NativeDevice.DrawUserPrimitives(primitiveType, vertexData, vertexOffset, primitiveCount, vertexDeclaration); } #endregion - - private VertexDeclaration GetDeclarationForDraw() where T : struct, IVertexType - { - //TODO: cache the instances to avoid reflection overhead - IVertexType vertexType = Activator.CreateInstance(); - return vertexType.VertexDeclaration; - } - + #if XNAEXT #region SetConstantBuffer /// @@ -210,7 +201,7 @@ namespace ANX.Framework.Graphics /// The managed constant buffer object to bind. public void SetConstantBuffer(int slot, ConstantBuffer constantBuffer) { - this.nativeDevice.SetConstantBuffer(slot, constantBuffer); + NativeDevice.SetConstantBuffer(slot, constantBuffer); } /// @@ -221,9 +212,7 @@ namespace ANX.Framework.Graphics public void SetConstantBuffers(params ConstantBuffer[] constantBuffers) { for (int slot = 0; slot < constantBuffers.Length; slot++) - { - this.nativeDevice.SetConstantBuffer(slot, constantBuffers[slot]); - } + NativeDevice.SetConstantBuffer(slot, constantBuffers[slot]); } #endregion @@ -234,20 +223,20 @@ namespace ANX.Framework.Graphics { VertexBufferBinding[] bindings = new VertexBufferBinding[] { new VertexBufferBinding(vertexBuffer) }; this.currentVertexBufferBindings = bindings; - this.nativeDevice.SetVertexBuffers(bindings); + NativeDevice.SetVertexBuffers(bindings); } public void SetVertexBuffer(VertexBuffer vertexBuffer, int vertexOffset) { VertexBufferBinding[] bindings = new VertexBufferBinding[] { new VertexBufferBinding(vertexBuffer, vertexOffset) }; this.currentVertexBufferBindings = bindings; - this.nativeDevice.SetVertexBuffers(bindings); + NativeDevice.SetVertexBuffers(bindings); } public void SetVertexBuffers(params Graphics.VertexBufferBinding[] vertexBuffers) { this.currentVertexBufferBindings = vertexBuffers; - nativeDevice.SetVertexBuffers(vertexBuffers); + NativeDevice.SetVertexBuffers(vertexBuffers); } #endregion // SetVertexBuffer @@ -259,25 +248,23 @@ namespace ANX.Framework.Graphics { RenderTargetBinding[] renderTargetBindings = new RenderTargetBinding[] { new RenderTargetBinding(renderTarget) }; this.currentRenderTargetBindings = renderTargetBindings; - nativeDevice.SetRenderTargets(renderTargetBindings); + NativeDevice.SetRenderTargets(renderTargetBindings); } else - { - nativeDevice.SetRenderTargets(null); - } + NativeDevice.SetRenderTargets(null); } public void SetRenderTarget(RenderTargetCube renderTarget, CubeMapFace cubeMapFace) { RenderTargetBinding[] renderTargetBindings = new RenderTargetBinding[] { new RenderTargetBinding(renderTarget, cubeMapFace) }; this.currentRenderTargetBindings = renderTargetBindings; - nativeDevice.SetRenderTargets(renderTargetBindings); + NativeDevice.SetRenderTargets(renderTargetBindings); } public void SetRenderTargets(params RenderTargetBinding[] renderTargets) { this.currentRenderTargetBindings = renderTargets; - nativeDevice.SetRenderTargets(renderTargets); + NativeDevice.SetRenderTargets(renderTargets); } #endregion // SetRenderTarget @@ -285,17 +272,17 @@ namespace ANX.Framework.Graphics #region GetBackBufferData public void GetBackBufferData(Nullable rect, T[] data, int startIndex, int elementCount) where T : struct { - nativeDevice.GetBackBufferData(rect, data, startIndex, elementCount); + NativeDevice.GetBackBufferData(rect, data, startIndex, elementCount); } public void GetBackBufferData(T[] data) where T : struct { - nativeDevice.GetBackBufferData(data); + NativeDevice.GetBackBufferData(data); } public void GetBackBufferData(T[] data, int startIndex, int elementCount) where T : struct { - nativeDevice.GetBackBufferData(data, startIndex, elementCount); + NativeDevice.GetBackBufferData(data, startIndex, elementCount); } #endregion // GetBackBufferData @@ -354,7 +341,7 @@ namespace ANX.Framework.Graphics } // reset presentation parameters - nativeDevice.ResizeBuffers(presentationParameters); + NativeDevice.ResizeBuffers(presentationParameters); this.viewport = new Graphics.Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight); @@ -374,10 +361,11 @@ namespace ANX.Framework.Graphics { if (isDisposed == false) { - if (nativeDevice != null) + isDisposed = true; + if (NativeDevice != null) { - nativeDevice.Dispose(); - nativeDevice = null; + NativeDevice.Dispose(); + NativeDevice = null; } raise_Disposing(this, EventArgs.Empty); @@ -622,69 +610,51 @@ namespace ANX.Framework.Graphics internal INativeGraphicsDevice NativeDevice { - get - { - return this.nativeDevice; - } - set - { - this.nativeDevice = value; - } + get; + set; } internal void Recreate(PresentationParameters presentationParameters) { - if (nativeDevice != null) + if (NativeDevice != null) { - nativeDevice.Dispose(); - raise_ResourceDestroyed(this, new ResourceDestroyedEventArgs("NativeGraphicsDevice", nativeDevice)); - nativeDevice = null; + NativeDevice.Dispose(); + raise_ResourceDestroyed(this, new ResourceDestroyedEventArgs("NativeGraphicsDevice", NativeDevice)); + NativeDevice = null; } - if (nativeDevice == null) + if (NativeDevice == null) { this.currentPresentationParameters = presentationParameters; var creator = AddInSystemFactory.Instance.GetDefaultCreator(); - nativeDevice = creator.CreateGraphicsDevice(presentationParameters); + NativeDevice = creator.CreateGraphicsDevice(presentationParameters); this.viewport = new Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight); - raise_ResourceCreated(this, new ResourceCreatedEventArgs(nativeDevice)); + raise_ResourceCreated(this, new ResourceCreatedEventArgs(NativeDevice)); GraphicsResourceTracker.Instance.UpdateGraphicsDeviceReference(this); if (this.indexBuffer != null) - { NativeDevice.SetIndexBuffer(this.indexBuffer); - } if (this.currentVertexBufferBindings != null) - { NativeDevice.SetVertexBuffers(this.currentVertexBufferBindings); - } if (this.blendState != null) - { this.blendState.NativeBlendState.Apply(this); - } if (this.rasterizerState != null) - { this.rasterizerState.NativeRasterizerState.Apply(this); - } if (this.depthStencilState != null) - { this.depthStencilState.NativeDepthStencilState.Apply(this); - } if (this.samplerStateCollection != null) { for (int i = 0; i < 8; i++) { if (this.samplerStateCollection[i] != null) - { this.samplerStateCollection[i].NativeSamplerState.Apply(this, i); - } } } } @@ -692,38 +662,38 @@ namespace ANX.Framework.Graphics protected void raise_Disposing(object sender, EventArgs args) { - if (Disposing != null) - Disposing(sender, args); + RaiseIfNotNull(Disposing, sender, args); } protected void raise_DeviceResetting(object sender, EventArgs args) { - if (DeviceResetting != null) - DeviceResetting(sender, args); + RaiseIfNotNull(DeviceResetting, sender, args); } protected void raise_DeviceReset(object sender, EventArgs args) { - if (DeviceReset != null) - DeviceReset(sender, args); + RaiseIfNotNull(DeviceReset, sender, args); } protected void raise_DeviceLost(object sender, EventArgs args) { - if (DeviceLost != null) - DeviceLost(sender, args); + RaiseIfNotNull(DeviceLost, sender, args); } protected void raise_ResourceCreated(object sender, ResourceCreatedEventArgs args) { - if (ResourceCreated != null) - ResourceCreated(sender, args); + RaiseIfNotNull(ResourceCreated, sender, args); } protected void raise_ResourceDestroyed(object sender, ResourceDestroyedEventArgs args) { - if (ResourceDestroyed != null) - ResourceDestroyed(sender, args); + RaiseIfNotNull(ResourceDestroyed, sender, args); + } + + private void RaiseIfNotNull(EventHandler handler, object sender, T args) where T : EventArgs + { + if (handler != null) + handler(sender, args); } } } diff --git a/ANX.Framework/Graphics/TextureCollection.cs b/ANX.Framework/Graphics/TextureCollection.cs index 6da2b630..7334f2fc 100644 --- a/ANX.Framework/Graphics/TextureCollection.cs +++ b/ANX.Framework/Graphics/TextureCollection.cs @@ -1,7 +1,5 @@ -#region Using Statements using System; - -#endregion // Using Statements +using ANX.Framework.NonXNA; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -9,18 +7,27 @@ using System; namespace ANX.Framework.Graphics { - public sealed class TextureCollection - { - public Texture this[int index] + public sealed class TextureCollection + { + private Texture[] textures; + + public Texture this[int index] + { + get { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } + return textures[index]; } - } + set + { + textures[index] = value; + var creator = AddInSystemFactory.Instance.GetDefaultCreator(); + creator.SetTextureSampler(index, value); + } + } + + internal TextureCollection(int maxNumberOfTextures) + { + textures = new Texture[maxNumberOfTextures]; + } + } } diff --git a/ANX.Framework/Input/Touch/TouchCollection.cs b/ANX.Framework/Input/Touch/TouchCollection.cs index 2897894a..e55652bb 100644 --- a/ANX.Framework/Input/Touch/TouchCollection.cs +++ b/ANX.Framework/Input/Touch/TouchCollection.cs @@ -9,7 +9,7 @@ using ANX.Framework.NonXNA.Development; namespace ANX.Framework.Input.Touch { - [PercentageComplete(90)] + [PercentageComplete(100)] [TestState(TestStateAttribute.TestState.Untested)] public struct TouchCollection : IList, ICollection, IEnumerable, IEnumerable { @@ -67,7 +67,7 @@ namespace ANX.Framework.Input.Touch private List locations; #endregion - #region Public (TODO) + #region Public public TouchLocation this[int index] { get @@ -92,7 +92,7 @@ namespace ANX.Framework.Input.Touch { get { - throw new NotImplementedException(); + return true; } } @@ -100,7 +100,7 @@ namespace ANX.Framework.Input.Touch { get { - throw new NotImplementedException(); + return true; } } #endregion diff --git a/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs b/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs index 51c64e8a..02e3dc12 100644 --- a/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs +++ b/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs @@ -46,5 +46,7 @@ namespace ANX.Framework.NonXNA EffectSourceLanguage GetStockShaderSourceLanguage { get; } ReadOnlyCollection GetAdapterList(); + + void SetTextureSampler(int index, Texture value); } } diff --git a/ANX.Framework/NonXNA/RenderSystem/VertexTypeHelper.cs b/ANX.Framework/NonXNA/RenderSystem/VertexTypeHelper.cs new file mode 100644 index 00000000..283176db --- /dev/null +++ b/ANX.Framework/NonXNA/RenderSystem/VertexTypeHelper.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using ANX.Framework.Graphics; + +namespace ANX.Framework.NonXNA.RenderSystem +{ + internal static class VertexTypeHelper + { + private static Dictionary rememberedInstances = new Dictionary(); + + public static VertexDeclaration GetDeclaration() where T : struct, IVertexType + { + Type type = typeof(T); + if (rememberedInstances.ContainsKey(type) == false) + rememberedInstances.Add(type, Activator.CreateInstance()); + + return rememberedInstances[type].VertexDeclaration; + } + } +} diff --git a/ANX.Framework/PlaneIntersectionType.cs b/ANX.Framework/PlaneIntersectionType.cs index 2e4863ef..c7a5420a 100644 --- a/ANX.Framework/PlaneIntersectionType.cs +++ b/ANX.Framework/PlaneIntersectionType.cs @@ -1,8 +1,3 @@ -#region Using Statements - - -#endregion // Using Statements - // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. // For details see: http://anxframework.codeplex.com/license diff --git a/ANX.Framework/Quaternion.cs b/ANX.Framework/Quaternion.cs index fcd8c694..f829b045 100644 --- a/ANX.Framework/Quaternion.cs +++ b/ANX.Framework/Quaternion.cs @@ -371,7 +371,7 @@ namespace ANX.Framework { Quaternion result; Quaternion.Slerp(ref quaternion1, ref quaternion2, amount, out result); - return result; throw new NotImplementedException(); + return result; } public static void Slerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result) @@ -409,9 +409,7 @@ namespace ANX.Framework public override string ToString() { var culture = CultureInfo.CurrentCulture; - return "{X:" + X.ToString(culture) + - " Y:" + Y.ToString(culture) + - " Z:" + Z.ToString(culture) + + return "{X:" + X.ToString(culture) + " Y:" + Y.ToString(culture) + " Z:" + Z.ToString(culture) + " W:" + W.ToString(culture) + "}"; } #endregion diff --git a/ANX.Framework/TitleContainer.cs b/ANX.Framework/TitleContainer.cs index 999ed6f8..61e2e8ae 100644 --- a/ANX.Framework/TitleContainer.cs +++ b/ANX.Framework/TitleContainer.cs @@ -1,6 +1,7 @@ using System.IO; using ANX.Framework.NonXNA; using ANX.Framework.NonXNA.PlatformSystem; +using ANX.Framework.NonXNA.Development; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -8,6 +9,9 @@ using ANX.Framework.NonXNA.PlatformSystem; namespace ANX.Framework { + [PercentageComplete(100)] + [TestState(TestStateAttribute.TestState.Untested)] + [Developer("AstrorEnales")] public static class TitleContainer { private static INativeTitleContainer nativeImplementation; diff --git a/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10.csproj b/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10.csproj index 0509c2d3..9bdc64e5 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10.csproj +++ b/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10.csproj @@ -87,7 +87,6 @@ - diff --git a/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_Linux.csproj b/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_Linux.csproj index be00d2ba..ad929e10 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_Linux.csproj +++ b/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_Linux.csproj @@ -87,7 +87,6 @@ - diff --git a/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_PSVita.csproj b/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_PSVita.csproj index a04b79aa..1ff387c1 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_PSVita.csproj +++ b/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_PSVita.csproj @@ -88,7 +88,6 @@ - diff --git a/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_WindowsMetro.csproj b/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_WindowsMetro.csproj index 4bc874ec..38b6463b 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_WindowsMetro.csproj +++ b/RenderSystems/ANX.Framework.Windows.DX10/ANX.RenderSystem.Windows.DX10_WindowsMetro.csproj @@ -89,7 +89,6 @@ - diff --git a/RenderSystems/ANX.Framework.Windows.DX10/Creator.cs b/RenderSystems/ANX.Framework.Windows.DX10/Creator.cs index 154310ef..662739e6 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/Creator.cs +++ b/RenderSystems/ANX.Framework.Windows.DX10/Creator.cs @@ -1,4 +1,3 @@ -#region Using Statements using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -8,8 +7,7 @@ using ANX.Framework.Graphics; using ANX.Framework.NonXNA; using ANX.Framework.NonXNA.RenderSystem; using SharpDX.DXGI; - -#endregion // Using Statements +using Dx10 = SharpDX.Direct3D10; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -19,6 +17,7 @@ namespace ANX.RenderSystem.Windows.DX10 { public class Creator : IRenderSystemCreator { + #region Public public string Name { get { return "DirectX10"; } @@ -38,132 +37,133 @@ namespace ANX.RenderSystem.Windows.DX10 } } + public EffectSourceLanguage GetStockShaderSourceLanguage + { + get + { + return EffectSourceLanguage.HLSL_FX; + } + } + #endregion + + #region CreateGraphicsDevice public INativeGraphicsDevice CreateGraphicsDevice(PresentationParameters presentationParameters) { PreventSystemChange(); return new GraphicsDeviceWindowsDX10(presentationParameters); } + #endregion + #region CreateIndexBuffer public INativeIndexBuffer CreateIndexBuffer(GraphicsDevice graphics, IndexBuffer managedBuffer, IndexElementSize size, int indexCount, BufferUsage usage) { PreventSystemChange(); return new IndexBuffer_DX10(graphics, size, indexCount, usage); } + #endregion + #region CreateVertexBuffer public INativeVertexBuffer CreateVertexBuffer(GraphicsDevice graphics, VertexBuffer managedBuffer, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage) { PreventSystemChange(); - - return new VertexBuffer_DX10(graphics, vertexDeclaration, vertexCount, usage); + return new VertexBuffer_DX10(graphics, vertexDeclaration, vertexCount, usage); } + #endregion #if XNAEXT - #region CreateConstantBuffer - public INativeConstantBuffer CreateConstantBuffer(GraphicsDevice graphics, ConstantBuffer managedBuffer, BufferUsage usage) - { - PreventSystemChange(); - - throw new NotImplementedException(); - } - #endregion -#endif - - public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream vertexShaderByteCode, - Stream pixelShaderByteCode) + #region CreateConstantBuffer + public INativeConstantBuffer CreateConstantBuffer(GraphicsDevice graphics, ConstantBuffer managedBuffer, BufferUsage usage) { PreventSystemChange(); + throw new NotImplementedException(); + } + #endregion +#endif + + #region CreateEffect + public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream vertexShaderByteCode, + Stream pixelShaderByteCode) + { + PreventSystemChange(); return new Effect_DX10(graphics, managedEffect, vertexShaderByteCode, pixelShaderByteCode); } public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream byteCode) { PreventSystemChange(); - return new Effect_DX10(graphics, managedEffect, byteCode); } + #endregion - public Texture2D CreateTexture(GraphicsDevice graphics, string fileName) + #region CreateTexture + public INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, + int mipCount) { PreventSystemChange(); - - //TODO: implement - throw new NotImplementedException(); - - //GraphicsDeviceWindowsDX10 graphicsDX10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10; - //SharpDX.Direct3D10.Texture2D nativeTexture = SharpDX.Direct3D10.Texture2D.FromFile(graphicsDX10.NativeDevice, fileName); - //Texture2D_DX10 texture = new Texture2D_DX10(graphics, nativeTexture.Description.Width, nativeTexture.Description.Height, FormatConverter.Translate(nativeTexture.Description.Format), nativeTexture.Description.MipLevels); - //texture.NativeTexture = nativeTexture; - - //return texture; + return new Texture2D_DX10(graphics, width, height, surfaceFormat, mipCount); } + #endregion + #region CreateBlendState public INativeBlendState CreateBlendState() { PreventSystemChange(); return new BlendState_DX10(); } + #endregion + #region CreateRasterizerState public INativeRasterizerState CreateRasterizerState() { PreventSystemChange(); return new RasterizerState_DX10(); } + #endregion + #region CreateDepthStencilState public INativeDepthStencilState CreateDepthStencilState() { PreventSystemChange(); return new DepthStencilState_DX10(); } + #endregion + #region CreateSamplerState public INativeSamplerState CreateSamplerState() { PreventSystemChange(); return new SamplerState_DX10(); } + #endregion + #region GetShaderByteCode public byte[] GetShaderByteCode(PreDefinedShader type) { PreventSystemChange(); - - if (type == PreDefinedShader.SpriteBatch) + switch (type) { - return ShaderByteCode.SpriteBatchByteCode; - } - else if (type == PreDefinedShader.AlphaTestEffect) - { - return ShaderByteCode.AlphaTestEffectByteCode; - } - else if (type == PreDefinedShader.BasicEffect) - { - return ShaderByteCode.BasicEffectByteCode; - } - else if (type == PreDefinedShader.DualTextureEffect) - { - return ShaderByteCode.DualTextureEffectByteCode; - } - else if (type == PreDefinedShader.EnvironmentMapEffect) - { - return ShaderByteCode.EnvironmentMapEffectByteCode; - } - else if (type == PreDefinedShader.SkinnedEffect) - { - return ShaderByteCode.SkinnedEffectByteCode; + case PreDefinedShader.SpriteBatch: + return ShaderByteCode.SpriteBatchByteCode; + case PreDefinedShader.AlphaTestEffect: + return ShaderByteCode.AlphaTestEffectByteCode; + case PreDefinedShader.BasicEffect: + return ShaderByteCode.BasicEffectByteCode; + case PreDefinedShader.DualTextureEffect: + return ShaderByteCode.DualTextureEffectByteCode; + case PreDefinedShader.EnvironmentMapEffect: + return ShaderByteCode.EnvironmentMapEffectByteCode; + case PreDefinedShader.SkinnedEffect: + return ShaderByteCode.SkinnedEffectByteCode; } throw new NotImplementedException("ByteCode for '" + type + "' is not yet available"); } + #endregion - public EffectSourceLanguage GetStockShaderSourceLanguage - { - get - { - return EffectSourceLanguage.HLSL_FX; - } - } - + #region GetAdapterList public ReadOnlyCollection GetAdapterList() { PreventSystemChange(); @@ -177,7 +177,7 @@ namespace ANX.RenderSystem.Windows.DX10 { using (Adapter adapter = factory.GetAdapter(i)) { - GraphicsAdapter ga = new GraphicsAdapter(); + var ga = new GraphicsAdapter(); //ga.CurrentDisplayMode = ; //ga.Description = ; ga.DeviceId = adapter.Description.DeviceId; @@ -218,23 +218,18 @@ namespace ANX.RenderSystem.Windows.DX10 return new ReadOnlyCollection(adapterList); } + #endregion - public INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, - int mipCount) - { - PreventSystemChange(); - - return new Texture2D_DX10(graphics, width, height, surfaceFormat, mipCount); - } - + #region CreateRenderTarget public INativeRenderTarget2D CreateRenderTarget(GraphicsDevice graphics, int width, int height, bool mipMap, - SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) + SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, + RenderTargetUsage usage) { PreventSystemChange(); - return new RenderTarget2D_DX10(graphics, width, height, mipMap, preferredFormat, preferredDepthFormat, preferredMultiSampleCount, usage); } + #endregion #region PreventSystemChange private void PreventSystemChange() @@ -243,16 +238,27 @@ namespace ANX.RenderSystem.Windows.DX10 } #endregion - public bool IsLanguageSupported(EffectSourceLanguage sourceLanguage) - { - return sourceLanguage == EffectSourceLanguage.HLSL_FX || sourceLanguage == EffectSourceLanguage.HLSL; - } + #region IsLanguageSupported + public bool IsLanguageSupported(EffectSourceLanguage sourceLanguage) + { + return sourceLanguage == EffectSourceLanguage.HLSL_FX || sourceLanguage == EffectSourceLanguage.HLSL; + } + #endregion #region CreateOcclusionQuery (TODO) public IOcclusionQuery CreateOcclusionQuery() { + PreventSystemChange(); throw new NotImplementedException(); } #endregion - } + + #region SetTextureSampler (TODO) + public void SetTextureSampler(int index, Texture value) + { + PreventSystemChange(); + throw new NotImplementedException(); + } + #endregion + } } diff --git a/RenderSystems/ANX.Framework.Windows.DX10/EffectPass_DX10.cs b/RenderSystems/ANX.Framework.Windows.DX10/EffectPass_DX10.cs index 4a7e62f4..e3896d7c 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/EffectPass_DX10.cs +++ b/RenderSystems/ANX.Framework.Windows.DX10/EffectPass_DX10.cs @@ -1,13 +1,6 @@ -#region Using Statements -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using ANX.Framework.NonXNA; using SharpDX.Direct3D10; -#endregion // Using Statements - // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. // For details see: http://anxframework.codeplex.com/license @@ -16,26 +9,19 @@ namespace ANX.RenderSystem.Windows.DX10 { public class EffectPass_DX10 : INativeEffectPass { - private EffectPass nativePass; - - public EffectPass NativePass - { - get - { - return this.nativePass; - } - internal set - { - this.nativePass = value; - } - } + public EffectPass NativePass { get; internal set; } public string Name { get { - return nativePass.Description.Name; + return NativePass.Description.Name; } } + + internal EffectPass_DX10(EffectPass setNativePass) + { + NativePass = setNativePass; + } } } diff --git a/RenderSystems/ANX.Framework.Windows.DX10/EffectTechnique_DX10.cs b/RenderSystems/ANX.Framework.Windows.DX10/EffectTechnique_DX10.cs index 7f1b0528..20437cf4 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/EffectTechnique_DX10.cs +++ b/RenderSystems/ANX.Framework.Windows.DX10/EffectTechnique_DX10.cs @@ -1,71 +1,49 @@ -#region Using Statements using System; using System.Collections.Generic; -using System.Linq; -using System.Text; +using ANX.Framework.Graphics; using ANX.Framework.NonXNA; -using SharpDX.Direct3D10; - -#endregion // Using Statements +using Dx10 = SharpDX.Direct3D10; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. // For details see: http://anxframework.codeplex.com/license -using EffectPass = ANX.Framework.Graphics.EffectPass; - namespace ANX.RenderSystem.Windows.DX10 { - public class EffectTechnique_DX10 : INativeEffectTechnique - { - private EffectTechnique nativeTechnique; - private ANX.Framework.Graphics.Effect parentEffect; + public class EffectTechnique_DX10 : INativeEffectTechnique + { + private Effect parentEffect; - internal EffectTechnique_DX10(ANX.Framework.Graphics.Effect parentEffect) - { - if (parentEffect == null) - { - throw new ArgumentNullException("parentEffect"); - } + public Dx10.EffectTechnique NativeTechnique { get; internal set; } - this.parentEffect = parentEffect; - } + public string Name + { + get + { + return NativeTechnique.Description.Name; + } + } - public EffectTechnique NativeTechnique - { - get - { - return this.nativeTechnique; - } - internal set - { - this.nativeTechnique = value; - } - } + public IEnumerable Passes + { + get + { + for (int i = 0; i < NativeTechnique.Description.PassCount; i++) + { + EffectPass_DX10 passDx10 = new EffectPass_DX10(NativeTechnique.GetPassByIndex(i)); + EffectPass pass = new EffectPass(this.parentEffect); + // TODO: wire up native pass and managed pass? + yield return pass; + } + } + } - public string Name - { - get - { - return nativeTechnique.Description.Name; - } - } + internal EffectTechnique_DX10(Effect parentEffect) + { + if (parentEffect == null) + throw new ArgumentNullException("parentEffect"); - - public IEnumerable Passes - { - get - { - for (int i = 0; i < nativeTechnique.Description.PassCount; i++) - { - EffectPass_DX10 passDx10 = new EffectPass_DX10(); - passDx10.NativePass = nativeTechnique.GetPassByIndex(i); - - EffectPass pass = new EffectPass(this.parentEffect); - - yield return pass; - } - } - } - } + this.parentEffect = parentEffect; + } + } } diff --git a/RenderSystems/ANX.Framework.Windows.DX10/IndexBuffer_DX10.cs b/RenderSystems/ANX.Framework.Windows.DX10/IndexBuffer_DX10.cs index 4d461d49..8f8e0683 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/IndexBuffer_DX10.cs +++ b/RenderSystems/ANX.Framework.Windows.DX10/IndexBuffer_DX10.cs @@ -1,15 +1,8 @@ -#region Using Statements using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using ANX.Framework.NonXNA; -using SharpDX.Direct3D10; +using System.IO; using ANX.Framework.Graphics; -using System.Runtime.InteropServices; using ANX.Framework.NonXNA.RenderSystem; - -#endregion // Using Statements +using SharpDX.Direct3D10; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -17,133 +10,123 @@ using ANX.Framework.NonXNA.RenderSystem; namespace ANX.RenderSystem.Windows.DX10 { - public class IndexBuffer_DX10 : INativeIndexBuffer, IDisposable - { - private SharpDX.Direct3D10.Buffer buffer; - private IndexElementSize size; + public class IndexBuffer_DX10 : INativeIndexBuffer, IDisposable + { + private IndexElementSize size; - public IndexBuffer_DX10(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage) - { - this.size = size; + public SharpDX.Direct3D10.Buffer NativeBuffer { get; private set; } - //TODO: translate and use usage + #region Constructor + public IndexBuffer_DX10(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage) + { + this.size = size; - GraphicsDeviceWindowsDX10 gd10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10; - SharpDX.Direct3D10.Device device = gd10 != null ? gd10.NativeDevice as SharpDX.Direct3D10.Device : null; + //TODO: translate and use usage - InitializeBuffer(device, size, indexCount, usage); - } + GraphicsDeviceWindowsDX10 gd10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10; + Device device = gd10 != null ? gd10.NativeDevice as Device : null; - internal IndexBuffer_DX10(SharpDX.Direct3D10.Device device, IndexElementSize size, int indexCount, BufferUsage usage) - { - this.size = size; - - InitializeBuffer(device, size, indexCount, usage); - } - - private void InitializeBuffer(SharpDX.Direct3D10.Device device, IndexElementSize size, int indexCount, BufferUsage usage) - { - BufferDescription description = new BufferDescription() - { - Usage = ResourceUsage.Dynamic, - SizeInBytes = (size == IndexElementSize.SixteenBits ? 2 : 4) * indexCount, - BindFlags = BindFlags.IndexBuffer, - CpuAccessFlags = CpuAccessFlags.Write, - OptionFlags = ResourceOptionFlags.None - }; - - this.buffer = new SharpDX.Direct3D10.Buffer(device, description); - this.buffer.Unmap(); - } - - public void SetData(GraphicsDevice graphicsDevice, T[] data) where T : struct - { - SetData(graphicsDevice, data, 0, data.Length); - } - - public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct - { - //TODO: check offsetInBytes parameter for bounds etc. - - GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned); - IntPtr dataPointer = pinnedArray.AddrOfPinnedObject(); - - int dataLength = Marshal.SizeOf(typeof(T)) * data.Length; - - unsafe - { - using (var vData = new SharpDX.DataStream(dataPointer, dataLength, true, true)) - { - if (offsetInBytes > 0) - { - vData.Seek(offsetInBytes / (size == IndexElementSize.SixteenBits ? 2 : 4), System.IO.SeekOrigin.Begin); - } - - using (var d = buffer.Map(MapMode.WriteDiscard)) - { - if (startIndex > 0 || elementCount < data.Length) - { - for (int i = startIndex; i < startIndex + elementCount; i++) - { - d.Write(data[i]); - } - } - else - { - vData.CopyTo(d); - } - buffer.Unmap(); - } - } - } - - pinnedArray.Free(); - } - - public void SetData(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct - { - SetData(graphicsDevice, 0, data, startIndex, elementCount); - } - - public SharpDX.Direct3D10.Buffer NativeBuffer - { - get - { - return this.buffer; - } - } - - public void Dispose() - { - if (this.buffer != null) - { - buffer.Dispose(); - buffer = null; - } - } - - #region INativeIndexBuffer Member - - public void GetData(int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct - { - throw new NotImplementedException(); - } - - #endregion - - #region INativeBuffer Member - - - public void GetData(T[] data) where T : struct - { - throw new NotImplementedException(); - } - - public void GetData(T[] data, int startIndex, int elementCount) where T : struct - { - throw new NotImplementedException(); - } - - #endregion + InitializeBuffer(device, size, indexCount, usage); } + + internal IndexBuffer_DX10(Device device, IndexElementSize size, int indexCount, BufferUsage usage) + { + this.size = size; + InitializeBuffer(device, size, indexCount, usage); + } + #endregion + + #region InitializeBuffer + private void InitializeBuffer(Device device, IndexElementSize size, int indexCount, BufferUsage usage) + { + BufferDescription description = new BufferDescription() + { + Usage = ResourceUsage.Dynamic, + SizeInBytes = (size == IndexElementSize.SixteenBits ? 2 : 4) * indexCount, + BindFlags = BindFlags.IndexBuffer, + CpuAccessFlags = CpuAccessFlags.Write, + OptionFlags = ResourceOptionFlags.None + }; + + NativeBuffer = new SharpDX.Direct3D10.Buffer(device, description); + NativeBuffer.Unmap(); + } + #endregion + + #region SetData + public void SetData(GraphicsDevice graphicsDevice, T[] data) where T : struct + { + SetData(graphicsDevice, data, 0, data.Length); + } + + public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) + where T : struct + { + //TODO: check offsetInBytes parameter for bounds etc. + + using (var stream = NativeBuffer.Map(MapMode.WriteDiscard)) + { + if (offsetInBytes > 0) + stream.Seek(offsetInBytes, SeekOrigin.Current); + + if (startIndex > 0 || elementCount < data.Length) + for (int i = startIndex; i < startIndex + elementCount; i++) + stream.Write(data[i]); + else + for (int i = 0; i < data.Length; i++) + stream.Write(data[i]); + + NativeBuffer.Unmap(); + } + } + + public void SetData(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct + { + SetData(graphicsDevice, 0, data, startIndex, elementCount); + } + #endregion + + #region Dispose + public void Dispose() + { + if (NativeBuffer != null) + { + NativeBuffer.Dispose(); + NativeBuffer = null; + } + } + #endregion + + #region GetData + public void GetData(T[] data) where T : struct + { + using (var stream = NativeBuffer.Map(MapMode.Read)) + { + stream.ReadRange(data, 0, data.Length); + NativeBuffer.Unmap(); + } + } + + public void GetData(T[] data, int startIndex, int elementCount) where T : struct + { + using (var stream = NativeBuffer.Map(MapMode.Read)) + { + stream.ReadRange(data, startIndex, elementCount); + NativeBuffer.Unmap(); + } + } + + public void GetData(int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct + { + using (var stream = NativeBuffer.Map(MapMode.Read)) + { + if (offsetInBytes > 0) + stream.Seek(offsetInBytes, SeekOrigin.Current); + + stream.ReadRange(data, startIndex, elementCount); + NativeBuffer.Unmap(); + } + } + #endregion + } } diff --git a/RenderSystems/ANX.Framework.Windows.DX10/NativeMethods.cs b/RenderSystems/ANX.Framework.Windows.DX10/NativeMethods.cs deleted file mode 100644 index 89b509cc..00000000 --- a/RenderSystems/ANX.Framework.Windows.DX10/NativeMethods.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Security; - -// This file is part of the ANX.Framework created by the -// "ANX.Framework developer group" and released under the Ms-PL license. -// For details see: http://anxframework.codeplex.com/license - -namespace ANX.RenderSystem.Windows.DX10 -{ - internal sealed class NativeMethods - { - // Not needed anymore, is in platforms now! - //[SuppressUnmanagedCodeSecurity, DllImport("user32.dll", CharSet = CharSet.Auto)] - //internal static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags); - - //// Nested Types - //[StructLayout(LayoutKind.Sequential)] - //public struct Message - //{ - // public IntPtr hWnd; - // public NativeMethods.WindowMessage msg; - // public IntPtr wParam; - // public IntPtr lParam; - // public uint time; - // public Point p; - //} - - internal enum WindowMessage : uint - { - ActivateApplication = 0x1c, - Character = 0x102, - Close = 0x10, - Destroy = 2, - EnterMenuLoop = 0x211, - EnterSizeMove = 0x231, - ExitMenuLoop = 530, - ExitSizeMove = 0x232, - GetMinMax = 0x24, - KeyDown = 0x100, - KeyUp = 0x101, - LeftButtonDoubleClick = 0x203, - LeftButtonDown = 0x201, - LeftButtonUp = 0x202, - MiddleButtonDoubleClick = 0x209, - MiddleButtonDown = 0x207, - MiddleButtonUp = 520, - MouseFirst = 0x201, - MouseLast = 0x20d, - MouseMove = 0x200, - MouseWheel = 0x20a, - NonClientHitTest = 0x84, - Paint = 15, - PowerBroadcast = 0x218, - Quit = 0x12, - RightButtonDoubleClick = 0x206, - RightButtonDown = 0x204, - RightButtonUp = 0x205, - SetCursor = 0x20, - Size = 5, - SystemCharacter = 0x106, - SystemCommand = 0x112, - SystemKeyDown = 260, - SystemKeyUp = 0x105, - XButtonDoubleClick = 0x20d, - XButtonDown = 0x20b, - XButtonUp = 0x20c - } - - } -} diff --git a/RenderSystems/ANX.Framework.Windows.DX10/Texture2D_DX10.cs b/RenderSystems/ANX.Framework.Windows.DX10/Texture2D_DX10.cs index f4fec07c..8a5f8be0 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/Texture2D_DX10.cs +++ b/RenderSystems/ANX.Framework.Windows.DX10/Texture2D_DX10.cs @@ -18,301 +18,301 @@ using ANX.Framework; namespace ANX.RenderSystem.Windows.DX10 { - public class Texture2D_DX10 : INativeTexture2D - { - #region Private Members - protected internal SharpDX.Direct3D10.Texture2D nativeTexture; - protected internal SharpDX.Direct3D10.ShaderResourceView nativeShaderResourceView; - protected internal int formatSize; - protected internal SurfaceFormat surfaceFormat; - protected internal GraphicsDevice graphicsDevice; + public class Texture2D_DX10 : INativeTexture2D + { + #region Private Members + protected internal SharpDX.Direct3D10.Texture2D nativeTexture; + protected internal SharpDX.Direct3D10.ShaderResourceView nativeShaderResourceView; + protected internal int formatSize; + protected internal SurfaceFormat surfaceFormat; + protected internal GraphicsDevice graphicsDevice; - #endregion // Private Members + #endregion // Private Members - internal Texture2D_DX10(GraphicsDevice graphicsDevice) - { - this.graphicsDevice = graphicsDevice; - } - - public Texture2D_DX10(GraphicsDevice graphicsDevice, int width, int height, SurfaceFormat surfaceFormat, int mipCount) - { - if (mipCount > 1) - { - throw new Exception("creating textures with mip map not yet implemented"); - } - - this.graphicsDevice = graphicsDevice; - this.surfaceFormat = surfaceFormat; - - GraphicsDeviceWindowsDX10 graphicsDX10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10; - SharpDX.Direct3D10.Device device = graphicsDX10.NativeDevice; - - SharpDX.Direct3D10.Texture2DDescription description = new SharpDX.Direct3D10.Texture2DDescription() - { - Width = width, - Height = height, - MipLevels = mipCount, - ArraySize = mipCount, - Format = FormatConverter.Translate(surfaceFormat), - SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), - Usage = SharpDX.Direct3D10.ResourceUsage.Dynamic, - BindFlags = SharpDX.Direct3D10.BindFlags.ShaderResource, - CpuAccessFlags = SharpDX.Direct3D10.CpuAccessFlags.Write, - OptionFlags = SharpDX.Direct3D10.ResourceOptionFlags.None, - }; - this.nativeTexture = new SharpDX.Direct3D10.Texture2D(graphicsDX10.NativeDevice, description); - this.nativeShaderResourceView = new SharpDX.Direct3D10.ShaderResourceView(graphicsDX10.NativeDevice, this.nativeTexture); - - // description of texture formats of DX10: http://msdn.microsoft.com/en-us/library/bb694531(v=VS.85).aspx - // more helpfull information on DX10 textures: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205131(v=vs.85).aspx - - this.formatSize = FormatConverter.FormatSize(surfaceFormat); - } - - public override int GetHashCode() - { - return NativeTexture.NativePointer.ToInt32(); - } - - internal SharpDX.Direct3D10.Texture2D NativeTexture - { - get - { - return this.nativeTexture; - } - set - { - if (this.nativeTexture != value) - { - if (this.nativeTexture != null) - { - this.nativeTexture.Dispose(); - } - - this.nativeTexture = value; - } - } - } - - internal SharpDX.Direct3D10.ShaderResourceView NativeShaderResourceView - { - get - { - return this.nativeShaderResourceView; - } - set - { - if (this.nativeShaderResourceView != value) - { - if (this.nativeShaderResourceView != null) - { - this.nativeShaderResourceView.Dispose(); - } - - this.nativeShaderResourceView = value; - } - } - } - - public void SetData(GraphicsDevice graphicsDevice, T[] data) where T : struct - { - SetData(graphicsDevice, 0, data, 0, data.Length); - } - - public void SetData(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct - { - SetData(graphicsDevice, 0, data, startIndex, elementCount); - } - - public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct - { - //TODO: handle offsetInBytes parameter - //TODO: handle startIndex parameter - //TODO: handle elementCount parameter - - if (this.surfaceFormat == SurfaceFormat.Color) - { - int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubResourceIndex(0, 0, 1); - SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None); - int rowPitch = rectangle.Pitch; - - unsafe - { - GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); - byte* colorData = (byte*)handle.AddrOfPinnedObject(); - - byte* pTexels = (byte*)rectangle.DataPointer; - int srcIndex = 0; - - for (int row = 0; row < Height; row++) - { - int rowStart = row * rowPitch; - - for (int col = 0; col < Width; col++) - { - int colStart = col * formatSize; - pTexels[rowStart + colStart + 0] = colorData[srcIndex++]; - pTexels[rowStart + colStart + 1] = colorData[srcIndex++]; - pTexels[rowStart + colStart + 2] = colorData[srcIndex++]; - pTexels[rowStart + colStart + 3] = colorData[srcIndex++]; - } - } - - handle.Free(); - } - - this.nativeTexture.Unmap(subresource); - } - else if (surfaceFormat == SurfaceFormat.Dxt5 || surfaceFormat == SurfaceFormat.Dxt3 || surfaceFormat == SurfaceFormat.Dxt1) - { - unsafe - { - GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); - byte* colorData = (byte*)handle.AddrOfPinnedObject(); - - int w = (Width + 3) >> 2; - int h = (Height + 3) >> 2; - formatSize = (surfaceFormat == SurfaceFormat.Dxt1) ? 8 : 16; - - int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubResourceIndex(0, 0, 1); - SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None); - SharpDX.DataStream ds = new SharpDX.DataStream(rectangle.DataPointer, Width * Height * 4 * 2, true, true); - int pitch = rectangle.Pitch; - int col = 0; - int index = 0; // startIndex - int count = data.Length; // elementCount - int actWidth = w * formatSize; - - for (int i = 0; i < h; i++) - { - ds.Position = (i * pitch) + (col * formatSize); - if (count <= 0) - { - break; - } - else if (count < actWidth) - { - for (int idx = index; idx < index + count; idx++) - { - ds.WriteByte(colorData[idx]); - } - //ds.WriteRange(colorDataArray, index, count); - - break; - } - - for (int idx = index; idx < index + actWidth; idx++) - { - ds.WriteByte(colorData[idx]); - } - //ds.WriteRange(colorDataArray, index, actWidth); - - index += actWidth; - count -= actWidth; - } - - handle.Free(); - - this.nativeTexture.Unmap(subresource); - } - } - else - { - throw new Exception(string.Format("creating textures of format {0} not yet implemented...", surfaceFormat.ToString())); - } - } - - public int Width - { - get - { - if (this.nativeTexture != null) - { - return this.nativeTexture.Description.Width; - } - - return 0; - } - } - - public int Height - { - get - { - if (this.nativeTexture != null) - { - return this.nativeTexture.Description.Height; - } - - return 0; - } - } - - public GraphicsDevice GraphicsDevice - { - get - { - return this.graphicsDevice; - } - } - - public void Dispose() - { - if (this.nativeShaderResourceView != null) - { - this.nativeShaderResourceView.Dispose(); - this.nativeShaderResourceView = null; - } - - if (this.nativeTexture != null) - { - 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 - - #region INativeTexture2D Member - - - public void GetData(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct - { - throw new NotImplementedException(); - } - - public void SetData(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct - { - throw new NotImplementedException(); - } - - #endregion - - #region INativeBuffer Member - - - public void GetData(T[] data) where T : struct - { - throw new NotImplementedException(); - } - - public void GetData(T[] data, int startIndex, int elementCount) where T : struct - { - throw new NotImplementedException(); - } - - #endregion + internal Texture2D_DX10(GraphicsDevice graphicsDevice) + { + this.graphicsDevice = graphicsDevice; } + + public Texture2D_DX10(GraphicsDevice graphicsDevice, int width, int height, SurfaceFormat surfaceFormat, int mipCount) + { + if (mipCount > 1) + { + throw new Exception("creating textures with mip map not yet implemented"); + } + + this.graphicsDevice = graphicsDevice; + this.surfaceFormat = surfaceFormat; + + GraphicsDeviceWindowsDX10 graphicsDX10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10; + SharpDX.Direct3D10.Device device = graphicsDX10.NativeDevice; + + SharpDX.Direct3D10.Texture2DDescription description = new SharpDX.Direct3D10.Texture2DDescription() + { + Width = width, + Height = height, + MipLevels = mipCount, + ArraySize = mipCount, + Format = FormatConverter.Translate(surfaceFormat), + SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), + Usage = SharpDX.Direct3D10.ResourceUsage.Dynamic, + BindFlags = SharpDX.Direct3D10.BindFlags.ShaderResource, + CpuAccessFlags = SharpDX.Direct3D10.CpuAccessFlags.Write, + OptionFlags = SharpDX.Direct3D10.ResourceOptionFlags.None, + }; + this.nativeTexture = new SharpDX.Direct3D10.Texture2D(graphicsDX10.NativeDevice, description); + this.nativeShaderResourceView = new SharpDX.Direct3D10.ShaderResourceView(graphicsDX10.NativeDevice, this.nativeTexture); + + // description of texture formats of DX10: http://msdn.microsoft.com/en-us/library/bb694531(v=VS.85).aspx + // more helpfull information on DX10 textures: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205131(v=vs.85).aspx + + this.formatSize = FormatConverter.FormatSize(surfaceFormat); + } + + public override int GetHashCode() + { + return NativeTexture.NativePointer.ToInt32(); + } + + internal SharpDX.Direct3D10.Texture2D NativeTexture + { + get + { + return this.nativeTexture; + } + set + { + if (this.nativeTexture != value) + { + if (this.nativeTexture != null) + { + this.nativeTexture.Dispose(); + } + + this.nativeTexture = value; + } + } + } + + internal SharpDX.Direct3D10.ShaderResourceView NativeShaderResourceView + { + get + { + return this.nativeShaderResourceView; + } + set + { + if (this.nativeShaderResourceView != value) + { + if (this.nativeShaderResourceView != null) + { + this.nativeShaderResourceView.Dispose(); + } + + this.nativeShaderResourceView = value; + } + } + } + + public void SetData(GraphicsDevice graphicsDevice, T[] data) where T : struct + { + SetData(graphicsDevice, 0, data, 0, data.Length); + } + + public void SetData(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct + { + SetData(graphicsDevice, 0, data, startIndex, elementCount); + } + + public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct + { + //TODO: handle offsetInBytes parameter + //TODO: handle startIndex parameter + //TODO: handle elementCount parameter + + if (this.surfaceFormat == SurfaceFormat.Color) + { + int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubResourceIndex(0, 0, 1); + SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None); + int rowPitch = rectangle.Pitch; + + unsafe + { + GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); + byte* colorData = (byte*)handle.AddrOfPinnedObject(); + + byte* pTexels = (byte*)rectangle.DataPointer; + int srcIndex = 0; + + for (int row = 0; row < Height; row++) + { + int rowStart = row * rowPitch; + + for (int col = 0; col < Width; col++) + { + int colStart = col * formatSize; + pTexels[rowStart + colStart + 0] = colorData[srcIndex++]; + pTexels[rowStart + colStart + 1] = colorData[srcIndex++]; + pTexels[rowStart + colStart + 2] = colorData[srcIndex++]; + pTexels[rowStart + colStart + 3] = colorData[srcIndex++]; + } + } + + handle.Free(); + } + + this.nativeTexture.Unmap(subresource); + } + else if (surfaceFormat == SurfaceFormat.Dxt5 || surfaceFormat == SurfaceFormat.Dxt3 || surfaceFormat == SurfaceFormat.Dxt1) + { + unsafe + { + GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); + byte* colorData = (byte*)handle.AddrOfPinnedObject(); + + int w = (Width + 3) >> 2; + int h = (Height + 3) >> 2; + formatSize = (surfaceFormat == SurfaceFormat.Dxt1) ? 8 : 16; + + int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubResourceIndex(0, 0, 1); + SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None); + SharpDX.DataStream ds = new SharpDX.DataStream(rectangle.DataPointer, Width * Height * 4 * 2, true, true); + int pitch = rectangle.Pitch; + int col = 0; + int index = 0; // startIndex + int count = data.Length; // elementCount + int actWidth = w * formatSize; + + for (int i = 0; i < h; i++) + { + ds.Position = (i * pitch) + (col * formatSize); + if (count <= 0) + { + break; + } + else if (count < actWidth) + { + for (int idx = index; idx < index + count; idx++) + { + ds.WriteByte(colorData[idx]); + } + //ds.WriteRange(colorDataArray, index, count); + + break; + } + + for (int idx = index; idx < index + actWidth; idx++) + { + ds.WriteByte(colorData[idx]); + } + //ds.WriteRange(colorDataArray, index, actWidth); + + index += actWidth; + count -= actWidth; + } + + handle.Free(); + + this.nativeTexture.Unmap(subresource); + } + } + else + { + throw new Exception(string.Format("creating textures of format {0} not yet implemented...", surfaceFormat.ToString())); + } + } + + public int Width + { + get + { + if (this.nativeTexture != null) + { + return this.nativeTexture.Description.Width; + } + + return 0; + } + } + + public int Height + { + get + { + if (this.nativeTexture != null) + { + return this.nativeTexture.Description.Height; + } + + return 0; + } + } + + public GraphicsDevice GraphicsDevice + { + get + { + return this.graphicsDevice; + } + } + + public void Dispose() + { + if (this.nativeShaderResourceView != null) + { + this.nativeShaderResourceView.Dispose(); + this.nativeShaderResourceView = null; + } + + if (this.nativeTexture != null) + { + 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 + + #region INativeTexture2D Member + + + public void GetData(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct + { + throw new NotImplementedException(); + } + + public void SetData(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct + { + throw new NotImplementedException(); + } + + #endregion + + #region INativeBuffer Member + + + public void GetData(T[] data) where T : struct + { + throw new NotImplementedException(); + } + + public void GetData(T[] data, int startIndex, int elementCount) where T : struct + { + throw new NotImplementedException(); + } + + #endregion + } } diff --git a/RenderSystems/ANX.Framework.Windows.DX10/VertexBuffer_DX10.cs b/RenderSystems/ANX.Framework.Windows.DX10/VertexBuffer_DX10.cs index 672bf661..57c63682 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/VertexBuffer_DX10.cs +++ b/RenderSystems/ANX.Framework.Windows.DX10/VertexBuffer_DX10.cs @@ -1,15 +1,8 @@ -#region Using Statements using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using ANX.Framework.NonXNA; -using SharpDX.Direct3D10; +using System.IO; using ANX.Framework.Graphics; -using System.Runtime.InteropServices; using ANX.Framework.NonXNA.RenderSystem; - -#endregion // Using Statements +using SharpDX.Direct3D10; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -17,139 +10,131 @@ using ANX.Framework.NonXNA.RenderSystem; namespace ANX.RenderSystem.Windows.DX10 { - public class VertexBuffer_DX10 : INativeVertexBuffer, IDisposable - { - SharpDX.Direct3D10.Buffer buffer; - int vertexStride; + public class VertexBuffer_DX10 : INativeVertexBuffer, IDisposable + { + int vertexStride; - public VertexBuffer_DX10(GraphicsDevice graphics, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage) - { - GraphicsDeviceWindowsDX10 gd10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10; - SharpDX.Direct3D10.Device device = gd10 != null ? gd10.NativeDevice as SharpDX.Direct3D10.Device : null; + public SharpDX.Direct3D10.Buffer NativeBuffer { get; private set; } - InitializeBuffer(device, vertexDeclaration, vertexCount, usage); - } + #region Constructor + public VertexBuffer_DX10(GraphicsDevice graphics, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage) + { + GraphicsDeviceWindowsDX10 gd10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10; + Device device = gd10 != null ? gd10.NativeDevice as Device : null; - internal VertexBuffer_DX10(SharpDX.Direct3D10.Device device, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage) - { - InitializeBuffer(device, vertexDeclaration, vertexCount, usage); - } - - private void InitializeBuffer(SharpDX.Direct3D10.Device device, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage) - { - this.vertexStride = vertexDeclaration.VertexStride; - - //TODO: translate and use usage - - if (device != null) - { - BufferDescription description = new BufferDescription() - { - Usage = ResourceUsage.Dynamic, - SizeInBytes = vertexDeclaration.VertexStride * vertexCount, - BindFlags = BindFlags.VertexBuffer, - CpuAccessFlags = CpuAccessFlags.Write, - OptionFlags = ResourceOptionFlags.None - }; - - this.buffer = new SharpDX.Direct3D10.Buffer(device, description); - this.buffer.Unmap(); - } - } - - public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct - { - //TODO: check offsetInBytes parameter for bounds etc. - - GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned); - IntPtr dataPointer = pinnedArray.AddrOfPinnedObject(); - - int dataLength = Marshal.SizeOf(typeof(T)) * data.Length; - - unsafe - { - using (var vData = new SharpDX.DataStream(dataPointer, dataLength, true, true)) - { - if (offsetInBytes > 0) - { - vData.Seek(offsetInBytes / vertexStride, System.IO.SeekOrigin.Begin); - } - - using (var d = buffer.Map(MapMode.WriteDiscard)) - { - if (startIndex > 0 || elementCount < data.Length) - { - for (int i = startIndex; i < startIndex + elementCount; i++) - { - d.Write(data[i]); - } - } - else - { - vData.CopyTo(d); - } - buffer.Unmap(); - } - } - } - - pinnedArray.Free(); - } - - public void SetData(GraphicsDevice graphicsDevice, T[] data) where T : struct - { - SetData(graphicsDevice, data, 0, data.Length); - } - - public void SetData(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct - { - SetData(graphicsDevice, 0, data, startIndex, elementCount); - } - - public SharpDX.Direct3D10.Buffer NativeBuffer - { - get - { - return this.buffer; - } - } - - public void Dispose() - { - if (this.buffer != null) - { - buffer.Dispose(); - buffer = null; - } - } - - #region INativeVertexBuffer Member - - public void GetData(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct - { - throw new NotImplementedException(); - } - - public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct - { - throw new NotImplementedException(); - } - - #endregion - - #region INativeBuffer Member - - - public void GetData(T[] data) where T : struct - { - throw new NotImplementedException(); - } - - public void GetData(T[] data, int startIndex, int elementCount) where T : struct - { - throw new NotImplementedException(); - } - - #endregion + InitializeBuffer(device, vertexDeclaration, vertexCount, usage); } + + internal VertexBuffer_DX10(Device device, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage) + { + InitializeBuffer(device, vertexDeclaration, vertexCount, usage); + } + #endregion + + #region InitializeBuffer + private void InitializeBuffer(Device device, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage) + { + this.vertexStride = vertexDeclaration.VertexStride; + + //TODO: translate and use usage + + if (device != null) + { + BufferDescription description = new BufferDescription() + { + Usage = ResourceUsage.Dynamic, + SizeInBytes = vertexDeclaration.VertexStride * vertexCount, + BindFlags = BindFlags.VertexBuffer, + CpuAccessFlags = CpuAccessFlags.Write, + OptionFlags = ResourceOptionFlags.None + }; + + NativeBuffer = new SharpDX.Direct3D10.Buffer(device, description); + NativeBuffer.Unmap(); + } + } + #endregion + + #region SetData + public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) + where T : struct + { + //TODO: check offsetInBytes parameter for bounds etc. + + using (var stream = NativeBuffer.Map(MapMode.WriteDiscard)) + { + if (offsetInBytes > 0) + stream.Seek(offsetInBytes, SeekOrigin.Current); + + if (startIndex > 0 || elementCount < data.Length) + for (int i = startIndex; i < startIndex + elementCount; i++) + stream.Write(data[i]); + else + for (int i = 0; i < data.Length; i++) + stream.Write(data[i]); + + NativeBuffer.Unmap(); + } + } + + public void SetData(GraphicsDevice graphicsDevice, T[] data) where T : struct + { + SetData(graphicsDevice, data, 0, data.Length); + } + + public void SetData(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct + { + SetData(graphicsDevice, 0, data, startIndex, elementCount); + } + + public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount, + int vertexStride) where T : struct + { + throw new NotImplementedException(); + } + #endregion + + #region GetData + public void GetData(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct + { + using (var stream = NativeBuffer.Map(MapMode.Read)) + { + if (offsetInBytes > 0) + stream.Seek(offsetInBytes, SeekOrigin.Current); + + stream.ReadRange(data, startIndex, elementCount); + NativeBuffer.Unmap(); + } + } + + public void GetData(T[] data) where T : struct + { + using (var stream = NativeBuffer.Map(MapMode.Read)) + { + stream.ReadRange(data, 0, data.Length); + NativeBuffer.Unmap(); + } + } + + public void GetData(T[] data, int startIndex, int elementCount) where T : struct + { + using (var stream = NativeBuffer.Map(MapMode.Read)) + { + stream.ReadRange(data, startIndex, elementCount); + NativeBuffer.Unmap(); + } + } + #endregion + + #region Dispose + public void Dispose() + { + if (this.NativeBuffer != null) + { + NativeBuffer.Dispose(); + NativeBuffer = null; + } + } + #endregion + } } diff --git a/RenderSystems/ANX.Framework.Windows.GL3/Creator.cs b/RenderSystems/ANX.Framework.Windows.GL3/Creator.cs index c2ce4eb9..653e2d74 100644 --- a/RenderSystems/ANX.Framework.Windows.GL3/Creator.cs +++ b/RenderSystems/ANX.Framework.Windows.GL3/Creator.cs @@ -9,6 +9,7 @@ using ANX.Framework.NonXNA.Development; using ANX.Framework.NonXNA.RenderSystem; using ANX.Framework.Windows.GL3; using OpenTK; +using OpenTK.Graphics.OpenGL; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -330,5 +331,17 @@ namespace ANX.RenderSystem.Windows.GL3 return new OcclusionQueryGL3(); } #endregion + + #region SetTextureSampler (TODO) + public void SetTextureSampler(int index, Texture value) + { + TextureUnit textureUnit = TextureUnit.Texture0 + index; + GL.ActiveTexture(textureUnit); + int handle = (value.NativeTexture as Texture2DGL3).NativeHandle; + GL.BindTexture(TextureTarget.Texture2D, handle); + int unitIndex = (int)(textureUnit - TextureUnit.Texture0); + //GL.Uniform1(UniformIndex, 1, ref unitIndex); + } + #endregion } } diff --git a/RenderSystems/ANX.Framework.Windows.GL3/EffectParameterGL3.cs b/RenderSystems/ANX.Framework.Windows.GL3/EffectParameterGL3.cs index fc267c5b..3d5f2432 100644 --- a/RenderSystems/ANX.Framework.Windows.GL3/EffectParameterGL3.cs +++ b/RenderSystems/ANX.Framework.Windows.GL3/EffectParameterGL3.cs @@ -121,7 +121,7 @@ namespace ANX.RenderSystem.Windows.GL3 if (textureCache == null || textureCache != value) { - textureCache = value; + textureCache = value; // TODO: multiple texture units TextureUnit textureUnit = TextureUnit.Texture0; GL.ActiveTexture(textureUnit); diff --git a/RenderSystems/ANX.RenderSystem.PsVita/Creator.cs b/RenderSystems/ANX.RenderSystem.PsVita/Creator.cs index 32cbb038..b59c7ecc 100644 --- a/RenderSystems/ANX.RenderSystem.PsVita/Creator.cs +++ b/RenderSystems/ANX.RenderSystem.PsVita/Creator.cs @@ -166,5 +166,12 @@ namespace ANX.RenderSystem.PsVita throw new NotImplementedException(); } #endregion + + #region SetTextureSampler (TODO) + public void SetTextureSampler(int index, Texture value) + { + throw new NotImplementedException(); + } + #endregion } } diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11.csproj b/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11.csproj index 4fbeb877..cc930c85 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11.csproj +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11.csproj @@ -100,7 +100,6 @@ - diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_Linux.csproj b/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_Linux.csproj index ca99bd97..711bdc95 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_Linux.csproj +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_Linux.csproj @@ -99,7 +99,6 @@ - diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_PSVita.csproj b/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_PSVita.csproj index 04dadfbb..9413080e 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_PSVita.csproj +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_PSVita.csproj @@ -100,7 +100,6 @@ - diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_WindowsMetro.csproj b/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_WindowsMetro.csproj index 1c03a4e3..3b8f5730 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_WindowsMetro.csproj +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11_WindowsMetro.csproj @@ -97,7 +97,6 @@ - diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/Creator.cs b/RenderSystems/ANX.RenderSystem.Windows.DX11/Creator.cs index 60514f08..d87b75a3 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/Creator.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/Creator.cs @@ -249,5 +249,12 @@ namespace ANX.RenderSystem.Windows.DX11 throw new NotImplementedException(); } #endregion + + #region SetTextureSampler (TODO) + public void SetTextureSampler(int index, Texture value) + { + throw new NotImplementedException(); + } + #endregion } } diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/IndexBuffer_DX11.cs b/RenderSystems/ANX.RenderSystem.Windows.DX11/IndexBuffer_DX11.cs index 79b8963a..22a083aa 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/IndexBuffer_DX11.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/IndexBuffer_DX11.cs @@ -1,16 +1,8 @@ -#region Using Statements using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using ANX.Framework.NonXNA; -using SharpDX.Direct3D11; -using ANX.Framework.Graphics; -using System.Runtime.InteropServices; -using ANX.Framework.NonXNA.RenderSystem; using System.IO; - -#endregion // Using Statements +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA.RenderSystem; +using SharpDX.Direct3D11; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -19,58 +11,66 @@ using System.IO; namespace ANX.RenderSystem.Windows.DX11 { public class IndexBuffer_DX11 : INativeIndexBuffer, IDisposable - { - private SharpDX.Direct3D11.Buffer buffer; - private IndexElementSize size; + { + private IndexElementSize size; - public IndexBuffer_DX11(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage) - { - this.size = size; + public SharpDX.Direct3D11.Buffer NativeBuffer { get; private set; } - //TODO: translate and use usage + #region Constructor + public IndexBuffer_DX11(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage) + { + this.size = size; - GraphicsDeviceWindowsDX11 gd11 = graphics.NativeDevice as GraphicsDeviceWindowsDX11; - SharpDX.Direct3D11.DeviceContext context = gd11 != null ? gd11.NativeDevice as SharpDX.Direct3D11.DeviceContext : null; + //TODO: translate and use usage - InitializeBuffer(context.Device, size, indexCount, usage); - } + GraphicsDeviceWindowsDX11 gd11 = graphics.NativeDevice as GraphicsDeviceWindowsDX11; + SharpDX.Direct3D11.DeviceContext context = gd11 != null ? + gd11.NativeDevice as SharpDX.Direct3D11.DeviceContext : + null; - internal IndexBuffer_DX11(SharpDX.Direct3D11.Device device, IndexElementSize size, int indexCount, BufferUsage usage) - { - this.size = size; + InitializeBuffer(context.Device, size, indexCount, usage); + } - InitializeBuffer(device, size, indexCount, usage); - } + internal IndexBuffer_DX11(SharpDX.Direct3D11.Device device, IndexElementSize size, int indexCount, BufferUsage usage) + { + this.size = size; + InitializeBuffer(device, size, indexCount, usage); + } + #endregion - private void InitializeBuffer(SharpDX.Direct3D11.Device device, IndexElementSize size, int indexCount, BufferUsage usage) - { - BufferDescription description = new BufferDescription() - { - Usage = ResourceUsage.Dynamic, - SizeInBytes = (size == IndexElementSize.SixteenBits ? 2 : 4) * indexCount, - BindFlags = BindFlags.IndexBuffer, - CpuAccessFlags = CpuAccessFlags.Write, - OptionFlags = ResourceOptionFlags.None - }; + #region InitializeBuffer + private void InitializeBuffer(SharpDX.Direct3D11.Device device, IndexElementSize size, int indexCount, BufferUsage usage) + { + BufferDescription description = new BufferDescription() + { + // TODO: translate usage + Usage = ResourceUsage.Dynamic, + SizeInBytes = (size == IndexElementSize.SixteenBits ? 2 : 4) * indexCount, + BindFlags = BindFlags.IndexBuffer, + CpuAccessFlags = CpuAccessFlags.Write, + OptionFlags = ResourceOptionFlags.None + }; - this.buffer = new SharpDX.Direct3D11.Buffer(device, description); - } + NativeBuffer = new SharpDX.Direct3D11.Buffer(device, description); + } + #endregion - public void SetData(GraphicsDevice graphicsDevice, T[] data) where T : struct - { - SetData(graphicsDevice, data, 0, data.Length); - } + #region SetData + public void SetData(GraphicsDevice graphicsDevice, T[] data) where T : struct + { + SetData(graphicsDevice, data, 0, data.Length); + } - public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) + public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct - { - GraphicsDeviceWindowsDX11 dx11GraphicsDevice = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11; - DeviceContext context = dx11GraphicsDevice.NativeDevice; + { + GraphicsDeviceWindowsDX11 dx11GraphicsDevice = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11; + DeviceContext context = dx11GraphicsDevice.NativeDevice; - //TODO: check offsetInBytes parameter for bounds etc. + //TODO: check offsetInBytes parameter for bounds etc. SharpDX.DataStream stream; - context.MapSubresource(this.buffer, MapMode.WriteDiscard, MapFlags.None, out stream); + context.MapSubresource(NativeBuffer, MapMode.WriteDiscard, MapFlags.None, out stream); if (offsetInBytes > 0) stream.Seek(offsetInBytes, SeekOrigin.Current); @@ -82,53 +82,61 @@ namespace ANX.RenderSystem.Windows.DX11 for (int i = 0; i < data.Length; i++) stream.Write(data[i]); - context.UnmapSubresource(this.buffer, 0); - } - - public void SetData(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct - { - SetData(graphicsDevice, 0, data, startIndex, elementCount); - } - - public SharpDX.Direct3D11.Buffer NativeBuffer - { - get - { - return this.buffer; - } - } - - public void Dispose() - { - if (this.buffer != null) - { - buffer.Dispose(); - buffer = null; - } - } - - #region INativeIndexBuffer Member - - public void GetData(int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct - { - throw new NotImplementedException(); - } - - #endregion - - #region INativeBuffer Member - - - public void GetData(T[] data) where T : struct - { - throw new NotImplementedException(); - } - - public void GetData(T[] data, int startIndex, int elementCount) where T : struct - { - throw new NotImplementedException(); - } - - #endregion + context.UnmapSubresource(NativeBuffer, 0); } + + public void SetData(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct + { + SetData(graphicsDevice, 0, data, startIndex, elementCount); + } + #endregion + + #region Dispose + public void Dispose() + { + if (NativeBuffer != null) + { + NativeBuffer.Dispose(); + NativeBuffer = null; + } + } + #endregion + + #region GetData + public void GetData(T[] data) where T : struct + { + DeviceContext context = NativeBuffer.Device.ImmediateContext; + + SharpDX.DataStream stream; + context.MapSubresource(NativeBuffer, MapMode.Read, MapFlags.None, out stream); + stream.ReadRange(data, 0, data.Length); + context.UnmapSubresource(NativeBuffer, 0); + } + + public void GetData(T[] data, int startIndex, int elementCount) where T : struct + { + DeviceContext context = NativeBuffer.Device.ImmediateContext; + + SharpDX.DataStream stream; + context.MapSubresource(NativeBuffer, MapMode.Read, MapFlags.None, out stream); + stream.ReadRange(data, startIndex, elementCount); + context.UnmapSubresource(NativeBuffer, 0); + } + + public void GetData(int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct + { + DeviceContext context = NativeBuffer.Device.ImmediateContext; + + SharpDX.DataStream stream; + context.MapSubresource(NativeBuffer, MapMode.Read, MapFlags.None, out stream); + + if (offsetInBytes > 0) + stream.Seek(offsetInBytes, SeekOrigin.Current); + + stream.ReadRange(data, startIndex, elementCount); + context.UnmapSubresource(NativeBuffer, 0); + } + + #endregion + } } diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/NativeMethods.cs b/RenderSystems/ANX.RenderSystem.Windows.DX11/NativeMethods.cs deleted file mode 100644 index 31d28c5a..00000000 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/NativeMethods.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; - -// This file is part of the ANX.Framework created by the -// "ANX.Framework developer group" and released under the Ms-PL license. -// For details see: http://anxframework.codeplex.com/license - -namespace ANX.RenderSystem.Windows.DX11 -{ - internal sealed class NativeMethods - { - // Not needed any more, in platforms now! - //[SuppressUnmanagedCodeSecurity, DllImport("user32.dll", CharSet = CharSet.Auto)] - //internal static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags); - - //// Nested Types - //[StructLayout(LayoutKind.Sequential)] - //public struct Message - //{ - // public IntPtr hWnd; - // public NativeMethods.WindowMessage msg; - // public IntPtr wParam; - // public IntPtr lParam; - // public uint time; - // public Point p; - //} - - internal enum WindowMessage : uint - { - ActivateApplication = 0x1c, - Character = 0x102, - Close = 0x10, - Destroy = 2, - EnterMenuLoop = 0x211, - EnterSizeMove = 0x231, - ExitMenuLoop = 530, - ExitSizeMove = 0x232, - GetMinMax = 0x24, - KeyDown = 0x100, - KeyUp = 0x101, - LeftButtonDoubleClick = 0x203, - LeftButtonDown = 0x201, - LeftButtonUp = 0x202, - MiddleButtonDoubleClick = 0x209, - MiddleButtonDown = 0x207, - MiddleButtonUp = 520, - MouseFirst = 0x201, - MouseLast = 0x20d, - MouseMove = 0x200, - MouseWheel = 0x20a, - NonClientHitTest = 0x84, - Paint = 15, - PowerBroadcast = 0x218, - Quit = 0x12, - RightButtonDoubleClick = 0x206, - RightButtonDown = 0x204, - RightButtonUp = 0x205, - SetCursor = 0x20, - Size = 5, - SystemCharacter = 0x106, - SystemCommand = 0x112, - SystemKeyDown = 260, - SystemKeyUp = 0x105, - XButtonDoubleClick = 0x20d, - XButtonDown = 0x20b, - XButtonUp = 0x20c - } - - } -} diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/VertexBuffer_DX11.cs b/RenderSystems/ANX.RenderSystem.Windows.DX11/VertexBuffer_DX11.cs index 3c2409d0..f73d7298 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/VertexBuffer_DX11.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/VertexBuffer_DX11.cs @@ -14,16 +14,12 @@ namespace ANX.RenderSystem.Windows.DX11 { int vertexStride; - public SharpDX.Direct3D11.Buffer NativeBuffer - { - get; - private set; - } + public SharpDX.Direct3D11.Buffer NativeBuffer { get; private set; } #region Constructor public VertexBuffer_DX11(GraphicsDevice graphics, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage) { - GraphicsDeviceWindowsDX11 gd11 = graphics.NativeDevice as GraphicsDeviceWindowsDX11; + var gd11 = graphics.NativeDevice as GraphicsDeviceWindowsDX11; SharpDX.Direct3D11.DeviceContext context = gd11 != null ? gd11.NativeDevice as SharpDX.Direct3D11.DeviceContext : null; @@ -115,20 +111,39 @@ namespace ANX.RenderSystem.Windows.DX11 } #endregion - #region GetData (TODO) + #region GetData public void GetData(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct { - throw new NotImplementedException(); + DeviceContext context = NativeBuffer.Device.ImmediateContext; + + SharpDX.DataStream stream; + context.MapSubresource(NativeBuffer, MapMode.Read, MapFlags.None, out stream); + + if (offsetInBytes > 0) + stream.Seek(offsetInBytes, SeekOrigin.Current); + + stream.ReadRange(data, startIndex, elementCount); + context.UnmapSubresource(NativeBuffer, 0); } public void GetData(T[] data) where T : struct { - throw new NotImplementedException(); + DeviceContext context = NativeBuffer.Device.ImmediateContext; + + SharpDX.DataStream stream; + context.MapSubresource(NativeBuffer, MapMode.Read, MapFlags.None, out stream); + stream.ReadRange(data, 0, data.Length); + context.UnmapSubresource(NativeBuffer, 0); } public void GetData(T[] data, int startIndex, int elementCount) where T : struct { - throw new NotImplementedException(); + DeviceContext context = NativeBuffer.Device.ImmediateContext; + + SharpDX.DataStream stream; + context.MapSubresource(NativeBuffer, MapMode.Read, MapFlags.None, out stream); + stream.ReadRange(data, startIndex, elementCount); + context.UnmapSubresource(NativeBuffer, 0); } #endregion } diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/Creator.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/Creator.cs index 947e901c..1a5d7506 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/Creator.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/Creator.cs @@ -279,5 +279,12 @@ namespace ANX.RenderSystem.Windows.Metro } #endregion + + #region SetTextureSampler (TODO) + public void SetTextureSampler(int index, Texture value) + { + throw new NotImplementedException(); + } + #endregion } } diff --git a/Tools/ANXStatusComparer/Data/AssembliesData.cs b/Tools/ANXStatusComparer/Data/AssembliesData.cs index faea0b20..716f973b 100644 --- a/Tools/ANXStatusComparer/Data/AssembliesData.cs +++ b/Tools/ANXStatusComparer/Data/AssembliesData.cs @@ -52,22 +52,16 @@ namespace ANXStatusComparer.Data foreach (Type type in types) { if (String.IsNullOrEmpty(type.Namespace)) - { continue; - } if (Namespaces.ContainsKey(type.Namespace) == false) - { Namespaces.Add(type.Namespace, new NamespaceData(type.Namespace)); - } Namespaces[type.Namespace].AllTypes.Add(type); } } foreach (string key in Namespaces.Keys) - { Namespaces[key].ParseTypes(); - } } #endregion } diff --git a/Tools/ANXStatusComparer/Data/BaseObject.cs b/Tools/ANXStatusComparer/Data/BaseObject.cs index 0d172bfd..29769ec5 100644 --- a/Tools/ANXStatusComparer/Data/BaseObject.cs +++ b/Tools/ANXStatusComparer/Data/BaseObject.cs @@ -1,10 +1,7 @@ -#region Private Members using System; using System.Collections.Generic; using System.Reflection; -#endregion // Private Members - // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. // For details see: http://anxframework.codeplex.com/license @@ -191,8 +188,7 @@ namespace ANXStatusComparer.Data public override string ToString() { - return (HasPercentageAttribute ? - PercentageComplete.ToString("000") : "-?-") + "% - " + Handle.FullName; + return (HasPercentageAttribute ? PercentageComplete.ToString("000") : "-?-") + "% - " + Handle.FullName; } #region IsCorrect @@ -201,21 +197,13 @@ namespace ANXStatusComparer.Data { bool isCorrect = true; if (CompareLists(Methods, otherObject.Methods, wrongPair) == false) - { isCorrect = false; - } if (CompareLists(Events, otherObject.Events, wrongPair) == false) - { isCorrect = false; - } if (CompareLists(Fields, otherObject.Fields, wrongPair) == false) - { isCorrect = false; - } if (CompareLists(Properties, otherObject.Properties, wrongPair) == false) - { isCorrect = false; - } foreach(string parent in ParentNames) { @@ -228,37 +216,33 @@ namespace ANXStatusComparer.Data if (Handle.IsPublic != otherObject.Handle.IsPublic) { - wrongPair.WrongAccesses.Add("[IsPublic(XNA:" + Handle.IsPublic + - "|ANX:" + otherObject.Handle.IsPublic + ")] "); + wrongPair.WrongAccesses.Add("[IsPublic(XNA:" + Handle.IsPublic + "|ANX:" + otherObject.Handle.IsPublic + ")] "); isCorrect = false; } if (Handle.IsSealed != otherObject.Handle.IsSealed) { - wrongPair.WrongAccesses.Add("[IsSealed(XNA:" + Handle.IsSealed + - "|ANX:" + otherObject.Handle.IsSealed + ")] "); + wrongPair.WrongAccesses.Add("[IsSealed(XNA:" + Handle.IsSealed + "|ANX:" + otherObject.Handle.IsSealed + ")] "); isCorrect = false; } if (Handle.IsAbstract != otherObject.Handle.IsAbstract) { - wrongPair.WrongAccesses.Add("[IsAbstract(XNA:" + Handle.IsAbstract + - "|ANX:" + otherObject.Handle.IsAbstract + ")] "); + wrongPair.WrongAccesses.Add("[IsAbstract(XNA:" + Handle.IsAbstract + "|ANX:" + otherObject.Handle.IsAbstract + ")] "); isCorrect = false; } if (Handle.IsGenericType != otherObject.Handle.IsGenericType) { - wrongPair.WrongAccesses.Add("[IsGenericType(XNA:" + - Handle.IsGenericType + - "|ANX:" + otherObject.Handle.IsGenericType + ")] "); + wrongPair.WrongAccesses.Add("[IsGenericType(XNA:" + Handle.IsGenericType + "|ANX:" + + otherObject.Handle.IsGenericType + ")] "); isCorrect = false; } if (Handle.IsVisible != otherObject.Handle.IsVisible) { - wrongPair.WrongAccesses.Add("[IsVisible(XNA:" + Handle.IsVisible + - "|ANX:" + otherObject.Handle.IsVisible + ")] "); + wrongPair.WrongAccesses.Add("[IsVisible(XNA:" + Handle.IsVisible + "|ANX:" + otherObject.Handle.IsVisible + + ")] "); isCorrect = false; } @@ -267,8 +251,7 @@ namespace ANXStatusComparer.Data #endregion #region CompareLists - private bool CompareLists(Dictionary dictXna, - Dictionary dictAnx, + private bool CompareLists(Dictionary dictXna, Dictionary dictAnx, ResultData.WrongObjectPair wrongPair) { bool isCorrect = true;