12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using Unity.Collections;
- using Unity.Mathematics;
- using UnityEngine;
- namespace Core.BRG
- {
- public class BatchShaderBind
- {
- public BRGShaderValue shaderValue;
- public int offset;
- private NativeArray<float4x4> _f4x4Buffer;
- private NativeArray<float3x4> _f3x4Buffer;
- private NativeArray<float4> _f4Buffer;
- private NativeArray<float> _f1Buffer;
- private int _count;
- private int _size;
- private void InitBuffer(int count)
- {
- this._count = count;
- _size = shaderValue.GetSize();
- switch (shaderValue.ValueType)
- {
- case BRGShaderValueType.F4X4:
- _f4x4Buffer = new NativeArray<float4x4>(count, Allocator.Persistent);
- break;
- case BRGShaderValueType.F3X4:
- _f3x4Buffer = new NativeArray<float3x4>(count, Allocator.Persistent);
- break;
- case BRGShaderValueType.F4:
- _f4Buffer = new NativeArray<float4>(count, Allocator.Persistent);
- break;
- case BRGShaderValueType.F1:
- _f1Buffer = new NativeArray<float>(count, Allocator.Persistent);
- break;
- }
- }
- public void SetData(GraphicsBuffer graphicsBuffer)
- {
- InitBuffer(graphicsBuffer.count);
- switch (shaderValue.ValueType)
- {
- case BRGShaderValueType.F4X4:
- graphicsBuffer.SetData(_f4x4Buffer, 0, offset / _size, _count);
- break;
- case BRGShaderValueType.F3X4:
- graphicsBuffer.SetData(_f3x4Buffer, 0, offset / _size, _count);
- break;
- case BRGShaderValueType.F4:
- graphicsBuffer.SetData(_f4Buffer, 0, offset / _size, _count);
- break;
- case BRGShaderValueType.F1:
- graphicsBuffer.SetData(_f1Buffer, 0, offset / _size, graphicsBuffer.count);
- break;
- }
- }
- }
- }
|