From da24643c64715b28be6678e214fc5dab7ceec395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sat, 11 Sep 2021 12:50:27 +0200 Subject: [PATCH] Added SetVariable for Matrix-arrays --- GlitchyEngine/src/Renderer/Material.bf | 36 ++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/GlitchyEngine/src/Renderer/Material.bf b/GlitchyEngine/src/Renderer/Material.bf index fb9fb21..e1ede97 100644 --- a/GlitchyEngine/src/Renderer/Material.bf +++ b/GlitchyEngine/src/Renderer/Material.bf @@ -126,8 +126,7 @@ namespace GlitchyEngine.Renderer public void SetVariable(String name, ColorRGB value) => SetVariable(name, value); public void SetVariable(String name, ColorRGBA value) => SetVariable(name, value); - - private void SetVariable(String name, Matrix3x3 value) + public void SetVariable(String name, Matrix3x3 value) { if(_variables.TryGetValue(name, let entry)) { @@ -140,10 +139,43 @@ namespace GlitchyEngine.Renderer Log.EngineLogger.Assert(false, scope $"The effect doesn't contain a variable named \"{name}\""); } } + + public void SetVariable(String name, Matrix3x3[] values) + { + if(_variables.TryGetValue(name, let entry)) + { + entry.Variable.EnsureTypeMatch(); + + int count = Math.Min(values.Count, entry.Variable._elements); + + for(int i < count) + { + (&RawPointer!(entry.Offset))[i] = Matrix4x3(values[i]); + } + } + else + { + Log.EngineLogger.Assert(false, scope $"The effect doesn't contain a variable named \"{name}\""); + } + } public void SetVariable(String name, Matrix4x3 value) => SetVariable(name, value); public void SetVariable(String name, Matrix value) => SetVariable(name, value); + public void SetVariable(String name, Matrix[] values) + { + if(_variables.TryGetValue(name, let entry)) + { + entry.Variable.EnsureTypeMatch(); + + Internal.MemCpy(&RawPointer!(entry.Offset), values.Ptr, Math.Min(values.Count, entry.Variable._elements)); + } + else + { + Log.EngineLogger.Assert(false, scope $"The effect doesn't contain a variable named \"{name}\""); + } + } + /** * Sets the raw data of the variable. * @param rawData The pointer to the raw data. If rawData is null the raw data will be set to zero.