This commit is contained in:
Max Westerlund
2025-09-02 13:17:15 +02:00
parent b6f9966eb9
commit 71c5f3a3aa
15 changed files with 618 additions and 37 deletions

View File

@@ -1,4 +1,5 @@
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -10,7 +11,7 @@ namespace Voxel
{
public class Shader
{
int handle;
private int _handle;
private bool disposedValue = false;
public Shader(string vertexPath, string fragmentPath)
@@ -41,36 +42,47 @@ namespace Voxel
// attach
handle = GL.CreateProgram();
_handle = GL.CreateProgram();
GL.AttachShader(handle, vertexShader);
GL.AttachShader(handle, fragmentShader);
GL.AttachShader(_handle, vertexShader);
GL.AttachShader(_handle, fragmentShader);
GL.LinkProgram(handle);
GL.LinkProgram(_handle);
GL.GetProgram(handle, GetProgramParameterName.LinkStatus, out success);
GL.GetProgram(_handle, GetProgramParameterName.LinkStatus, out success);
if (success == 0)
{
string infoLog = GL.GetProgramInfoLog(handle);
string infoLog = GL.GetProgramInfoLog(_handle);
Console.WriteLine(infoLog);
}
GL.DetachShader(handle, vertexShader);
GL.DetachShader(handle, fragmentShader);
GL.DetachShader(_handle, vertexShader);
GL.DetachShader(_handle, fragmentShader);
GL.DeleteShader(fragmentShader);
GL.DeleteShader(vertexShader);
}
public void SetMatrix4(string name, Matrix4 matrix)
{
int location = GL.GetUniformLocation(_handle, name);
if (location == -1)
{
Console.WriteLine($"Uniform '{name}' not found in shader.");
return;
}
GL.UniformMatrix4(location, false, ref matrix);
}
public void Use()
{
GL.UseProgram(handle);
GL.UseProgram(_handle);
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
GL.DeleteProgram(handle);
GL.DeleteProgram(_handle);
disposedValue = true;
}