MaterialTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Graphics.Tests MaterialTests

Namespace: DeltaEngine.Graphics.Tests
Assembly: DeltaEngine.Graphics.Tests (in DeltaEngine.Graphics.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class MaterialTests : TestWithMocksOrVisually

The MaterialTests type exposes the following members.

Constructors

  NameDescription
Public methodMaterialTests
Initializes a new instance of the MaterialTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodCreateCustomMaterial
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodLoadSavedMaterial
Public methodLoadSavedMaterialWithClearPadding
Public methodLoadSavedMaterialWithPadding
Public methodLoadSavedMaterialWithRotation
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodSetRenderSize
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test, CloseAfterFirstFrame]
public void CreateCustomMaterial()
{
    var shader = ContentLoader.Create<Shader>(
        new ShaderCreationData(ShaderFlags.Position2DTextured));
    var image = ContentLoader.Create<Image>(new ImageCreationData(Size.One));
    var generatedMaterial = new Material(shader, image);
    Assert.IsNotNull(generatedMaterial);
    Assert.AreEqual(shader, generatedMaterial.Shader);
    Assert.IsNotNull(generatedMaterial.DiffuseMap);
    Assert.AreEqual(ScreenSpace.Current.FromPixelSpace(Size.One),
        generatedMaterial.MaterialRenderSize);
}
[Test, CloseAfterFirstFrame]
public void LoadSavedMaterial()
{
    var loadedMaterial = ContentLoader.Load<Material>("DefaultMaterial");
    Assert.AreEqual("DefaultMaterial", loadedMaterial.Name);
    Assert.IsTrue(loadedMaterial.Shader.Name.Contains(loadedMaterial.Shader.Flags.ToString()),
        loadedMaterial.Shader.Name);
    Assert.AreEqual("DeltaEngineLogo", loadedMaterial.DiffuseMap.Name);
    Assert.AreEqual(Color.White, loadedMaterial.DefaultColor);
}
[Test, CloseAfterFirstFrame]
public void LoadSavedMaterialWithPadding()
{
    var loadedMaterial = ContentLoader.Load<Material>("DefaultMaterial");
    loadedMaterial.RenderingCalculator = new RenderingCalculator(new AtlasRegion
    {
        PadLeft = 0.5f,
        PadRight = 0.5f,
        PadTop = 0.5f,
        PadBottom = 0.5f,
        IsRotated = false
    });
    RenderingData result = loadedMaterial.RenderingCalculator.GetUVAndDrawArea(
        Rectangle.HalfCentered, Rectangle.One);
    Assert.AreEqual(result.RequestedUserUV, Rectangle.HalfCentered);
}
[Test, CloseAfterFirstFrame]
public void LoadSavedMaterialWithClearPadding()
{
    var loadedMaterial = ContentLoader.Load<Material>("DefaultMaterial");
    loadedMaterial.RenderingCalculator = new RenderingCalculator(new AtlasRegion
    {
        PadLeft = 0,
        PadRight = 0,
        PadTop = 0,
        PadBottom = 0,
        IsRotated = false
    });
    var result = loadedMaterial.RenderingCalculator.GetUVAndDrawArea(Rectangle.HalfCentered,
        Rectangle.One);
    Assert.AreEqual(result.RequestedUserUV, Rectangle.HalfCentered);
}
[Test, CloseAfterFirstFrame]
public void LoadSavedMaterialWithRotation()
{
    var loadedMaterial = ContentLoader.Load<Material>("DefaultMaterial");
    loadedMaterial.RenderingCalculator = new RenderingCalculator(new AtlasRegion
    {
        PadLeft = 0.5f,
        PadRight = 0.5f,
        PadTop = 0.5f,
        PadBottom = 0.5f,
        IsRotated = true
    });
    var result = loadedMaterial.RenderingCalculator.GetUVAndDrawArea(Rectangle.HalfCentered,
        Rectangle.One);
    Assert.AreEqual(result.RequestedUserUV, Rectangle.HalfCentered);
}
[Test, CloseAfterFirstFrame]
public void SetRenderSize()
{
    var loadedMaterial = ContentLoader.Load<Material>("DefaultMaterial");
    loadedMaterial.RenderSizeMode = RenderSizeMode.PixelBased;
    var pixelBasedSize = ScreenSpace.Current.ToPixelSpace(loadedMaterial.MaterialRenderSize);
    Assert.AreEqual(new Size(128), pixelBasedSize);
    SetPixelModeAndCheckTargetResolution(loadedMaterial, RenderSizeMode.SizeFor800X480, 800);
    SetPixelModeAndCheckTargetResolution(loadedMaterial, RenderSizeMode.SizeFor1024X768, 1024);
    SetPixelModeAndCheckTargetResolution(loadedMaterial, RenderSizeMode.SizeFor1280X720, 1280);
    SetPixelModeAndCheckTargetResolution(loadedMaterial, RenderSizeMode.SizeFor1920X1080, 1920);
    SetPixelModeAndCheckTargetResolution(loadedMaterial,
        RenderSizeMode.SizeForSettingsResolution, Settings.DefaultResolution.Width);
}
See Also