Пример #1
0
        public virtual void render()
        {
            makeCurrent();
            updateNativeOverlay();
            mSupport.nextFrame();
            if (mContext == null || mContext.getDriverInfo() == "Disposed")
            {
                return;
            }
            if (!mShareContext)
            {
                AsRenderSupport.clear(mStage.getColor(), 1.0f);
            }
            float scaleX = mViewPort.width / mStage.getStageWidth();
            float scaleY = mViewPort.height / mStage.getStageHeight();

            mContext.setDepthTest(false, AsContext3DCompareMode.ALWAYS);
            mContext.setCulling(AsContext3DTriangleFace.NONE);
            mSupport.setRenderTarget(null);
            mSupport.setOrthographicProjection(mViewPort.x < 0 ? -mViewPort.x / scaleX : 0.0f, mViewPort.y < 0 ? -mViewPort.y / scaleY : 0.0f, mViewPortClipped.width / scaleX, mViewPortClipped.height / scaleY);
            mStage.render(mSupport, 1.0f);
            mSupport.finishQuadBatch();
            if (mStatsDisplay != null)
            {
                mStatsDisplay.setDrawCount(mSupport.getDrawCount());
            }
            if (!mShareContext)
            {
                mContext.present();
            }
        }
Пример #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);
     }
 }
 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);
     }
 }
Пример #4
0
 public override void render(AsRenderSupport support, float parentAlpha)
 {
     support.finishQuadBatch();
     support.raiseDrawCount();
     renderCustom(support.getMvpMatrix(), getAlpha() * parentAlpha, support.getBlendMode());
 }
Пример #5
0
 public override void render(AsRenderSupport support, float parentAlpha)
 {
     support.batchQuad(this, parentAlpha);
 }
 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();
         }
     }
 }
 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;
     }
 }
 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 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);
     }
 }
Пример #11
0
        public AsStarling(AsClass rootClass, bc.flash.display.AsStage stage, AsRectangle viewPort, AsStage3D stage3D, String renderMode, String profile)
        {
            if (stage == null)
            {
                throw new AsArgumentError("Stage must not be null");
            }
            if (rootClass == null)
            {
                throw new AsArgumentError("Root class must not be null");
            }
            if (viewPort == null)
            {
                viewPort = new AsRectangle(0, 0, stage.getStageWidth(), stage.getStageHeight());
            }
            if (stage3D == null)
            {
                stage3D = stage.getStage3Ds()[0];
            }
            makeCurrent();
            mRootClass     = rootClass;
            mViewPort      = viewPort;
            mStage3D       = stage3D;
            mStage         = new AsStage(viewPort.width, viewPort.height, stage.getColor());
            mNativeOverlay = new AsSprite();
            mNativeStage   = stage;
            mNativeStage.addChild(mNativeOverlay);
            mTouchProcessor      = new AsTouchProcessor(mStage);
            mJuggler             = new AsJuggler();
            mAntiAliasing        = 0;
            mSimulateMultitouch  = false;
            mEnableErrorChecking = false;
            mLastFrameTimestamp  = AsGlobal.getTimer() / 1000.0f;
            mPrograms            = new AsDictionary();
            mCustomData          = new AsDictionary();
            mSupport             = new AsRenderSupport();
            AsArray __touchEventTypes_ = getTouchEventTypes();

            if (__touchEventTypes_ != null)
            {
                foreach (String touchEventType in __touchEventTypes_)
                {
                    stage.addEventListener(touchEventType, onTouch, false, 0, true);
                }
            }
            stage.addEventListener(AsEvent.ENTER_FRAME, onEnterFrame, false, 0, true);
            stage.addEventListener(AsKeyboardEvent.KEY_DOWN, onKey, false, 0, true);
            stage.addEventListener(AsKeyboardEvent.KEY_UP, onKey, false, 0, true);
            stage.addEventListener(AsEvent.RESIZE, onResize, false, 0, true);
            if (mStage3D.getContext3D() != null && mStage3D.getContext3D().getDriverInfo() != "Disposed")
            {
                mShareContext = true;
                AsGlobal.setTimeout(initialize, 1);
            }
            else
            {
                mShareContext = false;
                mStage3D.addEventListener(AsEvent.CONTEXT3D_CREATE, onContextCreated, false, 1, true);
                mStage3D.addEventListener(AsErrorEvent.ERROR, onStage3DError, false, 1, true);
                try
                {
                    mStage3D.requestContext3D(renderMode);
                }
                catch (AsError e)
                {
                    showFatalError("Context3D error: " + e.message);
                }
            }
        }
 public virtual void clear(uint rgb, float alpha)
 {
     AsRenderSupport.clear(rgb, alpha);
 }
 public virtual void render(AsRenderSupport support, float parentAlpha)
 {
     throw new AsAbstractMethodError("Method needs to be implemented in subclass");
 }
Пример #14
0
 public override void render(AsRenderSupport support, float parentAlpha)
 {
     if(mRequiresRedraw)
     {
         redrawContents();
     }
     base.render(support, parentAlpha);
 }
Пример #15
0
 public AsStarling(AsClass rootClass, bc.flash.display.AsStage stage, AsRectangle viewPort, AsStage3D stage3D, String renderMode, String profile)
 {
     if(stage == null)
     {
         throw new AsArgumentError("Stage must not be null");
     }
     if(rootClass == null)
     {
         throw new AsArgumentError("Root class must not be null");
     }
     if(viewPort == null)
     {
         viewPort = new AsRectangle(0, 0, stage.getStageWidth(), stage.getStageHeight());
     }
     if(stage3D == null)
     {
         stage3D = stage.getStage3Ds()[0];
     }
     makeCurrent();
     mRootClass = rootClass;
     mViewPort = viewPort;
     mStage3D = stage3D;
     mStage = new AsStage(viewPort.width, viewPort.height, stage.getColor());
     mNativeOverlay = new AsSprite();
     mNativeStage = stage;
     mNativeStage.addChild(mNativeOverlay);
     mTouchProcessor = new AsTouchProcessor(mStage);
     mJuggler = new AsJuggler();
     mAntiAliasing = 0;
     mSimulateMultitouch = false;
     mEnableErrorChecking = false;
     mLastFrameTimestamp = AsGlobal.getTimer() / 1000.0f;
     mPrograms = new AsDictionary();
     mCustomData = new AsDictionary();
     mSupport = new AsRenderSupport();
     AsArray __touchEventTypes_ = getTouchEventTypes();
     if (__touchEventTypes_ != null)
     {
         foreach (String touchEventType in __touchEventTypes_)
         {
             stage.addEventListener(touchEventType, onTouch, false, 0, true);
         }
     }
     stage.addEventListener(AsEvent.ENTER_FRAME, onEnterFrame, false, 0, true);
     stage.addEventListener(AsKeyboardEvent.KEY_DOWN, onKey, false, 0, true);
     stage.addEventListener(AsKeyboardEvent.KEY_UP, onKey, false, 0, true);
     stage.addEventListener(AsEvent.RESIZE, onResize, false, 0, true);
     if(mStage3D.getContext3D() != null && mStage3D.getContext3D().getDriverInfo() != "Disposed")
     {
         mShareContext = true;
         AsGlobal.setTimeout(initialize, 1);
     }
     else
     {
         mShareContext = false;
         mStage3D.addEventListener(AsEvent.CONTEXT3D_CREATE, onContextCreated, false, 1, true);
         mStage3D.addEventListener(AsErrorEvent.ERROR, onStage3DError, false, 1, true);
         try
         {
             mStage3D.requestContext3D(renderMode);
         }
         catch (AsError e)
         {
             showFatalError("Context3D error: " + e.message);
         }
     }
 }
Пример #16
0
 public override void render(AsRenderSupport support, float parentAlpha)
 {
     support.batchQuad(this, parentAlpha, mTexture, mSmoothing);
 }