Ejemplo n.º 1
0
        private RawList <T> GetVertexList <T>() where T : struct, IVertexData
        {
            // Fast path: Retrieve and return
            int         typeIndex  = VertexDeclaration.Get <T>().TypeIndex;
            RawList <T> vertexList = null;

            if (typeIndex < this.vertexDataSlots.Length && (vertexList = this.vertexDataSlots[typeIndex].Vertices as RawList <T>) != null)
            {
                return(vertexList);
            }
            // Slow / init path
            else
            {
                // Allocate slot for vertex type
                if (typeIndex >= this.vertexDataSlots.Length)
                {
                    Array.Resize(ref this.vertexDataSlots, typeIndex + 1);
                }
                this.usedSlotCount = Math.Max(this.usedSlotCount, typeIndex + 1);

                // Init batch storage for vertex type
                if (this.vertexDataSlots[typeIndex].Batches == null)
                {
                    this.vertexDataSlots[typeIndex].Batches = new List <IVertexBatch>();
                    this.vertexDataSlots[typeIndex].Batches.Add(new VertexBatch <T>());
                }

                // Assign current vertex batch for fast access
                VertexBatch <T> batch = (VertexBatch <T>) this.vertexDataSlots[typeIndex].Batches[0];
                this.vertexDataSlots[typeIndex].Vertices         = batch.Vertices;
                this.vertexDataSlots[typeIndex].ActiveBatchCount = 1;
                return(batch.Vertices);
            }
        }
Ejemplo n.º 2
0
        private RawList <T> AdvanceToNextBatch <T>() where T : struct, IVertexData
        {
            int typeIndex  = VertexDeclaration.Get <T>().TypeIndex;
            int batchIndex = this.vertexDataSlots[typeIndex].ActiveBatchCount;
            List <IVertexBatch> batchList = this.vertexDataSlots[typeIndex].Batches;

            // Create a new batch, if we didn't already have one ready
            if (batchList.Count <= batchIndex)
            {
                batchList.Add(new VertexBatch <T>());
            }

            // Assign current vertex batch for fast access
            VertexBatch <T> batch = (VertexBatch <T>)batchList[batchIndex];

            this.vertexDataSlots[typeIndex].Vertices = batch.Vertices;
            this.vertexDataSlots[typeIndex].ActiveBatchCount++;
            return(batch.Vertices);
        }
Ejemplo n.º 3
0
        private RawList <T> GetVertexList <T>() where T : struct, IVertexData
        {
            // Fast path: Retrieve and return
            int         typeIndex  = VertexDeclaration.Get <T>().TypeIndex;
            RawList <T> vertexList = null;

            if (typeIndex < this.vertices.Length && (vertexList = this.vertices[typeIndex] as RawList <T>) != null)
            {
                return(vertexList);
            }
            // Slow / init path
            else
            {
                if (typeIndex >= this.vertices.Length)
                {
                    Array.Resize(ref this.batches, typeIndex + 1);
                    Array.Resize(ref this.vertices, typeIndex + 1);
                }
                VertexBatch <T> batch = new VertexBatch <T>();
                this.batches[typeIndex]  = batch;
                this.vertices[typeIndex] = batch.Vertices;
                return(batch.Vertices);
            }
        }