public static AsTexture empty(int width, int height, bool premultipliedAlpha, bool optimizeForRenderTexture, float scale)
        {
            if (scale <= 0)
            {
                scale = AsStarling.getContentScaleFactor();
            }
            int         origWidth   = (int)(width * scale);
            int         origHeight  = (int)(height * scale);
            int         legalWidth  = AsGlobal.getNextPowerOfTwo(origWidth);
            int         legalHeight = AsGlobal.getNextPowerOfTwo(origHeight);
            String      format      = AsContext3DTextureFormat.BGRA;
            AsContext3D context     = AsStarling.getContext();

            if (context == null)
            {
                throw new AsMissingContextError();
            }
            bc.flash.display3D.textures.AsTexture nativeTexture = context.createTexture(legalWidth, legalHeight, AsContext3DTextureFormat.BGRA, optimizeForRenderTexture);
            AsConcreteTexture concreteTexture = new AsConcreteTexture(nativeTexture, format, legalWidth, legalHeight, false, premultipliedAlpha, optimizeForRenderTexture, scale);

            if (origWidth == legalWidth && origHeight == legalHeight)
            {
                return(concreteTexture);
            }
            else
            {
                return(new AsSubTexture(concreteTexture, new AsRectangle(0, 0, width, height), true));
            }
        }
        public static AsTexture fromColor(int width, int height, uint color, bool optimizeForRenderTexture, float scale)
        {
            if (scale <= 0)
            {
                scale = AsStarling.getContentScaleFactor();
            }
            AsBitmapData bitmapData = new AsBitmapData(width * scale, height * scale, true, color);
            AsTexture    texture    = fromBitmapData(bitmapData, false, optimizeForRenderTexture, scale);

            if (!AsStarling.getHandleLostContext())
            {
                bitmapData.dispose();
            }
            return(texture);
        }
        private void createRenderedContents()
        {
            if (mQuadBatch != null)
            {
                mQuadBatch.removeFromParent(true);
                mQuadBatch = null;
            }
            float        scale      = AsStarling.getContentScaleFactor();
            float        width      = mHitArea.getWidth() * scale;
            float        height     = mHitArea.getHeight() * scale;
            AsTextFormat textFormat = new AsTextFormat(mFontName, mFontSize * scale, mColor, mBold, mItalic, mUnderline, null, null, mHAlign);

            textFormat.setKerning(mKerning);
            sNativeTextField.setDefaultTextFormat(textFormat);
            sNativeTextField.setWidth(width);
            sNativeTextField.setHeight(height);
            sNativeTextField.setAntiAliasType(AsAntiAliasType.ADVANCED);
            sNativeTextField.setSelectable(false);
            sNativeTextField.setMultiline(true);
            sNativeTextField.setWordWrap(true);
            sNativeTextField.setText(mText);
            sNativeTextField.setEmbedFonts(true);
            sNativeTextField.setOwnProperty("filters", mNativeFilters);
            if (sNativeTextField.getTextWidth() == 0.0f || sNativeTextField.getTextHeight() == 0.0f)
            {
                sNativeTextField.setEmbedFonts(false);
            }
            if (mAutoScale)
            {
                autoScaleNativeTextField(sNativeTextField);
            }
            float textWidth  = sNativeTextField.getTextWidth();
            float textHeight = sNativeTextField.getTextHeight();
            float xOffset    = 0.0f;

            if (mHAlign == AsHAlign.LEFT)
            {
                xOffset = 2;
            }
            else
            {
                if (mHAlign == AsHAlign.CENTER)
                {
                    xOffset = (width - textWidth) / 2.0f;
                }
                else
                {
                    if (mHAlign == AsHAlign.RIGHT)
                    {
                        xOffset = width - textWidth - 2;
                    }
                }
            }
            float yOffset = 0.0f;

            if (mVAlign == AsVAlign.TOP)
            {
                yOffset = 2;
            }
            else
            {
                if (mVAlign == AsVAlign.CENTER)
                {
                    yOffset = (height - textHeight) / 2.0f;
                }
                else
                {
                    if (mVAlign == AsVAlign.BOTTOM)
                    {
                        yOffset = height - textHeight - 2;
                    }
                }
            }
            AsBitmapData bitmapData = new AsBitmapData(width, height, true, 0x0);

            bitmapData.draw(sNativeTextField, new AsMatrix(1, 0, 0, 1, 0, ((int)(yOffset)) - 2));
            sNativeTextField.setText("");
            if (mTextBounds == null)
            {
                mTextBounds = new AsRectangle();
            }
            mTextBounds.setTo(xOffset / scale, yOffset / scale, textWidth / scale, textHeight / scale);
            AsTexture texture = AsTexture.fromBitmapData(bitmapData, false, false, scale);

            if (mImage == null)
            {
                mImage = new AsImage(texture);
                mImage.setTouchable(false);
                addChild(mImage);
            }
            else
            {
                mImage.getTexture().dispose();
                mImage.setTexture(texture);
                mImage.readjustSize();
            }
        }
        public AsRenderTexture(int width, int height, bool persistent, float scale)
            : base(mActiveTexture = AsTexture.empty(width, height, PMA, true, scale = scale <= 0 ? AsStarling.getContentScaleFactor() : scale), new AsRectangle(0, 0, width, height), true)
        {
            int nativeWidth  = AsGlobal.getNextPowerOfTwo((int)(width * scale));
            int nativeHeight = AsGlobal.getNextPowerOfTwo((int)(height * scale));

            mSupport = new AsRenderSupport();
            mSupport.setOrthographicProjection(0, 0, nativeWidth / scale, nativeHeight / scale);
            if (persistent)
            {
                mBufferTexture = AsTexture.empty(width, height, PMA, true, scale);
                mHelperImage   = new AsImage(mBufferTexture);
                mHelperImage.setSmoothing(AsTextureSmoothing.NONE);
            }
        }