Skip to content

Commit b36574b

Browse files
committed
🚧 Move from render texture to texture2D and texture2DArray
1 parent c1e60f3 commit b36574b

File tree

3 files changed

+36
-80
lines changed

3 files changed

+36
-80
lines changed

InteropUnityCUDA/Assets/Actions/ActionUnitySampleTexture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public class ActionUnitySampleTexture : ActionUnity
1414
/// <summary>
1515
/// create a pointer to actionSampleTexture object that has been created in native plugin
1616
/// </summary>
17-
/// <param name="renderTexture">render texture that will be used in interoperability</param>
18-
public ActionUnitySampleTexture(RenderTexture renderTexture) : base()
17+
/// <param name="texture">texture that will be used in interoperability</param>
18+
public ActionUnitySampleTexture(Texture texture) : base()
1919
{
20-
_actionPtr = createActionSampleTextureBasic(renderTexture.GetNativeTexturePtr(), renderTexture.width, renderTexture.height);
20+
_actionPtr = createActionSampleTextureBasic(texture.GetNativeTexturePtr(), texture.width, texture.height);
2121
}
2222
}
2323

InteropUnityCUDA/Assets/Actions/ActionUnitySampleTextureArray.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public class ActionUnitySampleTextureArray : ActionUnity
1414
/// <summary>
1515
/// create a pointer to actionSampleTextureArray object that has been created in native plugin
1616
/// </summary>
17-
/// <param name="renderTexture">render texture that will be used in interoperability</param>
18-
public ActionUnitySampleTextureArray(RenderTexture renderTexture) : base()
17+
/// <param name="texture">render texture that will be used in interoperability</param>
18+
public ActionUnitySampleTextureArray(Texture2DArray texture) : base()
1919
{
20-
_actionPtr = createActionSampleTextureArrayBasic(renderTexture.GetNativeTexturePtr(), renderTexture.width, renderTexture.height, renderTexture.volumeDepth);
20+
_actionPtr = createActionSampleTextureArrayBasic(texture.GetNativeTexturePtr(), texture.width, texture.height, texture.depth);
2121
}
2222
}
2323

InteropUnityCUDA/Assets/Actions/InteropHandlerSample.cs

Lines changed: 30 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -26,76 +26,36 @@ public class InteropHandlerSample : InteropHandler
2626

2727
[SerializeField] private int _sizeTexture = 256;
2828
[SerializeField] private int _sizeBuffer = 256;
29-
3029

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;
3634
private ComputeBuffer _computeBuffer;
3735

3836
/// <summary>
3937
/// Create a render texture _sizeTexture x _sizeTexture with 4 channel and and set _renderTexture with it
4038
/// </summary>
4139
private void CreateTexture()
4240
{
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;
5644
}
5745

5846
private void CreateTextureArray()
5947
{
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();
8456

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;
9959
}
10060

10161
/// <summary>
@@ -127,30 +87,28 @@ protected override void InitializeActions()
12787
Debug.LogError("Set particles drawer in inspector !");
12888
return;
12989
}
90+
13091
InitSampleTexture();
131-
// InitSampleTextureArray();
92+
InitSampleTextureArray();
13293
// InitSampleVertexBuffer();
133-
13494
}
13595

13696
private void InitSampleTexture()
13797
{
13898
CreateTexture();
139-
ActionUnitySampleTexture actionUnitySampleTexture = new ActionUnitySampleTexture(_renderTexture);
99+
ActionUnitySampleTexture actionUnitySampleTexture = new ActionUnitySampleTexture(_texture);
140100
RegisterActionUnity(actionUnitySampleTexture, _ActionTextureName);
141101
CallFunctionStartInAction(_ActionTextureName);
142-
143102
}
144103

145104
private void InitSampleTextureArray()
146105
{
147106
CreateTextureArray();
148-
ActionUnitySampleTextureArray actionUnitySampleTextureArray = new ActionUnitySampleTextureArray(_renderTextureArray);
107+
ActionUnitySampleTextureArray actionUnitySampleTextureArray = new ActionUnitySampleTextureArray(_textureArray);
149108
RegisterActionUnity(actionUnitySampleTextureArray, _ActionTextureArrayName);
150109
CallFunctionStartInAction(_ActionTextureArrayName);
151-
152110
}
153-
111+
154112
private void InitSampleVertexBuffer()
155113
{
156114
CreateBuffer();
@@ -159,7 +117,7 @@ private void InitSampleVertexBuffer()
159117
CallFunctionStartInAction(_ActionVertexBufferName);
160118

161119
}
162-
120+
163121
public void Update()
164122
{
165123
UpdateInteropHandler();
@@ -171,18 +129,17 @@ public void Update()
171129
protected override void UpdateActions()
172130
{
173131
base.UpdateActions();
174-
// CallFunctionUpdateInAction(_ActionTextureArrayName);
175132
CallFunctionUpdateInAction(_ActionTextureName);
133+
CallFunctionUpdateInAction(_ActionTextureArrayName);
176134
// 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);
181138
}
182139

183140
public void OnDestroy()
184141
{
185-
// OnDestroyInteropHandler();
142+
OnDestroyInteropHandler();
186143
}
187144

188145
/// <summary>
@@ -192,9 +149,8 @@ protected override void OnDestroyActions()
192149
{
193150
base.OnDestroyActions();
194151
CallFunctionOnDestroyInAction(_ActionTextureName);
195-
// CallFunctionOnDestroyInAction(_ActionTextureArrayName);
152+
CallFunctionOnDestroyInAction(_ActionTextureArrayName);
196153
// CallFunctionOnDestroyInAction(_ActionVertexBufferName);
197154
}
198155
}
199-
200-
}
156+
}

0 commit comments

Comments
 (0)