protected void MakeDrawArguments( PrimitiveType primitiveType, ref Internal.VertexBuffer <GeometryVertex> vb, ref Internal.IndexBuffer ib, ref int vertexOffset, ref int indexOffset, int vertexCount, int indexCount ) { if ((vertexCount == 0) || (indexCount == 0)) { return; } int primCount = primitiveType.ComputePrimitiveCount(indexCount); _DrawArguments.Add(new DrawArguments { PrimitiveType = primitiveType, VertexOffset = vertexOffset, VertexCount = vertexCount, IndexOffset = indexOffset, IndexCount = indexCount, PrimitiveCount = primCount }); vertexOffset += vertexCount; indexOffset += indexCount; }
public override void Prepare() { if (Count > 0) { #if PSM _BufferGenerator = Container.RenderManager.GetBufferGenerator <PSMBufferGenerator <GeometryVertex> >(); #else _BufferGenerator = Container.RenderManager.GetBufferGenerator <XNABufferGenerator <GeometryVertex> >(); #endif _DrawArguments = _DrawArgumentsListPool.Allocate(null); var swb = _BufferGenerator.Allocate(VertexCount, IndexCount, true); _SoftwareBuffer = swb; var vb = new Internal.VertexBuffer <GeometryVertex>(swb.Vertices); var ib = new Internal.IndexBuffer(swb.Indices); int vertexOffset = 0, indexOffset = 0; foreach (var kvp in Lists) { var l = kvp.Value; var c = l.Count; #if PSM l.Timsort(_DrawCallSorter); #else l.Sort(_DrawCallSorter); #endif int vertexCount = vb.Count, indexCount = ib.Count; var _l = l.GetBuffer(); for (int i = 0; i < c; i++) { var dc = _l[i]; dc.Preparer(ref vb, ref ib, ref dc); } vertexCount = vb.Count - vertexCount; indexCount = ib.Count - indexCount; MakeDrawArguments(kvp.Key, ref vb, ref ib, ref vertexOffset, ref indexOffset, vertexCount, indexCount); } int done = 0; done = 1; } }
protected override void Prepare(PrepareManager manager) { if (Count > 0) { _BufferGenerator = Container.RenderManager.GetBufferGenerator <BufferGenerator <GeometryVertex> >(); _DrawArguments = _DrawArgumentsListPool.Allocate(null); var swb = _BufferGenerator.Allocate(VertexCount, IndexCount, true); _SoftwareBuffer = swb; var vb = new Internal.VertexBuffer <GeometryVertex>(swb.Vertices); var ib = new Internal.IndexBuffer(swb.Indices); int vertexOffset = 0, indexOffset = 0; int totalPrimCount = 0; foreach (var kvp in Lists) { var l = kvp.Value; var c = l.Count; l.FastCLRSort(_DrawCallSorter); int vertexCount = vb.Count, indexCount = ib.Count; var _l = l.GetBuffer(); for (int i = 0; i < c; i++) { var dc = _l[i]; dc.Preparer(ref vb, ref ib, ref dc); } vertexCount = vb.Count - vertexCount; indexCount = ib.Count - indexCount; int primCount; MakeDrawArguments(kvp.Key, ref vb, ref ib, ref vertexOffset, ref indexOffset, out primCount, vertexCount, indexCount); totalPrimCount += primCount; } NativeBatch.RecordPrimitives(totalPrimCount); } }
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); }