Пример #1
0
 public virtual void addQuad(AsQuad quad, float parentAlpha, AsTexture texture, String smoothing, AsMatrix modelViewMatrix, String blendMode)
 {
     if(modelViewMatrix == null)
     {
         modelViewMatrix = quad.getTransformationMatrix();
     }
     bool tinted = texture != null ? quad.getTinted() || parentAlpha != 1.0f : false;
     float alpha = parentAlpha * quad.getAlpha();
     int vertexID = mNumQuads * 4;
     if(mNumQuads + 1 > mVertexData.getNumVertices() / 4)
     {
         expand();
     }
     if(mNumQuads == 0)
     {
         this.setBlendMode(blendMode != null ? blendMode : quad.getBlendMode());
         mTexture = texture;
         mTinted = tinted;
         mSmoothing = smoothing;
         mVertexData.setPremultipliedAlpha(texture != null ? texture.getPremultipliedAlpha() : true, false);
     }
     quad.copyVertexDataTo(mVertexData, vertexID);
     mVertexData.transformVertex(vertexID, modelViewMatrix, 4);
     if(alpha != 1.0f)
     {
         mVertexData.scaleAlpha(vertexID, alpha, 4);
     }
     mSyncRequired = true;
     mNumQuads++;
 }
Пример #2
0
        public virtual void addQuad(AsQuad quad, float parentAlpha, AsTexture texture, String smoothing, AsMatrix modelViewMatrix, String blendMode)
        {
            if (modelViewMatrix == null)
            {
                modelViewMatrix = quad.getTransformationMatrix();
            }
            bool tinted = texture != null?quad.getTinted() || parentAlpha != 1.0f : false;

            float alpha    = parentAlpha * quad.getAlpha();
            int   vertexID = mNumQuads * 4;

            if (mNumQuads + 1 > mVertexData.getNumVertices() / 4)
            {
                expand();
            }
            if (mNumQuads == 0)
            {
                this.setBlendMode(blendMode != null ? blendMode : quad.getBlendMode());
                mTexture   = texture;
                mTinted    = tinted;
                mSmoothing = smoothing;
                mVertexData.setPremultipliedAlpha(texture != null ? texture.getPremultipliedAlpha() : true, false);
            }
            quad.copyVertexDataTo(mVertexData, vertexID);
            mVertexData.transformVertex(vertexID, modelViewMatrix, 4);
            if (alpha != 1.0f)
            {
                mVertexData.scaleAlpha(vertexID, alpha, 4);
            }
            mSyncRequired = true;
            mNumQuads++;
        }
Пример #3
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);
        }
 public virtual void batchQuad(AsQuad quad, float parentAlpha, AsTexture texture, String smoothing)
 {
     if(mQuadBatches[mCurrentQuadBatchID].isStateChange(quad.getTinted(), parentAlpha, texture, smoothing, mBlendMode))
     {
         finishQuadBatch();
     }
     mQuadBatches[mCurrentQuadBatchID].addQuad(quad, parentAlpha, texture, smoothing, mModelViewMatrix, mBlendMode);
 }