refactor(lifetime): own render resource prefixes

Give terrain, sky, retained UI, portal preparation, and the update/render frame pair explicit single owners. Make shader, texture, text, bindless, and GL construction prefixes checked and retryable so partial failure cannot lose or replay resource ownership.

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-22 14:42:14 +02:00
parent fec0d94148
commit c87b15303d
41 changed files with 3768 additions and 355 deletions

View file

@ -7,36 +7,17 @@ public sealed class Shader : IDisposable
{
private readonly GL _gl;
private readonly Dictionary<string, int> _uniformLocations = new(StringComparer.Ordinal);
public uint Program { get; }
public uint Program { get; private set; }
public Shader(GL gl, string vertexPath, string fragmentPath)
{
_gl = gl;
uint vert = Compile(File.ReadAllText(vertexPath), ShaderType.VertexShader);
uint frag = Compile(File.ReadAllText(fragmentPath), ShaderType.FragmentShader);
Program = _gl.CreateProgram();
_gl.AttachShader(Program, vert);
_gl.AttachShader(Program, frag);
_gl.LinkProgram(Program);
_gl.GetProgram(Program, ProgramPropertyARB.LinkStatus, out int linked);
if (linked == 0)
throw new Exception("program link failed: " + _gl.GetProgramInfoLog(Program));
_gl.DetachShader(Program, vert);
_gl.DetachShader(Program, frag);
_gl.DeleteShader(vert);
_gl.DeleteShader(frag);
}
private uint Compile(string source, ShaderType type)
{
uint id = _gl.CreateShader(type);
_gl.ShaderSource(id, source);
_gl.CompileShader(id);
_gl.GetShader(id, ShaderParameterName.CompileStatus, out int ok);
if (ok == 0)
throw new Exception($"{type} compile failed: " + _gl.GetShaderInfoLog(id));
return id;
string vertexSource = File.ReadAllText(vertexPath);
string fragmentSource = File.ReadAllText(fragmentPath);
Program = ShaderProgramConstruction.Build(
new GlShaderProgramBuildApi(gl),
vertexSource,
fragmentSource);
}
public void Use() => _gl.UseProgram(Program);
@ -90,7 +71,12 @@ public sealed class Shader : IDisposable
public void Dispose()
{
uint program = Program;
if (program == 0)
return;
_uniformLocations.Clear();
_gl.DeleteProgram(Program);
GlResourceCommand.DeleteProgram(_gl, program, $"delete Shader program {program}");
Program = 0;
}
}