#region CPL License /* Nuclex Framework Copyright (C) 2002-2009 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #endregion #if UNITTEST using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using NUnit.Framework; using TestVertex = Microsoft.Xna.Framework.Graphics.VertexPositionColor; namespace Nuclex.Graphics.Batching { /// Unit tests for the queuer internal class QueuerTest { #region class DummyDrawContext /// Drawing context used for the unit test protected class DummyDrawContext : DrawContext { /// Number of passes this draw context requires for rendering public override int Passes { get { return 123; } } /// Prepares the graphics device for drawing /// Index of the pass to begin rendering /// /// Should only be called between the normal Begin() and End() methods. /// public override void Apply(int pass) { } /// Tests whether another draw context is identical to this one /// Other context to check for equality /// True if the other context is identical to this one public override bool Equals(DrawContext otherContext) { return ReferenceEquals(this, otherContext); } } #endregion // class DummyDrawContext #region class DummyBatchDrawer /// Dummy drawer for vertex batches protected class DummyBatchDrawer : IBatchDrawer { /// Initializes as new instance of the vertex drawer public DummyBatchDrawer() { this.drawnBatches = new List>(); } /// /// Maximum number of vertices or indices a single batch is allowed to have /// public int MaximumBatchSize { get { return 16; } } /// Selects the vertices that will be used for drawing /// Primitive vertices /// Number of vertices to draw /// Indices of the vertices to draw /// Number of vertex indices to draw public void Select( TestVertex[] vertices, int vertexCount, short[] indices, int indexCount ) { this.vertices = vertices; this.indices = indices; } /// Selects the vertices that will be used for drawing /// Primitive vertices /// Number of vertices to draw public void Select(TestVertex[] vertices, int vertexCount) { this.vertices = vertices; } /// Draws a batch of indexed primitives /// /// Index of the first vertex in the vertex array. This vertex will become /// the new index 0 for the index buffer. /// /// Number of vertices used in the call /// /// Position at which to begin processing the index array /// /// Number of indices that will be processed /// Type of primitives to draw /// Desired graphics device settings for the primitives public void Draw( int startVertex, int vertexCount, int startIndex, int indexCount, PrimitiveType type, DrawContext context ) { List drawnVertices = new List(indexCount); for(int index = startIndex; index < startIndex + indexCount; ++index) { int vertexIndex = this.indices[index] + startVertex; drawnVertices.Add(this.vertices[vertexIndex]); } this.drawnBatches.Add(drawnVertices); } /// Draws a batch of primitives /// Index of vertex to begin drawing with /// Number of vertices used /// Type of primitives that will be drawn /// Desired graphics device settings for the primitives public void Draw( int startVertex, int vertexCount, PrimitiveType type, DrawContext context ) { List drawnVertices = new List(vertexCount); for(int index = startVertex; index < startVertex + vertexCount; ++index) { drawnVertices.Add(this.vertices[index]); } this.drawnBatches.Add(drawnVertices); } /// Batchs that would have been drawn so far public List> DrawnBatches { get { return this.drawnBatches; } } /// Vertices currently selected for drawing private TestVertex[] vertices; /// Indices currently selected for drawing private short[] indices; /// Records the batches that would have been drawn so far private List> drawnBatches; } #endregion // class DummyBatchDrawer #region class DummyQueuer /// Dummy implementation for testing the Queuer class private class DummyQueuer : Queuer { /// Initializes a new dummy queuer public DummyQueuer() : base(null) { } /// Queues a series of indexed primitives /// Primitive vertices /// /// Index in the vertex array of the first vertex. This vertex will become /// the new index 0 for the index buffer. /// /// Number of vertices to draw /// Indices of the vertices to draw /// Index of the vertex index to begin drawing with /// Number of vertex indices to draw /// Type of primitives to draw /// Desired graphics device settings for the primitives public override void Queue( TestVertex[] vertices, int startVertex, int vertexCount, short[] indices, int startIndex, int indexCount, PrimitiveType type, DrawContext context ) { } /// Queues a series of primitives /// Primitive vertices /// Index of vertex to begin drawing with /// Number of vertices to draw /// Type of primitives to draw /// Desired graphics device settings for the primitives public override void Queue( TestVertex[] vertices, int startVertex, int vertexCount, PrimitiveType type, DrawContext context ) { } } #endregion // class DummyQueuer /// Static constructor that initializes the test vertex array static QueuerTest() { const int TestVertexCount = 64; TestVertices = new TestVertex[TestVertexCount]; TestIndices = new short[TestVertexCount]; for(int index = 0; index < TestVertexCount; ++index) { TestVertices[index] = new TestVertex( new Vector3((float)index, (float)index, (float)index), Color.White ); TestIndices[index] = (short)(index + 2); } } /// Array of vertices being used for testing protected static readonly TestVertex[] TestVertices; /// Array of indices being used for testing, ordered in reverse protected static readonly short[] TestIndices; } } // namespace Nuclex.Graphics #endif // UNITTEST