@@ -11,87 +11,85 @@ struct uiVertex
11
11
public Vector2 uv ;
12
12
}
13
13
14
- static ComputeBuffer _computeBuffer ;
15
- static List < uiVertex > _vertices ;
14
+ ComputeBuffer _computeBuffer ;
15
+ List < uiVertex > _vertices ;
16
16
17
- static ComputeBuffer _indexBuffer ;
18
- static List < int > _indices ;
17
+ ComputeBuffer _indexBuffer ;
18
+ List < int > _indices ;
19
19
20
- static int _startVertex ;
21
- static int _startIndex ;
22
-
23
- static int _instanceNum ;
20
+ int _startVertex ;
21
+ int _startIndex ;
24
22
25
23
public const int COMPUTE_BUFFER_MAX_ITEM_NUM = 1024 * 1024 ; // maxsize = 1M vertex/index
26
24
27
- static void _releaseComputeBuffer ( ) {
28
- if ( ! CanvasShader . supportComputeBuffer ) {
29
- return ;
30
- }
25
+ bool supportComputeBuffer {
26
+ get { return CanvasShader . supportComputeBuffer ; }
27
+ }
31
28
32
- if ( _computeBuffer == null ) {
29
+ void _releaseComputeBuffer ( ) {
30
+ if ( ! this . supportComputeBuffer ) {
33
31
return ;
34
32
}
35
33
36
- if ( _instanceNum != 0 ) {
34
+ if ( this . _computeBuffer == null ) {
37
35
return ;
38
36
}
39
37
40
- _computeBuffer . Dispose ( ) ;
41
- _indexBuffer . Dispose ( ) ;
42
- _vertices = null ;
43
- _indices = null ;
44
- _computeBuffer = null ;
45
- _indexBuffer = null ;
38
+ this . _computeBuffer . Dispose ( ) ;
39
+ this . _indexBuffer . Dispose ( ) ;
40
+ this . _vertices = null ;
41
+ this . _indices = null ;
42
+ this . _computeBuffer = null ;
43
+ this . _indexBuffer = null ;
46
44
}
47
45
48
46
void _initComputeBuffer ( ) {
49
47
var stride = Marshal . SizeOf ( typeof ( uiVertex ) ) ;
50
48
var strideIndex = Marshal . SizeOf ( typeof ( int ) ) ;
51
- _computeBuffer = new ComputeBuffer ( COMPUTE_BUFFER_MAX_ITEM_NUM , stride ) ;
52
- _vertices = new List < uiVertex > ( ) ;
49
+ this . _computeBuffer = new ComputeBuffer ( COMPUTE_BUFFER_MAX_ITEM_NUM , stride ) ;
50
+ this . _vertices = new List < uiVertex > ( ) ;
53
51
54
- _indexBuffer = new ComputeBuffer ( COMPUTE_BUFFER_MAX_ITEM_NUM , strideIndex ) ;
55
- _indices = new List < int > ( ) ;
52
+ this . _indexBuffer = new ComputeBuffer ( COMPUTE_BUFFER_MAX_ITEM_NUM , strideIndex ) ;
53
+ this . _indices = new List < int > ( ) ;
56
54
}
57
55
58
56
void _resetComputeBuffer ( ) {
59
- if ( ! CanvasShader . supportComputeBuffer ) return ;
57
+ if ( ! this . supportComputeBuffer ) return ;
60
58
61
- if ( _computeBuffer == null ) {
59
+ if ( this . _computeBuffer == null ) {
62
60
this . _initComputeBuffer ( ) ;
63
61
}
64
62
65
- _vertices . Clear ( ) ;
66
- _indices . Clear ( ) ;
67
- _startVertex = 0 ;
68
- _startIndex = 0 ;
63
+ this . _vertices . Clear ( ) ;
64
+ this . _indices . Clear ( ) ;
65
+ this . _startVertex = 0 ;
66
+ this . _startIndex = 0 ;
69
67
}
70
68
71
69
void _bindComputeBuffer ( ) {
72
- if ( ! CanvasShader . supportComputeBuffer ) return ;
70
+ if ( ! this . supportComputeBuffer ) return ;
73
71
74
- _computeBuffer . SetData ( _vertices ) ;
75
- _indexBuffer . SetData ( _indices ) ;
72
+ this . _computeBuffer . SetData ( this . _vertices ) ;
73
+ this . _indexBuffer . SetData ( this . _indices ) ;
76
74
}
77
75
78
76
void _addMeshToComputeBuffer ( List < Vector3 > vertex , List < Vector2 > uv , List < int > triangles ) {
79
- if ( ! CanvasShader . supportComputeBuffer ) return ;
77
+ if ( ! this . supportComputeBuffer ) return ;
80
78
81
- _startVertex = _vertices . Count ;
82
- _startIndex = _indices . Count ;
79
+ this . _startVertex = this . _vertices . Count ;
80
+ this . _startIndex = this . _indices . Count ;
83
81
84
82
var hasUv = uv != null ;
85
83
86
84
for ( int i = 0 ; i < vertex . Count ; i ++ ) {
87
- _vertices . Add ( new uiVertex {
85
+ this . _vertices . Add ( new uiVertex {
88
86
position = new Vector2 ( vertex [ i ] . x , vertex [ i ] . y ) ,
89
87
uv = hasUv ? uv [ i ] : Vector2 . zero
90
88
} ) ;
91
89
}
92
90
93
91
foreach ( var triangleId in triangles ) {
94
- _indices . Add ( triangleId + _startVertex ) ;
92
+ this . _indices . Add ( triangleId + this . _startVertex ) ;
95
93
}
96
94
}
97
95
}
0 commit comments