58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using System;
|
|
using SlatedGameToolkit.Framework.Exceptions;
|
|
using SlatedGameToolkit.Framework.Graphics.Shaders;
|
|
|
|
namespace SlatedGameToolkit.Framework.Graphics.Programs
|
|
{
|
|
public class GLShaderProgram : GLProgram
|
|
{
|
|
private readonly GLShader[] shaders;
|
|
private readonly GLAttachShader attachShader;
|
|
private readonly GLDetachShader detachShader;
|
|
private GLBindAttribLocation bindAttribLocation;
|
|
public GLShaderProgram(bool separable = true, params GLShader[] shaders) : base() {
|
|
if (shaders.Length == 0) throw new ArgumentException("Requires at least one shader for shader program.");
|
|
this.shaders = shaders;
|
|
|
|
attachShader = GLFunctionUtils.RetrieveGLDelegate<GLAttachShader>("glAttachShader");
|
|
bindAttribLocation = GLFunctionUtils.RetrieveGLDelegate<GLBindAttribLocation>("glBindAttribLocation");
|
|
detachShader = GLFunctionUtils.RetrieveGLDelegate<GLDetachShader>("glDetachShader");
|
|
|
|
Use();
|
|
|
|
foreach (GLShader shader in shaders)
|
|
{
|
|
attachShader(handle, shader.Handle);
|
|
}
|
|
|
|
linkProgram(handle);
|
|
uint length;
|
|
string log;
|
|
getProgramInfoLog(handle, 1024, out length, out log);
|
|
if (length > 0) {
|
|
Dispose();
|
|
throw new OpenGLException(log);
|
|
}
|
|
|
|
foreach (GLShader shader in shaders)
|
|
{
|
|
detachShader(handle, shader.Handle);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Disposes of the shaders and this program.
|
|
/// </summary>
|
|
public override void Dispose() {
|
|
foreach (GLShader shader in shaders)
|
|
{
|
|
shader.Dispose();
|
|
}
|
|
base.Dispose();
|
|
}
|
|
|
|
~GLShaderProgram() {
|
|
Dispose();
|
|
}
|
|
}
|
|
} |