|
|
|
|
|
|
public Vector2 uv; |
|
|
|
} |
|
|
|
|
|
|
|
static ComputeBuffer computeBuffer; |
|
|
|
static List<uiVertex> vertexes; |
|
|
|
static ComputeBuffer _computeBuffer; |
|
|
|
static List<uiVertex> _vertices; |
|
|
|
static ComputeBuffer indexBuffer; |
|
|
|
static List<int> indexes; |
|
|
|
static ComputeBuffer _indexBuffer; |
|
|
|
static List<int> _indices; |
|
|
|
static int startVertex; |
|
|
|
static int startIndex; |
|
|
|
static int _startVertex; |
|
|
|
static int _startIndex; |
|
|
|
|
|
|
|
static int _instanceNum; |
|
|
|
|
|
|
|
public static bool enableComputeBuffer = true; |
|
|
|
|
|
|
|
public const int COMPUTE_BUFFER_MAX_ITEM_NUM = 1024 * 1024; // maxsize = 1M vertex/index
|
|
|
|
get { return CanvasShader.supportComputeBuffer; } |
|
|
|
get { return SystemInfo.supportsComputeShaders && CanvasShader.supportComputeBuffer && enableComputeBuffer; } |
|
|
|
} |
|
|
|
|
|
|
|
static void tryReleaseComputeBuffer() { |
|
|
|
_instanceNum--; |
|
|
|
|
|
|
|
if (!supportComputeBuffer) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (_computeBuffer == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (_instanceNum != 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
_computeBuffer.Dispose(); |
|
|
|
_indexBuffer.Dispose(); |
|
|
|
_vertices = null; |
|
|
|
_indices = null; |
|
|
|
_computeBuffer = null; |
|
|
|
_indexBuffer = null; |
|
|
|
computeBuffer = new ComputeBuffer(1024 * 1024, stride); |
|
|
|
vertexes = new List<uiVertex>(); |
|
|
|
var strideIndex = Marshal.SizeOf(typeof(int)); |
|
|
|
_computeBuffer = new ComputeBuffer(COMPUTE_BUFFER_MAX_ITEM_NUM, stride); |
|
|
|
_vertices = new List<uiVertex>(); |
|
|
|
indexBuffer = new ComputeBuffer(1024 * 1024, Marshal.SizeOf(typeof(int))); |
|
|
|
indexes = new List<int>(); |
|
|
|
_indexBuffer = new ComputeBuffer(COMPUTE_BUFFER_MAX_ITEM_NUM, strideIndex); |
|
|
|
_indices = new List<int>(); |
|
|
|
if (computeBuffer == null) { |
|
|
|
if (_computeBuffer == null) { |
|
|
|
vertexes.Clear(); |
|
|
|
indexes.Clear(); |
|
|
|
startVertex = 0; |
|
|
|
startIndex = 0; |
|
|
|
_vertices.Clear(); |
|
|
|
_indices.Clear(); |
|
|
|
_startVertex = 0; |
|
|
|
_startIndex = 0; |
|
|
|
computeBuffer.SetData(vertexes); |
|
|
|
indexBuffer.SetData(indexes); |
|
|
|
_computeBuffer.SetData(_vertices); |
|
|
|
_indexBuffer.SetData(_indices); |
|
|
|
startVertex = vertexes.Count; |
|
|
|
startIndex = indexes.Count; |
|
|
|
_startVertex = _vertices.Count; |
|
|
|
_startIndex = _indices.Count; |
|
|
|
vertexes.Add(new uiVertex { |
|
|
|
_vertices.Add(new uiVertex { |
|
|
|
position = new Vector2(vertex[i].x, vertex[i].y), |
|
|
|
uv = hasUv ? uv[i] : Vector2.zero |
|
|
|
}); |
|
|
|
|
|
|
indexes.Add(triangleId + startVertex); |
|
|
|
_indices.Add(triangleId + _startVertex); |
|
|
|
if (this.computeBuffer == null) |
|
|
|
if (this._computeBuffer == null) |
|
|
|
{ |
|
|
|
this.initComputeBuffer(); |
|
|
|
} |
|
|
|
|
|
|
this.addMeshToComputeBuffer(vert, null, index); |
|
|
|
|
|
|
|
var mpb = new MaterialPropertyBlock(); |
|
|
|
mpb.SetBuffer("databuffer", this.computeBuffer); |
|
|
|
mpb.SetBuffer("indexbuffer", this.indexBuffer); |
|
|
|
mpb.SetInt("_startVertex", this.startIndex); |
|
|
|
mpb.SetBuffer("databuffer", this._computeBuffer); |
|
|
|
mpb.SetBuffer("indexbuffer", this._indexBuffer); |
|
|
|
mpb.SetInt("_startVertex", this._startIndex); |
|
|
|
cmdBuf.DrawProcedural(Matrix4x4.identity, this.material, 0, MeshTopology.Triangles, 6, 1, mpb); |
|
|
|
} |
|
|
|
} |
|
|
|