Material.GetVariable and (maybe) fixed SetVariable for Matrix3x3

This commit is contained in:
Simon Lübeß
2022-05-10 22:06:07 +02:00
parent 336e52fbac
commit 2e0cc289df
+25 -14
View File
@@ -108,25 +108,14 @@ namespace GlitchyEngine.Renderer
[Inline] [Inline]
private void SetVariable<T>(String name, T value) where T : struct private void SetVariable<T>(String name, T value) where T : struct
{ {
bool b = false; Debug.Profiler.ProfileRendererFunction!();
(uint32 Offset, BufferVariable Variable) entry;
{ if(_variables.TryGetValue(name, let entry))
Debug.Profiler.ProfileRendererScope!("TryGetValue");
b = _variables.TryGetValue(name, out entry);
}
if(b)
{ {
entry.Variable.EnsureTypeMatch<T>(); entry.Variable.EnsureTypeMatch<T>();
{
Debug.Profiler.ProfileRendererScope!("RawPointer!");
RawPointer!<T>(entry.Offset) = value; RawPointer!<T>(entry.Offset) = value;
} }
}
else else
{ {
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}\"");
@@ -153,7 +142,12 @@ namespace GlitchyEngine.Renderer
{ {
entry.Variable.EnsureTypeMatch<Matrix3x3>(); entry.Variable.EnsureTypeMatch<Matrix3x3>();
RawPointer!<Matrix4x3>(entry.Offset) = Matrix4x3(value); // TODO: I'm not sure how to handle Matrix3x3
// It seems to be 44 Bytes (11 Floats) large.
Log.EngineLogger.AssertDebug(entry.Variable._sizeInBytes == 44, "Made wrong assumption about the size of float3x3 in a hlsl constant-buffer.");
#unwarn
RawPointer!<float[11]>(entry.Offset) = *(float[11]*)&Matrix4x3(value);
} }
else else
{ {
@@ -211,6 +205,23 @@ namespace GlitchyEngine.Renderer
// public void Set(String name, VALUE)... // public void Set(String name, VALUE)...
public void GetVariable<T>(String name, out T value) where T : struct
{
Debug.Profiler.ProfileRendererFunction!();
if(_variables.TryGetValue(name, let entry))
{
entry.Variable.EnsureTypeMatch<T>();
value = RawPointer!<T>(entry.Offset);
}
else
{
value = ?;
Log.EngineLogger.Assert(false, scope $"The effect doesn't contain a variable named \"{name}\"");
}
}
// Float, Float2, Float3, Float4 // Float, Float2, Float3, Float4
// Color, ColorRGB, ColorRGBA // Color, ColorRGB, ColorRGBA
// Matrix3x3, Matrix4x3, Matrix // Matrix3x3, Matrix4x3, Matrix