示例#1
0
        public RenderBatch <TVertex> GetBatch <TVertex>(ITexture texture1, ITexture texture2, IMaterial material, int vertexCount, int indexCount)
            where TVertex : unmanaged
        {
            var atlas1         = texture1?.AtlasTexture;
            var atlas2         = texture2?.AtlasTexture;
            var typedLastBatch = lastBatch as RenderBatch <TVertex>;
            var needMesh       = typedLastBatch == null ||
                                 typedLastBatch.LastVertex + vertexCount > RenderBatchLimits.MaxVertices ||
                                 typedLastBatch.LastIndex + indexCount > RenderBatchLimits.MaxIndices;

            if (needMesh ||
                typedLastBatch.Texture1 != atlas1 ||
                typedLastBatch.Texture2 != atlas2 ||
                typedLastBatch.Material != material ||
                typedLastBatch.Material.PassCount != 1
                )
            {
                typedLastBatch = RenderBatch <TVertex> .Acquire(needMesh?null : typedLastBatch);

                typedLastBatch.Texture1 = atlas1;
                typedLastBatch.Texture2 = atlas2;
                typedLastBatch.Material = material;
                Batches.Add(typedLastBatch);
                lastBatch = typedLastBatch;
            }
            return(typedLastBatch);
        }
示例#2
0
        public RenderBatch GetBatch(IMaterial material, int vertexCount, int indexCount)
        {
            bool needMesh = lastBatch == null ||
                            lastBatch.LastVertex + vertexCount > RenderBatch.VertexBufferCapacity ||
                            lastBatch.LastIndex + indexCount > RenderBatch.IndexBufferCapacity;

            if (!needMesh && lastBatch.Material == material && material.PassCount == 1)
            {
                return(lastBatch);
            }
            var batch = RenderBatch.Acquire(needMesh ? null : lastBatch);

            batch.Material = material;
            Batches.Add(batch);
            lastBatch = batch;
            return(batch);
        }