void UpdateSpriteMesh(bool isClipping, Vector3 cameraPos, float radius)
        {
            int triangles = 0;
            int priCount  = getAndSortPrimitives(ref triangles, isClipping, cameraPos, radius);

            lastCommitSpriteConnt   = priCount;
            lastCommitTriangleCount = triangles;

            if (priCount == 0)
            {
                if (renderMesh != null && renderMesh.vertexCount > 0)
                {
                    renderMesh.subMeshCount = 0;
                }

                return;
            }


            //set vertices, uvs, colors
            int l      = priCount * 4;
            int arrlen = _vertices.Length;

            if (l > arrlen || l < arrlen >> 1)
            {
                if (l > arrlen)
                {
                    arrlen = l + 128;
                }
                else if (l < arrlen >> 1)
                {
                    arrlen = arrlen >> 1;
                }

                _vertices = new Vector3[arrlen];
                _uvs      = new Vector2[arrlen];
                _colors   = new Color[arrlen];
            }

            renderMesh.subMeshCount = 0;

            System.Array.Copy(vertices, _vertices, l);
            System.Array.Copy(UVs, _uvs, l);
            System.Array.Copy(colors, _colors, l);

            renderMesh.vertices = _vertices;
            renderMesh.colors   = _colors;
            renderMesh.uv       = _uvs;


            if (mats.Length != subMeshCount)
            {
                System.Array.Resize <Material>(ref mats, subMeshCount);
            }


            int c = 0;

            //set submesh count
            renderMesh.subMeshCount = subMeshCount;

            //set triangles
            for (int i = 0; i < subMeshCount; i++)
            {
                SubMeshInfo info = subMeshs[i];
                int         len  = info.triangleCnt * 3;
                //get closest array
                FixedIntArrayAllocator.FixedArrayInfo arrayInfo = FixedIntArrayAllocator.GetArray(len);

                //copy index
                System.Array.Copy(indices, info.indexBase, arrayInfo.array, 0, len);
                //clean last
                System.Array.Clear(arrayInfo.array, len, arrayInfo.fixedSize - len);
                //set triangle list
                renderMesh.SetTriangles(arrayInfo.array, i);
                //set submesh material
                mats[i] = info.mat;

                c += arrayInfo.fixedSize;
            }

            renderer.materials = mats;

            OnCommitEnd();
        }
        internal void Init(int maxPrimitiveCount)
        {
            renderer.materials = new Material[0];


            //init component
            meshFilter            = GetComponent <MeshFilter>();
            meshFilter.sharedMesh = new Mesh();
            renderMesh            = meshFilter.sharedMesh;


            this.maxPrimitiveCount = maxPrimitiveCount;
            int count = maxPrimitiveCount;


            if (vertices == null || count > vertices.Length)
            {
                //init vertices, uv, color
                vertices = new Vector3[count * 4];
            }

            if (UVs == null || count > UVs.Length)
            {
                UVs = new Vector2[count * 4];
            }

            if (colors == null || count > colors.Length)
            {
                colors = new Color[count * 4];
            }

            if (indices == null || count > indices.Length)
            {
                //init index with triangle list
                indices = new int[count * 6];
                for (int i = 0; i < count; i++)
                {
                    int srcIdxBase = i * 4;
                    int idxBase    = i * 6;

                    indices[idxBase + 0] = srcIdxBase + 0;
                    indices[idxBase + 1] = srcIdxBase + 1;
                    indices[idxBase + 2] = srcIdxBase + 2;
                    indices[idxBase + 3] = srcIdxBase + 0;
                    indices[idxBase + 4] = srcIdxBase + 2;
                    indices[idxBase + 5] = srcIdxBase + 3;
                }
            }



            //init submesh
            subMeshCount = 0;


            if (subMeshs == null)
            {
                subMeshs = new SubMeshInfo[512];
                for (int i = 0, l = subMeshs.Length; i < l; i++)
                {
                    subMeshs[i] = new SubMeshInfo();
                }
            }

            if (_primitives == null || count > _primitives.Length)
            {
                //init primitive pool
                _primitives = new SpritePrimitive[count];
            }

            if (sortKeys == null || count > sortKeys.Length)
            {
                sortKeys = new int[count];
            }


            FixedIntArrayAllocator.AddArray(1, 8, 6, 2);
            FixedIntArrayAllocator.AddArray(256 * 6, count * 6, 256 * 6);

            vertices[0] = new Vector3(-1000000f, -1000000f, -100000f);
            vertices[1] = new Vector3(1000000f, -1000000f, -100000f);
            vertices[2] = new Vector3(-1000000f, 1000000f, 100000f);
            vertices[3] = new Vector3(1000000f, 1000000f, 100000f);

            renderMesh.vertices  = vertices;
            renderMesh.uv        = UVs;
            renderMesh.colors    = colors;
            renderMesh.triangles = new int[] { 0, 1, 2, 1, 2, 3 };

            renderMesh.RecalculateBounds();

            isInit = true;
        }
        private int groupPrimitive(int priCount, ref int visTriangles)
        {
            subMeshCount = 0;

            int              vertexIdx   = 0;
            Texture          lastTex     = null;
            uint             lastTexId   = 0;
            int              triangleCnt = 0;
            int              startIdx    = 0;
            SpriteRenderMode lastSRM     = SpriteRenderMode.None;


            SpritePrimitive primitive   = null;
            int             visPriCount = 0;

            for (int pi = 0; pi < priCount; pi++)
            {
                primitive = _primitives[pi];
                if (lastSRM != primitive.renderMode || lastTexId != primitive.texId)
                {
                    if (lastTexId != 0)
                    {
                        SubMeshInfo info = subMeshs[subMeshCount];

                        info.indexBase   = startIdx;
                        info.triangleCnt = triangleCnt;
                        info.mat         = SpriteMaterialManager.GetMaterial(lastSRM, lastTex);

                        subMeshCount++;

                        startIdx      = (vertexIdx >> 2) * 6;
                        visTriangles += triangleCnt;
                        triangleCnt   = 0;
                    }

                    lastTexId = primitive.texId;
                    lastTex   = primitive.texture;
                    lastSRM   = primitive.renderMode;
                }

                int c = primitive.size << 2;
                for (int i = 0; i < c; i++)
                {
                    int idx = vertexIdx + i;
                    vertices[idx] = primitive.position[i];
                    UVs[idx]      = primitive.uv[i];
                    colors[idx]   = primitive.color[i];
                }

                vertexIdx   += c;
                triangleCnt += (c >> 1);
                visPriCount++;
            }

            {
                SubMeshInfo _info = subMeshs[subMeshCount];

                _info.indexBase   = startIdx;
                _info.triangleCnt = triangleCnt;
                _info.mat         = SpriteMaterialManager.GetMaterial(lastSRM, lastTex);

                visTriangles += triangleCnt;
            }

            subMeshCount++;
            return(visPriCount);
        }
        internal void Init( int maxPrimitiveCount)
        {
            renderer.materials = new Material[0];


            //init component
            meshFilter = GetComponent<MeshFilter>();
            meshFilter.sharedMesh = new Mesh();
            renderMesh = meshFilter.sharedMesh;


            this.maxPrimitiveCount = maxPrimitiveCount;
            int count = maxPrimitiveCount;


            if (vertices == null || count > vertices.Length )
                //init vertices, uv, color
                vertices = new Vector3[count * 4];

            if (UVs == null || count > UVs.Length)
                UVs = new Vector2[count * 4];

            if (colors == null || count > colors.Length)   
                colors = new Color[count * 4];

            if (indices == null || count > indices.Length)
            {
                //init index with triangle list
                indices = new int[count * 6];
                for (int i = 0; i < count; i++)
                {
                    int srcIdxBase = i * 4;
                    int idxBase = i * 6;

                    indices[idxBase + 0] = srcIdxBase + 0;
                    indices[idxBase + 1] = srcIdxBase + 1;
                    indices[idxBase + 2] = srcIdxBase + 2;
                    indices[idxBase + 3] = srcIdxBase + 0;
                    indices[idxBase + 4] = srcIdxBase + 2;
                    indices[idxBase + 5] = srcIdxBase + 3;
                }
            }



            //init submesh
            subMeshCount = 0;


            if (subMeshs == null )
            {
                subMeshs = new SubMeshInfo[512];
                for (int i = 0, l = subMeshs.Length; i < l; i++)
                    subMeshs[i] = new SubMeshInfo();
            }

            if (_primitives == null || count > _primitives.Length)
                //init primitive pool
                _primitives = new SpritePrimitive[count];

            if (sortKeys == null || count > sortKeys.Length)
                sortKeys = new int[count];


            FixedIntArrayAllocator.AddArray(1, 8, 6, 2);
            FixedIntArrayAllocator.AddArray(256 * 6, count * 6, 256 * 6);

            vertices[0] = new Vector3(-1000000f, -1000000f, -100000f);
            vertices[1] = new Vector3(1000000f, -1000000f, -100000f);
            vertices[2] = new Vector3(-1000000f, 1000000f, 100000f);
            vertices[3] = new Vector3(1000000f, 1000000f, 100000f);

            renderMesh.vertices = vertices;
            renderMesh.uv = UVs;
            renderMesh.colors = colors;
            renderMesh.triangles = new int[] { 0, 1, 2, 1, 2, 3 };

            renderMesh.RecalculateBounds();

            isInit = true;
        }