protected override void ResizeUVVertices(int newNumberOfVertices) { var newVerticesUV = new VertexPosition2DUV[newNumberOfVertices]; Array.Copy(verticesUV, newVerticesUV, verticesUV.Length); verticesUV = newVerticesUV; }
public void UsingTexturing() { var vertices = new VertexPosition2DUV[4]; buffer2D.Add(image, vertices); Assert.IsTrue(buffer2D.UsesTexturing); }
public void IndicesAreComputedWhenNotPassedAsArgument() { var vertices = new VertexPosition2DUV[4]; buffer2D.Add(image, vertices); Assert.AreEqual(quadIndices, buffer2D.CachedIndices); }
public void ExpectExceptionIfTryingToAddTooManyVertices() { const int NumberOfTooMuchVertices = CircularBuffer.TotalMaximumVerticesLimit + 1; var dummyVertices = new VertexPosition2DUV[1]; Assert.Throws<CircularBuffer.TooManyVerticesForCircularBuffer>( () => buffer2D.Add(null, dummyVertices, new short[1], NumberOfTooMuchVertices, 1)); }
public void LerpPositionTextured2D() { var vertex = new VertexPosition2DUV(Vector2D.UnitX, Vector2D.One); var vertex2 = new VertexPosition2DUV(Vector2D.UnitY, Vector2D.Zero); var lerpedVertex = vertex.Lerp(vertex2, 0.5f); Assert.AreEqual(lerpedVertex.Position, Vector2D.Half); Assert.AreEqual(lerpedVertex.UV, Vector2D.One); }
public void ExpectExceptionIfTryingToAddTooManyVertices() { const int NumberOfTooMuchVertices = CircularBuffer.TotalMaximumVerticesLimit + 1; var dummyVertices = new VertexPosition2DUV[1]; Assert.Throws <CircularBuffer.TooManyVerticesForCircularBuffer>( () => buffer2D.Add(null, dummyVertices, new short[1], NumberOfTooMuchVertices, 1)); }
public void OffsetIncrement() { const int VerticesCount = 32; const int IndicesCount = 48; var vertices = new VertexPosition2DUV[VerticesCount]; var indices = new short[IndicesCount]; buffer2D.Add(null, vertices, indices); Assert.AreEqual(VerticesCount * vertexSize, buffer2D.VertexOffset); Assert.AreEqual(IndicesCount * sizeof(short), buffer2D.IndexOffset); }
public void DataBiggerThanBufferSize() { var verticesCount = buffer2D.MaxNumberOfVertices * 3; var indicesCount = buffer2D.MaxNumberOfVertices * 4; var vertices = new VertexPosition2DUV[verticesCount]; var indices = new short[indicesCount]; buffer2D.Add(null, vertices, indices); Assert.AreEqual(verticesCount * vertexSize, buffer2D.VertexOffset); Assert.AreEqual(indicesCount * sizeof(short), buffer2D.IndexOffset); }
public void IndicesAreRemappedWhenAddedVerticesAreNotAtTheBeginningOfTheBuffer() { var remappedIndices = new short[] { 4, 5, 6, 4, 6, 7 }; var vertices = new VertexPosition2DUV[4]; buffer2D.Add(image, vertices, quadIndices); Assert.AreEqual(quadIndices, buffer2D.CachedIndices); buffer2D.Add(image, vertices, quadIndices); Assert.AreEqual(remappedIndices, buffer2D.CachedIndices); }
public void DataBiggerThanHalfOfTheBufferSize() { const int VerticesCount = 12288; const int IndicesCount = 16384; var vertices = new VertexPosition2DUV[VerticesCount]; var indices = new short[IndicesCount]; buffer2D.Add(null, vertices, indices); Assert.AreEqual(VerticesCount * vertexSize, buffer2D.VertexOffset); Assert.AreEqual(IndicesCount * sizeof(short), buffer2D.IndexOffset); Assert.IsFalse(buffer2D.HasDrawn); }
public void MakeBufferResize() { const int VerticesCount = 12288; const int IndicesCount = 16384; var vertices = new VertexPosition2DUV[VerticesCount]; var indices = new short[IndicesCount]; buffer2D.Add(null, vertices, indices); Assert.IsFalse(buffer2D.HasDrawn); buffer2D.Add(null, vertices, indices); Assert.IsTrue(buffer2D.HasDrawn); }
private void AddVerticesRotated(Sprite sprite, Vector2D rotationCenter) { float sin = MathExtensions.Sin(rotation); float cos = MathExtensions.Cos(rotation); if (!hasUV) { var color = sprite.Color; verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.TopRight.RotateAround(rotationCenter, sin, cos)), color); } else if (hasColor) { var color = sprite.Color; verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)), color, uv.TopLeft); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)), color, uv.BottomLeft); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)), color, uv.BottomRight); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.TopRight.RotateAround(rotationCenter, sin, cos)), color, uv.TopRight); } else { verticesUV[verticesIndex++] = new VertexPosition2DUV( screen.ToPixelSpaceRounded(drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)), uv.TopLeft); verticesUV[verticesIndex++] = new VertexPosition2DUV( screen.ToPixelSpaceRounded(drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)), uv.BottomLeft); verticesUV[verticesIndex++] = new VertexPosition2DUV( screen.ToPixelSpaceRounded(drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)), uv.BottomRight); verticesUV[verticesIndex++] = new VertexPosition2DUV( screen.ToPixelSpaceRounded(drawArea.TopRight.RotateAround(rotationCenter, sin, cos)), uv.TopRight); } }
public void OffsetSeveralIncrements() { const int VerticesCount = 32; const int IndicesCount = 48; var vertices = new VertexPosition2DUV[VerticesCount]; var indices = new short[IndicesCount]; for (int i = 1; i <= IncrementCount; i++) { buffer2D.Add(null, vertices, indices); Assert.AreEqual(i * VerticesCount * vertexSize, buffer2D.VertexOffset); Assert.AreEqual(i * IndicesCount * sizeof(short), buffer2D.IndexOffset); } }
public void DrawAndReset() { const int VerticesCount = 32; const int IndicesCount = 48; var vertices = new VertexPosition2DUV[VerticesCount]; var indices = new short[IndicesCount]; buffer2D.Add(null, vertices, indices); Assert.IsFalse(buffer2D.HasDrawn); buffer2D.DrawAllTextureChunks(); Assert.IsTrue(buffer2D.HasDrawn); Assert.AreEqual(512, buffer2D.VertexOffset); Assert.AreEqual(96, buffer2D.IndexOffset); }
public Batch2D(Material material, BlendMode blendMode, int minimumNumberOfQuads = MinNumberOfQuads) { Material = material; BlendMode = blendMode; minimumNumberOfQuads = MathExtensions.Max(minimumNumberOfQuads, MinNumberOfQuads); hasUV = ((material.Shader.Flags & ShaderFlags.Textured) != 0); hasColor = ((material.Shader.Flags & ShaderFlags.Colored) != 0); indices = new short[minimumNumberOfQuads * IndicesPerQuad]; if (!hasUV) verticesColor = new VertexPosition2DColor[minimumNumberOfQuads * VerticesPerQuad]; else if (hasColor) verticesColorUV = new VertexPosition2DColorUV[minimumNumberOfQuads * VerticesPerQuad]; else verticesUV = new VertexPosition2DUV[minimumNumberOfQuads * VerticesPerQuad]; }
public void LoadDataWithDifferentSize() { const int Data1VerticesCount = 100; const int Data1IndicesCount = 150; const int Data2VerticesCount = 400; const int Data2IndicesCount = 500; var vertices1 = new VertexPosition2DUV[Data1VerticesCount]; var indices1 = new short[Data1IndicesCount]; var vertices2 = new VertexPosition2DUV[Data2VerticesCount]; var indices2 = new short[Data2IndicesCount]; buffer2D.Add(null, vertices1, indices1); Assert.AreEqual(Data1VerticesCount * vertexSize, buffer2D.VertexOffset); Assert.AreEqual(Data1IndicesCount * sizeof(short), buffer2D.IndexOffset); buffer2D.Add(null, vertices2, indices2); Assert.AreEqual((Data1VerticesCount + Data2VerticesCount) * vertexSize, buffer2D.VertexOffset); Assert.AreEqual((Data1IndicesCount + Data2IndicesCount) * sizeof(short), buffer2D.IndexOffset); }
public Batch2D(Material material, BlendMode blendMode, int minimumNumberOfQuads = MinNumberOfQuads) { Material = material; BlendMode = blendMode; minimumNumberOfQuads = MathExtensions.Max(minimumNumberOfQuads, MinNumberOfQuads); hasUV = ((material.Shader.Flags & ShaderFlags.Textured) != 0); hasColor = ((material.Shader.Flags & ShaderFlags.Colored) != 0); indices = new short[minimumNumberOfQuads * IndicesPerQuad]; if (!hasUV) { verticesColor = new VertexPosition2DColor[minimumNumberOfQuads * VerticesPerQuad]; } else if (hasColor) { verticesColorUV = new VertexPosition2DColorUV[minimumNumberOfQuads * VerticesPerQuad]; } else { verticesUV = new VertexPosition2DUV[minimumNumberOfQuads * VerticesPerQuad]; } }
} //ncrunch: no coverage end private void AddVerticesNotRotated(Sprite sprite) { if (!hasUV) { var color = sprite.Color; verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopLeft), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomLeft), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomRight), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopRight), color); } else if (hasColor) { var color = sprite.Color; verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopLeft), color, uv.TopLeft); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomLeft), color, uv.BottomLeft); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomRight), color, uv.BottomRight); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopRight), color, uv.TopRight); } else { verticesUV[verticesIndex++] = new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.TopLeft), uv.TopLeft); verticesUV[verticesIndex++] = new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.BottomLeft), uv.BottomLeft); verticesUV[verticesIndex++] = new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.BottomRight), uv.BottomRight); verticesUV[verticesIndex++] = new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.TopRight), uv.TopRight); } }
//ncrunch: no coverage start private void AddVerticesAtlasRotated(Sprite sprite) { if (!hasUV) { var color = sprite.Color; verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopLeft), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomLeft), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomRight), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopRight), color); } else if (hasColor) { var color = sprite.Color; verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopLeft), color, uv.TopLeft); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomLeft), color, uv.BottomLeft); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.BottomRight), color, uv.BottomRight); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded(drawArea.TopRight), color, uv.TopRight); } else { verticesUV[verticesIndex++] = new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.TopLeft), uv.TopLeft); verticesUV[verticesIndex++] = new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.BottomLeft), uv.BottomLeft); verticesUV[verticesIndex++] = new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.BottomRight), uv.BottomRight); verticesUV[verticesIndex++] = new VertexPosition2DUV(screen.ToPixelSpaceRounded(drawArea.TopRight), uv.TopRight); } }
public void IndicesAreNotChangedWhenPassedAsArgument() { var vertices = new VertexPosition2DUV[4]; buffer2D.Add(image, vertices, quadIndices); Assert.AreEqual(quadIndices, buffer2D.CachedIndices); }