Example #1
0
        public void AddVertices <T>(BatchInfo material, VertexMode vertexMode, T[] vertexBuffer, int vertexCount) where T : struct, IVertexData
        {
            if (vertexCount == 0)
            {
                return;
            }
            if (vertexBuffer == null || vertexBuffer.Length == 0)
            {
                return;
            }
            if (vertexCount > vertexBuffer.Length)
            {
                vertexCount = vertexBuffer.Length;
            }
            if (material == null)
            {
                material = Material.Checkerboard.Res.InfoDirect;
            }

            if (this.pickingIndex != 0)
            {
                ColorRgba clr = new ColorRgba((this.pickingIndex << 8) | 0xFF);
                for (int i = 0; i < vertexCount; ++i)
                {
                    vertexBuffer[i].Color = clr;
                }

                material           = new BatchInfo(material);
                material.Technique = DrawTechnique.Picking;
                if (material.Textures == null)
                {
                    material.MainTexture = Texture.White;
                }
            }
            else if (material.Technique == null || !material.Technique.IsAvailable)
            {
                material           = new BatchInfo(material);
                material.Technique = DrawTechnique.Solid;
            }

            // When rendering without depth writing, use z sorting everywhere - there's no real depth buffering!
            bool zSort = !this.DepthWrite || material.Technique.Res.NeedsZSort;
            List <IDrawBatch> buffer     = zSort ? this.drawBufferZSort : this.drawBuffer;
            float             zSortIndex = zSort ? DrawBatch <T> .CalcZSortIndex(vertexBuffer, vertexCount) : 0.0f;

            if (buffer.Count > 0 && buffer[buffer.Count - 1].CanAppendJIT <T>(
                    zSort ? 1.0f / this.zSortAccuracy : 0.0f,
                    zSortIndex,
                    material,
                    vertexMode))
            {
                buffer[buffer.Count - 1].AppendJIT(vertexBuffer, vertexCount);
            }
            else
            {
                buffer.Add(new DrawBatch <T>(material, vertexMode, vertexBuffer, vertexCount, zSortIndex));
            }
            ++this.numRawBatches;
        }
Example #2
0
        public void AddVertices <T>(BatchInfo material, VertexMode vertexMode, T[] vertexBuffer, int vertexCount) where T : struct, IVertexData
        {
            if (vertexCount == 0)
            {
                return;
            }
            if (vertexBuffer == null || vertexBuffer.Length == 0)
            {
                return;
            }
            if (vertexCount > vertexBuffer.Length)
            {
                vertexCount = vertexBuffer.Length;
            }
            if (material == null)
            {
                material = Material.Checkerboard.Res.InfoDirect;
            }

            if (this.pickingIndex != 0)
            {
                ColorRgba clr = new ColorRgba((this.pickingIndex << 8) | 0xFF);
                for (int i = 0; i < vertexCount; ++i)
                {
                    vertexBuffer[i].Color = clr;
                }

                material           = new BatchInfo(material);
                material.Technique = DrawTechnique.Picking;
                if (material.Textures == null)
                {
                    material.MainTexture = Texture.White;
                }
            }
            else if (material.Technique == null || !material.Technique.IsAvailable)
            {
                material           = new BatchInfo(material);
                material.Technique = DrawTechnique.Solid;
            }

            // When rendering without depth writing, use z sorting everywhere - there's no real depth buffering!
            bool zSort = !this.DepthWrite || material.Technique.Res.NeedsZSort;
            List <IDrawBatch> buffer     = zSort ? this.drawBufferZSort : this.drawBuffer;
            float             zSortIndex = zSort ? DrawBatch <T> .CalcZSortIndex(vertexBuffer, vertexCount) : 0.0f;

            // Determine if we can append the incoming vertices into the previous batch
            IDrawBatch prevBatch = buffer.Count > 0 ? buffer[buffer.Count - 1] : null;

            if (prevBatch != null &&
                // ToDo: Move into CanAppendJIT on next major version step:
                // Make sure to not generate batches that will be in the Large Object Heap (>= 85k bytes)
                // because this will trigger lots and lots of Gen2 collections over time.
                vertexCount + prevBatch.VertexCount < 1024 &&
                // Check if the batches do match enough for being merged
                prevBatch.CanAppendJIT <T>(
                    zSort ? 1.0f : 0.0f,                     // Obsolete as of 2016-06-17, can be replcaed with zSort bool.
                    zSortIndex,
                    material,
                    vertexMode))
            {
                prevBatch.AppendJIT(vertexBuffer, vertexCount);
            }
            else
            {
                buffer.Add(new DrawBatch <T>(material, vertexMode, vertexBuffer, vertexCount, zSortIndex));
            }
            ++this.numRawBatches;
        }