@@ -26,76 +26,36 @@ public class InteropHandlerSample : InteropHandler
26
26
27
27
[ SerializeField ] private int _sizeTexture = 256 ;
28
28
[ SerializeField ] private int _sizeBuffer = 256 ;
29
-
30
29
31
-
32
- private RenderTexture _renderTexture ;
33
- private RenderTexture _renderTextureArray ;
34
- private RenderTexture _renderTextureForDisplay0 ;
35
- private RenderTexture _renderTextureForDisplay1 ;
30
+ private Texture2D _texture ;
31
+ private Texture2DArray _textureArray ;
32
+ private Texture2D _textureForDisplay0 ;
33
+ private Texture2D _textureForDisplay1 ;
36
34
private ComputeBuffer _computeBuffer ;
37
35
38
36
/// <summary>
39
37
/// Create a render texture _sizeTexture x _sizeTexture with 4 channel and and set _renderTexture with it
40
38
/// </summary>
41
39
private void CreateTexture ( )
42
40
{
43
- _renderTexture = new RenderTexture ( _sizeTexture , _sizeTexture , 0
44
- , RenderTextureFormat . ARGBFloat , RenderTextureReadWrite . Linear )
45
- {
46
- useMipMap = false ,
47
- autoGenerateMips = false ,
48
- anisoLevel = 6 ,
49
- filterMode = FilterMode . Trilinear ,
50
- wrapMode = TextureWrapMode . Clamp ,
51
- enableRandomWrite = true
52
- } ;
53
-
54
- _renderTexture . Create ( ) ;
55
- _rawImageOneTexture . texture = _renderTexture ;
41
+ _texture = new Texture2D ( _sizeTexture , _sizeTexture , TextureFormat . RGBAFloat , false , true ) ;
42
+ _texture . Apply ( ) ;
43
+ _rawImageOneTexture . texture = _texture ;
56
44
}
57
45
58
46
private void CreateTextureArray ( )
59
47
{
60
- _renderTextureArray = new RenderTexture ( _sizeTexture , _sizeTexture , 0
61
- , RenderTextureFormat . ARGBFloat , RenderTextureReadWrite . Linear )
62
- {
63
- useMipMap = false ,
64
- autoGenerateMips = false ,
65
- anisoLevel = 6 ,
66
- filterMode = FilterMode . Trilinear ,
67
- wrapMode = TextureWrapMode . Clamp ,
68
- enableRandomWrite = true ,
69
- volumeDepth = 3 ,
70
- dimension = TextureDimension . Tex2DArray
71
- } ;
72
-
73
-
74
- _renderTextureForDisplay0 = new RenderTexture ( _sizeTexture , _sizeTexture , 0
75
- , RenderTextureFormat . ARGBFloat , RenderTextureReadWrite . Linear )
76
- {
77
- useMipMap = false ,
78
- autoGenerateMips = false ,
79
- anisoLevel = 6 ,
80
- filterMode = FilterMode . Trilinear ,
81
- wrapMode = TextureWrapMode . Clamp ,
82
- enableRandomWrite = true
83
- } ;
48
+ _textureArray = new Texture2DArray ( _sizeTexture , _sizeTexture , 2 , TextureFormat . RGBAFloat , false , true ) ;
49
+ _textureArray . Apply ( ) ;
50
+
51
+ _textureForDisplay0 = new Texture2D ( _sizeTexture , _sizeTexture , TextureFormat . RGBAFloat , false , true ) ;
52
+ _textureForDisplay0 . Apply ( ) ;
53
+
54
+ _textureForDisplay1 = new Texture2D ( _sizeTexture , _sizeTexture , TextureFormat . RGBAFloat , false , true ) ;
55
+ _textureForDisplay1 . Apply ( ) ;
84
56
85
- _renderTextureForDisplay1 = new RenderTexture ( _sizeTexture , _sizeTexture , 0
86
- , RenderTextureFormat . ARGBFloat , RenderTextureReadWrite . Linear )
87
- {
88
- useMipMap = false ,
89
- autoGenerateMips = false ,
90
- anisoLevel = 6 ,
91
- filterMode = FilterMode . Trilinear ,
92
- wrapMode = TextureWrapMode . Clamp ,
93
- enableRandomWrite = true
94
- } ;
95
-
96
- _renderTextureArray . Create ( ) ;
97
- _rawImageTextureArray0 . texture = _renderTextureForDisplay0 ;
98
- _rawImageTextureArray1 . texture = _renderTextureForDisplay1 ;
57
+ _rawImageTextureArray0 . texture = _textureForDisplay0 ;
58
+ _rawImageTextureArray1 . texture = _textureForDisplay1 ;
99
59
}
100
60
101
61
/// <summary>
@@ -127,30 +87,28 @@ protected override void InitializeActions()
127
87
Debug . LogError ( "Set particles drawer in inspector !" ) ;
128
88
return ;
129
89
}
90
+
130
91
InitSampleTexture ( ) ;
131
- // InitSampleTextureArray();
92
+ InitSampleTextureArray ( ) ;
132
93
// InitSampleVertexBuffer();
133
-
134
94
}
135
95
136
96
private void InitSampleTexture ( )
137
97
{
138
98
CreateTexture ( ) ;
139
- ActionUnitySampleTexture actionUnitySampleTexture = new ActionUnitySampleTexture ( _renderTexture ) ;
99
+ ActionUnitySampleTexture actionUnitySampleTexture = new ActionUnitySampleTexture ( _texture ) ;
140
100
RegisterActionUnity ( actionUnitySampleTexture , _ActionTextureName ) ;
141
101
CallFunctionStartInAction ( _ActionTextureName ) ;
142
-
143
102
}
144
103
145
104
private void InitSampleTextureArray ( )
146
105
{
147
106
CreateTextureArray ( ) ;
148
- ActionUnitySampleTextureArray actionUnitySampleTextureArray = new ActionUnitySampleTextureArray ( _renderTextureArray ) ;
107
+ ActionUnitySampleTextureArray actionUnitySampleTextureArray = new ActionUnitySampleTextureArray ( _textureArray ) ;
149
108
RegisterActionUnity ( actionUnitySampleTextureArray , _ActionTextureArrayName ) ;
150
109
CallFunctionStartInAction ( _ActionTextureArrayName ) ;
151
-
152
110
}
153
-
111
+
154
112
private void InitSampleVertexBuffer ( )
155
113
{
156
114
CreateBuffer ( ) ;
@@ -159,7 +117,7 @@ private void InitSampleVertexBuffer()
159
117
CallFunctionStartInAction ( _ActionVertexBufferName ) ;
160
118
161
119
}
162
-
120
+
163
121
public void Update ( )
164
122
{
165
123
UpdateInteropHandler ( ) ;
@@ -171,18 +129,17 @@ public void Update()
171
129
protected override void UpdateActions ( )
172
130
{
173
131
base . UpdateActions ( ) ;
174
- // CallFunctionUpdateInAction(_ActionTextureArrayName);
175
132
CallFunctionUpdateInAction ( _ActionTextureName ) ;
133
+ CallFunctionUpdateInAction ( _ActionTextureArrayName ) ;
176
134
// CallFunctionUpdateInAction(_ActionVertexBufferName);
177
- // Graphics.CopyTexture(_renderTextureArray,0,_renderTextureForDisplay0,0);
178
- // Graphics.CopyTexture(_renderTextureArray,1,_renderTextureForDisplay1,0);
179
- // _rawImageTextureArray0.texture = _renderTextureForDisplay0;
180
- // _rawImageTextureArray1.texture = _renderTextureForDisplay1;
135
+
136
+ Graphics . CopyTexture ( _textureArray , 0 , _textureForDisplay0 , 0 ) ;
137
+ Graphics . CopyTexture ( _textureArray , 1 , _textureForDisplay1 , 0 ) ;
181
138
}
182
139
183
140
public void OnDestroy ( )
184
141
{
185
- // OnDestroyInteropHandler();
142
+ OnDestroyInteropHandler ( ) ;
186
143
}
187
144
188
145
/// <summary>
@@ -192,9 +149,8 @@ protected override void OnDestroyActions()
192
149
{
193
150
base . OnDestroyActions ( ) ;
194
151
CallFunctionOnDestroyInAction ( _ActionTextureName ) ;
195
- // CallFunctionOnDestroyInAction(_ActionTextureArrayName);
152
+ CallFunctionOnDestroyInAction ( _ActionTextureArrayName ) ;
196
153
// CallFunctionOnDestroyInAction(_ActionVertexBufferName);
197
154
}
198
155
}
199
-
200
- }
156
+ }
0 commit comments