using Silk.NET.OpenGL; namespace Godosa.Desktop; /// Shader program helpers: compile + link with the driver's info log in the /// exception, so a bad shader fails loudly at startup instead of drawing nothing. public static class GlProgram { public static uint Link(GL gl, string vertexSource, string fragmentSource) { uint vs = Compile(gl, ShaderType.VertexShader, vertexSource); uint fs = Compile(gl, ShaderType.FragmentShader, fragmentSource); uint program = gl.CreateProgram(); gl.AttachShader(program, vs); gl.AttachShader(program, fs); gl.LinkProgram(program); gl.GetProgram(program, ProgramPropertyARB.LinkStatus, out int linkStatus); if (linkStatus == 0) throw new InvalidOperationException($"Shader link failed: {gl.GetProgramInfoLog(program)}"); gl.DeleteShader(vs); gl.DeleteShader(fs); return program; } public static uint Compile(GL gl, ShaderType type, string source) { uint shader = gl.CreateShader(type); gl.ShaderSource(shader, source); gl.CompileShader(shader); gl.GetShader(shader, ShaderParameterName.CompileStatus, out int status); if (status == 0) throw new InvalidOperationException($"Shader compile failed: {gl.GetShaderInfoLog(shader)}"); return shader; } }