smrendererv3/SMCode/SM.OGL/Shaders/ShaderFile.cs
Michel Fedde 9889366317 16.09.2020
~ Fixed shading import
~ Fixed "Plate" mesh
~ Move the dll files into "SMCode"
2020-09-16 19:12:53 +02:00

40 lines
No EOL
1.1 KiB
C#

using System;
using System.Collections.Generic;
using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders
{
public class ShaderFile : GLObject
{
private string _data;
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Shader;
public Dictionary<string, string> StringOverrides = new Dictionary<string, string>();
public List<ShaderFile> GLSLExtensions = new List<ShaderFile>();
public ShaderFile(string data)
{
_data = data;
}
private void GenerateSource()
{
foreach (KeyValuePair<string, string> 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);
}
}
}