Esempio n. 1
0
        void DrawBatchedQuads()
        {
            int numOfQuads = 0;
            int startIndex = 0;

            if (currentBatchedQuads.Count <= 0 || quadCommands.Count == 0)
            {
                return;
            }

            var  quadElements           = currentBatchedQuads.Elements;
            uint lastMaterialId         = 0;
            bool originalDepthTestState = drawManager.DepthTest;
            bool usingDepthTest         = originalDepthTestState;

            drawManager.PushMatrix();
            drawManager.SetIdentityMatrix();

            CCQuadCommand prevCommand = null;

            foreach (CCQuadCommand command in quadCommands)
            {
                var  newMaterialID        = command.MaterialId;
                bool commandUsesDepthTest = command.UsingDepthTest;

                if (lastMaterialId != newMaterialID || commandUsesDepthTest != usingDepthTest)
                {
                    if (numOfQuads > 0 && prevCommand != null)
                    {
                        prevCommand.UseMaterial(drawManager);
                        drawManager.DrawQuads(currentBatchedQuads, startIndex, numOfQuads);

                        startIndex += numOfQuads;
                        numOfQuads  = 0;
                    }

                    lastMaterialId = newMaterialID;
                    usingDepthTest = commandUsesDepthTest;

                    drawManager.DepthTest = usingDepthTest;
                }

                numOfQuads += command.QuadCount;
                prevCommand = command;
            }

            // Draw any remaining quads
            if (numOfQuads > 0 && prevCommand != null)
            {
                prevCommand.UseMaterial(drawManager);
                drawManager.DrawQuads(currentBatchedQuads, startIndex, numOfQuads);
            }

            quadCommands.Clear();
            currentBatchedQuads.Clear();

            drawManager.PopMatrix();

            drawManager.DepthTest = originalDepthTestState;
        }