update
This commit is contained in:
34
Shader.cs
34
Shader.cs
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user