using System; using System.Collections.Generic; using OpenTK.Graphics.OpenGL4; namespace Platformer.Util { public class Program : GlObj { private Dictionary _unifCache; private Dictionary _attrCache; private Dictionary _unifBlockCache; public Program() : base(GL.CreateProgram()) { _unifCache = new Dictionary(); _attrCache = new Dictionary(); _unifBlockCache = new Dictionary(); } public int UnifLoc(string name) { if (!_unifCache.ContainsKey(name)) _unifCache[name] = GL.GetUniformLocation(this, name); return _unifCache[name]; } public int UnifBlockInd(string name) { if (!_unifBlockCache.ContainsKey(name)) _unifBlockCache[name] = GL.GetUniformBlockIndex(this, name); return _unifBlockCache[name]; } public int AttrLoc(string name) { if (!_attrCache.ContainsKey(name)) _attrCache[name] = GL.GetAttribLocation(this, name); return _attrCache[name]; } public static Program Link(params Shader[] shaders) { var p = new Program(); foreach (var s in shaders) GL.AttachShader(p, s); GL.LinkProgram(p); Console.Error.WriteLine(GL.GetProgramInfoLog(p)); return p; } } }