#region usings
using OpenTK.Graphics.OpenGL4;
#endregion
namespace SM.OGL.Shaders
{
///
/// Collects all files that are needed for a shader.
///
public struct ShaderFileCollection
{
///
/// Contains the vertex file.
///
public ShaderFile Vertex;
///
/// Contains the geometry file.
///
public ShaderFile Geometry;
///
/// Contains the fragment file.
///
public ShaderFile Fragment;
///
/// Creating the collection with vertex and fragment files.
///
/// The vertex source file.
/// The fragment source file.
public ShaderFileCollection(string vertex, string fragment) : this(new ShaderFile(vertex),
new ShaderFile(fragment))
{
}
///
/// Creating the collection with shader files.
///
///
///
///
public ShaderFileCollection(ShaderFile vertex, ShaderFile fragment, ShaderFile geometry = default)
{
Vertex = vertex;
Geometry = geometry;
Fragment = fragment;
}
///
/// Appends the files to the shader.
///
///
internal void Append(GenericShader shader)
{
Vertex.Compile(shader, ShaderType.VertexShader);
Geometry?.Compile(shader, ShaderType.GeometryShader);
Fragment.Compile(shader, ShaderType.FragmentShader);
}
///
/// Removes the files form the shader.
///
///
internal void Detach(GenericShader shader)
{
GL.DetachShader(shader, Vertex);
if (Geometry != null) GL.DetachShader(shader, Geometry);
GL.DetachShader(shader, Fragment);
GLDebugging.CheckGLErrors($"Error at detaching '{shader.GetType()}'");
}
}
}