Example #1
0
        /// <summary>Sets up the current batch as a 'globally isolated' batch. This acts like a hybrid between isolated
        /// and shared.</summary>
        /// <param name="property">The displayable property which wants the batch.</param>
        /// <param name="fontTexture">The font texture to use with this batch.</param>
        public void SetupBatchGI(DisplayableProperty property, TextureAtlas graphics, TextureAtlas font)
        {
            if (!property.Isolated)
            {
                // Ordinary non-isolated batch:
                SetupBatch(property, graphics, font);
                return;
            }

            if (property.GotBatchAlready)
            {
                // Re-use existing batch?

                if (font != null)
                {
                    if (CurrentBatch.FontAtlas == null)
                    {
                        // Didn't have one assigned before. Assign now:
                        CurrentBatch.SetFontAtlas(font);
                    }
                    else if (font != CurrentBatch.FontAtlas)
                    {
                        // Font atlas changed. Can't share.
                        CurrentBatch = null;
                    }
                }

                if (graphics != null)
                {
                    if (CurrentBatch.GraphicsAtlas == null)
                    {
                        // Didn't have one assigned before. Assign now:
                        CurrentBatch.SetGraphicsAtlas(graphics);
                    }
                    else if (graphics != CurrentBatch.GraphicsAtlas)
                    {
                        // Atlas changed. Can't share.
                        CurrentBatch = null;
                    }
                }

                if (CurrentBatch != null)
                {
                    // Yep - reuse it.
                    return;
                }
            }

            // First timer or new one required - create:
            CurrentBatch = UIBatchPool.Get(this);

            if (CurrentBatch == null)
            {
                CurrentBatch = new UIBatch(this);
            }

            property.GotBatchAlready = true;

            // And push it to the active stack:
            AddBatch(CurrentBatch);

            // Use the global material, but set it as isolated
            // (note that we don't want to set CurrentBatch.IsolatedProperty as it may get unintentionally spammed):
            CurrentBatch.NotIsolated(graphics, font);
            CurrentBatch.Isolated = true;

            // Finally, prepare it for layout:
            CurrentBatch.PrepareForLayout();
        }