#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.
/// The geometry source file.
public ShaderFileCollection(string vertex, string fragment, string geometry = "") : this(new ShaderFile(vertex),
new ShaderFile(fragment), geometry != "" ? new ShaderFile(geometry) : null)
{
}
///
/// Creating the collection with shader files.
///
///
///
///
public ShaderFileCollection(ShaderFile vertex, ShaderFile fragment, ShaderFile geometry = default)
{
Vertex = new []{vertex};
if (geometry != null) Geometry = new[] {geometry};
else Geometry = default;
Fragment = new []{fragment};
}
///
/// Creates a collection with arrays of 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)
{
foreach (ShaderFile file in Vertex)
file.Compile(shader, ShaderType.VertexShader);
if (Geometry != null)
foreach (ShaderFile file in Geometry)
file.Compile(shader, ShaderType.GeometryShader);
foreach (ShaderFile file in Fragment)
file.Compile(shader, ShaderType.FragmentShader);
}
///
/// Removes the files form the shader.
///
///
internal void Detach(GenericShader shader)
{
foreach (ShaderFile file in Vertex)
GL.DetachShader(shader, file);
if (Geometry != null)
foreach (ShaderFile file in Geometry)
GL.DetachShader(shader, file);
foreach (ShaderFile file in Fragment)
GL.DetachShader(shader, file);
GLDebugging.CheckGLErrors($"Error at detaching '{shader.GetType()}'");
}
}
}