From 8ab740fa2e4f5f7b2ad09bfca6cc2e8fa3e520f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Wed, 25 Aug 2021 22:27:04 +0200 Subject: [PATCH] Added basic support for arrays in BufferVariables --- .../Platform/DX11/Renderer/Dx11ConstantBuffer.bf | 1 + GlitchyEngine/src/Renderer/BufferVariable.bf | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11ConstantBuffer.bf b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11ConstantBuffer.bf index 7984ab5..e9a196f 100644 --- a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11ConstantBuffer.bf +++ b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11ConstantBuffer.bf @@ -37,6 +37,7 @@ namespace GlitchyEngine.Renderer _columns = shaderTypeDescription.Columns; _rows = shaderTypeDescription.Rows; + _elements = shaderTypeDescription.Elements; SetRawData(variableDescription.DefaultValue); } diff --git a/GlitchyEngine/src/Renderer/BufferVariable.bf b/GlitchyEngine/src/Renderer/BufferVariable.bf index e3e7199..5734099 100644 --- a/GlitchyEngine/src/Renderer/BufferVariable.bf +++ b/GlitchyEngine/src/Renderer/BufferVariable.bf @@ -16,6 +16,8 @@ namespace GlitchyEngine.Renderer internal uint32 _rows; private uint32 _offset; internal uint32 _sizeInBytes; + // Number of elements in the array + internal uint32 _elements; private bool _isUsed; @@ -33,7 +35,7 @@ namespace GlitchyEngine.Renderer [Inline] internal uint8* firstByte => _constantBuffer.rawData.CArray() + _offset; - public this(ConstantBuffer constantBuffer, ShaderVariableType type, uint32 columns, uint32 rows, uint32 offset, uint32 sizeInBytes, bool isUsed) + public this(ConstantBuffer constantBuffer, ShaderVariableType type, uint32 columns, uint32 rows, uint32 offset, uint32 sizeInBytes, uint32 elements, bool isUsed) { _constantBuffer = constantBuffer..AddRef(); _type = type; @@ -41,6 +43,7 @@ namespace GlitchyEngine.Renderer _rows = rows; _offset = offset; _sizeInBytes = sizeInBytes; + _elements = elements; _isUsed = isUsed; } @@ -151,6 +154,15 @@ namespace GlitchyEngine.Renderer *(Matrix*)firstByte = value; } + + public void SetData(Matrix[] value) + { + EnsureTypeMatch(4, 4, .Float); + + // TODO: assert length + + Internal.MemCpy(firstByte, value.Ptr, sizeof(Matrix) * Math.Min(value.Count, _elements)); + } public void SetData(ColorRGB value) {