diff --git a/ANX.Framework/Graphics/GraphicsDevice.cs b/ANX.Framework/Graphics/GraphicsDevice.cs index 89507935..807b11c3 100644 --- a/ANX.Framework/Graphics/GraphicsDevice.cs +++ b/ANX.Framework/Graphics/GraphicsDevice.cs @@ -413,7 +413,8 @@ namespace ANX.Framework.Graphics } set { - this.viewport = value; + this.viewport = value; + NativeDevice.SetViewport(this.viewport); //TODO: this is not optimal... } } diff --git a/ANX.Framework/Graphics/SpriteBatch.cs b/ANX.Framework/Graphics/SpriteBatch.cs index d110d9a8..7b6eb776 100644 --- a/ANX.Framework/Graphics/SpriteBatch.cs +++ b/ANX.Framework/Graphics/SpriteBatch.cs @@ -644,7 +644,7 @@ namespace ANX.Framework.Graphics else if (hash1 < hash2) return 1; - return 0; + return y.layerDepth.CompareTo(x.layerDepth); } } diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX10/GraphicsDeviceDX.cs b/RenderSystems/ANX.RenderSystem.Windows.DX10/GraphicsDeviceDX.cs index 9876ac4b..c9f1161f 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX10/GraphicsDeviceDX.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.DX10/GraphicsDeviceDX.cs @@ -260,10 +260,19 @@ namespace ANX.RenderSystem.Windows.DX10 nativeDevice.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings); DxIndexBuffer idx10 = new DxIndexBuffer(nativeDevice, indexFormat, indexCount, BufferUsage.None); - if (indexData.GetType() == typeof(Int16[])) + IndexElementSize indexElementSize; + if (indexData.GetType() == typeof(Int16[])) + { idx10.SetData(null, (short[])indexData); + indexElementSize = IndexElementSize.SixteenBits; + } else + { idx10.SetData(null, (int[])indexData); + indexElementSize = IndexElementSize.ThirtyTwoBits; + } + + nativeDevice.InputAssembler.SetIndexBuffer(idx10.NativeBuffer, DxFormatConverter.Translate(indexElementSize), 0); DrawIndexedPrimitives(primitiveType, 0, vertexOffset, numVertices, indexOffset, primitiveCount); } diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX10/Properties/AssemblyInfo.cs b/RenderSystems/ANX.RenderSystem.Windows.DX10/Properties/AssemblyInfo.cs index e52aa9fb..187d6b72 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX10/Properties/AssemblyInfo.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.DX10/Properties/AssemblyInfo.cs @@ -32,7 +32,7 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.7.17.0")] -[assembly: AssemblyFileVersion("0.7.17.0")] +[assembly: AssemblyVersion("0.7.18.*")] +[assembly: AssemblyFileVersion("0.7.18.0")] [assembly: InternalsVisibleTo("ANX.Framework.ContentPipeline")] diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/GraphicsDeviceDX.cs b/RenderSystems/ANX.RenderSystem.Windows.DX11/GraphicsDeviceDX.cs index 18b86a81..a0a17cb5 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/GraphicsDeviceDX.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/GraphicsDeviceDX.cs @@ -275,11 +275,20 @@ namespace ANX.RenderSystem.Windows.DX11 nativeDevice.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings); - DxIndexBuffer idx10 = new DxIndexBuffer(nativeDevice.Device, indexFormat, indexCount, BufferUsage.None); + DxIndexBuffer idx11 = new DxIndexBuffer(nativeDevice.Device, indexFormat, indexCount, BufferUsage.None); + IndexElementSize indexElementSize; if (indexData.GetType() == typeof(Int16[])) - idx10.SetData(null, (short[])indexData); + { + idx11.SetData(null, (short[])indexData); + indexElementSize = IndexElementSize.SixteenBits; + } else - idx10.SetData(null, (int[])indexData); + { + idx11.SetData(null, (int[])indexData); + indexElementSize = IndexElementSize.ThirtyTwoBits; + } + + nativeDevice.InputAssembler.SetIndexBuffer(idx11.NativeBuffer, DxFormatConverter.Translate(indexElementSize), 0); DrawIndexedPrimitives(primitiveType, 0, vertexOffset, numVertices, indexOffset, primitiveCount); } diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/Properties/AssemblyInfo.cs b/RenderSystems/ANX.RenderSystem.Windows.DX11/Properties/AssemblyInfo.cs index 71e813f8..44d3cea9 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/Properties/AssemblyInfo.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Buildnummer // Revision // -[assembly: AssemblyVersion("0.7.9.0")] -[assembly: AssemblyFileVersion("0.7.9.0")] +[assembly: AssemblyVersion("0.7.10.*")] +[assembly: AssemblyFileVersion("0.7.10.0")] diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/GraphicsDeviceWindowsMetro.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/GraphicsDeviceWindowsMetro.cs index 707160a5..6b6e1f82 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/GraphicsDeviceWindowsMetro.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/GraphicsDeviceWindowsMetro.cs @@ -177,15 +177,20 @@ namespace ANX.RenderSystem.Windows.Metro NativeDevice.NativeContext.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings); IndexBuffer_Metro idxMetro = new IndexBuffer_Metro(NativeDevice.NativeDevice, indexFormat, indexCount, BufferUsage.None); + IndexElementSize indexElementSize; if (indexData.GetType() == typeof(Int16[])) { idxMetro.SetData(null, (short[])indexData); + indexElementSize = IndexElementSize.SixteenBits; } else { idxMetro.SetData(null, (int[])indexData); + indexElementSize = IndexElementSize.ThirtyTwoBits; } + NativeDevice.NativeContext.InputAssembler.SetIndexBuffer(idxMetro.NativeBuffer, FormatConverter.Translate(indexElementSize), 0); + DrawIndexedPrimitives(primitiveType, 0, vertexOffset, numVertices, indexOffset, primitiveCount); } diff --git a/RenderSystems/ANX.RenderSystem.Windows.Metro/Properties/AssemblyInfo.cs b/RenderSystems/ANX.RenderSystem.Windows.Metro/Properties/AssemblyInfo.cs index 87f8b076..bade8c4e 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.Metro/Properties/AssemblyInfo.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.Metro/Properties/AssemblyInfo.cs @@ -24,6 +24,6 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.5.*")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.2.6.*")] +[assembly: AssemblyFileVersion("0.2.6.0")] [assembly: GuidAttribute("855A261E-DB66-4CB2-97F3-34BC9DA4DAA1")] diff --git a/Samples/Primitives/Game1.cs b/Samples/Primitives/Game1.cs index 25b6c798..3b69884c 100644 --- a/Samples/Primitives/Game1.cs +++ b/Samples/Primitives/Game1.cs @@ -41,6 +41,9 @@ namespace Primitives VertexBuffer cubeVertexBuffer; IndexBuffer cubeIndexBuffer; + bool[] enabled = new bool[] { true, true, true, true, true }; + KeyboardState lastKeyState; + #region Corners of cube static Vector3 topLeftFront = new Vector3( -1.0f, 1.0f, 1.0f ); static Vector3 bottomLeftFront = new Vector3(-1.0f, -1.0f, 1.0f); @@ -158,6 +161,8 @@ namespace Primitives protected override void Initialize() { base.Initialize(); + + lastKeyState = Keyboard.GetState(); } protected override void LoadContent() @@ -215,6 +220,25 @@ namespace Primitives this.worldMatrix = Matrix.CreateRotationY(rotation); + KeyboardState keyState = Keyboard.GetState(); + + if (keyState.IsKeyDown(Keys.D1) && !lastKeyState.IsKeyDown(Keys.D1)) + enabled[0] = !enabled[0]; + + if (keyState.IsKeyDown(Keys.D2) && !lastKeyState.IsKeyDown(Keys.D2)) + enabled[1] = !enabled[1]; + + if (keyState.IsKeyDown(Keys.D3) && !lastKeyState.IsKeyDown(Keys.D3)) + enabled[2] = !enabled[2]; + + if (keyState.IsKeyDown(Keys.D4) && !lastKeyState.IsKeyDown(Keys.D4)) + enabled[3] = !enabled[3]; + + if (keyState.IsKeyDown(Keys.D5) && !lastKeyState.IsKeyDown(Keys.D5)) + enabled[4] = !enabled[4]; + + lastKeyState = keyState; + base.Update(gameTime); } @@ -231,11 +255,11 @@ namespace Primitives spriteBatch.Draw(bgTexture, new Rectangle(0, 400, 300, 200), Color.Green); spriteBatch.Draw(bgTexture, new Rectangle(300, 400, 300, 200), Color.LightSeaGreen); - DrawShadowText(spriteBatch, this.font, "DrawInstancedPrimitives", new Vector2(10, 10), Color.White, Color.Black); - DrawShadowText(spriteBatch, this.font, "DrawPrimitives", new Vector2(10, 210), Color.White, Color.Black); - DrawShadowText(spriteBatch, this.font, "DrawIndexedPrimitives", new Vector2(310, 210), Color.White, Color.Black); - DrawShadowText(spriteBatch, this.font, "DrawUserPrimitives", new Vector2(10, 410), Color.White, Color.Black); - DrawShadowText(spriteBatch, this.font, "DrawUserIndexedPrimitives", new Vector2(310, 410), Color.White, Color.Black); + DrawShadowText(spriteBatch, this.font, "DrawInstancedPrimitives\n (press 1 to " + (enabled[0] ? "disable" : "enable") + ")" , new Vector2(10, 10), Color.White, Color.Black); + DrawShadowText(spriteBatch, this.font, "DrawPrimitives\n (press 2 to " + (enabled[1] ? "disable" : "enable") + ")", new Vector2(10, 210), Color.White, Color.Black); + DrawShadowText(spriteBatch, this.font, "DrawIndexedPrimitives\n (press 3 to " + (enabled[2] ? "disable" : "enable") + ")", new Vector2(310, 210), Color.White, Color.Black); + DrawShadowText(spriteBatch, this.font, "DrawUserPrimitives\n (press 4 to " + (enabled[3] ? "disable" : "enable") + ")", new Vector2(10, 410), Color.White, Color.Black); + DrawShadowText(spriteBatch, this.font, "DrawUserIndexedPrimitives\n (press 5 to " + (enabled[4] ? "disable" : "enable") + ")", new Vector2(310, 410), Color.White, Color.Black); spriteBatch.End(); @@ -249,49 +273,59 @@ namespace Primitives this.basicEffect.CurrentTechnique.Passes[0].Apply(); #region DrawPrimitives - GraphicsDevice.Viewport = new Viewport(0, 200, 300, 200); - - GraphicsDevice.SetVertexBuffer(this.cubeNoIndicesBuffer); - GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, cubeNoIndices.Length / 3); + if (enabled[1]) + { + GraphicsDevice.Viewport = new Viewport(0, 200, 300, 200); + GraphicsDevice.SetVertexBuffer(this.cubeNoIndicesBuffer); + GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, cubeNoIndices.Length / 3); + } #endregion // DrawPrimitives #region DrawIndexedPrimitives - GraphicsDevice.Viewport = new Viewport(300, 200, 300, 200); - - GraphicsDevice.SetVertexBuffer(this.cubeVertexBuffer); - GraphicsDevice.Indices = this.cubeIndexBuffer; - GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, cubeVertices.Length, 0, cubeNoIndices.Length / 3); + if (enabled[2]) + { + GraphicsDevice.Viewport = new Viewport(300, 200, 300, 200); + GraphicsDevice.SetVertexBuffer(this.cubeVertexBuffer); + GraphicsDevice.Indices = this.cubeIndexBuffer; + GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, cubeVertices.Length, 0, cubeNoIndices.Length / 3); + } #endregion #region DrawUserPrimitives - GraphicsDevice.Viewport = new Viewport(0, 400, 300, 200); - - GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, this.cubeNoIndices, 0, this.cubeNoIndices.Length / 3); + if (enabled[3]) + { + GraphicsDevice.Viewport = new Viewport(0, 400, 300, 200); + GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, this.cubeNoIndices, 0, this.cubeNoIndices.Length / 3); + } #endregion #region DrawUserIndexedPrimitives - GraphicsDevice.Viewport = new Viewport(300, 400, 300, 200); - - GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, this.cubeVertices, 0, this.cubeVertices.Length, this.cubeIndices, 0, this.cubeIndices.Length / 3); + if (enabled[4]) + { + GraphicsDevice.Viewport = new Viewport(300, 400, 300, 200); + GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, this.cubeVertices, 0, this.cubeVertices.Length, this.cubeIndices, 0, this.cubeIndices.Length / 3); + } #endregion #region DrawInstancedPrimitives - GraphicsDevice.Viewport = new Viewport(0, 0, 600, 200); + if (enabled[0]) + { + GraphicsDevice.Viewport = new Viewport(0, 0, 600, 200); - this.hardwareInstanceEffect.Parameters["View"].SetValue(this.instancedViewMatrix); - this.hardwareInstanceEffect.Parameters["Projection"].SetValue(this.instancedProjectionMatrix); - this.hardwareInstanceEffect.Parameters["World"].SetValue(this.worldMatrix); - this.hardwareInstanceEffect.CurrentTechnique.Passes[0].Apply(); - - instanceVertexBuffer.SetData(this.instanceTransformMatrices, 0, this.instanceTransformMatrices.Length, SetDataOptions.Discard); - GraphicsDevice.SetVertexBuffers(cubeVertexBuffer, new VertexBufferBinding(instanceVertexBuffer, 0, 1)); - GraphicsDevice.Indices = this.cubeIndexBuffer; - GraphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0, this.cubeVertices.Length, 0, this.cubeIndices.Length / 3, 5); + this.hardwareInstanceEffect.Parameters["View"].SetValue(this.instancedViewMatrix); + this.hardwareInstanceEffect.Parameters["Projection"].SetValue(this.instancedProjectionMatrix); + this.hardwareInstanceEffect.Parameters["World"].SetValue(this.worldMatrix); + this.hardwareInstanceEffect.CurrentTechnique.Passes[0].Apply(); + instanceVertexBuffer.SetData(this.instanceTransformMatrices, 0, this.instanceTransformMatrices.Length, SetDataOptions.Discard); + GraphicsDevice.SetVertexBuffers(cubeVertexBuffer, new VertexBufferBinding(instanceVertexBuffer, 0, 1)); + GraphicsDevice.Indices = this.cubeIndexBuffer; + GraphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0, this.cubeVertices.Length, 0, this.cubeIndices.Length / 3, 5); + } #endregion base.Draw(gameTime); @@ -300,8 +334,8 @@ namespace Primitives private void DrawShadowText(SpriteBatch spriteBatch, SpriteFont font, String text, Vector2 position, Color foreground, Color shadow) { - spriteBatch.DrawString(font, text, position + new Vector2(2, 2), shadow); - spriteBatch.DrawString(font, text, position, foreground); + spriteBatch.DrawString(font, text, position + new Vector2(2, 2), shadow, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); + spriteBatch.DrawString(font, text, position, foreground, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f); } } }