ShaderProgram - Update GetUniformLocation to retrive all active uniforms when linking program

This commit is contained in:
miku-666
2024-10-08 11:45:02 +02:00
parent 05ebf400e4
commit a1fd791fdd

View File

@@ -95,10 +95,8 @@ namespace PckStudio.Rendering.Shader
{
if (locationCache.ContainsKey(name))
return locationCache[name];
int location = GL.GetUniformLocation(_programId, name);
Debug.Assert(location != -1);
locationCache.Add(name, location);
return location;
Debug.Assert(false, $"Uniform location '{name}' not found");
return -1;
}
private bool Link()
@@ -108,9 +106,26 @@ namespace PckStudio.Rendering.Shader
bool success = status != 0;
if (!success)
Debug.WriteLine(GL.GetProgramInfoLog(_programId), category: nameof(ShaderProgram));
GetActiveUniformLocations();
return success;
}
private void GetActiveUniformLocations()
{
GL.GetProgram(_programId, GetProgramParameterName.ActiveUniforms, out int count);
Debug.WriteLine("Active Uniforms: {0}", count);
for (int i = 0; i < count; i++)
{
GL.GetActiveUniform(_programId, i, 256, out int length, out int size, out ActiveUniformType type, out string name);
int id = GL.GetUniformLocation(_programId, name);
Debug.Assert(id != -1);
RegisterUniform(name, id, type);
Debug.WriteLine("Uniform {0}(id:{1}) Type: {2} Name: {3}", i, id, type, name);
}
}
private void RegisterUniform(string name, int id, ActiveUniformType type) => locationCache.Add(name, id);
public bool Validate()
{
#if DEBUG