public override void render(AsRenderSupport support, float parentAlpha)
        {
            float  alpha       = parentAlpha * this.getAlpha();
            int    numChildren = (int)(mChildren.getLength());
            String blendMode   = support.getBlendMode();
            int    i           = 0;

            for (; i < numChildren; ++i)
            {
                AsDisplayObject child = mChildren[i];
                if (child.getHasVisibleArea())
                {
                    AsFragmentFilter filter = child.getFilter();
                    support.pushMatrix();
                    support.transformMatrix(child);
                    support.setBlendMode(child.getBlendMode());
                    if (filter != null)
                    {
                        filter.render(child, support, alpha);
                    }
                    else
                    {
                        child.render(support, alpha);
                    }
                    support.setBlendMode(blendMode);
                    support.popMatrix();
                }
            }
        }
 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);
     }
 }
 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);
     }
 }
 public override void render(AsRenderSupport support, float parentAlpha)
 {
     if (mRequiresRedraw)
     {
         redrawContents();
     }
     base.render(support, parentAlpha);
 }
        public NativeApplication(int width, int height, ContentManager content)
        {
            resFactory = new BcResFactory(content);

            renderSupport = new AsRenderSupport();

            input = new NativeInput();
            input.AddGamePadListener(this);
            input.AddKeyboardListener(this);
            input.AddTouchListener(this);
            running = true;

            stage = new AsStage(width, height);
        }
        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);
            }
        }
        public override void render(AsRenderSupport support, float alpha)
        {
            alpha = alpha * this.getAlpha();
            int childsCount = getNumChildren();
            int i           = 0;

            for (; i < childsCount; ++i)
            {
                AsDisplayObject child = mChildren[i];
                if (child.getAlpha() != 0.0f && child.getVisible() && child.getScaleX() != 0.0f && child.getScaleY() != 0.0f)
                {
                    support.pushMatrix();
                    support.transform(child.getTransform().getMatrix());
                    child.render(support, alpha);
                    support.popMatrix();
                }
            }
        }
 public virtual AsQuadBatch compile(AsDisplayObject _object)
 {
     if (mCache != null)
     {
         return(mCache);
     }
     else
     {
         AsRenderSupport renderSupport = null;
         AsStage         stage         = _object.getStage();
         if (stage == null)
         {
             throw new AsError("Filtered object must be on the stage.");
         }
         renderSupport = new AsRenderSupport();
         _object.getTransformationMatrix(stage, renderSupport.getModelViewMatrix());
         return(renderPasses(_object, renderSupport, 1.0f, true));
     }
 }
        public virtual void renderCustom(AsMatrix mvpMatrix, float parentAlpha, String blendMode)
        {
            if (mNumQuads == 0)
            {
                return;
            }
            if (mSyncRequired)
            {
                syncBuffers();
            }
            bool        pma         = mVertexData.getPremultipliedAlpha();
            AsContext3D context     = AsStarling.getContext();
            bool        tinted      = mTinted || (parentAlpha != 1.0f);
            String      programName = mTexture != null?getImageProgramName(tinted, mTexture.getMipMapping(), mTexture.getRepeat(), mTexture.getFormat(), mSmoothing) : QUAD_PROGRAM_NAME;

            sRenderAlpha[0] = sRenderAlpha[1] = sRenderAlpha[2] = pma ? parentAlpha : 1.0f;
            sRenderAlpha[3] = parentAlpha;
            AsMatrixUtil.convertTo3D(mvpMatrix, sRenderMatrix);
            AsRenderSupport.setBlendFactors(pma, blendMode != null ? blendMode : this.getBlendMode());
            context.setProgram(AsStarling.getCurrent().getProgram(programName));
            context.setProgramConstantsFromVector(AsContext3DProgramType.VERTEX, 0, sRenderAlpha, 1);
            context.setProgramConstantsFromMatrix(AsContext3DProgramType.VERTEX, 1, sRenderMatrix, true);
            context.setVertexBufferAt(0, mVertexBuffer, AsVertexData.POSITION_OFFSET, AsContext3DVertexBufferFormat.FLOAT_2);
            if (mTexture == null || tinted)
            {
                context.setVertexBufferAt(1, mVertexBuffer, AsVertexData.COLOR_OFFSET, AsContext3DVertexBufferFormat.FLOAT_4);
            }
            if (mTexture != null)
            {
                context.setTextureAt(0, mTexture.get_base());
                context.setVertexBufferAt(2, mVertexBuffer, AsVertexData.TEXCOORD_OFFSET, AsContext3DVertexBufferFormat.FLOAT_2);
            }
            context.drawTriangles(mIndexBuffer, 0, mNumQuads * 2);
            if (mTexture != null)
            {
                context.setTextureAt(0, null);
                context.setVertexBufferAt(2, null);
            }
            context.setVertexBufferAt(1, null);
            context.setVertexBufferAt(0, null);
        }
 public override void render(AsRenderSupport support, float parentAlpha)
 {
     support.batchQuad(this, parentAlpha, mTexture, mSmoothing);
 }
 public virtual void render(AsRenderSupport support, float alpha)
 {
     throw new AsAbstractMethodError("Method needs to be implemented in subclass");
 }
Beispiel #12
0
 public override void render(AsRenderSupport support, float alpha)
 {
 }
        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);
        }
 public override void render(AsRenderSupport support, float parentAlpha)
 {
     support.finishQuadBatch();
     support.raiseDrawCount();
     renderCustom(support.getMvpMatrix(), getAlpha() * parentAlpha, support.getBlendMode());
 }
Beispiel #15
0
 public override void render(AsRenderSupport support, float parentAlpha)
 {
     support.batchQuad(this, parentAlpha);
 }
 private AsQuadBatch renderPasses(AsDisplayObject _object, AsRenderSupport support, float parentAlpha)
 {
     return(renderPasses(_object, support, parentAlpha, false));
 }
        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);
            }
        }