Esempio n. 1
0
        /// <summary>Returns a pooled RegionItem.</summary>
        public RegionItem NextItem()
        {
            RegionItem item = freeItems.Count > 0 ? freeItems.Dequeue() : new RegionItem();

            items.Add(item);
            return(item);
        }
Esempio n. 2
0
        public void Draw(GraphicsDevice device)
        {
            if (items.Count == 0)
            {
                return;
            }

            int itemIndex = 0;
            int itemCount = items.Count;

            while (itemCount > 0)
            {
                int itemsToProcess = Math.Min(itemCount, maxBatchSize);
                EnsureArrayCapacity(itemsToProcess);

                var       count   = 0;
                Texture2D texture = null;
                for (int i = 0; i < itemsToProcess; i++, itemIndex++)
                {
                    RegionItem item = items[itemIndex];
                    if (item.texture != texture)
                    {
                        FlushVertexArray(device, count);
                        texture            = item.texture;
                        count              = 0;
                        device.Textures[0] = texture;
                    }

                    vertexArray[count++] = item.vertexTL;
                    vertexArray[count++] = item.vertexTR;
                    vertexArray[count++] = item.vertexBL;
                    vertexArray[count++] = item.vertexBR;

                    item.texture = null;
                    freeItems.Enqueue(item);
                }
                FlushVertexArray(device, count);
                itemCount -= itemsToProcess;
            }
            items.Clear();
        }
Esempio n. 3
0
        public void Draw(Skeleton skeleton)
        {
            List <Slot> drawOrder = skeleton.DrawOrder;
            float       skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A;

            for (int i = 0, n = drawOrder.Count; i < n; i++)
            {
                Slot             slot             = drawOrder[i];
                RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
                if (regionAttachment != null)
                {
                    BlendState blend = slot.Data.AdditiveBlending ? BlendState.Additive : defaultBlendState;
                    if (device.BlendState != blend)
                    {
                        End();
                        device.BlendState = blend;
                    }

                    RegionItem item = batcher.NextItem();

                    AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject;
                    item.texture = (Texture2D)region.page.rendererObject;

                    Color color;
                    float a = skeletonA * slot.A;
                    if (premultipliedAlpha)
                    {
                        color = new Color(skeletonR * slot.R * a, skeletonG * slot.G * a, skeletonB * slot.B * a, a);
                    }
                    else
                    {
                        color = new Color(skeletonR * slot.R, skeletonG * slot.G, skeletonB * slot.B, a);
                    }
                    item.vertexTL.Color = color;
                    item.vertexBL.Color = color;
                    item.vertexBR.Color = color;
                    item.vertexTR.Color = color;

                    float[] vertices = this.vertices;
                    regionAttachment.ComputeWorldVertices(slot.Bone, vertices);
                    item.vertexTL.Position.X = vertices[RegionAttachment.X1];
                    item.vertexTL.Position.Y = vertices[RegionAttachment.Y1];
                    item.vertexTL.Position.Z = 0;
                    item.vertexBL.Position.X = vertices[RegionAttachment.X2];
                    item.vertexBL.Position.Y = vertices[RegionAttachment.Y2];
                    item.vertexBL.Position.Z = 0;
                    item.vertexBR.Position.X = vertices[RegionAttachment.X3];
                    item.vertexBR.Position.Y = vertices[RegionAttachment.Y3];
                    item.vertexBR.Position.Z = 0;
                    item.vertexTR.Position.X = vertices[RegionAttachment.X4];
                    item.vertexTR.Position.Y = vertices[RegionAttachment.Y4];
                    item.vertexTR.Position.Z = 0;

                    float[] uvs = regionAttachment.UVs;
                    item.vertexTL.TextureCoordinate.X = uvs[RegionAttachment.X1];
                    item.vertexTL.TextureCoordinate.Y = uvs[RegionAttachment.Y1];
                    item.vertexBL.TextureCoordinate.X = uvs[RegionAttachment.X2];
                    item.vertexBL.TextureCoordinate.Y = uvs[RegionAttachment.Y2];
                    item.vertexBR.TextureCoordinate.X = uvs[RegionAttachment.X3];
                    item.vertexBR.TextureCoordinate.Y = uvs[RegionAttachment.Y3];
                    item.vertexTR.TextureCoordinate.X = uvs[RegionAttachment.X4];
                    item.vertexTR.TextureCoordinate.Y = uvs[RegionAttachment.Y4];
                }
            }
        }