Пример #1
0
        public virtual void addQuadBatch(AsQuadBatch quadBatch, float parentAlpha, AsMatrix modelViewMatrix, String blendMode)
        {
            if (modelViewMatrix == null)
            {
                modelViewMatrix = quadBatch.getTransformationMatrix();
            }
            bool  tinted   = quadBatch.mTinted || parentAlpha != 1.0f;
            float alpha    = parentAlpha * quadBatch.getAlpha();
            int   vertexID = mNumQuads * 4;
            int   numQuads = quadBatch.getNumQuads();

            if (mNumQuads + numQuads > getCapacity())
            {
                expand(mNumQuads + numQuads);
            }
            if (mNumQuads == 0)
            {
                this.setBlendMode(blendMode != null ? blendMode : quadBatch.getBlendMode());
                mTexture   = quadBatch.mTexture;
                mTinted    = tinted;
                mSmoothing = quadBatch.mSmoothing;
                mVertexData.setPremultipliedAlpha(quadBatch.mVertexData.getPremultipliedAlpha(), false);
            }
            quadBatch.mVertexData.copyTo(mVertexData, vertexID, 0, numQuads * 4);
            mVertexData.transformVertex(vertexID, modelViewMatrix, numQuads * 4);
            if (alpha != 1.0f)
            {
                mVertexData.scaleAlpha(vertexID, alpha, numQuads * 4);
            }
            mSyncRequired = true;
            mNumQuads     = mNumQuads + numQuads;
        }
Пример #2
0
 public override void render(AsRenderSupport support, float parentAlpha)
 {
     if (mFlattenedContents != null || mFlattenRequested)
     {
         if (mFlattenedContents == null)
         {
             mFlattenedContents = new AsVector <AsQuadBatch>();
         }
         if (mFlattenRequested)
         {
             AsQuadBatch.compile(this, mFlattenedContents);
             mFlattenRequested = false;
         }
         float    alpha      = parentAlpha * this.getAlpha();
         int      numBatches = (int)(mFlattenedContents.getLength());
         AsMatrix mvpMatrix  = support.getMvpMatrix();
         support.finishQuadBatch();
         support.raiseDrawCount((uint)(numBatches));
         int i = 0;
         for (; i < numBatches; ++i)
         {
             AsQuadBatch quadBatch = mFlattenedContents[i];
             String      blendMode = quadBatch.getBlendMode() == AsBlendMode.AUTO ? support.getBlendMode() : quadBatch.getBlendMode();
             quadBatch.renderCustom(mvpMatrix, alpha, blendMode);
         }
     }
     else
     {
         base.render(support, parentAlpha);
     }
 }
Пример #3
0
        public virtual AsQuadBatch clone()
        {
            AsQuadBatch clone = new AsQuadBatch();

            clone.mVertexData   = mVertexData.clone(0, mNumQuads * 4);
            clone.mIndexData    = mIndexData.slice(0, mNumQuads * 6);
            clone.mNumQuads     = mNumQuads;
            clone.mTinted       = mTinted;
            clone.mTexture      = mTexture;
            clone.mSmoothing    = mSmoothing;
            clone.mSyncRequired = true;
            clone.setBlendMode(getBlendMode());
            clone.setAlpha(getAlpha());
            return(clone);
        }
Пример #4
0
 public virtual void addQuadBatch(AsQuadBatch quadBatch, float parentAlpha, AsMatrix modelViewMatrix)
 {
     addQuadBatch(quadBatch, parentAlpha, modelViewMatrix, null);
 }
Пример #5
0
 public virtual void addQuadBatch(AsQuadBatch quadBatch, float parentAlpha, AsMatrix modelViewMatrix, String blendMode)
 {
     if(modelViewMatrix == null)
     {
         modelViewMatrix = quadBatch.getTransformationMatrix();
     }
     bool tinted = quadBatch.mTinted || parentAlpha != 1.0f;
     float alpha = parentAlpha * quadBatch.getAlpha();
     int vertexID = mNumQuads * 4;
     int numQuads = quadBatch.getNumQuads();
     if(mNumQuads + numQuads > getCapacity())
     {
         expand(mNumQuads + numQuads);
     }
     if(mNumQuads == 0)
     {
         this.setBlendMode(blendMode != null ? blendMode : quadBatch.getBlendMode());
         mTexture = quadBatch.mTexture;
         mTinted = tinted;
         mSmoothing = quadBatch.mSmoothing;
         mVertexData.setPremultipliedAlpha(quadBatch.mVertexData.getPremultipliedAlpha(), false);
     }
     quadBatch.mVertexData.copyTo(mVertexData, vertexID, 0, numQuads * 4);
     mVertexData.transformVertex(vertexID, modelViewMatrix, numQuads * 4);
     if(alpha != 1.0f)
     {
         mVertexData.scaleAlpha(vertexID, alpha, numQuads * 4);
     }
     mSyncRequired = true;
     mNumQuads = mNumQuads + numQuads;
 }
Пример #6
0
        private static int compileObject(AsDisplayObject _object, AsVector <AsQuadBatch> quadBatches, int quadBatchID, AsMatrix transformationMatrix, float alpha, String blendMode, bool ignoreCurrentFilter)
        {
            int         i                      = 0;
            AsQuadBatch quadBatch              = null;
            bool        isRootObject           = false;
            float       objectAlpha            = _object.getAlpha();
            AsDisplayObjectContainer container = _object as AsDisplayObjectContainer;
            AsQuad           quad              = _object as AsQuad;
            AsQuadBatch      batch             = _object as AsQuadBatch;
            AsFragmentFilter filter            = _object.getFilter();

            if (quadBatchID == -1)
            {
                isRootObject = true;
                quadBatchID  = 0;
                objectAlpha  = 1.0f;
                blendMode    = _object.getBlendMode();
                if (quadBatches.getLength() == 0)
                {
                    quadBatches.push(new AsQuadBatch());
                }
                else
                {
                    quadBatches[0].reset();
                }
            }
            if (filter != null && !ignoreCurrentFilter)
            {
                if (filter.getMode() == AsFragmentFilterMode.ABOVE)
                {
                    quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true);
                }
                quadBatchID = compileObject(filter.compile(_object), quadBatches, quadBatchID, transformationMatrix, alpha, blendMode);
                if (filter.getMode() == AsFragmentFilterMode.BELOW)
                {
                    quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true);
                }
            }
            else
            {
                if (container != null)
                {
                    int      numChildren = container.getNumChildren();
                    AsMatrix childMatrix = new AsMatrix();
                    for (i = 0; i < numChildren; ++i)
                    {
                        AsDisplayObject child        = container.getChildAt(i);
                        bool            childVisible = child.getAlpha() != 0.0f && child.getVisible() && child.getScaleX() != 0.0f && child.getScaleY() != 0.0f;
                        if (childVisible)
                        {
                            String childBlendMode = child.getBlendMode() == AsBlendMode.AUTO ? blendMode : child.getBlendMode();
                            childMatrix.copyFrom(transformationMatrix);
                            AsRenderSupport.transformMatrixForObject(childMatrix, child);
                            quadBatchID = compileObject(child, quadBatches, quadBatchID, childMatrix, alpha * objectAlpha, childBlendMode);
                        }
                    }
                }
                else
                {
                    if (quad != null || batch != null)
                    {
                        AsTexture texture   = null;
                        String    smoothing = null;
                        bool      tinted    = false;
                        int       numQuads  = 0;
                        if (quad != null)
                        {
                            AsImage image = quad as AsImage;
                            texture = image != null?image.getTexture() : null;

                            smoothing = image != null?image.getSmoothing() : null;

                            tinted   = quad.getTinted();
                            numQuads = 1;
                        }
                        else
                        {
                            texture   = batch.mTexture;
                            smoothing = batch.mSmoothing;
                            tinted    = batch.mTinted;
                            numQuads  = batch.mNumQuads;
                        }
                        quadBatch = quadBatches[quadBatchID];
                        if (quadBatch.isStateChange(tinted, alpha * objectAlpha, texture, smoothing, blendMode, numQuads))
                        {
                            quadBatchID++;
                            if (quadBatches.getLength() <= quadBatchID)
                            {
                                quadBatches.push(new AsQuadBatch());
                            }
                            quadBatch = quadBatches[quadBatchID];
                            quadBatch.reset();
                        }
                        if (quad != null)
                        {
                            quadBatch.addQuad(quad, alpha, texture, smoothing, transformationMatrix, blendMode);
                        }
                        else
                        {
                            quadBatch.addQuadBatch(batch, alpha, transformationMatrix, blendMode);
                        }
                    }
                    else
                    {
                        throw new AsError("Unsupported display object: " + AsGlobal.getQualifiedClassName(_object));
                    }
                }
            }
            if (isRootObject)
            {
                for (i = (int)(quadBatches.getLength() - 1); i > quadBatchID; --i)
                {
                    quadBatches.pop().dispose();
                }
            }
            return(quadBatchID);
        }
Пример #7
0
 public virtual void addQuadBatch(AsQuadBatch quadBatch, float parentAlpha)
 {
     addQuadBatch(quadBatch, parentAlpha, null, null);
 }
Пример #8
0
 public virtual void addQuadBatch(AsQuadBatch quadBatch)
 {
     addQuadBatch(quadBatch, 1.0f, null, null);
 }
Пример #9
0
 public virtual AsQuadBatch clone()
 {
     AsQuadBatch clone = new AsQuadBatch();
     clone.mVertexData = mVertexData.clone(0, mNumQuads * 4);
     clone.mIndexData = mIndexData.slice(0, mNumQuads * 6);
     clone.mNumQuads = mNumQuads;
     clone.mTinted = mTinted;
     clone.mTexture = mTexture;
     clone.mSmoothing = mSmoothing;
     clone.mSyncRequired = true;
     clone.setBlendMode(getBlendMode());
     clone.setAlpha(getAlpha());
     return clone;
 }
 private void disposeCache()
 {
     if(mCache != null)
     {
         mCache.getTexture().dispose();
         mCache.dispose();
         mCache = null;
     }
 }
Пример #11
0
 public virtual void fillQuadBatch(AsQuadBatch quadBatch, float width, float height, String text, float fontSize, uint color)
 {
     fillQuadBatch(quadBatch, width, height, text, fontSize, color, "center", "center", true, true);
 }
Пример #12
0
 public virtual void fillQuadBatch(AsQuadBatch quadBatch, float width, float height, String text)
 {
     fillQuadBatch(quadBatch, width, height, text, -1, (uint)(0xffffff), "center", "center", true, true);
 }
Пример #13
0
 public virtual void fillQuadBatch(AsQuadBatch quadBatch, float width, float height, String text, float fontSize, uint color, String hAlign, String vAlign)
 {
     fillQuadBatch(quadBatch, width, height, text, fontSize, color, hAlign, vAlign, true, true);
 }
Пример #14
0
 public virtual void fillQuadBatch(AsQuadBatch quadBatch, float width, float height, String text, float fontSize, uint color, String hAlign, String vAlign, bool autoScale, bool kerning)
 {
     AsVector<AsCharLocation> charLocations = arrangeChars(width, height, text, fontSize, hAlign, vAlign, autoScale, kerning);
     int numChars = (int)(charLocations.getLength());
     mHelperImage.setColor(color);
     if(numChars > 8192)
     {
         throw new AsArgumentError("Bitmap Font text is limited to 8192 characters.");
     }
     int i = 0;
     for (; i < numChars; ++i)
     {
         AsCharLocation charLocation = charLocations[i];
         mHelperImage.setTexture(charLocation._char.getTexture());
         mHelperImage.readjustSize();
         mHelperImage.setX(charLocation.x);
         mHelperImage.setY(charLocation.y);
         mHelperImage.setScaleX(mHelperImage.setScaleY(charLocation.scale));
         quadBatch.addImage(mHelperImage);
     }
 }
 private AsQuadBatch renderPasses(AsDisplayObject _object, AsRenderSupport support, float parentAlpha, bool intoCache)
 {
     AsTexture cacheTexture = null;
     AsStage stage = _object.getStage();
     AsContext3D context = AsStarling.getContext();
     float scale = AsStarling.getCurrent().getContentScaleFactor();
     if(stage == null)
     {
         throw new AsError("Filtered object must be on the stage.");
     }
     if(context == null)
     {
         throw new AsMissingContextError();
     }
     support.finishQuadBatch();
     support.raiseDrawCount((uint)(mNumPasses));
     support.pushMatrix();
     support.setBlendMode(AsBlendMode.NORMAL);
     AsRenderSupport.setBlendFactors(PMA);
     mProjMatrix.copyFrom(support.getProjectionMatrix());
     AsTexture previousRenderTarget = support.getRenderTarget();
     if(previousRenderTarget != null)
     {
         throw new AsIllegalOperationError("It's currently not possible to stack filters! " + "This limitation will be removed in a future Stage3D version.");
     }
     calculateBounds(_object, stage, sBounds);
     updateBuffers(context, sBounds);
     updatePassTextures((int)(sBounds.width), (int)(sBounds.height), mResolution * scale);
     if(intoCache)
     {
         cacheTexture = AsTexture.empty((int)(sBounds.width), (int)(sBounds.height), PMA, true, mResolution * scale);
     }
     support.setRenderTarget(mPassTextures[0]);
     support.clear();
     support.setOrthographicProjection(sBounds.x, sBounds.y, sBounds.width, sBounds.height);
     _object.render(support, parentAlpha);
     support.finishQuadBatch();
     AsRenderSupport.setBlendFactors(PMA);
     support.loadIdentity();
     context.setVertexBufferAt(0, mVertexBuffer, AsVertexData.POSITION_OFFSET, AsContext3DVertexBufferFormat.FLOAT_2);
     context.setVertexBufferAt(1, mVertexBuffer, AsVertexData.TEXCOORD_OFFSET, AsContext3DVertexBufferFormat.FLOAT_2);
     int i = 0;
     for (; i < mNumPasses; ++i)
     {
         if(i < mNumPasses - 1)
         {
             support.setRenderTarget(getPassTexture(i + 1));
             support.clear();
         }
         else
         {
             if(intoCache)
             {
                 support.setRenderTarget(cacheTexture);
                 support.clear();
             }
             else
             {
                 support.setRenderTarget(previousRenderTarget);
                 support.getProjectionMatrix().copyFrom(mProjMatrix);
                 support.translateMatrix(mOffsetX, mOffsetY);
                 support.setBlendMode(_object.getBlendMode());
                 support.applyBlendMode(PMA);
             }
         }
         AsTexture passTexture = getPassTexture(i);
         context.setProgramConstantsFromMatrix(AsContext3DProgramType.VERTEX, 0, support.getMvpMatrix3D(), true);
         context.setTextureAt(0, passTexture.get_base());
         activate(i, context, passTexture);
         context.drawTriangles(mIndexBuffer, 0, 2);
         deactivate(i, context, passTexture);
     }
     context.setVertexBufferAt(0, null);
     context.setVertexBufferAt(1, null);
     context.setTextureAt(0, null);
     support.popMatrix();
     if(intoCache)
     {
         support.setRenderTarget(previousRenderTarget);
         support.getProjectionMatrix().copyFrom(mProjMatrix);
         AsQuadBatch quadBatch = new AsQuadBatch();
         AsImage image = new AsImage(cacheTexture);
         stage.getTransformationMatrix(_object, sTransformationMatrix);
         AsMatrixUtil.prependTranslation(sTransformationMatrix, sBounds.x + mOffsetX, sBounds.y + mOffsetY);
         quadBatch.addImage(image, 1.0f, sTransformationMatrix);
         return quadBatch;
     }
     else
     {
         return null;
     }
 }
Пример #16
0
 public virtual void addQuadBatch(AsQuadBatch quadBatch, float parentAlpha)
 {
     addQuadBatch(quadBatch, parentAlpha, null, null);
 }
Пример #17
0
 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();
     }
 }
Пример #18
0
 public virtual void addQuadBatch(AsQuadBatch quadBatch)
 {
     addQuadBatch(quadBatch, 1.0f, null, null);
 }
 public virtual void render(AsDisplayObject _object, AsRenderSupport support, float parentAlpha)
 {
     if(getMode() == AsFragmentFilterMode.ABOVE)
     {
         _object.render(support, parentAlpha);
     }
     if(mCacheRequested)
     {
         mCacheRequested = false;
         mCache = renderPasses(_object, support, 1.0f, true);
         disposePassTextures();
     }
     if(mCache != null)
     {
         mCache.render(support, _object.getAlpha() * parentAlpha);
     }
     else
     {
         renderPasses(_object, support, parentAlpha, false);
     }
     if(getMode() == AsFragmentFilterMode.BELOW)
     {
         _object.render(support, parentAlpha);
     }
 }
Пример #20
0
 public virtual void addQuadBatch(AsQuadBatch quadBatch, float parentAlpha, AsMatrix modelViewMatrix)
 {
     addQuadBatch(quadBatch, parentAlpha, modelViewMatrix, null);
 }
Пример #21
0
 private void createComposedContents()
 {
     if(mImage != null)
     {
         mImage.removeFromParent(true);
         mImage = null;
     }
     if(mQuadBatch == null)
     {
         mQuadBatch = new AsQuadBatch();
         mQuadBatch.setTouchable(false);
         addChild(mQuadBatch);
     }
     else
     {
         mQuadBatch.reset();
     }
     AsBitmapFont bitmapFont = (AsBitmapFont)(getBitmapFonts()[mFontName]);
     if(bitmapFont == null)
     {
         throw new AsError("Bitmap font not registered: " + mFontName);
     }
     bitmapFont.fillQuadBatch(mQuadBatch, mHitArea.getWidth(), mHitArea.getHeight(), mText, mFontSize, mColor, mHAlign, mVAlign, mAutoScale, mKerning);
     mTextBounds = null;
 }