Ejemplo n.º 1
0
        protected void ShowMaterial(params object[] materialContents)
        {
            Test(() =>
            {
                Queue <string> assets = new Queue <string>();
                foreach (var materialContent in materialContents)
                {
                    assets.Enqueue(BuildObjectUsingDefaultContentProcessor(materialContent));
                }
                BuildFont("Consolas.spritefont");
                BuildTexture("box.dds");
                BuildNormalMap("box_n.dds");
                RunTheBuild();

                var spriteBatch = new SpriteBatch(GraphicsDevice);
                var scene       = new Scene(GraphicsDevice);
                var surface     = new DrawableSurface(GraphicsDevice, 1, 64, 64, 8)
                {
                    Position = new Vector3(-32, -32, 0)
                };
                surface.ConvertVertexType <VertexPositionNormalTangentBinormalTexture>(InitializeSurfaceVertices);
                scene.Camera = new TopDownEditorCamera(GraphicsDevice)
                {
                    Radius = 100
                };
                scene.Add(surface);
                scene.Add(new Nine.Graphics.ObjectModel.DirectionalLight(GraphicsDevice));

                foreach (var materialContent in materialContents)
                {
                    surface.Material = Content.Load <Material>(assets.Dequeue());

                    SaveScreenShot(materialContent.GetType().Name, () =>
                    {
                        scene.Draw(TimeSpan.Zero);

                        DrawDescription(spriteBatch, materialContent);
                    });
                }
                scene.Dispose();
                spriteBatch.Dispose();
            });
        }
Ejemplo n.º 2
0
        /// <param name="materialContents">Material contents to be tested in pair.</param>
        private void MaterialEqualityTest(bool equals, double errorCap, params object[] materialContents)
        {
            Test(() =>
            {
                Queue <string> assets = new Queue <string>();
                foreach (var materialContent in materialContents)
                {
                    assets.Enqueue(BuildObjectUsingDefaultContentProcessor(materialContent));
                }
                foreach (var materialContent in materialContents)
                {
                    assets.Enqueue(BuildObjectUsingDefaultContentProcessor(GetDeferredMaterialContent(materialContent)));
                }
                BuildFont("Consolas.spritefont");
                BuildTexture("box.dds");
                BuildNormalMap("box_n.dds");
                RunTheBuild();

                var spriteBatch = new SpriteBatch(GraphicsDevice);
                var scene       = new Scene(GraphicsDevice);
                var surface     = new DrawableSurface(GraphicsDevice, 1, 64, 64, 8)
                {
                    Position = new Vector3(-32, -32, 0)
                };
                surface.ConvertVertexType <VertexPositionNormalTangentBinormalTexture>(InitializeSurfaceVertices);
                var backgroundColor            = RandomColor(0, 0.3f);
                scene.Settings.BackgroundColor = backgroundColor;
                scene.Camera = new TopDownEditorCamera(GraphicsDevice)
                {
                    Radius = 100
                };
                scene.Add(surface);
                scene.Add(new AmbientLight(GraphicsDevice)
                {
                    AmbientLightColor = RandomColor(0, 0.2f).ToVector3()
                });
                scene.Add(new Nine.Graphics.ObjectModel.DirectionalLight(GraphicsDevice)
                {
                    DiffuseColor  = LightDiffuseColor,
                    SpecularColor = LightSpecularColor,
                });
                if (FogEnabled)
                {
                    scene.Add(new Fog()
                    {
                        FogColor = FogColor, FogEnabled = true, FogStart = 0.1f, FogEnd = 200.0f
                    });
                }

                for (int i = 0; i < materialContents.Length /* * 2 */; i += 2)
                {
                    var material1 = Content.Load <Material>(assets.Dequeue());
                    var material2 = Content.Load <Material>(assets.Dequeue());

                    var file1 = material1.GetType().Name;
                    var file2 = material2.GetType().Name;

                    surface.Material = material1;
                    var result1      = SaveScreenShot(ref file1,
                                                      () => { scene.Draw(TimeSpan.Zero); },
                                                      () => { DrawDescription(spriteBatch, GetDeferredMaterialContent(materialContents[i % materialContents.Length], i >= materialContents.Length)); });

                    surface.Material = material2;
                    var result2      = SaveScreenShot(ref file2,
                                                      () => { scene.Draw(TimeSpan.Zero); },
                                                      () => { DrawDescription(spriteBatch, GetDeferredMaterialContent(materialContents[(i + 1) % materialContents.Length], i >= materialContents.Length)); });

                    bool compareResult = TextureEquals(result1, result2, errorCap) ^ equals;

                    result1.Dispose();
                    result2.Dispose();

                    if (compareResult)
                    {
#if DEBUG
                        ShowImage(file1);
                        ShowImage(file2);
#endif
                    }
                    Assert.IsFalse(compareResult);
                }
                scene.Dispose();
            });
        }