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; public 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(int index, float4 data) { _f4Buffer[index] = data; } public void SetData(int index, float4x4 data) { _f4x4Buffer[index] = data; } public void SetData(int index, float3x4 data) { _f3x4Buffer[index] = data; } public void SetData(int index, float data) { _f1Buffer[index] = data; } public void SetData(GraphicsBuffer graphicsBuffer) { // IitBuffer(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; } } } }