diff --git a/Myre/Myre.Debugging.UI/(360) Myre.Debugging.UI.ncrunchproject b/Myre/Myre.Debugging.UI/(360) Myre.Debugging.UI.ncrunchproject new file mode 100644 index 00000000..575717ac --- /dev/null +++ b/Myre/Myre.Debugging.UI/(360) Myre.Debugging.UI.ncrunchproject @@ -0,0 +1,20 @@ + + false + false + false + true + false + false + false + false + true + true + false + true + true + 60000 + + + + AutoDetect + \ No newline at end of file diff --git a/Myre/Myre.Debugging/(360) Myre.Debugging.ncrunchproject b/Myre/Myre.Debugging/(360) Myre.Debugging.ncrunchproject new file mode 100644 index 00000000..575717ac --- /dev/null +++ b/Myre/Myre.Debugging/(360) Myre.Debugging.ncrunchproject @@ -0,0 +1,20 @@ + + false + false + false + true + false + false + false + false + true + true + false + true + true + 60000 + + + + AutoDetect + \ No newline at end of file diff --git a/Myre/Myre.Entities/(360) Myre.Entities.ncrunchproject b/Myre/Myre.Entities/(360) Myre.Entities.ncrunchproject new file mode 100644 index 00000000..575717ac --- /dev/null +++ b/Myre/Myre.Entities/(360) Myre.Entities.ncrunchproject @@ -0,0 +1,20 @@ + + false + false + false + true + false + false + false + false + true + true + false + true + true + 60000 + + + + AutoDetect + \ No newline at end of file diff --git a/Myre/Myre.Graphics/Geometry/ModelInstance.cs b/Myre/Myre.Graphics/Geometry/ModelInstance.cs index e5ce4a15..08d4da02 100644 --- a/Myre/Myre.Graphics/Geometry/ModelInstance.cs +++ b/Myre/Myre.Graphics/Geometry/ModelInstance.cs @@ -66,6 +66,8 @@ class MeshInstance public BoundingSphere Bounds { get; private set; } + public Matrix WorldView; + public void UpdateBounds() { Bounds = Mesh.BoundingSphere.Transform(Instance.Transform); @@ -165,6 +167,11 @@ public void Draw(string phase, BoxedValueStore metadata) foreach (var item in buffer) item.IsVisible = true & !item.Instance.IsInvisible; + var view = metadata.Get("view"); + CalculateWorldViews(meshes, ref view.Value); //Calculate WorldView for all mesh instances + + DepthSortMeshes(meshes); //Sort batches by first item in batch + foreach (var mesh in meshes) { foreach (var instance in mesh.Instances) @@ -185,6 +192,32 @@ public void Draw(string phase, BoxedValueStore metadata) buffer.Clear(); } + private void DepthSortMeshes(List meshes) + { + meshes.Sort(RenderDataComparator); + } + + private int RenderDataComparator(MeshRenderData a, MeshRenderData b) + { + if (a.Instances.Count > 0 && b.Instances.Count > 0) + return CompareWorldViews(ref a.Instances[0].WorldView, ref b.Instances[0].WorldView); + return a.Instances.Count.CompareTo(b.Instances.Count); + } + + private void CalculateWorldViews(List batches, ref Matrix view) + { + for (int b = 0; b < batches.Count; b++) + { + var instances = batches[b].Instances; + for (int i = 0; i < instances.Count; i++) + { + var instance = instances[i]; + Matrix world = instance.Instance.Transform; + Matrix.Multiply(ref world, ref view, out instance.WorldView); + } + } + } + private void QueryVisible(BoundingVolume volume, List instances) { cullableBuffer.Clear(); @@ -212,11 +245,12 @@ private void DrawMesh(MeshRenderData data, BoxedValueStore metadata) device.Indices = mesh.IndexBuffer; var world = metadata.Get("world"); - var view = metadata.Get("view"); var projection = metadata.Get("projection"); var worldView = metadata.Get("worldview"); var worldViewProjection = metadata.Get("worldviewprojection"); + DepthSortInstances(visibleInstances); + int maxPrimitives = device.GraphicsProfile == GraphicsProfile.HiDef ? 1048575 : 65535; for (int i = 0; i < visibleInstances.Count; i++) @@ -224,7 +258,7 @@ private void DrawMesh(MeshRenderData data, BoxedValueStore metadata) var instance = visibleInstances[i]; world.Value = instance.Instance.Transform; - Matrix.Multiply(ref world.Value, ref view.Value, out worldView.Value); + worldView.Value = instance.WorldView; Matrix.Multiply(ref worldView.Value, ref projection.Value, out worldViewProjection.Value); foreach (var pass in data.Material.Begin(metadata)) @@ -255,6 +289,23 @@ private void DrawMesh(MeshRenderData data, BoxedValueStore metadata) } } + private void DepthSortInstances(List instances) + { + if (instances.Count > 1) + instances.Sort(InstanceComparator); + } + + private int InstanceComparator(MeshInstance a, MeshInstance b) + { + return CompareWorldViews(ref a.WorldView, ref b.WorldView); + } + + public static int CompareWorldViews(ref Matrix worldViewA, ref Matrix worldViewB) + { + //Negated, because XNA uses a negative Z space + return -worldViewA.Translation.Z.CompareTo(worldViewB.Translation.Z); + } + private List GetInstanceList(Mesh mesh) { List value; diff --git a/Myre/Myre.Physics2D/(x86) Myre.Physics2D.ncrunchproject b/Myre/Myre.Physics2D/(x86) Myre.Physics2D.ncrunchproject new file mode 100644 index 00000000..8641d361 --- /dev/null +++ b/Myre/Myre.Physics2D/(x86) Myre.Physics2D.ncrunchproject @@ -0,0 +1,19 @@ + + false + false + false + true + false + false + false + false + true + true + false + true + true + 60000 + + + AutoDetect + \ No newline at end of file diff --git a/Myre/Myre.Serialisation/(x86) Myre.Serialisation.ncrunchproject b/Myre/Myre.Serialisation/(x86) Myre.Serialisation.ncrunchproject new file mode 100644 index 00000000..575717ac --- /dev/null +++ b/Myre/Myre.Serialisation/(x86) Myre.Serialisation.ncrunchproject @@ -0,0 +1,20 @@ + + false + false + false + true + false + false + false + false + true + true + false + true + true + 60000 + + + + AutoDetect + \ No newline at end of file diff --git a/Myre/Myre.StateManagement/(360) Myre.StateManagement.ncrunchproject b/Myre/Myre.StateManagement/(360) Myre.StateManagement.ncrunchproject new file mode 100644 index 00000000..575717ac --- /dev/null +++ b/Myre/Myre.StateManagement/(360) Myre.StateManagement.ncrunchproject @@ -0,0 +1,20 @@ + + false + false + false + true + false + false + false + false + true + true + false + true + true + 60000 + + + + AutoDetect + \ No newline at end of file diff --git a/Myre/Myre.UI/(360) Myre.UI.ncrunchproject b/Myre/Myre.UI/(360) Myre.UI.ncrunchproject new file mode 100644 index 00000000..575717ac --- /dev/null +++ b/Myre/Myre.UI/(360) Myre.UI.ncrunchproject @@ -0,0 +1,20 @@ + + false + false + false + true + false + false + false + false + true + true + false + true + true + 60000 + + + + AutoDetect + \ No newline at end of file diff --git a/Myre/Myre/(360) Myre.ncrunchproject b/Myre/Myre/(360) Myre.ncrunchproject new file mode 100644 index 00000000..575717ac --- /dev/null +++ b/Myre/Myre/(360) Myre.ncrunchproject @@ -0,0 +1,20 @@ + + false + false + false + true + false + false + false + false + true + true + false + true + true + 60000 + + + + AutoDetect + \ No newline at end of file diff --git a/Testing/Myre.Serialisation.Tests/Myre.Serialisation.Tests.ncrunchproject b/Testing/Myre.Serialisation.Tests/Myre.Serialisation.Tests.ncrunchproject new file mode 100644 index 00000000..575717ac --- /dev/null +++ b/Testing/Myre.Serialisation.Tests/Myre.Serialisation.Tests.ncrunchproject @@ -0,0 +1,20 @@ + + false + false + false + true + false + false + false + false + true + true + false + true + true + 60000 + + + + AutoDetect + \ No newline at end of file diff --git a/Testing/Myre.Testing.ncrunchsolution b/Testing/Myre.Testing.ncrunchsolution index c1a8525e..f2e00196 100644 --- a/Testing/Myre.Testing.ncrunchsolution +++ b/Testing/Myre.Testing.ncrunchsolution @@ -1,7 +1,8 @@ - 0 - Default - false + 1 + True + true + true UseDynamicAnalysis UseStaticAnalysis UseStaticAnalysis diff --git a/Testing/Myre.Testing.sln b/Testing/Myre.Testing.sln index 5da45d78..0dd77644 100644 --- a/Testing/Myre.Testing.sln +++ b/Testing/Myre.Testing.sln @@ -50,6 +50,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Myre.Serialisation.Tests", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "(x86) Myre.Serialisation", "..\Myre\Myre.Serialisation\(x86) Myre.Serialisation.csproj", "{73911D37-4250-40BD-8F15-20824D586319}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Myre.Tests", "Myre.Tests\Myre.Tests.csproj", "{523C09C2-B475-4CCC-9CCE-C19B54E4C829}" +EndProject Global GlobalSection(TestCaseManagementSettings) = postSolution CategoryFile = Myre.Testing.vsmdi @@ -450,6 +452,24 @@ Global {73911D37-4250-40BD-8F15-20824D586319}.Release|x86.ActiveCfg = Release|x86 {73911D37-4250-40BD-8F15-20824D586319}.Release|x86.Build.0 = Release|x86 {73911D37-4250-40BD-8F15-20824D586319}.Release|Xbox 360.ActiveCfg = Release|x86 + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|Any CPU.Build.0 = Debug|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|x86.ActiveCfg = Debug|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|Xbox 360.ActiveCfg = Debug|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|Any CPU.ActiveCfg = Release|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|Any CPU.Build.0 = Release|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|Mixed Platforms.ActiveCfg = Release|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|Mixed Platforms.Build.0 = Release|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|x86.ActiveCfg = Release|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|Xbox 360.ActiveCfg = Release|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|Any CPU.ActiveCfg = Release|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|Any CPU.Build.0 = Release|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|x86.ActiveCfg = Release|Any CPU + {523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|Xbox 360.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Testing/Myre.Tests/Myre.Tests.csproj b/Testing/Myre.Tests/Myre.Tests.csproj new file mode 100644 index 00000000..66002638 --- /dev/null +++ b/Testing/Myre.Tests/Myre.Tests.csproj @@ -0,0 +1,77 @@ + + + + Debug + AnyCPU + + + 2.0 + {523C09C2-B475-4CCC-9CCE-C19B54E4C829} + Library + Properties + Myre.Tests + Myre.Tests + v4.0 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + 3.5 + + + + + False + + + + + + + + + + + + {5CDABE8C-7C9C-4163-8C85-FEA731088239} + %28x86%29 Myre.Entities + + + {FC3D8E34-3333-42FB-9B47-3A273B1B50D8} + %28x86%29 Myre.Graphics + + + {FDB5A9D8-9266-4F7B-BDE7-D4E720F5B45F} + %28x86%29 Myre + + + + + \ No newline at end of file diff --git a/Testing/Myre.Tests/Myre.Tests.ncrunchproject b/Testing/Myre.Tests/Myre.Tests.ncrunchproject new file mode 100644 index 00000000..575717ac --- /dev/null +++ b/Testing/Myre.Tests/Myre.Tests.ncrunchproject @@ -0,0 +1,20 @@ + + false + false + false + true + false + false + false + false + true + true + false + true + true + 60000 + + + + AutoDetect + \ No newline at end of file diff --git a/Testing/Myre.Tests/Properties/AssemblyInfo.cs b/Testing/Myre.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..0c136c29 --- /dev/null +++ b/Testing/Myre.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Myre.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Myre.Tests")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("743c3471-b9af-4933-b6c9-16d7b6fa5fc9")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// 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.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Testing/Myre.Tests/UnitTest1.cs b/Testing/Myre.Tests/UnitTest1.cs new file mode 100644 index 00000000..b1ced089 --- /dev/null +++ b/Testing/Myre.Tests/UnitTest1.cs @@ -0,0 +1,22 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.Xna.Framework; +using Myre.Graphics.Geometry; +using TestAssert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; + +namespace Myre.Tests +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void DepthSort() + { + var view = Matrix.CreateLookAt(Vector3.Zero, Vector3.UnitX, Vector3.Up); + + Matrix worldViewA = Matrix.CreateTranslation(10, 0, 0) * view; + Matrix worldViewB = Matrix.CreateTranslation(20, 0, 0) * view; + + TestAssert.AreEqual(-1, ModelInstance.Manager.CompareWorldViews(ref worldViewA, ref worldViewB)); + } + } +} diff --git a/Testing/Myre.Tests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Testing/Myre.Tests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 00000000..0972327b Binary files /dev/null and b/Testing/Myre.Tests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/Testing/_NCrunch_Myre.Testing/Myre.Testing.crunchsolution.cache b/Testing/_NCrunch_Myre.Testing/Myre.Testing.crunchsolution.cache new file mode 100644 index 00000000..afb90428 Binary files /dev/null and b/Testing/_NCrunch_Myre.Testing/Myre.Testing.crunchsolution.cache differ