using System; using System.Collections.Generic; using OpenTK.Graphics.OpenGL4; namespace SM.OGL.Shaders { /// /// Contains/Represents a file used in shaders. /// public class ShaderFile : GLObject { private string _data; /// public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Shader; /// /// Contains overrides, that can be used to import values from the CPU to the shader before it is been send to the GPU. /// public Dictionary StringOverrides = new Dictionary(); /// /// Contains other shader files to allow access to their functions. /// public List GLSLExtensions = new List(); /// /// Creates a file. /// /// The source file. public ShaderFile(string data) { _data = data; } private void GenerateSource() { foreach (KeyValuePair kvp in StringOverrides) _data = _data.Replace("//! " + kvp.Key, kvp.Value); } internal void Compile(GenericShader shader, ShaderType type) { if (_id < 0) { GenerateSource(); _id = GL.CreateShader(type); GL.ShaderSource(_id, _data); GL.CompileShader(_id); } GL.AttachShader(shader, _id); } } }