diff --git a/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_Linux.csproj b/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_Linux.csproj index 1cca44c9..948875e8 100644 --- a/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_Linux.csproj +++ b/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_Linux.csproj @@ -34,6 +34,11 @@ + + + + + @@ -48,7 +53,7 @@ - + @@ -72,6 +77,9 @@ + + + @@ -82,18 +90,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -129,6 +165,7 @@ + diff --git a/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_PSVita.csproj b/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_PSVita.csproj index 9a522928..ec6e611e 100644 --- a/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_PSVita.csproj +++ b/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_PSVita.csproj @@ -34,6 +34,11 @@ + + + + + @@ -48,7 +53,7 @@ - + @@ -72,6 +77,9 @@ + + + @@ -82,18 +90,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -129,6 +165,7 @@ + diff --git a/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_WindowsMetro.csproj b/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_WindowsMetro.csproj index 8197b494..cc821926 100644 --- a/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_WindowsMetro.csproj +++ b/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline_WindowsMetro.csproj @@ -36,6 +36,11 @@ + + + + + @@ -50,7 +55,7 @@ - + @@ -74,6 +79,9 @@ + + + @@ -84,18 +92,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -131,6 +167,7 @@ + diff --git a/ANX.Framework.TestCenter/ReflectionLearningTests.cs b/ANX.Framework.TestCenter/ReflectionLearningTests.cs index cfdd3d53..cff2dd51 100644 --- a/ANX.Framework.TestCenter/ReflectionLearningTests.cs +++ b/ANX.Framework.TestCenter/ReflectionLearningTests.cs @@ -2,6 +2,10 @@ using System.Reflection; using NUnit.Framework; +// 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.Framework.TestCenter { public static class ReflectionLearningTests diff --git a/ANX.Framework/BoundingSphere.cs b/ANX.Framework/BoundingSphere.cs index 78836693..6a41b0c5 100644 --- a/ANX.Framework/BoundingSphere.cs +++ b/ANX.Framework/BoundingSphere.cs @@ -410,22 +410,18 @@ namespace ANX.Framework result.Center.Y += matrix.M42; result.Center.Z += matrix.M43; } + #endregion - public override string ToString() + #region ToString + public override string ToString() { var culture = CultureInfo.CurrentCulture; // This may look a bit more ugly, but String.Format should // be avoided cause of it's bad performance! return "{Center:" + Center.ToString() + " Radius:" + Radius.ToString(culture) + "}"; - - //return string.Format(culture, "{{Center:{0} Radius:{1}}}", new object[] - //{ - // this.Center.ToString(), - // this.Radius.ToString(culture) - //}); - } - #endregion + } + #endregion #region IEquatable implementation public override bool Equals(Object obj) diff --git a/ANX.Framework/Graphics/GraphicsDevice.cs b/ANX.Framework/Graphics/GraphicsDevice.cs index 4496fb88..3c43765d 100644 --- a/ANX.Framework/Graphics/GraphicsDevice.cs +++ b/ANX.Framework/Graphics/GraphicsDevice.cs @@ -324,6 +324,7 @@ namespace ANX.Framework.Graphics // reset presentation parameters nativeDevice.ResizeBuffers(presentationParameters); + this.viewport = new Graphics.Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight); raise_DeviceReset(this, EventArgs.Empty); } diff --git a/ANX.Framework/Graphics/SpriteBatch.cs b/ANX.Framework/Graphics/SpriteBatch.cs index c6ca7af8..228ae103 100644 --- a/ANX.Framework/Graphics/SpriteBatch.cs +++ b/ANX.Framework/Graphics/SpriteBatch.cs @@ -1,8 +1,7 @@ #region Using Statements using System; -using System.Text; -using System.Collections; using System.Collections.Generic; +using System.Text; using ANX.Framework.NonXNA; #endregion // Using Statements @@ -47,16 +46,16 @@ namespace ANX.Framework.Graphics #endregion // Private Members + #region Constructor public SpriteBatch(GraphicsDevice graphicsDevice) { if (graphicsDevice == null) - { throw new ArgumentNullException("graphicsDevice"); - } base.GraphicsDevice = graphicsDevice; - this.spriteBatchEffect = new Effect(graphicsDevice, AddInSystemFactory.Instance.GetDefaultCreator().GetShaderByteCode(NonXNA.PreDefinedShader.SpriteBatch)); + var renderSystemCreator = AddInSystemFactory.Instance.GetDefaultCreator(); + this.spriteBatchEffect = new Effect(graphicsDevice, renderSystemCreator.GetShaderByteCode(NonXNA.PreDefinedShader.SpriteBatch)); this.spriteInfos = new SpriteInfo[InitialBatchSize]; @@ -64,6 +63,7 @@ namespace ANX.Framework.Graphics this.InitializeVertexBuffer(); } + #endregion #region Begin-Method public void Begin() @@ -241,6 +241,7 @@ namespace ANX.Framework.Graphics #endregion // DrawString-Method + #region End public void End() { if (hasBegun == false) @@ -284,10 +285,11 @@ namespace ANX.Framework.Graphics Flush(); } + #endregion private void Draw(Texture2D texture, Vector2 topLeft, Vector2 destinationSize, Rectangle? sourceRectangle, Color tint, Vector2 origin, float layerDepth, float rotation, Vector2 scale, SpriteEffects effects) { - if (!hasBegun) + if (hasBegun == false) { throw new InvalidOperationException("Begin() must be called before Draw()"); } @@ -385,35 +387,25 @@ namespace ANX.Framework.Graphics { SpriteInfo currentSprite = this.spriteInfos[i]; - this.vertices[vertexPos + 0] = new VertexPositionColorTexture() - { - Position = new Vector3(currentSprite.Corners[0], currentSprite.layerDepth), - Color = currentSprite.Tint, - TextureCoordinate = currentSprite.topLeftUV - }; + vertices[vertexPos].Position = new Vector3(currentSprite.Corners[0], currentSprite.layerDepth); + vertices[vertexPos].Color = currentSprite.Tint; + vertices[vertexPos].TextureCoordinate = currentSprite.topLeftUV; + vertexPos++; - this.vertices[vertexPos + 1] = new VertexPositionColorTexture() - { - Position = new Vector3(currentSprite.Corners[1], currentSprite.layerDepth), - Color = currentSprite.Tint, - TextureCoordinate = new Vector2(currentSprite.bottomRightUV.X, currentSprite.topLeftUV.Y) - }; + vertices[vertexPos].Position = new Vector3(currentSprite.Corners[1], currentSprite.layerDepth); + vertices[vertexPos].Color = currentSprite.Tint; + vertices[vertexPos].TextureCoordinate = new Vector2(currentSprite.bottomRightUV.X, currentSprite.topLeftUV.Y); + vertexPos++; - this.vertices[vertexPos + 2] = new VertexPositionColorTexture() - { - Position = new Vector3(currentSprite.Corners[2], currentSprite.layerDepth), - Color = currentSprite.Tint, - TextureCoordinate = currentSprite.bottomRightUV - }; + vertices[vertexPos].Position = new Vector3(currentSprite.Corners[2], currentSprite.layerDepth); + vertices[vertexPos].Color = currentSprite.Tint; + vertices[vertexPos].TextureCoordinate = currentSprite.bottomRightUV; + vertexPos++; - this.vertices[vertexPos + 3] = new VertexPositionColorTexture() - { - Position = new Vector3(currentSprite.Corners[3], currentSprite.layerDepth), - Color = currentSprite.Tint, - TextureCoordinate = new Vector2(currentSprite.topLeftUV.X, currentSprite.bottomRightUV.Y) - }; - - vertexPos += 4; + vertices[vertexPos].Position = new Vector3(currentSprite.Corners[3], currentSprite.layerDepth); + vertices[vertexPos].Color = currentSprite.Tint; + vertices[vertexPos].TextureCoordinate = new Vector2(currentSprite.topLeftUV.X, currentSprite.bottomRightUV.Y); + vertexPos++; } this.vertexBuffer.SetData(this.vertices, 0, vertexCount); @@ -466,10 +458,10 @@ namespace ANX.Framework.Graphics baseIndex = i * 4; baseArrayIndex = baseIndex + i + i; - indices[baseArrayIndex + 0] = (short)(baseIndex + 0); + indices[baseArrayIndex] = (short)baseIndex; indices[baseArrayIndex + 1] = (short)(baseIndex + 1); indices[baseArrayIndex + 2] = (short)(baseIndex + 2); - indices[baseArrayIndex + 3] = (short)(baseIndex + 0); + indices[baseArrayIndex + 3] = (short)baseIndex; indices[baseArrayIndex + 4] = (short)(baseIndex + 2); indices[baseArrayIndex + 5] = (short)(baseIndex + 3); } diff --git a/ANX.Framework/Matrix.cs b/ANX.Framework/Matrix.cs index f2b62de6..1ec0da81 100644 --- a/ANX.Framework/Matrix.cs +++ b/ANX.Framework/Matrix.cs @@ -1231,56 +1231,23 @@ namespace ANX.Framework } public override string ToString() - { - var culture = CultureInfo.CurrentCulture; - // This may look a bit more ugly, but String.Format should - // be avoided cause of it's bad performance! - return "{ " + - "{M11:" + M11.ToString(culture) + " M12:" + M12.ToString(culture) + - " M13:" + M13.ToString(culture) + " M14:" + M14.ToString(culture) + + { + var culture = CultureInfo.CurrentCulture; + // This may look a bit more ugly, but String.Format should + // be avoided cause of it's bad performance! + return "{ " + + "{M11:" + M11.ToString(culture) + " M12:" + M12.ToString(culture) + + " M13:" + M13.ToString(culture) + " M14:" + M14.ToString(culture) + - "} {M21:" + M21.ToString(culture) + " M22:" + M22.ToString(culture) + - " M23:" + M23.ToString(culture) + " M24:" + M24.ToString(culture) + + "} {M21:" + M21.ToString(culture) + " M22:" + M22.ToString(culture) + + " M23:" + M23.ToString(culture) + " M24:" + M24.ToString(culture) + - "} {M31:" + M31.ToString(culture) + " M32:" + M32.ToString(culture) + - " M33:" + M33.ToString(culture) + " M34:" + M34.ToString(culture) + + "} {M31:" + M31.ToString(culture) + " M32:" + M32.ToString(culture) + + " M33:" + M33.ToString(culture) + " M34:" + M34.ToString(culture) + - "} {M41:" + M41.ToString(culture) + " M42:" + M42.ToString(culture) + - " M43:" + M43.ToString(culture) + " M44:" + M44.ToString(culture) + - "} }"; - - //var parts = new string[6]; - //parts[0] = "{ "; - //parts[1] = string.Format(culture, "{{M11:{0} M12:{1} M13:{2} M14:{3}}} ", new object[] - //{ - // M11.ToString(culture), - // M12.ToString(culture), - // M13.ToString(culture), - // M14.ToString(culture) - //}); - //parts[2] = string.Format(culture, "{{M21:{0} M22:{1} M23:{2} M24:{3}}} ", new object[] - //{ - // M21.ToString(culture), - // M22.ToString(culture), - // M23.ToString(culture), - // M24.ToString(culture) - //}); - //parts[3] = string.Format(culture, "{{M31:{0} M32:{1} M33:{2} M34:{3}}} ", new object[] - //{ - // M31.ToString(culture), - // M32.ToString(culture), - // M33.ToString(culture), - // M34.ToString(culture) - //}); - //parts[4] = string.Format(culture, "{{M41:{0} M42:{1} M43:{2} M44:{3}}} ", new object[] - //{ - // M41.ToString(culture), - // M42.ToString(culture), - // M43.ToString(culture), - // M44.ToString(culture) - //}); - //parts[5] = "}"; - //return string.Concat(parts); + "} {M41:" + M41.ToString(culture) + " M42:" + M42.ToString(culture) + + " M43:" + M43.ToString(culture) + " M44:" + M44.ToString(culture) + + "} }"; } #endregion diff --git a/ANX.Framework/Point.cs b/ANX.Framework/Point.cs index 4e77a390..b03c72b2 100644 --- a/ANX.Framework/Point.cs +++ b/ANX.Framework/Point.cs @@ -7,75 +7,74 @@ using System.Globalization; namespace ANX.Framework { - [ANX.Framework.NonXNA.Development.PercentageComplete(100)] - public struct Point : IEquatable - { - #region fields - public int X; - public int Y; - #endregion - - #region properties - public static Point Zero - { - get - { - return new Point(0, 0); - } - } - #endregion - - #region constructors - public Point(int x, int y) - { - this.X = x; - this.Y = y; - } - #endregion - - #region public methods - public override int GetHashCode() - { - return this.X + this.Y; - } - - public override string ToString() - { - var culture = CultureInfo.CurrentCulture; - // This may look a bit more ugly, but String.Format should - // be avoided cause of it's bad performance! - return "{X:" + X.ToString(culture) + - " Y:" + Y.ToString(culture) + "}"; - - //return string.Format(culture, "{{X:{0} Y:{1}}}", new object[] - //{ - // this.X.ToString(culture), - // this.Y.ToString(culture) - //}); - } - #endregion - - #region IEquatable implementation - public override bool Equals(Object obj) - { - return (obj is Point) ? this.Equals((Point)obj) : false; - } - public bool Equals(Point other) - { - return this.X == other.X && this.Y == other.Y; - } - #endregion - - #region operator overloading - public static bool operator ==(Point first, Point second) + [ANX.Framework.NonXNA.Development.PercentageComplete(100)] + public struct Point : IEquatable + { + #region Constants + public static Point Zero + { + get { - return first.X == second.X && first.Y == second.Y; + return new Point(0, 0); } + } + #endregion - public static bool operator !=(Point first, Point second) - { - return first.X != second.X || first.Y != second.Y; - } - #endregion - } + #region Public + public int X; + public int Y; + #endregion + + #region Constructor + public Point(int x, int y) + { + this.X = x; + this.Y = y; + } + #endregion + + #region GetHashCode + public override int GetHashCode() + { + return this.X + this.Y; + } + #endregion + + #region ToString + public override string ToString() + { + var culture = CultureInfo.CurrentCulture; + // This may look a bit more ugly, but String.Format should + // be avoided cause of it's bad performance! + return "{X:" + X.ToString(culture) + + " Y:" + Y.ToString(culture) + "}"; + } + #endregion + + #region Equals + public override bool Equals(Object obj) + { + return (obj is Point) ? + this.Equals((Point)obj) : + false; + } + + public bool Equals(Point other) + { + return this.X == other.X && this.Y == other.Y; + } + #endregion + + #region operator overloading + public static bool operator ==(Point first, Point second) + { + return first.X == second.X && first.Y == second.Y; + } + + public static bool operator !=(Point first, Point second) + { + return first.X != second.X || first.Y != second.Y; + } + #endregion + } } diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/GamePad.cs b/InputSystems/ANX.InputDevices.Windows.XInput/GamePad.cs index 79b1642d..3efaef8a 100644 --- a/InputSystems/ANX.InputDevices.Windows.XInput/GamePad.cs +++ b/InputSystems/ANX.InputDevices.Windows.XInput/GamePad.cs @@ -1,13 +1,8 @@ #region Using Statements using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.IO; -using System.Runtime.InteropServices; -using ANX.Framework.NonXNA; -using ANX.Framework.Input; using ANX.Framework; +using ANX.Framework.Input; +using ANX.Framework.NonXNA; using SharpDX.XInput; #endregion // Using Statements diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/Keyboard.cs b/InputSystems/ANX.InputDevices.Windows.XInput/Keyboard.cs index 7c7b308e..bdfbf1bd 100644 --- a/InputSystems/ANX.InputDevices.Windows.XInput/Keyboard.cs +++ b/InputSystems/ANX.InputDevices.Windows.XInput/Keyboard.cs @@ -1,12 +1,8 @@ #region Using Statements using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using ANX.InputDevices; using ANX.Framework.NonXNA; using SharpDX.DirectInput; -using DXKeyboard=SharpDX.DirectInput.Keyboard; +using DXKeyboard = SharpDX.DirectInput.Keyboard; #endregion // Using Statements // This file is part of the ANX.Framework created by the diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/Mouse.cs b/InputSystems/ANX.InputDevices.Windows.XInput/Mouse.cs index 002bc18b..b953a502 100644 --- a/InputSystems/ANX.InputDevices.Windows.XInput/Mouse.cs +++ b/InputSystems/ANX.InputDevices.Windows.XInput/Mouse.cs @@ -1,8 +1,5 @@ #region Using Statements using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using ANX.Framework.NonXNA; using ANX.Framework.Input; using SharpDX.DirectInput; diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/GraphicsDeviceWindowsDX11.cs b/RenderSystems/ANX.RenderSystem.Windows.DX11/GraphicsDeviceWindowsDX11.cs index ee539dae..6860943c 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/GraphicsDeviceWindowsDX11.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/GraphicsDeviceWindowsDX11.cs @@ -269,9 +269,12 @@ namespace ANX.RenderSystem.Windows.DX11 #endregion // Present #region DrawPrimitives & DrawIndexedPrimitives - public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount) + public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, + int numVertices, int startIndex, int primitiveCount) { - SharpDX.Direct3D11.EffectPass pass; SharpDX.Direct3D11.EffectTechnique technique; ShaderBytecode passSignature; + SharpDX.Direct3D11.EffectPass pass; + SharpDX.Direct3D11.EffectTechnique technique; + ShaderBytecode passSignature; SetupEffectForDraw(out pass, out technique, out passSignature); SetupInputLayout(passSignature); diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro.csproj b/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro.csproj index e9d823a1..41e03cc3 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro.csproj +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro.csproj @@ -58,6 +58,8 @@ + + diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_Linux.csproj b/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_Linux.csproj index 94dfab7d..b35d3fce 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_Linux.csproj +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_Linux.csproj @@ -58,6 +58,8 @@ + + diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_PSVita.csproj b/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_PSVita.csproj index 01803d1e..177ecdcb 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_PSVita.csproj +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_PSVita.csproj @@ -59,6 +59,8 @@ + + diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_WindowsMetro.csproj b/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_WindowsMetro.csproj index a428d088..b2621f16 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_WindowsMetro.csproj +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/ANX.RenderSystem.Windows.Metro_WindowsMetro.csproj @@ -60,6 +60,8 @@ + + diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/EffectParameter_Metro.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/EffectParameter_Metro.cs index 945943d5..cfd8297d 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/EffectParameter_Metro.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/EffectParameter_Metro.cs @@ -3,7 +3,6 @@ using ANX.Framework; using ANX.Framework.Graphics; using ANX.Framework.NonXNA; using ANX.RenderSystem.Windows.Metro.Shader; -using Dx11 = SharpDX.Direct3D11; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -13,8 +12,12 @@ namespace ANX.RenderSystem.Windows.Metro { public class EffectParameter_Metro : INativeEffectParameter { + #region Private + private Effect_Metro parentEffect; private ExtendedShaderParameter nativeParameter; + #endregion + #region Public public string Name { get @@ -22,134 +25,122 @@ namespace ANX.RenderSystem.Windows.Metro return nativeParameter.Name; } } + #endregion - public EffectParameter_Metro(ExtendedShaderParameter setNativeParameter) + #region Constructor + public EffectParameter_Metro(Effect_Metro setParentEffect, + ExtendedShaderParameter setNativeParameter) { + parentEffect = setParentEffect; nativeParameter = setNativeParameter; } + #endregion - public void SetValue(bool value) - { - //nativeEffectVariable.AsScalar().Set(value); - throw new NotImplementedException(); - } - - public void SetValue(bool[] value) - { - //nativeEffectVariable.AsScalar().Set(value); - throw new NotImplementedException(); - } - + #region SetValue (int) public void SetValue(int value) { - //nativeEffectVariable.AsScalar().Set(value); - throw new NotImplementedException(); + var bytes = BitConverter.GetBytes(value); + parentEffect.paramBuffer.SetParameter(Name, bytes); } + #endregion + #region SetValue (int[]) public void SetValue(int[] value) { - //nativeEffectVariable.AsScalar().Set(value); - throw new NotImplementedException(); + parentEffect.paramBuffer.SetParameter(Name, value); } + #endregion + #region SetValue (Matrix) public void SetValue(Matrix value) { - //SharpDX.Matrix m = new SharpDX.Matrix(value.M11, value.M12, value.M13, value.M14, value.M21, value.M22, value.M23, value.M24, value.M31, value.M32, value.M33, value.M34, value.M41, value.M42, value.M43, value.M44); - //nativeEffectVariable.AsMatrix().SetMatrix(m); - throw new NotImplementedException(); + value = Matrix.Transpose(value); + parentEffect.paramBuffer.SetParameter(Name, value); } + #endregion + #region SetValue (Matrix[]) public void SetValue(Matrix[] value) { - int count = value.Length; - SharpDX.Matrix[] m = new SharpDX.Matrix[count]; - Matrix anxMatrix; - for (int i = 0; i < count; i++) + Matrix[] transposedMatrices = new Matrix[value.Length]; + for (int index = 0; index < value.Length; index++) { - anxMatrix = value[i]; - m[i] = new SharpDX.Matrix(anxMatrix.M11, anxMatrix.M12, anxMatrix.M13, anxMatrix.M14, - anxMatrix.M21, anxMatrix.M22, anxMatrix.M23, anxMatrix.M24, - anxMatrix.M31, anxMatrix.M32, anxMatrix.M33, anxMatrix.M34, - anxMatrix.M41, anxMatrix.M42, anxMatrix.M43, anxMatrix.M44); + transposedMatrices[index] = Matrix.Transpose(value[index]); } - - //nativeEffectVariable.AsMatrix().SetMatrix(m); - throw new NotImplementedException(); + parentEffect.paramBuffer.SetParameter(Name, transposedMatrices); } + #endregion + #region SetValue (Quaternion) public void SetValue(Quaternion value) { - SharpDX.Vector4 q = new SharpDX.Vector4(value.X, value.Y, value.Z, value.W); - //nativeEffectVariable.AsVector().Set(q); - throw new NotImplementedException(); + parentEffect.paramBuffer.SetParameter(Name, value); } + #endregion + #region SetValue (Quaternion[]) public void SetValue(Quaternion[] value) { - int count = value.Length; - SharpDX.Vector4[] q = new SharpDX.Vector4[count]; - for (int i = 0; i < count; i++) - { - q[i] = new SharpDX.Vector4(value[i].X, value[i].Y, value[i].Z, value[i].W); - } - //nativeEffectVariable.AsVector().Set(q); - throw new NotImplementedException(); + parentEffect.paramBuffer.SetParameter(Name, value); } + #endregion + #region SetValue (float) public void SetValue(float value) { - //nativeEffectVariable.AsScalar().Set(value); - throw new NotImplementedException(); + var bytes = BitConverter.GetBytes(value); + parentEffect.paramBuffer.SetParameter(Name, bytes); } + #endregion + #region SetValue (float[]) public void SetValue(float[] value) { - //nativeEffectVariable.AsScalar().Set(value); - throw new NotImplementedException(); + parentEffect.paramBuffer.SetParameter(Name, value); } + #endregion + #region SetValue (Vector2) public void SetValue(Vector2 value) { - SharpDX.Vector2 v = new SharpDX.Vector2(value.X, value.Y); - //nativeEffectVariable.AsVector().Set(v); - throw new NotImplementedException(); + parentEffect.paramBuffer.SetParameter(Name, value); } + #endregion + #region SetValue (Vector2[]) public void SetValue(Vector2[] value) { - throw new NotImplementedException(); + parentEffect.paramBuffer.SetParameter(Name, value); } + #endregion + #region SetValue (Vector3) public void SetValue(Vector3 value) { - SharpDX.Vector3 v = new SharpDX.Vector3(value.X, value.Y, value.Z); - //nativeEffectVariable.AsVector().Set(v); - throw new NotImplementedException(); + parentEffect.paramBuffer.SetParameter(Name, value); } + #endregion + #region SetValue (Vector3[]) public void SetValue(Vector3[] value) { - throw new NotImplementedException(); + parentEffect.paramBuffer.SetParameter(Name, value); } + #endregion + #region SetValue (Vector4) public void SetValue(Vector4 value) { - SharpDX.Vector4 v = new SharpDX.Vector4(value.X, value.Y, value.Z, value.W); - //nativeEffectVariable.AsVector().Set(v); - throw new NotImplementedException(); + parentEffect.paramBuffer.SetParameter(Name, value); } + #endregion + #region SetValue (Vector4[]) public void SetValue(Vector4[] value) { - int count = value.Length; - SharpDX.Vector4[] q = new SharpDX.Vector4[count]; - for (int i = 0; i < count; i++) - { - q[i] = new SharpDX.Vector4(value[i].X, value[i].Y, value[i].Z, value[i].W); - } - //nativeEffectVariable.AsVector().Set(q); - throw new NotImplementedException(); + parentEffect.paramBuffer.SetParameter(Name, value); } + #endregion #region SetValue (Texture) (TODO) public void SetValue(Texture value) @@ -157,35 +148,58 @@ namespace ANX.RenderSystem.Windows.Metro Texture2D_Metro tex = value.NativeTexture as Texture2D_Metro; var context = NativeDxDevice.Current.NativeContext; - // TODO: slot + // TODO: slot context.PixelShader.SetShaderResource(0, tex.NativeShaderResourceView); } #endregion - #region SetValue (Matrix) (TODO) + #region SetValue (Matrix, transpose) public void SetValue(Matrix value, bool transpose) { - var context = NativeDxDevice.Current.NativeContext; - var device = NativeDxDevice.Current.NativeDevice; + if (transpose == false) + value = Matrix.Transpose(value); - var constantBuffer = new Dx11.Buffer(device, - SharpDX.Utilities.SizeOf(), Dx11.ResourceUsage.Default, - Dx11.BindFlags.ConstantBuffer, Dx11.CpuAccessFlags.None, Dx11.ResourceOptionFlags.None, 0); - - context.VertexShader.SetConstantBuffer(0, constantBuffer); - value = Matrix.Transpose(value); - context.UpdateSubresource(ref value, constantBuffer); + parentEffect.paramBuffer.SetParameter(Name, value); } #endregion + #region SetValue (Matrix[], transpose) public void SetValue(Matrix[] value, bool transpose) + { + if (transpose) + { + parentEffect.paramBuffer.SetParameter(Name, value); + } + else + { + Matrix[] transposedMatrices = new Matrix[value.Length]; + for (int index = 0; index < value.Length; index++) + { + transposedMatrices[index] = Matrix.Transpose(value[index]); + } + parentEffect.paramBuffer.SetParameter(Name, transposedMatrices); + } + } + #endregion + + #region SetValue (TODO) + public void SetValue(bool value) { throw new NotImplementedException(); } - #region INativeEffectParameter Member + public void SetValue(bool[] value) + { + throw new NotImplementedException(); + } + public void SetValue(string value) + { + throw new NotImplementedException(); + } + #endregion + #region GetValue (TODO) public bool GetValueBoolean() { throw new NotImplementedException(); @@ -295,11 +309,6 @@ namespace ANX.RenderSystem.Windows.Metro { throw new NotImplementedException(); } - - public void SetValue(string value) - { - throw new NotImplementedException(); - } #endregion } } diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/Effect_Metro.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/Effect_Metro.cs index 0777a760..b06d953a 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/Effect_Metro.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/Effect_Metro.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using ANX.Framework.Graphics; using ANX.Framework.NonXNA; -using Dx11 = SharpDX.Direct3D11; using ANX.RenderSystem.Windows.Metro.Shader; // This file is part of the ANX.Framework created by the @@ -17,8 +16,13 @@ namespace ANX.RenderSystem.Windows.Metro #region Private private List techniques; private List parameters; + internal ParameterBuffer paramBuffer; - private ExtendedShader shader; + internal ExtendedShader shader + { + get; + private set; + } #endregion #region Public @@ -100,9 +104,11 @@ namespace ANX.RenderSystem.Windows.Metro foreach (ExtendedShaderParameter parameter in shader.Parameters) { EffectParameter newParam = new EffectParameter(); - newParam.NativeParameter = new EffectParameter_Metro(parameter); + newParam.NativeParameter = new EffectParameter_Metro(this, parameter); parameters.Add(newParam); } + + paramBuffer = new ParameterBuffer(this, NativeDxDevice.Current); } #endregion @@ -126,6 +132,7 @@ namespace ANX.RenderSystem.Windows.Metro public void Apply(GraphicsDevice graphicsDevice) { ((GraphicsDeviceWindowsMetro)graphicsDevice.NativeDevice).currentEffect = this; + paramBuffer.Apply(); } #endregion diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/GraphicsDeviceWindowsMetro.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/GraphicsDeviceWindowsMetro.cs index 91de7aa3..a5c15bff 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/GraphicsDeviceWindowsMetro.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/GraphicsDeviceWindowsMetro.cs @@ -20,7 +20,6 @@ namespace ANX.RenderSystem.Windows.Metro #region Private internal Effect_Metro currentEffect; private VertexBuffer currentVertexBuffer; - private IndexBuffer currentIndexBuffer; private Dx11.Viewport currentViewport; private uint lastClearColor; private SharpDX.Color4 clearColor; @@ -119,73 +118,57 @@ namespace ANX.RenderSystem.Windows.Metro #endregion // Present - #region DrawPrimitives & DrawIndexedPrimitives - public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, + #region DrawIndexedPrimitives + public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount) { - var d3dContext = NativeDevice.NativeContext; - var d3dDevice = NativeDevice.NativeDevice; + var technique = currentEffect.ManagedEffect.CurrentTechnique; + var nativeTechnique = technique.NativeTechnique as EffectTechnique_Metro; + EffectPass_Metro nativePass = nativeTechnique.GetPass(0); - NativeDevice.SetDefaultTargets(); + SetInputLayout(currentVertexBuffer.VertexDeclaration, nativePass); - var nativeVertexBuffer = currentVertexBuffer.NativeVertexBuffer as VertexBuffer_Metro; - - VertexDeclaration vertexDeclaration = currentVertexBuffer.VertexDeclaration; - VertexElement[] vertexElements = vertexDeclaration.GetVertexElements(); - int elementCount = vertexElements.Length; - var inputElements = new Dx11.InputElement[elementCount]; - - for (int i = 0; i < elementCount; i++) - { - inputElements[i] = CreateInputElementFromVertexElement(vertexElements[i]); - } - - var technique = currentEffect.ManagedEffect.CurrentTechnique; - var nativeTechnique = technique.NativeTechnique as EffectTechnique_Metro; - EffectPass_Metro nativePass = nativeTechnique.GetPass(0); - - var inputLayout = nativePass.BuildLayout(d3dDevice, inputElements); - var vertexBufferBinding = new Dx11.VertexBufferBinding( - nativeVertexBuffer.NativeBuffer, vertexDeclaration.VertexStride, 0); - - d3dContext.InputAssembler.SetVertexBuffers(0, vertexBufferBinding); - d3dContext.InputAssembler.InputLayout = inputLayout; - d3dContext.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType); - + var d3dContext = NativeDevice.NativeContext; + d3dContext.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType); d3dContext.VertexShader.Set(nativePass.VertexShader); d3dContext.PixelShader.Set(nativePass.PixelShader); //d3dContext.PixelShader.SetSampler(0, sampler); - //for (int i = 0; i < technique.Description.PassCount; ++i) - //{ - // pass.Apply(); - d3dContext.DrawIndexed(CalculateVertexCount(primitiveType, primitiveCount), - startIndex, baseVertex); - //} - } - - public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, int primitiveCount) - { - //Dx11.EffectPass pass; Dx11.EffectTechnique technique; ShaderBytecode passSignature; - //SetupEffectForDraw(out pass, out technique, out passSignature); - - //SetupInputLayout(passSignature); - - //// Prepare All the stages - //deviceContext.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType); - //deviceContext.Rasterizer.SetViewports(currentViewport); - - //deviceContext.OutputMerger.SetTargets(this.depthStencilView, this.renderView); + NativeDevice.SetDefaultTargets(); //for (int i = 0; i < technique.Description.PassCount; ++i) //{ // pass.Apply(); - // deviceContext.Draw(primitiveCount, vertexOffset); + int indexCount = CalculateVertexCount(primitiveType, primitiveCount); + d3dContext.DrawIndexed(indexCount, startIndex, baseVertex); + //} + } + #endregion + + #region DrawPrimitives + public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, int primitiveCount) + { + var technique = currentEffect.ManagedEffect.CurrentTechnique; + var nativeTechnique = technique.NativeTechnique as EffectTechnique_Metro; + EffectPass_Metro nativePass = nativeTechnique.GetPass(0); + + SetInputLayout(currentVertexBuffer.VertexDeclaration, nativePass); + + var d3dContext = NativeDevice.NativeContext; + d3dContext.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType); + d3dContext.VertexShader.Set(nativePass.VertexShader); + d3dContext.PixelShader.Set(nativePass.PixelShader); + + NativeDevice.SetDefaultTargets(); + + //for (int i = 0; i < technique.Description.PassCount; ++i) + //{ + // pass.Apply(); + d3dContext.Draw(primitiveCount, vertexOffset); //} } - - #endregion // DrawPrimitives & DrawIndexedPrimitives + #endregion #region DrawInstancedPrimitives public void DrawInstancedPrimitives(PrimitiveType primitiveType, @@ -251,25 +234,15 @@ namespace ANX.RenderSystem.Windows.Metro private int CalculateVertexCount(PrimitiveType type, int primitiveCount) { if (type == PrimitiveType.TriangleList) - { return primitiveCount * 3; - } else if (type == PrimitiveType.LineList) - { return primitiveCount * 2; - } else if (type == PrimitiveType.LineStrip) - { return primitiveCount + 1; - } else if (type == PrimitiveType.TriangleStrip) - { return primitiveCount + 2; - } else - { - throw new NotImplementedException("couldn't calculate vertex count for PrimitiveType '" + type.ToString() + "'"); - } + throw new NotImplementedException("couldn't calculate vertex count for PrimitiveType '" + type + "'"); } #endregion @@ -277,17 +250,14 @@ namespace ANX.RenderSystem.Windows.Metro public void SetIndexBuffer(IndexBuffer indexBuffer) { if (indexBuffer == null) - { throw new ArgumentNullException("indexBuffer"); - } - - this.currentIndexBuffer = indexBuffer; IndexBuffer_Metro nativeIndexBuffer = indexBuffer.NativeIndexBuffer as IndexBuffer_Metro; if (nativeIndexBuffer != null) { - NativeDevice.NativeContext.InputAssembler.SetIndexBuffer(nativeIndexBuffer.NativeBuffer, FormatConverter.Translate(indexBuffer.IndexElementSize), 0); + NativeDevice.NativeContext.InputAssembler.SetIndexBuffer(nativeIndexBuffer.NativeBuffer, + FormatConverter.Translate(indexBuffer.IndexElementSize), 0); } else { @@ -300,21 +270,22 @@ namespace ANX.RenderSystem.Windows.Metro public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers) { if (vertexBuffers == null) - { throw new ArgumentNullException("vertexBuffers"); - } this.currentVertexBuffer = vertexBuffers[0].VertexBuffer; //TODO: hmmmmm, not nice :-) - Dx11.VertexBufferBinding[] nativeVertexBufferBindings = new Dx11.VertexBufferBinding[vertexBuffers.Length]; + var nativeVertexBufferBindings = new Dx11.VertexBufferBinding[vertexBuffers.Length]; for (int i = 0; i < vertexBuffers.Length; i++) { - ANX.Framework.Graphics.VertexBufferBinding anxVertexBufferBinding = vertexBuffers[i]; - VertexBuffer_Metro nativeVertexBuffer = anxVertexBufferBinding.VertexBuffer.NativeVertexBuffer as VertexBuffer_Metro; + VertexBufferBinding anxVertexBufferBinding = vertexBuffers[i]; + VertexBuffer_Metro nativeVertexBuffer = + anxVertexBufferBinding.VertexBuffer.NativeVertexBuffer as VertexBuffer_Metro; if (nativeVertexBuffer != null) { - nativeVertexBufferBindings[i] = new Dx11.VertexBufferBinding(nativeVertexBuffer.NativeBuffer, anxVertexBufferBinding.VertexBuffer.VertexDeclaration.VertexStride, anxVertexBufferBinding.VertexOffset); + nativeVertexBufferBindings[i] = new Dx11.VertexBufferBinding(nativeVertexBuffer.NativeBuffer, + anxVertexBufferBinding.VertexBuffer.VertexDeclaration.VertexStride, + anxVertexBufferBinding.VertexOffset); } else { @@ -333,9 +304,26 @@ namespace ANX.RenderSystem.Windows.Metro viewport.Width, viewport.Height, viewport.MinDepth, viewport.MaxDepth); } #endregion - - #region CreateInputElementFromVertexElement - private Dx11.InputElement CreateInputElementFromVertexElement(VertexElement vertexElement) + + #region SetInputLayout + private void SetInputLayout(VertexDeclaration vertexDeclaration, EffectPass_Metro nativePass) + { + VertexElement[] vertexElements = vertexDeclaration.GetVertexElements(); + int elementCount = vertexElements.Length; + var inputElements = new Dx11.InputElement[elementCount]; + + for (int i = 0; i < elementCount; i++) + { + inputElements[i] = CreateInputElementFromVertexElement(vertexElements[i]); + } + + NativeDevice.NativeContext.InputAssembler.InputLayout = + nativePass.BuildLayout(NativeDevice.NativeDevice, inputElements); + } + #endregion + + #region CreateInputElementFromVertexElement + private Dx11.InputElement CreateInputElementFromVertexElement(VertexElement vertexElement) { string elementName = FormatConverter.Translate(vertexElement.VertexElementUsage); diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/NativeDxDevice.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/NativeDxDevice.cs index 27c157c2..6feb97b2 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/NativeDxDevice.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/NativeDxDevice.cs @@ -144,7 +144,7 @@ namespace ANX.RenderSystem.Windows.Metro { // TODO: find better solution to lazy init the swapChain from the coreWindow!! EnsureScreenBuffersAvailable(); - + nativeContext.ClearRenderTargetView(renderTargetView, color); } #endregion diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/RenderTarget2D_Metro.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/RenderTarget2D_Metro.cs index b5a50b7f..f887aee4 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/RenderTarget2D_Metro.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/RenderTarget2D_Metro.cs @@ -40,8 +40,8 @@ namespace ANX.RenderSystem.Windows.Metro CpuAccessFlags = Dx11.CpuAccessFlags.None, OptionFlags = Dx11.ResourceOptionFlags.None, }; - this.nativeTexture = new Dx11.Texture2D(device, description); - this.nativeShaderResourceView = new Dx11.ShaderResourceView(device, this.nativeTexture); + this.NativeTexture = new Dx11.Texture2D(device, description); + this.NativeShaderResourceView = new Dx11.ShaderResourceView(device, 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 diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/Shader/ExtendedShaderParameter.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/Shader/ExtendedShaderParameter.cs index a2c7e5d6..d8d738d5 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/Shader/ExtendedShaderParameter.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/Shader/ExtendedShaderParameter.cs @@ -7,11 +7,21 @@ namespace ANX.RenderSystem.Windows.Metro.Shader { public string Type; public string Name; + public int ArraySize; + public int[] TypeDimensions; public ExtendedShaderParameter(BinaryReader reader) { Type = reader.ReadString(); Name = reader.ReadString(); + ArraySize = reader.ReadInt32(); + + int numberOfDimensions = reader.ReadByte(); + TypeDimensions = new int[numberOfDimensions]; + for (int dimIndex = 0; dimIndex < numberOfDimensions; dimIndex++) + { + TypeDimensions[dimIndex] = (int)reader.ReadByte(); + } } } } diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/Shader/ParameterBuffer.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/Shader/ParameterBuffer.cs new file mode 100644 index 00000000..41490a98 --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/Shader/ParameterBuffer.cs @@ -0,0 +1,224 @@ +using System; +using System.IO; +using System.Runtime.InteropServices; +using Dx11 = SharpDX.Direct3D11; + +// 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.Metro.Shader +{ + public class ParameterBuffer : IDisposable + { + #region Private + private Dx11.Buffer nativeBuffer; + private NativeDxDevice graphicsDevice; + private Effect_Metro parentEffect; + + private Array[] setData; + + private int dataSize; + #endregion + + #region Constructor + public ParameterBuffer(Effect_Metro setParentEffect, + NativeDxDevice setGraphicsDevice) + { + graphicsDevice = setGraphicsDevice; + parentEffect = setParentEffect; + setData = new Array[parentEffect.shader.Parameters.Count]; + } + #endregion + + #region SetParameter (T) + public void SetParameter(string parameterName, T value) where T : struct + { + int indexOfParameter = FindParameterIndex(parameterName); + if (indexOfParameter == -1) + return; + + setData[indexOfParameter] = StructureToBytes(value); + } + #endregion + + #region SetParameter (T[]) + public void SetParameter(string parameterName, T[] value) where T : struct + { + int indexOfParameter = FindParameterIndex(parameterName); + if (indexOfParameter == -1) + return; + + value = FillArrayIfNeeded(value, indexOfParameter); + + int sizePerItem = Marshal.SizeOf(typeof(T)); + byte[] result = new byte[sizePerItem * value.Length]; + int offset = 0; + IntPtr ptr = Marshal.AllocHGlobal(sizePerItem); + for (int index = 0; index < value.Length; index++) + { + Marshal.StructureToPtr(value[index], ptr, true); + Marshal.Copy(ptr, result, offset, sizePerItem); + offset += sizePerItem; + } + Marshal.FreeHGlobal(ptr); + + setData[indexOfParameter] = result; + } + #endregion + + #region SetParameter (float[]) + public void SetParameter(string parameterName, float[] value) + { + int indexOfParameter = FindParameterIndex(parameterName); + if (indexOfParameter == -1) + return; + + value = FillArrayIfNeeded(value, indexOfParameter); + + byte[] convertData = null; + byte[] result = UnionArraySerializer.Unify(value); + convertData = new byte[result.Length]; + Array.Copy(result, convertData, result.Length); + + setData[indexOfParameter] = convertData; + } + #endregion + + #region SetParameter (int[]) + public void SetParameter(string parameterName, int[] value) + { + int indexOfParameter = FindParameterIndex(parameterName); + if (indexOfParameter == -1) + return; + + value = FillArrayIfNeeded(value, indexOfParameter); + + byte[] convertData = null; + byte[] result = UnionArraySerializer.Unify(value); + convertData = new byte[result.Length]; + Array.Copy(result, convertData, result.Length); + + setData[indexOfParameter] = convertData; + } + #endregion + + #region SetParameter (byte[]) + public void SetParameter(string parameterName, byte[] value) + { + int indexOfParameter = FindParameterIndex(parameterName); + if (indexOfParameter == -1) + return; + + setData[indexOfParameter] = value; + } + #endregion + + #region StructureToBytes + private byte[] StructureToBytes(T value) where T : struct + { + int size = Marshal.SizeOf(value); + byte[] result = new byte[size]; + IntPtr ptr = Marshal.AllocHGlobal(size); + + Marshal.StructureToPtr(value, ptr, true); + Marshal.Copy(ptr, result, 0, size); + Marshal.FreeHGlobal(ptr); + + return result; + } + #endregion + + #region FindParameterIndex + private int FindParameterIndex(string parameterName) + { + int searchIndex = 0; + foreach (var parameter in parentEffect.shader.Parameters) + { + if (parameter.Name == parameterName) + { + return searchIndex; + } + + searchIndex++; + } + + return -1; + } + #endregion + + #region FillArrayIfNeeded + private T[] FillArrayIfNeeded(T[] original, int parameterIndex) where T : struct + { + int paramArraySize = parentEffect.shader.Parameters[parameterIndex].ArraySize; + if (paramArraySize > 0) + { + T[] filledArray = new T[paramArraySize]; + Array.Copy(original, filledArray, original.Length); + return filledArray; + } + + return original; + } + #endregion + + #region Apply + public void Apply() + { + var data = CreateBufferData(); + + nativeBuffer = new Dx11.Buffer(graphicsDevice.NativeDevice, dataSize, + Dx11.ResourceUsage.Default, Dx11.BindFlags.ConstantBuffer, + Dx11.CpuAccessFlags.None, Dx11.ResourceOptionFlags.None, 0); + graphicsDevice.NativeContext.VertexShader.SetConstantBuffer(0, nativeBuffer); + graphicsDevice.NativeContext.UpdateSubresource(data, nativeBuffer); + } + #endregion + + #region CreateBufferData + private SharpDX.DataBox CreateBufferData() + { + MemoryStream stream = new MemoryStream(); + BinaryWriter writer = new BinaryWriter(stream); + + foreach (byte[] data in setData) + { + if (data != null) + { + writer.Write(data); + } + } + + byte[] streamBytes = stream.ToArray(); + stream.Dispose(); + + IntPtr dataPtr; + unsafe + { + fixed (byte* ptr = &streamBytes[0]) + { + dataPtr = (IntPtr)ptr; + } + } + + dataSize = streamBytes.Length; + + setData = new Array[parentEffect.shader.Parameters.Count]; + return new SharpDX.DataBox(dataPtr); + } + #endregion + + #region Dispose + public void Dispose() + { + if (nativeBuffer != null) + { + nativeBuffer.Dispose(); + nativeBuffer = null; + } + + graphicsDevice = null; + } + #endregion + } +} diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/Shader/UnionArraySerializer.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/Shader/UnionArraySerializer.cs new file mode 100644 index 00000000..715d7839 --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/Shader/UnionArraySerializer.cs @@ -0,0 +1,79 @@ +using System; +using System.Runtime.InteropServices; + +// 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.Metro.Shader +{ + public static class UnionArraySerializer + { + #region Union (private helper struct) + [StructLayout(LayoutKind.Explicit)] + private struct Union + { + [FieldOffset(0)] + public byte[] bytes; + [FieldOffset(0)] + public float[] floats; + [FieldOffset(0)] + public int[] ints; + } + #endregion + + #region Private + private static readonly UIntPtr BYTE_ARRAY; + private static unsafe readonly int PTR_SIZE = sizeof(UIntPtr); + #endregion + + #region Constructor + static unsafe UnionArraySerializer() + { + var byteArray = new byte[1]; + + fixed (byte* pBytes = byteArray) + { + BYTE_ARRAY = *(UIntPtr*)(pBytes - 2 * PTR_SIZE); + } + } + #endregion + + #region Unify (float[]) + public static unsafe byte[] Unify(float[] floats) + { + var union = new Union(); + union.floats = floats; + + fixed (float* pValues = union.floats) + UpdatePointers((byte*)pValues, floats.Length * 4); + + return union.bytes; + } + #endregion + + #region Unify (int[]) + public static unsafe byte[] Unify(int[] ints) + { + var union = new Union(); + union.ints = ints; + + fixed (int* pValues = union.ints) + UpdatePointers((byte*)pValues, ints.Length * 4); + + return union.bytes; + } + #endregion + + #region UpdatePointers + private static unsafe void UpdatePointers(byte* pBytes, int byteSize) + { + var pSize = (UIntPtr*)(pBytes - PTR_SIZE); + var pArrayType = (UIntPtr*)(pBytes - 2 * PTR_SIZE); + + *pSize = (UIntPtr)byteSize; + *pArrayType = BYTE_ARRAY; + } + #endregion + } +} diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/ShaderByteCode.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/ShaderByteCode.cs index 3e30c066..2f8cbad0 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/ShaderByteCode.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/ShaderByteCode.cs @@ -12,152 +12,152 @@ namespace ANX.RenderSystem.Windows.Metro internal static byte[] SpriteBatchByteCode = new byte[] { 002, 000, 000, 000, 005, 102, 108, 111, 097, 116, 015, 077, 097, 116, 114, - 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, 017, 084, 101, 120, - 116, 117, 114, 101, 050, 068, 060, 102, 108, 111, 097, 116, 052, 062, 007, - 084, 101, 120, 116, 117, 114, 101, 002, 000, 000, 000, 017, 086, 101, 114, - 116, 101, 120, 083, 104, 097, 100, 101, 114, 073, 110, 112, 117, 116, 003, - 000, 000, 000, 005, 102, 108, 111, 097, 116, 003, 112, 111, 115, 008, 080, - 079, 083, 073, 084, 073, 079, 078, 005, 102, 108, 111, 097, 116, 003, 099, - 111, 108, 005, 067, 079, 076, 079, 082, 005, 102, 108, 111, 097, 116, 003, - 116, 101, 120, 009, 084, 069, 088, 067, 079, 079, 082, 068, 048, 016, 080, - 105, 120, 101, 108, 083, 104, 097, 100, 101, 114, 073, 110, 112, 117, 116, - 003, 000, 000, 000, 005, 102, 108, 111, 097, 116, 003, 112, 111, 115, 011, - 083, 086, 095, 080, 079, 083, 073, 084, 073, 079, 078, 005, 102, 108, 111, - 097, 116, 003, 099, 111, 108, 005, 067, 079, 076, 079, 082, 005, 102, 108, - 111, 097, 116, 003, 116, 101, 120, 009, 084, 069, 088, 067, 079, 079, 082, - 068, 048, 001, 000, 000, 000, 015, 083, 112, 114, 105, 116, 101, 084, 101, - 099, 104, 110, 105, 113, 117, 101, 001, 000, 000, 000, 015, 083, 112, 114, - 105, 116, 101, 067, 111, 108, 111, 114, 080, 097, 115, 115, 096, 004, 000, - 000, 068, 088, 066, 067, 232, 119, 032, 081, 037, 179, 161, 217, 149, 118, - 064, 131, 239, 136, 225, 141, 001, 000, 000, 000, 096, 004, 000, 000, 006, - 000, 000, 000, 056, 000, 000, 000, 024, 001, 000, 000, 048, 002, 000, 000, - 172, 002, 000, 000, 124, 003, 000, 000, 236, 003, 000, 000, 065, 111, 110, - 057, 216, 000, 000, 000, 216, 000, 000, 000, 000, 002, 254, 255, 164, 000, - 000, 000, 052, 000, 000, 000, 001, 000, 036, 000, 000, 000, 048, 000, 000, - 000, 048, 000, 000, 000, 036, 000, 001, 000, 048, 000, 000, 000, 000, 000, - 004, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 002, 254, - 255, 031, 000, 000, 002, 005, 000, 000, 128, 000, 000, 015, 144, 031, 000, - 000, 002, 005, 000, 001, 128, 001, 000, 015, 144, 031, 000, 000, 002, 005, - 000, 002, 128, 002, 000, 015, 144, 009, 000, 000, 003, 000, 000, 004, 192, - 000, 000, 228, 144, 003, 000, 228, 160, 009, 000, 000, 003, 000, 000, 001, - 128, 000, 000, 228, 144, 001, 000, 228, 160, 009, 000, 000, 003, 000, 000, - 002, 128, 000, 000, 228, 144, 002, 000, 228, 160, 009, 000, 000, 003, 000, - 000, 004, 128, 000, 000, 228, 144, 004, 000, 228, 160, 004, 000, 000, 004, - 000, 000, 003, 192, 000, 000, 170, 128, 000, 000, 228, 160, 000, 000, 228, - 128, 001, 000, 000, 002, 000, 000, 008, 192, 000, 000, 170, 128, 001, 000, - 000, 002, 000, 000, 015, 224, 001, 000, 228, 144, 001, 000, 000, 002, 001, - 000, 003, 224, 002, 000, 228, 144, 255, 255, 000, 000, 083, 072, 068, 082, - 016, 001, 000, 000, 064, 000, 001, 000, 068, 000, 000, 000, 089, 000, 000, - 004, 070, 142, 032, 000, 000, 000, 000, 000, 004, 000, 000, 000, 095, 000, - 000, 003, 242, 016, 016, 000, 000, 000, 000, 000, 095, 000, 000, 003, 242, - 016, 016, 000, 001, 000, 000, 000, 095, 000, 000, 003, 050, 016, 016, 000, - 002, 000, 000, 000, 103, 000, 000, 004, 242, 032, 016, 000, 000, 000, 000, - 000, 001, 000, 000, 000, 101, 000, 000, 003, 242, 032, 016, 000, 001, 000, - 000, 000, 101, 000, 000, 003, 050, 032, 016, 000, 002, 000, 000, 000, 017, - 000, 000, 008, 018, 032, 016, 000, 000, 000, 000, 000, 070, 030, 016, 000, - 000, 000, 000, 000, 070, 142, 032, 000, 000, 000, 000, 000, 000, 000, 000, - 000, 017, 000, 000, 008, 034, 032, 016, 000, 000, 000, 000, 000, 070, 030, - 016, 000, 000, 000, 000, 000, 070, 142, 032, 000, 000, 000, 000, 000, 001, - 000, 000, 000, 017, 000, 000, 008, 066, 032, 016, 000, 000, 000, 000, 000, - 070, 030, 016, 000, 000, 000, 000, 000, 070, 142, 032, 000, 000, 000, 000, - 000, 002, 000, 000, 000, 017, 000, 000, 008, 130, 032, 016, 000, 000, 000, - 000, 000, 070, 030, 016, 000, 000, 000, 000, 000, 070, 142, 032, 000, 000, - 000, 000, 000, 003, 000, 000, 000, 054, 000, 000, 005, 242, 032, 016, 000, - 001, 000, 000, 000, 070, 030, 016, 000, 001, 000, 000, 000, 054, 000, 000, - 005, 050, 032, 016, 000, 002, 000, 000, 000, 070, 016, 016, 000, 002, 000, - 000, 000, 062, 000, 000, 001, 083, 084, 065, 084, 116, 000, 000, 000, 007, - 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 006, 000, 000, 000, - 004, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 003, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 082, 068, 069, 070, 200, - 000, 000, 000, 001, 000, 000, 000, 072, 000, 000, 000, 001, 000, 000, 000, - 028, 000, 000, 000, 000, 004, 254, 255, 000, 001, 000, 000, 152, 000, 000, - 000, 060, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 000, - 000, 000, 000, 036, 071, 108, 111, 098, 097, 108, 115, 000, 171, 171, 171, - 060, 000, 000, 000, 001, 000, 000, 000, 096, 000, 000, 000, 064, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 000, 000, 120, 000, 000, 000, 000, 000, - 000, 000, 064, 000, 000, 000, 002, 000, 000, 000, 136, 000, 000, 000, 000, - 000, 000, 000, 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115, 102, - 111, 114, 109, 000, 003, 000, 003, 000, 004, 000, 004, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 077, 105, 099, 114, 111, 115, 111, 102, 116, 032, - 040, 082, 041, 032, 072, 076, 083, 076, 032, 083, 104, 097, 100, 101, 114, - 032, 067, 111, 109, 112, 105, 108, 101, 114, 032, 057, 046, 051, 048, 046, - 056, 052, 048, 048, 046, 048, 000, 171, 073, 083, 071, 078, 104, 000, 000, - 000, 003, 000, 000, 000, 008, 000, 000, 000, 080, 000, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 000, 000, 000, 000, 015, - 015, 000, 000, 089, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 003, 000, 000, 000, 001, 000, 000, 000, 015, 015, 000, 000, 095, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 002, 000, - 000, 000, 003, 003, 000, 000, 080, 079, 083, 073, 084, 073, 079, 078, 000, - 067, 079, 076, 079, 082, 000, 084, 069, 088, 067, 079, 079, 082, 068, 000, - 079, 083, 071, 078, 108, 000, 000, 000, 003, 000, 000, 000, 008, 000, 000, - 000, 080, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 003, 000, - 000, 000, 000, 000, 000, 000, 015, 000, 000, 000, 092, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 001, 000, 000, 000, - 015, 000, 000, 000, 098, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 000, 003, 000, 000, 000, 002, 000, 000, 000, 003, 012, 000, 000, 083, 086, - 095, 080, 079, 083, 073, 084, 073, 079, 078, 000, 067, 079, 076, 079, 082, - 000, 084, 069, 088, 067, 079, 079, 082, 068, 000, 171, 044, 003, 000, 000, - 068, 088, 066, 067, 025, 072, 003, 020, 255, 152, 205, 017, 113, 110, 162, - 086, 146, 094, 200, 041, 001, 000, 000, 000, 044, 003, 000, 000, 006, 000, - 000, 000, 056, 000, 000, 000, 192, 000, 000, 000, 092, 001, 000, 000, 216, - 001, 000, 000, 132, 002, 000, 000, 248, 002, 000, 000, 065, 111, 110, 057, - 128, 000, 000, 000, 128, 000, 000, 000, 000, 002, 255, 255, 088, 000, 000, - 000, 040, 000, 000, 000, 000, 000, 040, 000, 000, 000, 040, 000, 000, 000, - 040, 000, 001, 000, 036, 000, 000, 000, 040, 000, 000, 000, 000, 000, 000, - 002, 255, 255, 031, 000, 000, 002, 000, 000, 000, 128, 000, 000, 015, 176, - 031, 000, 000, 002, 000, 000, 000, 128, 001, 000, 003, 176, 031, 000, 000, - 002, 000, 000, 000, 144, 000, 008, 015, 160, 066, 000, 000, 003, 000, 000, - 015, 128, 001, 000, 228, 176, 000, 008, 228, 160, 005, 000, 000, 003, 000, - 000, 015, 128, 000, 000, 228, 128, 000, 000, 228, 176, 001, 000, 000, 002, - 000, 008, 015, 128, 000, 000, 228, 128, 255, 255, 000, 000, 083, 072, 068, - 082, 148, 000, 000, 000, 064, 000, 000, 000, 037, 000, 000, 000, 090, 000, - 000, 003, 000, 096, 016, 000, 000, 000, 000, 000, 088, 024, 000, 004, 000, - 112, 016, 000, 000, 000, 000, 000, 085, 085, 000, 000, 098, 016, 000, 003, - 242, 016, 016, 000, 001, 000, 000, 000, 098, 016, 000, 003, 050, 016, 016, - 000, 002, 000, 000, 000, 101, 000, 000, 003, 242, 032, 016, 000, 000, 000, - 000, 000, 104, 000, 000, 002, 001, 000, 000, 000, 069, 000, 000, 009, 242, - 000, 016, 000, 000, 000, 000, 000, 070, 016, 016, 000, 002, 000, 000, 000, - 070, 126, 016, 000, 000, 000, 000, 000, 000, 096, 016, 000, 000, 000, 000, - 000, 056, 000, 000, 007, 242, 032, 016, 000, 000, 000, 000, 000, 070, 014, - 016, 000, 000, 000, 000, 000, 070, 030, 016, 000, 001, 000, 000, 000, 062, - 000, 000, 001, 083, 084, 065, 084, 116, 000, 000, 000, 003, 000, 000, 000, - 001, 000, 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 001, 000, 000, + 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, 000, 000, 000, 000, + 002, 004, 004, 017, 084, 101, 120, 116, 117, 114, 101, 050, 068, 060, 102, + 108, 111, 097, 116, 052, 062, 007, 084, 101, 120, 116, 117, 114, 101, 000, + 000, 000, 000, 000, 002, 000, 000, 000, 017, 086, 101, 114, 116, 101, 120, + 083, 104, 097, 100, 101, 114, 073, 110, 112, 117, 116, 003, 000, 000, 000, + 005, 102, 108, 111, 097, 116, 003, 112, 111, 115, 008, 080, 079, 083, 073, + 084, 073, 079, 078, 005, 102, 108, 111, 097, 116, 003, 099, 111, 108, 005, + 067, 079, 076, 079, 082, 005, 102, 108, 111, 097, 116, 003, 116, 101, 120, + 009, 084, 069, 088, 067, 079, 079, 082, 068, 048, 016, 080, 105, 120, 101, + 108, 083, 104, 097, 100, 101, 114, 073, 110, 112, 117, 116, 003, 000, 000, + 000, 005, 102, 108, 111, 097, 116, 003, 112, 111, 115, 011, 083, 086, 095, + 080, 079, 083, 073, 084, 073, 079, 078, 005, 102, 108, 111, 097, 116, 003, + 099, 111, 108, 005, 067, 079, 076, 079, 082, 005, 102, 108, 111, 097, 116, + 003, 116, 101, 120, 009, 084, 069, 088, 067, 079, 079, 082, 068, 048, 001, + 000, 000, 000, 015, 083, 112, 114, 105, 116, 101, 084, 101, 099, 104, 110, + 105, 113, 117, 101, 001, 000, 000, 000, 015, 083, 112, 114, 105, 116, 101, + 067, 111, 108, 111, 114, 080, 097, 115, 115, 096, 004, 000, 000, 068, 088, + 066, 067, 232, 119, 032, 081, 037, 179, 161, 217, 149, 118, 064, 131, 239, + 136, 225, 141, 001, 000, 000, 000, 096, 004, 000, 000, 006, 000, 000, 000, + 056, 000, 000, 000, 024, 001, 000, 000, 048, 002, 000, 000, 172, 002, 000, + 000, 124, 003, 000, 000, 236, 003, 000, 000, 065, 111, 110, 057, 216, 000, + 000, 000, 216, 000, 000, 000, 000, 002, 254, 255, 164, 000, 000, 000, 052, + 000, 000, 000, 001, 000, 036, 000, 000, 000, 048, 000, 000, 000, 048, 000, + 000, 000, 036, 000, 001, 000, 048, 000, 000, 000, 000, 000, 004, 000, 001, + 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 002, 254, 255, 031, 000, + 000, 002, 005, 000, 000, 128, 000, 000, 015, 144, 031, 000, 000, 002, 005, + 000, 001, 128, 001, 000, 015, 144, 031, 000, 000, 002, 005, 000, 002, 128, + 002, 000, 015, 144, 009, 000, 000, 003, 000, 000, 004, 192, 000, 000, 228, + 144, 003, 000, 228, 160, 009, 000, 000, 003, 000, 000, 001, 128, 000, 000, + 228, 144, 001, 000, 228, 160, 009, 000, 000, 003, 000, 000, 002, 128, 000, + 000, 228, 144, 002, 000, 228, 160, 009, 000, 000, 003, 000, 000, 004, 128, + 000, 000, 228, 144, 004, 000, 228, 160, 004, 000, 000, 004, 000, 000, 003, + 192, 000, 000, 170, 128, 000, 000, 228, 160, 000, 000, 228, 128, 001, 000, + 000, 002, 000, 000, 008, 192, 000, 000, 170, 128, 001, 000, 000, 002, 000, + 000, 015, 224, 001, 000, 228, 144, 001, 000, 000, 002, 001, 000, 003, 224, + 002, 000, 228, 144, 255, 255, 000, 000, 083, 072, 068, 082, 016, 001, 000, + 000, 064, 000, 001, 000, 068, 000, 000, 000, 089, 000, 000, 004, 070, 142, + 032, 000, 000, 000, 000, 000, 004, 000, 000, 000, 095, 000, 000, 003, 242, + 016, 016, 000, 000, 000, 000, 000, 095, 000, 000, 003, 242, 016, 016, 000, + 001, 000, 000, 000, 095, 000, 000, 003, 050, 016, 016, 000, 002, 000, 000, + 000, 103, 000, 000, 004, 242, 032, 016, 000, 000, 000, 000, 000, 001, 000, + 000, 000, 101, 000, 000, 003, 242, 032, 016, 000, 001, 000, 000, 000, 101, + 000, 000, 003, 050, 032, 016, 000, 002, 000, 000, 000, 017, 000, 000, 008, + 018, 032, 016, 000, 000, 000, 000, 000, 070, 030, 016, 000, 000, 000, 000, + 000, 070, 142, 032, 000, 000, 000, 000, 000, 000, 000, 000, 000, 017, 000, + 000, 008, 034, 032, 016, 000, 000, 000, 000, 000, 070, 030, 016, 000, 000, + 000, 000, 000, 070, 142, 032, 000, 000, 000, 000, 000, 001, 000, 000, 000, + 017, 000, 000, 008, 066, 032, 016, 000, 000, 000, 000, 000, 070, 030, 016, + 000, 000, 000, 000, 000, 070, 142, 032, 000, 000, 000, 000, 000, 002, 000, + 000, 000, 017, 000, 000, 008, 130, 032, 016, 000, 000, 000, 000, 000, 070, + 030, 016, 000, 000, 000, 000, 000, 070, 142, 032, 000, 000, 000, 000, 000, + 003, 000, 000, 000, 054, 000, 000, 005, 242, 032, 016, 000, 001, 000, 000, + 000, 070, 030, 016, 000, 001, 000, 000, 000, 054, 000, 000, 005, 050, 032, + 016, 000, 002, 000, 000, 000, 070, 016, 016, 000, 002, 000, 000, 000, 062, + 000, 000, 001, 083, 084, 065, 084, 116, 000, 000, 000, 007, 000, 000, 000, + 000, 000, 000, 000, 000, 000, 000, 000, 006, 000, 000, 000, 004, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 003, 000, 000, + 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 000, 000, 082, 068, 069, 070, 200, 000, 000, 000, + 001, 000, 000, 000, 072, 000, 000, 000, 001, 000, 000, 000, 028, 000, 000, + 000, 000, 004, 254, 255, 000, 001, 000, 000, 152, 000, 000, 000, 060, 000, + 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, + 036, 071, 108, 111, 098, 097, 108, 115, 000, 171, 171, 171, 060, 000, 000, + 000, 001, 000, 000, 000, 096, 000, 000, 000, 064, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 000, 120, 000, 000, 000, 000, 000, 000, 000, 064, + 000, 000, 000, 002, 000, 000, 000, 136, 000, 000, 000, 000, 000, 000, 000, + 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, + 000, 003, 000, 003, 000, 004, 000, 004, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 077, 105, 099, 114, 111, 115, 111, 102, 116, 032, 040, 082, 041, + 032, 072, 076, 083, 076, 032, 083, 104, 097, 100, 101, 114, 032, 067, 111, + 109, 112, 105, 108, 101, 114, 032, 057, 046, 051, 048, 046, 056, 052, 048, + 048, 046, 048, 000, 171, 073, 083, 071, 078, 104, 000, 000, 000, 003, 000, + 000, 000, 008, 000, 000, 000, 080, 000, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 003, 000, 000, 000, 000, 000, 000, 000, 015, 015, 000, 000, + 089, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 003, 000, 000, + 000, 001, 000, 000, 000, 015, 015, 000, 000, 095, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 002, 000, 000, 000, 003, + 003, 000, 000, 080, 079, 083, 073, 084, 073, 079, 078, 000, 067, 079, 076, + 079, 082, 000, 084, 069, 088, 067, 079, 079, 082, 068, 000, 079, 083, 071, + 078, 108, 000, 000, 000, 003, 000, 000, 000, 008, 000, 000, 000, 080, 000, + 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 003, 000, 000, 000, 000, + 000, 000, 000, 015, 000, 000, 000, 092, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 003, 000, 000, 000, 001, 000, 000, 000, 015, 000, 000, + 000, 098, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 003, 000, + 000, 000, 002, 000, 000, 000, 003, 012, 000, 000, 083, 086, 095, 080, 079, + 083, 073, 084, 073, 079, 078, 000, 067, 079, 076, 079, 082, 000, 084, 069, + 088, 067, 079, 079, 082, 068, 000, 171, 044, 003, 000, 000, 068, 088, 066, + 067, 025, 072, 003, 020, 255, 152, 205, 017, 113, 110, 162, 086, 146, 094, + 200, 041, 001, 000, 000, 000, 044, 003, 000, 000, 006, 000, 000, 000, 056, + 000, 000, 000, 192, 000, 000, 000, 092, 001, 000, 000, 216, 001, 000, 000, + 132, 002, 000, 000, 248, 002, 000, 000, 065, 111, 110, 057, 128, 000, 000, + 000, 128, 000, 000, 000, 000, 002, 255, 255, 088, 000, 000, 000, 040, 000, + 000, 000, 000, 000, 040, 000, 000, 000, 040, 000, 000, 000, 040, 000, 001, + 000, 036, 000, 000, 000, 040, 000, 000, 000, 000, 000, 000, 002, 255, 255, + 031, 000, 000, 002, 000, 000, 000, 128, 000, 000, 015, 176, 031, 000, 000, + 002, 000, 000, 000, 128, 001, 000, 003, 176, 031, 000, 000, 002, 000, 000, + 000, 144, 000, 008, 015, 160, 066, 000, 000, 003, 000, 000, 015, 128, 001, + 000, 228, 176, 000, 008, 228, 160, 005, 000, 000, 003, 000, 000, 015, 128, + 000, 000, 228, 128, 000, 000, 228, 176, 001, 000, 000, 002, 000, 008, 015, + 128, 000, 000, 228, 128, 255, 255, 000, 000, 083, 072, 068, 082, 148, 000, + 000, 000, 064, 000, 000, 000, 037, 000, 000, 000, 090, 000, 000, 003, 000, + 096, 016, 000, 000, 000, 000, 000, 088, 024, 000, 004, 000, 112, 016, 000, + 000, 000, 000, 000, 085, 085, 000, 000, 098, 016, 000, 003, 242, 016, 016, + 000, 001, 000, 000, 000, 098, 016, 000, 003, 050, 016, 016, 000, 002, 000, + 000, 000, 101, 000, 000, 003, 242, 032, 016, 000, 000, 000, 000, 000, 104, + 000, 000, 002, 001, 000, 000, 000, 069, 000, 000, 009, 242, 000, 016, 000, + 000, 000, 000, 000, 070, 016, 016, 000, 002, 000, 000, 000, 070, 126, 016, + 000, 000, 000, 000, 000, 000, 096, 016, 000, 000, 000, 000, 000, 056, 000, + 000, 007, 242, 032, 016, 000, 000, 000, 000, 000, 070, 014, 016, 000, 000, + 000, 000, 000, 070, 030, 016, 000, 001, 000, 000, 000, 062, 000, 000, 001, + 083, 084, 065, 084, 116, 000, 000, 000, 003, 000, 000, 000, 001, 000, 000, + 000, 000, 000, 000, 000, 003, 000, 000, 000, 001, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 082, 068, 069, 070, 164, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 000, 002, 000, 000, 000, 028, 000, 000, - 000, 000, 004, 255, 255, 000, 001, 000, 000, 115, 000, 000, 000, 092, 000, - 000, 000, 003, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 001, 000, 000, 000, - 107, 000, 000, 000, 002, 000, 000, 000, 005, 000, 000, 000, 004, 000, 000, - 000, 255, 255, 255, 255, 000, 000, 000, 000, 001, 000, 000, 000, 013, 000, - 000, 000, 084, 101, 120, 116, 117, 114, 101, 083, 097, 109, 112, 108, 101, - 114, 000, 084, 101, 120, 116, 117, 114, 101, 000, 077, 105, 099, 114, 111, - 115, 111, 102, 116, 032, 040, 082, 041, 032, 072, 076, 083, 076, 032, 083, - 104, 097, 100, 101, 114, 032, 067, 111, 109, 112, 105, 108, 101, 114, 032, - 057, 046, 051, 048, 046, 056, 052, 048, 048, 046, 048, 000, 171, 171, 073, - 083, 071, 078, 108, 000, 000, 000, 003, 000, 000, 000, 008, 000, 000, 000, - 080, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 003, 000, 000, - 000, 000, 000, 000, 000, 015, 000, 000, 000, 092, 000, 000, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 001, 000, 000, 000, 015, - 015, 000, 000, 098, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, - 003, 000, 000, 000, 002, 000, 000, 000, 003, 003, 000, 000, 083, 086, 095, - 080, 079, 083, 073, 084, 073, 079, 078, 000, 067, 079, 076, 079, 082, 000, - 084, 069, 088, 067, 079, 079, 082, 068, 000, 171, 079, 083, 071, 078, 044, - 000, 000, 000, 001, 000, 000, 000, 008, 000, 000, 000, 032, 000, 000, 000, - 000, 000, 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 000, 000, 000, - 000, 015, 000, 000, 000, 083, 086, 095, 084, 097, 114, 103, 101, 116, 000, - 171, 171 + 000, 000, 000, 000, 082, 068, 069, 070, 164, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 002, 000, 000, 000, 028, 000, 000, 000, 000, 004, + 255, 255, 000, 001, 000, 000, 115, 000, 000, 000, 092, 000, 000, 000, 003, + 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 001, 000, 000, 000, 001, 000, 000, 000, 107, 000, 000, + 000, 002, 000, 000, 000, 005, 000, 000, 000, 004, 000, 000, 000, 255, 255, + 255, 255, 000, 000, 000, 000, 001, 000, 000, 000, 013, 000, 000, 000, 084, + 101, 120, 116, 117, 114, 101, 083, 097, 109, 112, 108, 101, 114, 000, 084, + 101, 120, 116, 117, 114, 101, 000, 077, 105, 099, 114, 111, 115, 111, 102, + 116, 032, 040, 082, 041, 032, 072, 076, 083, 076, 032, 083, 104, 097, 100, + 101, 114, 032, 067, 111, 109, 112, 105, 108, 101, 114, 032, 057, 046, 051, + 048, 046, 056, 052, 048, 048, 046, 048, 000, 171, 171, 073, 083, 071, 078, + 108, 000, 000, 000, 003, 000, 000, 000, 008, 000, 000, 000, 080, 000, 000, + 000, 000, 000, 000, 000, 001, 000, 000, 000, 003, 000, 000, 000, 000, 000, + 000, 000, 015, 000, 000, 000, 092, 000, 000, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 003, 000, 000, 000, 001, 000, 000, 000, 015, 015, 000, 000, + 098, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 003, 000, 000, + 000, 002, 000, 000, 000, 003, 003, 000, 000, 083, 086, 095, 080, 079, 083, + 073, 084, 073, 079, 078, 000, 067, 079, 076, 079, 082, 000, 084, 069, 088, + 067, 079, 079, 082, 068, 000, 171, 079, 083, 071, 078, 044, 000, 000, 000, + 001, 000, 000, 000, 008, 000, 000, 000, 032, 000, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 003, 000, 000, 000, 000, 000, 000, 000, 015, 000, + 000, 000, 083, 086, 095, 084, 097, 114, 103, 101, 116, 000, 171, 171 }; #endregion //SpriteBatchShader diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/SwapChainMetro.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/SwapChainMetro.cs index 564a3455..24469f7d 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/SwapChainMetro.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/SwapChainMetro.cs @@ -71,7 +71,7 @@ namespace ANX.RenderSystem.Windows.Metro var comWindow = new ComObject(gameWindow.Form); swapChain = dxgiFactory2.CreateSwapChainForCoreWindow(graphicsDevice.NativeDevice, - comWindow, ref desc, null); + comWindow, ref desc, null); dxgiDevice2.MaximumFrameLatency = 1; } } diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/Texture2D_Metro.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/Texture2D_Metro.cs index 3ad865a4..05fa8753 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/Texture2D_Metro.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/Texture2D_Metro.cs @@ -15,60 +15,20 @@ namespace ANX.RenderSystem.Windows.Metro public class Texture2D_Metro : INativeTexture2D { #region Private - protected internal Dx11.Texture2D nativeTexture; - protected internal Dx11.ShaderResourceView nativeShaderResourceView; - protected internal int formatSize; - protected internal SurfaceFormat surfaceFormat; - protected internal GraphicsDevice graphicsDevice; + protected internal Dx11.Texture2D NativeTexture; + protected internal Dx11.ShaderResourceView NativeShaderResourceView; + protected int formatSize; + protected SurfaceFormat surfaceFormat; + protected GraphicsDevice graphicsDevice; #endregion #region Public - internal Dx11.Texture2D NativeTexture - { - get - { - return nativeTexture; - } - set - { - if (nativeTexture != value) - { - if (nativeTexture != null) - { - nativeTexture.Dispose(); - } - - nativeTexture = value; - } - } - } - - internal Dx11.ShaderResourceView NativeShaderResourceView - { - get - { - return this.nativeShaderResourceView; - } - set - { - if (nativeShaderResourceView != value) - { - if (nativeShaderResourceView != null) - { - nativeShaderResourceView.Dispose(); - } - - nativeShaderResourceView = value; - } - } - } - public int Width { get { - return nativeTexture != null ? - nativeTexture.Description.Width : + return NativeTexture != null ? + NativeTexture.Description.Width : 0; } } @@ -77,23 +37,15 @@ namespace ANX.RenderSystem.Windows.Metro { get { - return nativeTexture != null ? - nativeTexture.Description.Height : + return NativeTexture != null ? + NativeTexture.Description.Height : 0; } } - - public GraphicsDevice GraphicsDevice - { - get - { - return graphicsDevice; - } - } #endregion #region Constructor - internal Texture2D_Metro(GraphicsDevice graphicsDevice) + protected Texture2D_Metro(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; } @@ -125,8 +77,8 @@ namespace ANX.RenderSystem.Windows.Metro CpuAccessFlags = Dx11.CpuAccessFlags.Write, OptionFlags = Dx11.ResourceOptionFlags.None, }; - this.nativeTexture = new Dx11.Texture2D(device, description); - this.nativeShaderResourceView = new Dx11.ShaderResourceView(device, this.nativeTexture); + this.NativeTexture = new Dx11.Texture2D(device, description); + this.NativeShaderResourceView = new Dx11.ShaderResourceView(device, 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 @@ -171,7 +123,7 @@ namespace ANX.RenderSystem.Windows.Metro if (this.surfaceFormat == SurfaceFormat.Color) { int subresource = Dx11.Texture2D.CalculateSubResourceIndex(0, 0, 1); - SharpDX.DataBox rectangle = NativeDxDevice.Current.MapSubresource(nativeTexture, subresource); + SharpDX.DataBox rectangle = NativeDxDevice.Current.MapSubresource(NativeTexture, subresource); int rowPitch = rectangle.RowPitch; unsafe @@ -199,7 +151,7 @@ namespace ANX.RenderSystem.Windows.Metro handle.Free(); } - NativeDxDevice.Current.UnmapSubresource(nativeTexture, subresource); + NativeDxDevice.Current.UnmapSubresource(NativeTexture, subresource); } else if (surfaceFormat == SurfaceFormat.Dxt5 || surfaceFormat == SurfaceFormat.Dxt3 || surfaceFormat == SurfaceFormat.Dxt1) { @@ -214,7 +166,7 @@ namespace ANX.RenderSystem.Windows.Metro int subresource = Dx11.Texture2D.CalculateSubResourceIndex(0, 0, 1); SharpDX.DataBox rectangle = - NativeDxDevice.Current.MapSubresource(nativeTexture, subresource); + NativeDxDevice.Current.MapSubresource(NativeTexture, subresource); SharpDX.DataStream ds = new SharpDX.DataStream(rectangle.DataPointer, Width * Height * 4 * 2, true, true); int pitch = rectangle.RowPitch; int col = 0; @@ -249,7 +201,7 @@ namespace ANX.RenderSystem.Windows.Metro handle.Free(); - NativeDxDevice.Current.UnmapSubresource(nativeTexture, subresource); + NativeDxDevice.Current.UnmapSubresource(NativeTexture, subresource); } } else @@ -262,16 +214,16 @@ namespace ANX.RenderSystem.Windows.Metro #region Dispose public void Dispose() { - if (nativeShaderResourceView != null) + if (NativeShaderResourceView != null) { - nativeShaderResourceView.Dispose(); - nativeShaderResourceView = null; + NativeShaderResourceView.Dispose(); + NativeShaderResourceView = null; } - if (nativeTexture != null) + if (NativeTexture != null) { - nativeTexture.Dispose(); - nativeTexture = null; + NativeTexture.Dispose(); + NativeTexture = null; } } #endregion diff --git a/Samples/WindowsGame/WindowsGame_Linux.csproj b/Samples/WindowsGame/WindowsGame_Linux.csproj index 6ff3250f..358be1d0 100644 --- a/Samples/WindowsGame/WindowsGame_Linux.csproj +++ b/Samples/WindowsGame/WindowsGame_Linux.csproj @@ -142,6 +142,10 @@ {97185A92-077D-4498-8B6A-8BFF04079044} ANX.MediaSystem.Windows.OpenAL + + {068EB2E9-963C-4E1B-8831-E25011F11FFE} + ANX.PlatformSystem.Windows + {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 diff --git a/Samples/WindowsGame/WindowsGame_PSVita.csproj b/Samples/WindowsGame/WindowsGame_PSVita.csproj index 3e9f5750..807a7e91 100644 --- a/Samples/WindowsGame/WindowsGame_PSVita.csproj +++ b/Samples/WindowsGame/WindowsGame_PSVita.csproj @@ -144,6 +144,10 @@ {97185A92-077D-4498-8B6A-8BFF04079044} ANX.MediaSystem.Windows.OpenAL + + {068EB2E9-963C-4E1B-8831-E25011F11FFE} + ANX.PlatformSystem.Windows + {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 diff --git a/Tools/DX11MetroShaderGenerator/MetroCodeGenerator.cs b/Tools/DX11MetroShaderGenerator/MetroCodeGenerator.cs index 46ff77f8..2a81e31f 100644 --- a/Tools/DX11MetroShaderGenerator/MetroCodeGenerator.cs +++ b/Tools/DX11MetroShaderGenerator/MetroCodeGenerator.cs @@ -135,7 +135,13 @@ namespace DX11MetroShaderGenerator foreach (Variable variable in sourceEffect.Variables) { writer.Write(variable.Type); - writer.Write(variable.Name); + writer.Write(variable.Name); + writer.Write(variable.ArraySize); + writer.Write((byte)variable.Dimensions.Length); + for (int dimIndex = 0; dimIndex < variable.Dimensions.Length; dimIndex++) + { + writer.Write((byte)variable.Dimensions[dimIndex]); + } } } #endregion