Tanoda
AccessShaderOutputData.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9#if LEAP_TESTS
10using UnityEngine;
11
13
14 public static class AccessShaderOutputExtensions {
15
16 private static ComputeBuffer _buffer;
17
18 public static void BeginCollectingVertData(this LeapGraphicRenderer renderer) {
19 Camera targetCamera = renderer.GetComponentInChildren<Camera>();
20 var renderingMethod = renderer.groups[0].renderingMethod as LeapMesherBase;
21 var material = renderingMethod.material;
22
23 var graphic = renderer.groups[0].graphics[0] as LeapMeshGraphicBase;
24 graphic.RefreshMeshData();
25 var mesh = graphic.mesh;
26
27 _buffer = new ComputeBuffer(mesh.vertexCount, sizeof(float) * 3);
28 material.SetBuffer("_FinalVertexPositions", _buffer);
29
30 Graphics.ClearRandomWriteTargets();
31 Graphics.SetRandomWriteTarget(1, _buffer);
32
33 targetCamera.allowMSAA = false;
34 targetCamera.enabled = true;
35 }
36
37 public static Vector3[] FinishCollectingVertData(this LeapGraphicRenderer renderer) {
38 Camera targetCamera = renderer.GetComponentInChildren<Camera>();
39 var renderingMethod = renderer.groups[0].renderingMethod as LeapMesherBase;
40 var material = renderingMethod.material;
41
42 var graphic = renderer.groups[0].graphics[0] as LeapMeshGraphicBase;
43 graphic.RefreshMeshData();
44 var mesh = graphic.mesh;
45
46 Vector3[] array = new Vector3[mesh.vertexCount];
47 _buffer.GetData(array);
48
49 Graphics.ClearRandomWriteTargets();
50
51 _buffer.Release();
52 targetCamera.enabled = false;
53
54 return array;
55 }
56 }
57}
58#endif