public MeshWriteData DrawMesh(int vertexCount, int indexCount, Texture texture, Material material, MeshGenerationContext.MeshFlags flags)
        {
            var mwd = GetPooledMeshWriteData();

            if (vertexCount == 0 || indexCount == 0)
            {
                mwd.Reset(new NativeSlice <Vertex>(), new NativeSlice <ushort>());
                return(mwd);
            }

            m_CurrentEntry = new Entry()
            {
                vertices         = m_VertsPool.Alloc(vertexCount),
                indices          = m_IndicesPool.Alloc(indexCount),
                material         = material,
                uvIsDisplacement = (flags & MeshGenerationContext.MeshFlags.UVisDisplacement) == MeshGenerationContext.MeshFlags.UVisDisplacement,
                clipRectID       = m_ClipRectID,
                stencilRef       = m_StencilRef,
                maskDepth        = m_MaskDepth,
                addFlags         = VertexFlags.IsSolid
            };

            Debug.Assert(m_CurrentEntry.vertices.Length == vertexCount);
            Debug.Assert(m_CurrentEntry.indices.Length == indexCount);

            Rect uvRegion = new Rect(0, 0, 1, 1);

            if (texture != null)
            {
                // Attempt to override with an atlas.
                if (!((flags & MeshGenerationContext.MeshFlags.SkipDynamicAtlas) == MeshGenerationContext.MeshFlags.SkipDynamicAtlas) && m_Atlas != null && m_Atlas.TryGetAtlas(currentElement, texture as Texture2D, out TextureId atlas, out RectInt atlasRect))
                {
                    m_CurrentEntry.addFlags = VertexFlags.IsDynamic;
                    uvRegion = new Rect(atlasRect.x, atlasRect.y, atlasRect.width, atlasRect.height);
                    m_CurrentEntry.texture = atlas;
                    m_Owner.AppendTexture(currentElement, texture, atlas, true);
                }
                else
                {
                    TextureId id = TextureRegistry.instance.Acquire(texture);
                    m_CurrentEntry.addFlags = VertexFlags.IsTextured;
                    m_CurrentEntry.texture  = id;
                    m_Owner.AppendTexture(currentElement, texture, id, false);
                }
            }