65 lines
1.1 KiB
C#
65 lines
1.1 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
namespace org.budnhead.graphics
|
|
{
|
|
public class Shader
|
|
{
|
|
private int id;
|
|
|
|
private ShaderType shaderType;
|
|
private String source;
|
|
|
|
public Shader(ShaderType shaderType, String source)
|
|
{
|
|
this.id = GL.CreateShader(shaderType);
|
|
|
|
this.shaderType = shaderType;
|
|
this.source = source;
|
|
|
|
compile();
|
|
}
|
|
|
|
public int ID
|
|
{
|
|
get { return this.id; }
|
|
}
|
|
|
|
public Shader(ShaderType shaderType, FileStream file)
|
|
{
|
|
this.id = GL.CreateShader(shaderType);
|
|
this.shaderType = shaderType;
|
|
|
|
StreamReader sr = new StreamReader(file);
|
|
this.source = sr.ReadToEnd();
|
|
|
|
|
|
compile();
|
|
}
|
|
|
|
private void compile()
|
|
{
|
|
int result;
|
|
|
|
GL.ShaderSource(this.id, source);
|
|
GL.CompileShader(this.id);
|
|
|
|
string msg = GL.GetShaderInfoLog((int)this.id);
|
|
GL.GetShader(this.id, ShaderParameter.CompileStatus, out result);
|
|
|
|
if (result != 1){
|
|
Console.WriteLine("Shader compile failed: {0}", msg);
|
|
throw new Exception(String.Format("OpenGL: Shader did not compile. ({0})",msg));
|
|
}
|
|
|
|
}
|
|
|
|
public ShaderType ShaderType
|
|
{
|
|
get { return this.shaderType; }
|
|
}
|
|
}
|
|
}
|