using Unity.Collections; using Unity.Mathematics; using UnityEngine; namespace Core.BRG { public class BatchShaderBind { public BRGShaderValue shaderValue; public int offset; private NativeArray _f4x4Buffer; private NativeArray _f3x4Buffer; private NativeArray _f4Buffer; private NativeArray _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(count, Allocator.Persistent); break; case BRGShaderValueType.F3X4: _f3x4Buffer = new NativeArray(count, Allocator.Persistent); break; case BRGShaderValueType.F4: _f4Buffer = new NativeArray(count, Allocator.Persistent); break; case BRGShaderValueType.F1: _f1Buffer = new NativeArray(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; } } } }