protected override void ResizeColorVertices(int newNumberOfVertices) { var newVerticesColor = new VertexPosition2DColor[newNumberOfVertices]; Array.Copy(verticesColor, newVerticesColor, verticesColor.Length); verticesColor = newVerticesColor; }
private void AddToBatch(Entity2D entity) { var points = entity.GetInterpolatedList <Vector2D>(); if (points.Count < 3) { return; } if (points.Count > CircularBuffer.TotalMaximumVerticesLimit) { throw new TooManyVerticesForPolygon(points.Count); //ncrunch: no coverage } var color = entity.Color; if (offset + points.Count > vertices.Length) { ResizeVertices(); //ncrunch: no coverage } for (int num = 0; num < points.Count; num++) { vertices[offset + num] = new VertexPosition2DColor(ScreenSpace.Current.ToPixelSpace(points[num]), color); } BuildIndices(points.Count); offset += points.Count; }
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 Update() { var random = Randomizer.Current; for (int line = 0; line < vertices.Count; line++) { vertices[line] = new VertexPosition2DColor( vertices[line].Position + new Vector2D(random.Get(-30, 30), random.Get(-20, 20)), Color.GetRandomColor()); } }
private void AddToBatch(GradientFilledRect entity) { var startColor = entity.Color; var finalColor = entity.FinalColor; vertices[0] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(entity.Points[0]), startColor); vertices[1] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(entity.Points[1]), finalColor); vertices[2] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(entity.Points[2]), finalColor); vertices[3] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded(entity.Points[3]), startColor); draw.Add(material, vertices, Indices); }
private void CreateRandomLines(int numberOfLines) { var oldVertices = Get<VertexPosition2DColor[]>(); var vertices = new VertexPosition2DColor[2 * numberOfLines]; var random = Randomizer.Current; for (int i = 0; i < oldVertices.Length; i++) vertices[i] = oldVertices[i]; for (int i = oldVertices.Length / 2; i < numberOfLines; i++) { var startPoint = new Vector2D(random.Get(0, 1280), random.Get(0, 720)); var endPoint = startPoint + new Vector2D(random.Get(-100, 100), random.Get(-100, 100)); vertices[i * 2 + 0] = new VertexPosition2DColor(startPoint, Color.GetRandomColor()); vertices[i * 2 + 1] = new VertexPosition2DColor(endPoint, Color.GetRandomColor()); } Set(vertices); } //ncrunch: no coverage end
public void Draw30000LinesPerFrame() { var manyLines = new DrawingTests.Line(Vector2D.Zero, new Vector2D(1280, 720), Color.Red); const int NumberOfRandomLines = 30000; var vertices = new VertexPosition2DColor[2 * NumberOfRandomLines]; var random = Randomizer.Current; var viewport = Resolve<Window>().ViewportPixelSize; for (int i = 0; i < NumberOfRandomLines; i++) { var startPoint = new Vector2D(random.Get(0, viewport.Width), random.Get(0, viewport.Height)); var endPoint = startPoint + new Vector2D(random.Get(-50, 50), random.Get(-50, 50)); vertices[i * 2 + 0] = new VertexPosition2DColor(startPoint, Color.GetRandomColor()); vertices[i * 2 + 1] = new VertexPosition2DColor(endPoint, Color.GetRandomColor()); } manyLines.Set(vertices); }
private void AddToBatch(Entity2D entity) { var points = entity.GetInterpolatedList<Vector2D>(); if (points.Count < 3) return; if (points.Count > CircularBuffer.TotalMaximumVerticesLimit) throw new TooManyVerticesForPolygon(points.Count); //ncrunch: no coverage var color = entity.Color; if (offset + points.Count > vertices.Length) ResizeVertices(); //ncrunch: no coverage for (int num = 0; num < points.Count; num++) vertices[offset + num] = new VertexPosition2DColor(ScreenSpace.Current.ToPixelSpace(points[num]), color); BuildIndices(points.Count); offset += points.Count; }
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 Draw30000LinesPerFrame() { var manyLines = new DrawingTests.Line(Vector2D.Zero, new Vector2D(1280, 720), Color.Red); const int NumberOfRandomLines = 30000; var vertices = new VertexPosition2DColor[2 * NumberOfRandomLines]; var random = Randomizer.Current; var viewport = Resolve <Window>().ViewportPixelSize; for (int i = 0; i < NumberOfRandomLines; i++) { var startPoint = new Vector2D(random.Get(0, viewport.Width), random.Get(0, viewport.Height)); var endPoint = startPoint + new Vector2D(random.Get(-50, 50), random.Get(-50, 50)); vertices[i * 2 + 0] = new VertexPosition2DColor(startPoint, Color.GetRandomColor()); vertices[i * 2 + 1] = new VertexPosition2DColor(endPoint, Color.GetRandomColor()); } manyLines.Set(vertices); }
private void CreateRandomLines(int numberOfLines) { var oldVertices = Get <VertexPosition2DColor[]>(); var vertices = new VertexPosition2DColor[2 * numberOfLines]; var random = Randomizer.Current; for (int i = 0; i < oldVertices.Length; i++) { vertices[i] = oldVertices[i]; } for (int i = oldVertices.Length / 2; i < numberOfLines; i++) { var startPoint = new Vector2D(random.Get(0, 1280), random.Get(0, 720)); var endPoint = startPoint + new Vector2D(random.Get(-100, 100), random.Get(-100, 100)); vertices[i * 2 + 0] = new VertexPosition2DColor(startPoint, Color.GetRandomColor()); vertices[i * 2 + 1] = new VertexPosition2DColor(endPoint, Color.GetRandomColor()); } Set(vertices); } //ncrunch: no coverage end
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 Update() { var random = Randomizer.Current; for (int line = 0; line < vertices.Count; line++) vertices[line] = new VertexPosition2DColor( vertices[line].Position + new Vector2D(random.Get(-30, 30), random.Get(-20, 20)), Color.GetRandomColor()); }