Exemplo n.º 1
0
        //private HashSet<string> crap = new HashSet<string>();
        internal void setBatchState(DrawItem item)
        {
            //if (materialState != null && materialState.textureName == item.material.textureName)
            //    materialState = item.material;

            endBatchState();


            //if (!crap.Add(item.material.textureName))
            //    materialState = item.material;

            materialState = item.material;
            var blendState      = item.material.BlendState;
            var depthState      = item.material.DepthStencilState;
            var rasterizerState = item.applyScissor ? item.material.ScissorRasterizerState : item.material.RasterizerState;
            var samplerState    = item.material.SamplerState;

            if (item.applyScissor)
            {
                batch.GraphicsDevice.ScissorRectangle = item.scissorRect;
                applyingScissor = true;
            }

            batch.Begin(SpriteSortMode.Deferred, blendState, samplerState, depthState, rasterizerState, materialState.effect, currentMatrix);
        }
Exemplo n.º 2
0
        internal void DrawInternal(Material material,
                                   Vector2 position,
                                   Vector2 scale,
                                   AxisAlignedBox sourceRectangle,
                                   Color color,
                                   float rotation,
                                   Vector2 origin,
                                   SpriteEffects effect,
                                   float depth)
        {
            var item = new DrawItem();

            item.material = material ?? Root.instance.resources.defaultMaterial;
            //item.texture = texture ?? Root.instance.resources.basewhite;
            item.position        = position;
            item.scale           = scale;
            item.sourceRectangle = sourceRectangle;
            item.color           = color;
            item.rotation        = rotation;
            item.origin          = origin;
            item.effect          = effect;
            item.depth           = depth;
            item.applyScissor    = Root.instance.graphics.scissorEnabled;
            item.scissorRect     = Root.instance.graphics.scissorRect;

            minDepth = Math.Min(item.depth, minDepth);
            maxDepth = Math.Max(item.depth, maxDepth);

            switch (sortMode)
            {
            case RenderQueueSortMode.Material:
                item.key = item.material.id;
                break;

            case RenderQueueSortMode.ReverseOrder:
            case RenderQueueSortMode.PreserverOrder:
                item.key = renderableIndex;
                break;
            }

            if (renderableItems.Length == renderableIndex)
            {
                Array.Resize(ref renderableItems, renderableItems.Length * 2 / 2);
                //var tempItems = new DrawItem[(renderableItems.Length * 3) / 2];
                //Array.Copy(renderableItems, tempItems, renderableItems.Length);
                //renderableItems = tempItems;
            }

            renderableItems[renderableIndex++] = item;
        }
Exemplo n.º 3
0
 internal void updateBatchState(DrawItem item)
 {
     if (materialState == null)
     {
         setBatchState(item);
     }
     else if (materialState != item.material)
     {
         setBatchState(item);
     }
     else if (item.applyScissor != applyingScissor)
     {
         setBatchState(item);
     }
     else if (item.applyScissor && applyingScissor && item.scissorRect != batch.GraphicsDevice.ScissorRectangle)
     {
         setBatchState(item);
     }
     else if ((spritesSubmittedThisBatch % 2048) == 0)
     {
         setBatchState(item);
     }
 }