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 drawBundled(AsDrawingBlockCallback drawingBlock, int antiAliasing) { float scale = mActiveTexture.getScale(); AsContext3D context = AsStarling.getContext(); if (context == null) { throw new AsMissingContextError(); } sScissorRect.setTo(0, 0, mActiveTexture.getWidth() * scale, mActiveTexture.getHeight() * scale); context.setScissorRectangle(sScissorRect); if (getIsPersistent()) { AsTexture tmpTexture = mActiveTexture; mActiveTexture = mBufferTexture; mBufferTexture = tmpTexture; mHelperImage.setTexture(mBufferTexture); } mSupport.setRenderTarget(mActiveTexture); mSupport.clear(); if (getIsPersistent() && mBufferReady) { mHelperImage.render(mSupport, 1.0f); } else { mBufferReady = true; } try { mDrawing = true; if (drawingBlock != null) { drawingBlock(); } } finally { mDrawing = false; mSupport.finishQuadBatch(); mSupport.nextFrame(); mSupport.setRenderTarget(null); context.setScissorRectangle(null); } }
public override void render(AsRenderSupport support, float parentAlpha) { support.finishQuadBatch(); support.raiseDrawCount(); renderCustom(support.getMvpMatrix(), getAlpha() * parentAlpha, support.getBlendMode()); }
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); } }