Exemple #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;
        }
Exemple #2
0
        internal void ProcessQuadRenderCommand(CCQuadCommand quadCommand)
        {
            var worldTransform = quadCommand.WorldTransform;
            var identity       = worldTransform == CCAffineTransform.Identity;

            quadCommands.Add(quadCommand);

            var quads = quadCommand.Quads;

            for (int i = 0, N = quadCommand.QuadCount; i < N; ++i)
            {
                if (identity)
                {
                    currentBatchedQuads.Add(quads[i]);
                }
                else
                {
                    currentBatchedQuads.Add(worldTransform.Transform(quads[i]));
                }
            }

            // We're changing command types so render any pending sequence of commandss
            // e.g. Batched quad commands
            if ((currentCommandType & CCCommandType.Quad) == CCCommandType.None)
            {
                Flush();
            }

            currentCommandType = CCCommandType.Quad;
        }
Exemple #3
0
        public CCSprite()
        {
            quadCommand = new CCQuadCommand(1);

            IsTextureRectRotated = false;

            opacityModifyRGB = true;
            BlendFunc        = CCBlendFunc.AlphaBlend;

            texQuadDirty = true;
        }
        protected CCQuadCommand(CCQuadCommand copy)
            : base(copy)
        {
            Quads     = copy.quads;
            QuadCount = copy.QuadCount;
            Texture   = copy.Texture;
            BlendType = copy.BlendType;

            materialId      = copy.materialId;
            materialIdDirty = copy.materialIdDirty;
        }
Exemple #5
0
        public CCAtlasNode(CCTexture2D texture, int tileWidth, int tileHeight, int itemsToRender)
        {
            ItemWidth  = tileWidth;
            ItemHeight = tileHeight;

            ColorUnmodified    = CCColor3B.White;
            IsOpacityModifyRGB = false;
            BlendFunc          = CCBlendFunc.AlphaBlend;

            TextureAtlas = new CCTextureAtlas(texture, itemsToRender);

            UpdateBlendFunc();
            UpdateOpacityModifyRgb();

            CalculateMaxItems();
            QuadsToDraw = itemsToRender;

            quadCommand = new CCQuadCommand(QuadsToDraw);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CocosSharp.CCLabel"/> class.
        /// </summary>
        /// <param name="str">Initial text of the label.</param>
        /// <param name="fntFile">Font definition file to use.</param>
        /// <param name="size">Font point size.</param>
        /// <param name="dimensions">Dimensions that the label should use to layout it's text.</param>
        /// <param name="labelFormat">Label format <see cref="CocosSharp.CCLabelFormat"/>.</param>
        /// <param name="imageOffset">Image offset.</param>
        /// <param name="texture">Texture atlas to be used.</param>
        public CCLabel(string str, string fntFile, float size, CCSize dimensions, CCLabelFormat labelFormat, CCPoint imageOffset, CCTexture2D texture)
        {
            quadCommand = new CCQuadCommand(str.Length);

            this.labelFormat = (size == 0 && labelFormat.FormatFlags == CCLabelFormatFlags.Unknown) 
                ? CCLabelFormat.BitMapFont 
                : labelFormat;

            if (this.labelFormat.FormatFlags == CCLabelFormatFlags.Unknown)
            {
                // First we try loading BitMapFont
                CCLog.Log("Label Format Unknown: Trying BitmapFont ...");
                InitBMFont(str, fntFile, dimensions, labelFormat.Alignment, labelFormat.LineAlignment, imageOffset, texture);
                // If we do not load a Bitmap Font then try a SpriteFont
                if (FontAtlas == null)
                {
                    CCLog.Log("Label Format Unknown: Trying SpriteFont ...");
                    InitSpriteFont(str, fntFile, size, dimensions, labelFormat, imageOffset, texture);
                }
                // If we do not load a Bitmap Font nor a SpriteFont then try the last time for a System Font
                if (FontAtlas == null)
                {
                    CCLog.Log("Label Format Unknown: Trying System Font ...");
                    LabelType = CCLabelType.SystemFont;
                    SystemFont = fntFile;
                    SystemFontSize = size;
                    Dimensions = dimensions;
                    AnchorPoint = CCPoint.AnchorMiddle;
                    BlendFunc = CCBlendFunc.AlphaBlend;
                    Text = str;
                }
            }
            else if(this.labelFormat.FormatFlags == CCLabelFormatFlags.BitmapFont)
            {
                // Initialize the BitmapFont
                InitBMFont(str, fntFile, dimensions, labelFormat.Alignment, labelFormat.LineAlignment, imageOffset, texture);
            }
            else if(this.labelFormat.FormatFlags == CCLabelFormatFlags.SpriteFont)
            {
                // Initialize the SpriteFont
                InitSpriteFont(str, fntFile, size, dimensions, labelFormat, imageOffset, texture);

            }
            else if(this.labelFormat.FormatFlags == CCLabelFormatFlags.SystemFont)
            {
                LabelType = CCLabelType.SystemFont;
                SystemFont = fntFile;
                SystemFontSize = size;
                Dimensions = dimensions;
                AnchorPoint = CCPoint.AnchorMiddle;
                BlendFunc = CCBlendFunc.AlphaBlend;
                Text = str;
            }

        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CocosSharp.CCLabel"/> class.
        /// </summary>
        /// <param name="str">Initial text of the label.</param>
        /// <param name="fntFile">Font definition file to use.</param>
        /// <param name="size">Font point size.</param>
        /// <param name="dimensions">Dimensions that the label should use to layout it's text.</param>
        /// <param name="labelFormat">Label format <see cref="CocosSharp.CCLabelFormat"/>.</param>
        /// <param name="imageOffset">Image offset.</param>
        /// <param name="texture">Texture atlas to be used.</param>
        public CCLabel(CCFontFNT fntFontConfig, string str, CCSize dimensions, CCLabelFormat labelFormat)
        {
            quadCommand = new CCQuadCommand(str.Length);

            labelFormat.FormatFlags = CCLabelFormatFlags.BitmapFont;
            AnchorPoint = CCPoint.AnchorMiddle;

            try
            {
                FontAtlas = CCFontAtlasCache.GetFontAtlasFNT(fntFontConfig);
            }
            catch { }

            if (FontAtlas == null)
            {
                CCLog.Log("Bitmap Font CCLabel: Impossible to create font. Please check CCFontFNT file: ");
                return;
            }

            LabelType = CCLabelType.BitMapFont;
            this.labelFormat = labelFormat;

            if (String.IsNullOrEmpty(str))
            {
                str = String.Empty;
            }

            // Initialize the TextureAtlas along with children.
            var capacity = str.Length;

            BlendFunc = CCBlendFunc.AlphaBlend;

            if (capacity == 0)
            {
                capacity = defaultSpriteBatchCapacity;
            }

            UpdateBlendFunc();

            // no lazy alloc in this node
            Children = new CCRawList<CCNode>(capacity);
            Descendants = new CCRawList<CCSprite>(capacity);

            this.labelDimensions = dimensions;

            horzAlignment = labelFormat.Alignment;
            vertAlignment = labelFormat.LineAlignment;

            IsOpacityCascaded = true;

            // We use base here so we do not trigger an update internally.
            base.ContentSize = CCSize.Zero;

            IsColorModifiedByOpacity = TextureAtlas.Texture.HasPremultipliedAlpha;
            AnchorPoint = CCPoint.AnchorMiddle;

            ImageOffset = CCPoint.Zero;

            Text = str;
        }
Exemple #8
0
        internal void ProcessQuadRenderCommand(CCQuadCommand quadCommand)
        {
            var worldTransform = quadCommand.WorldTransform;
            var identity = worldTransform == CCAffineTransform.Identity;

            quadCommands.Add(quadCommand);

            var quads = quadCommand.Quads;
            for (int i = 0, N = quadCommand.QuadCount; i < N; ++i)
            {
                if (identity)
                    currentBatchedQuads.Add(quads[i]);
                else
                    currentBatchedQuads.Add(worldTransform.Transform(quads[i]));
            }

            // We're changing command types so render any pending sequence of commandss
            // e.g. Batched quad commands
            if((currentCommandType & CCCommandType.Quad) == CCCommandType.None)
                Flush();

            currentCommandType = CCCommandType.Quad;
        }
        protected CCQuadCommand(CCQuadCommand copy)
            : base(copy)
        {
            Quads = copy.quads;
            QuadCount = copy.QuadCount;
            Texture = copy.Texture;
            BlendType = copy.BlendType;

            materialId = copy.materialId;
            materialIdDirty = copy.materialIdDirty;
        }
        public CCSprite()
        {
            quadCommand = new CCQuadCommand(1);

            IsTextureRectRotated = false;

            opacityModifyRGB = true;
            BlendFunc = CCBlendFunc.AlphaBlend;

            texQuadDirty = true;
        }
Exemple #11
0
 protected override void VisitRenderer(ref CCAffineTransform worldTransform)
 {
     var quadsCommand = new CCQuadCommand(worldTransform.Tz, worldTransform, Texture, BlendFunc, QuadsToDraw, TextureAtlas.Quads.Elements);
     Renderer.AddCommand(quadsCommand);
 }
        protected override void VisitRenderer(ref CCAffineTransform worldTransform)
        {
            var quadsCommand = new CCQuadCommand(worldTransform.Tz, worldTransform, Texture, BlendFunc, QuadsToDraw, TextureAtlas.Quads.Elements);

            Renderer.AddCommand(quadsCommand);
        }