Added basic support for arrays in BufferVariables

This commit is contained in:
Simon Lübeß
2021-08-25 22:27:04 +02:00
parent 93513f3ea8
commit 8ab740fa2e
2 changed files with 14 additions and 1 deletions
@@ -37,6 +37,7 @@ namespace GlitchyEngine.Renderer
_columns = shaderTypeDescription.Columns; _columns = shaderTypeDescription.Columns;
_rows = shaderTypeDescription.Rows; _rows = shaderTypeDescription.Rows;
_elements = shaderTypeDescription.Elements;
SetRawData(variableDescription.DefaultValue); SetRawData(variableDescription.DefaultValue);
} }
+13 -1
View File
@@ -16,6 +16,8 @@ namespace GlitchyEngine.Renderer
internal uint32 _rows; internal uint32 _rows;
private uint32 _offset; private uint32 _offset;
internal uint32 _sizeInBytes; internal uint32 _sizeInBytes;
// Number of elements in the array
internal uint32 _elements;
private bool _isUsed; private bool _isUsed;
@@ -33,7 +35,7 @@ namespace GlitchyEngine.Renderer
[Inline] [Inline]
internal uint8* firstByte => _constantBuffer.rawData.CArray() + _offset; 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(); _constantBuffer = constantBuffer..AddRef();
_type = type; _type = type;
@@ -41,6 +43,7 @@ namespace GlitchyEngine.Renderer
_rows = rows; _rows = rows;
_offset = offset; _offset = offset;
_sizeInBytes = sizeInBytes; _sizeInBytes = sizeInBytes;
_elements = elements;
_isUsed = isUsed; _isUsed = isUsed;
} }
@@ -151,6 +154,15 @@ namespace GlitchyEngine.Renderer
*(Matrix*)firstByte = value; *(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) public void SetData(ColorRGB value)
{ {