mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-30 13:36:37 +00:00
Shader.cs - Added 'SetUniform2' and added 2nd 'Create' function to not only create vertex and fragment shader
This commit is contained in:
@@ -37,6 +37,12 @@ namespace PckStudio.Rendering
|
||||
GL.Uniform1(location, value);
|
||||
}
|
||||
|
||||
public void SetUniform2(string name, Vector2 value)
|
||||
{
|
||||
int location = GetUniformLocation(name);
|
||||
GL.Uniform2(location, value);
|
||||
}
|
||||
|
||||
public void SetUniform4(string name, Vector4 value)
|
||||
{
|
||||
int location = GetUniformLocation(name);
|
||||
@@ -76,30 +82,42 @@ namespace PckStudio.Rendering
|
||||
{
|
||||
GL.GetShader(shaderId, ShaderParameter.InfoLogLength, out int length);
|
||||
GL.GetShaderInfoLog(shaderId, length, out _, out string infoLog);
|
||||
Trace.TraceError(infoLog);
|
||||
GL.DeleteShader(shaderId);
|
||||
Trace.Fail(infoLog);
|
||||
return 0;
|
||||
}
|
||||
return shaderId;
|
||||
}
|
||||
|
||||
public static Shader Create(string vertexSource, string fragmentSource)
|
||||
{
|
||||
return Create(
|
||||
new KeyValuePair<ShaderType, string>(ShaderType.VertexShader, vertexSource),
|
||||
new KeyValuePair<ShaderType, string>(ShaderType.FragmentShader, fragmentSource)
|
||||
);
|
||||
}
|
||||
|
||||
public static Shader Create(params KeyValuePair<ShaderType, string>[] shaderSources)
|
||||
{
|
||||
int programId = GL.CreateProgram();
|
||||
|
||||
int vertexShader = CompileShader(ShaderType.VertexShader, vertexSource);
|
||||
int fragmentShader = CompileShader(ShaderType.FragmentShader, fragmentSource);
|
||||
|
||||
GL.AttachShader(programId, vertexShader);
|
||||
GL.AttachShader(programId, fragmentShader);
|
||||
var shaderIds = new List<int>(shaderSources.Length);
|
||||
|
||||
foreach (var shaderSource in shaderSources)
|
||||
{
|
||||
int shaderId = CompileShader(shaderSource.Key, shaderSource.Value);
|
||||
GL.AttachShader(programId, shaderId);
|
||||
shaderIds.Add(shaderId);
|
||||
}
|
||||
GL.LinkProgram(programId);
|
||||
GL.ValidateProgram(programId);
|
||||
|
||||
Debug.WriteLine(GL.GetProgramInfoLog(programId), category: nameof(Shader));
|
||||
|
||||
GL.DeleteShader(vertexShader);
|
||||
GL.DeleteShader(fragmentShader);
|
||||
foreach (var shaderId in shaderIds)
|
||||
{
|
||||
GL.DeleteShader(shaderId);
|
||||
}
|
||||
return new Shader(programId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user