1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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;
- public 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(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;
- }
- }
- }
- }
|