public void AddFilledQuad(Vector2 topLeft, Vector2 bottomRight, Color fillColor) { var dc = new GeometryDrawCall { Preparer = PrepareQuad, PrimitiveType = PrimitiveType.TriangleList, Vector0 = topLeft, Vector1 = bottomRight, Color0 = fillColor }; Add(ref dc, 4, QuadIndices.Length); }
public void AddOutlinedQuad(Vector2 topLeft, Vector2 bottomRight, Color outlineColor) { var dc = new GeometryDrawCall { Preparer = PrepareOutlinedQuad, PrimitiveType = PrimitiveType.LineList, Vector0 = topLeft, Vector1 = bottomRight, Color0 = outlineColor }; Add(ref dc, 4, OutlinedQuadIndices.Length); }
public void AddLine(Vector2 start, Vector2 end, Color firstColor, Color secondColor) { var dc = new GeometryDrawCall { Preparer = PrepareLine, PrimitiveType = PrimitiveType.LineList, Vector0 = start, Vector1 = end, Color0 = firstColor, Color1 = secondColor }; Add(ref dc, 2, LineIndices.Length); }
public void AddQuadBorder(Vector2 topLeft, Vector2 bottomRight, Color colorInner, Color colorOuter, float borderSize) { var dc = new GeometryDrawCall { Preparer = PrepareQuadBorder, PrimitiveType = PrimitiveType.TriangleList, Vector0 = topLeft, Vector1 = bottomRight, Color0 = colorInner, Color1 = colorOuter, Scalar0 = borderSize }; Add(ref dc, 8, QuadBorderIndices.Length); }
public void AddGradientFilledQuad(Vector2 topLeft, Vector2 bottomRight, Color topLeftColor, Color topRightColor, Color bottomLeftColor, Color bottomRightColor) { var dc = new GeometryDrawCall { Preparer = PrepareGradientQuad, PrimitiveType = PrimitiveType.TriangleList, Vector0 = topLeft, Vector1 = bottomRight, Color0 = topLeftColor, Color1 = topRightColor, Color2 = bottomLeftColor, Color3 = bottomRightColor }; Add(ref dc, 4, QuadIndices.Length); }
public void AddFilledRing(Vector2 center, Vector2 innerRadius, Vector2 outerRadius, Color innerColorStart, Color outerColorStart, Color?innerColorEnd = null, Color?outerColorEnd = null, float startAngle = 0, float endAngle = (float)(Math.PI * 2)) { var dc = new GeometryDrawCall { Preparer = PrepareRing, PrimitiveType = PrimitiveType.TriangleList, Vector0 = center, Vector1 = innerRadius, Vector2 = outerRadius, Color0 = innerColorStart, Color1 = outerColorStart, Color2 = innerColorEnd.GetValueOrDefault(innerColorStart), Color3 = outerColorEnd.GetValueOrDefault(outerColorStart), Scalar0 = startAngle, Scalar1 = endAngle }; int numPoints = ComputeRingPoints(ref outerRadius); Add(ref dc, numPoints * 2, (numPoints - 1) * 6); }
protected void Add(ref GeometryDrawCall drawCall, int vertexCount, int indexCount) { Count += 1; VertexCount += vertexCount; IndexCount += indexCount; if (VertexCount >= MaxVertexCount) { throw new InternalBufferOverflowException("This GeometryBatch contains too many primitives. Split your primitives into multiple batches."); } UnorderedList <GeometryDrawCall> list; if (!Lists.TryGetValue(drawCall.PrimitiveType, out list)) { list = Lists[drawCall.PrimitiveType] = _ListPool.Allocate(null); } list.Add(drawCall); }
public static unsafe void _PrepareRing(ref Internal.VertexBuffer <GeometryVertex> vb, ref Internal.IndexBuffer ib, ref GeometryDrawCall dc) { int numPoints = ComputeRingPoints(ref dc.Vector2); const int vertexStride = 2; const int indexStride = 6; var vw = vb.GetWriter(numPoints * vertexStride); var iw = ib.GetWriter((numPoints - 1) * indexStride, ref vw); float a = dc.Scalar0; float step = (float)((dc.Scalar1 - dc.Scalar0) / (numPoints - 1)); float cos, sin; float colorA = 0, colorStep = 1.0f / (numPoints - 1); var vertexInner = new GeometryVertex(new Vector3(0, 0, dc.Z), dc.Color0); var vertexOuter = new GeometryVertex(new Vector3(0, 0, dc.Z), dc.Color1); fixed(GeometryVertex *pVertices = &vw.Storage.Array[vw.Storage.Offset]) fixed(ushort *pIndices = &iw.Storage.Array[iw.Storage.Offset]) for (int i = 0, j = 0, k = 0; i < numPoints; i++, j += vertexStride, k += indexStride) { cos = (float)Math.Cos(a); sin = (float)Math.Sin(a); vertexInner.Position.X = dc.Vector0.X + (float)(cos * dc.Vector1.X); vertexInner.Position.Y = dc.Vector0.Y + (float)(sin * dc.Vector1.Y); vertexInner.Color = Color.Lerp(dc.Color0, dc.Color2, colorA); pVertices[j] = vertexInner; vertexOuter.Position.X = dc.Vector0.X + (float)(cos * dc.Vector2.X); vertexOuter.Position.Y = dc.Vector0.Y + (float)(sin * dc.Vector2.Y); vertexOuter.Color = Color.Lerp(dc.Color1, dc.Color3, colorA); pVertices[j + 1] = vertexOuter; if (i == (numPoints - 1)) { break; } pIndices[k] = (ushort)(j + vw.IndexOffset); pIndices[k + 1] = (ushort)(j + 1 + vw.IndexOffset); pIndices[k + 2] = (ushort)(j + 3 + vw.IndexOffset); pIndices[k + 3] = (ushort)(j + 2 + vw.IndexOffset); pIndices[k + 4] = (ushort)(j + vw.IndexOffset); pIndices[k + 5] = (ushort)(j + 3 + vw.IndexOffset); a += step; colorA += colorStep; } }
protected static void _PrepareLine(ref Internal.VertexBuffer <GeometryVertex> vb, ref Internal.IndexBuffer ib, ref GeometryDrawCall dc) { var vw = vb.GetWriter(2); var iw = ib.GetWriter(LineIndices.Length, ref vw); vw.Write(MakeVertex(dc.Vector0.X, dc.Vector0.Y, dc.Z, dc.Color0)); vw.Write(MakeVertex(dc.Vector1.X, dc.Vector1.Y, dc.Z, dc.Color1)); iw.Write(LineIndices); }
protected static void _PrepareQuadBorder(ref Internal.VertexBuffer <GeometryVertex> vb, ref Internal.IndexBuffer ib, ref GeometryDrawCall dc) { var vw = vb.GetWriter(8); var iw = ib.GetWriter(QuadBorderIndices.Length, ref vw); var tl = dc.Vector0; var br = dc.Vector1; var border = dc.Scalar0; var vInner = new GeometryVertex(new Vector3(tl.X, tl.Y, dc.Z), dc.Color0); var vOuter = new GeometryVertex(new Vector3(tl.X - border, tl.Y - border, dc.Z), dc.Color1); vw.Write(ref vInner); vw.Write(ref vOuter); vInner.Position.X = br.X; vOuter.Position.X = br.X + border; vw.Write(ref vInner); vw.Write(ref vOuter); vInner.Position.Y = br.Y; vOuter.Position.Y = br.Y + border; vw.Write(ref vInner); vw.Write(ref vOuter); vInner.Position.X = tl.X; vOuter.Position.X = tl.X - border; vw.Write(ref vInner); vw.Write(ref vOuter); iw.Write(QuadBorderIndices); }