Added SetVariable for Matrix-arrays

This commit is contained in:
Simon Lübeß
2021-09-11 12:50:27 +02:00
parent f761f87e1d
commit da24643c64
+34 -2
View File
@@ -126,8 +126,7 @@ namespace GlitchyEngine.Renderer
public void SetVariable(String name, ColorRGB value) => SetVariable<ColorRGB>(name, value); public void SetVariable(String name, ColorRGB value) => SetVariable<ColorRGB>(name, value);
public void SetVariable(String name, ColorRGBA value) => SetVariable<ColorRGBA>(name, value); public void SetVariable(String name, ColorRGBA value) => SetVariable<ColorRGBA>(name, value);
public void SetVariable(String name, Matrix3x3 value)
private void SetVariable(String name, Matrix3x3 value)
{ {
if(_variables.TryGetValue(name, let entry)) 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}\""); 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<Matrix3x3>();
int count = Math.Min(values.Count, entry.Variable._elements);
for(int i < count)
{
(&RawPointer!<Matrix4x3>(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<Matrix4x3>(name, value); public void SetVariable(String name, Matrix4x3 value) => SetVariable<Matrix4x3>(name, value);
public void SetVariable(String name, Matrix value) => SetVariable<Matrix>(name, value); public void SetVariable(String name, Matrix value) => SetVariable<Matrix>(name, value);
public void SetVariable(String name, Matrix[] values)
{
if(_variables.TryGetValue(name, let entry))
{
entry.Variable.EnsureTypeMatch<Matrix>();
Internal.MemCpy(&RawPointer!<Matrix>(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. * 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. * @param rawData The pointer to the raw data. If rawData is null the raw data will be set to zero.