Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using OpenTK;
- using OpenTK.Graphics.OpenGL;
- using Wicked.Engine;
- namespace Wicked.Shaders
- {
- public class Shader
- {
- private int _handle;
- public Shader CompileShader(ShaderObject[] shaders)
- {
- int status = -1;
- string info = "";
- List<int> compiled = new List<int>();
- foreach (var shader in shaders)
- {
- var index = GL.CreateShader(shader.ShaderInformation);
- GL.ShaderSource(index, shader.ShaderCode);
- GL.CompileShader(index);
- GL.GetShaderInfoLog(index, out info);
- GL.GetShader(index, ShaderParameter.CompileStatus, out status);
- if (status != 1)
- throw new ApplicationException(info);
- compiled.Add(index);
- }
- _handle = GL.CreateProgram();
- foreach (var shader in compiled) { GL.AttachShader(_handle, shader); }
- GL.LinkProgram(_handle);
- foreach (var shader in compiled)
- {
- GL.DetachShader(_handle, shader);
- GL.DeleteShader(shader);
- }
- return this;
- }
- public void Use()
- {
- GL.UseProgram(_handle);
- }
- public void SetInt(string name, int value)
- {
- int location = GL.GetUniformLocation(_handle, name);
- if (location == -1)
- {
- throw new ArgumentException("uniform name not found");
- }
- GL.Uniform1(location, value);
- }
- public void SetMatrix4(string name, Matrix4 matrix)
- {
- int location = GL.GetUniformLocation(_handle, name);
- if (location == -1)
- {
- throw new ArgumentException("uniform name not found");
- }
- GL.UniformMatrix4(location, true, ref matrix);
- }
- public int GetAttribLocation(string attribName)
- {
- return GL.GetAttribLocation(_handle, attribName);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement