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; } }