Loads and loads of small improvements I added while developing on my game
This commit is contained in:
parent
41421b1df9
commit
a7c71e7ea1
107 changed files with 2278 additions and 1023 deletions
|
|
@ -106,6 +106,11 @@ namespace SM.OGL.Shaders
|
|||
GLDebugging.CheckGLErrors($"A error occured at shader creation for '{GetType()}': %code%");
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
GL.UseProgram(ID);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Compile()
|
||||
{
|
||||
|
|
@ -122,7 +127,7 @@ namespace SM.OGL.Shaders
|
|||
/// </summary>
|
||||
/// <param name="mesh">The mesh.</param>
|
||||
/// <param name="amount">The amounts for instancing.</param>
|
||||
protected void DrawObject(GenericMesh mesh, int amount = 1)
|
||||
public static void DrawObject(GenericMesh mesh, int amount = 1)
|
||||
{
|
||||
if (mesh.Indices != null)
|
||||
GL.DrawElementsInstanced(mesh.PrimitiveType, 0, DrawElementsType.UnsignedInt, mesh.Indices, amount);
|
||||
|
|
@ -138,7 +143,6 @@ namespace SM.OGL.Shaders
|
|||
Uniforms.NextTexture = 0;
|
||||
|
||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,17 +14,17 @@ namespace SM.OGL.Shaders
|
|||
/// <summary>
|
||||
/// Contains the vertex file.
|
||||
/// </summary>
|
||||
public ShaderFile Vertex;
|
||||
public ShaderFile[] Vertex;
|
||||
|
||||
/// <summary>
|
||||
/// Contains the geometry file.
|
||||
/// </summary>
|
||||
public ShaderFile Geometry;
|
||||
public ShaderFile[] Geometry;
|
||||
|
||||
/// <summary>
|
||||
/// Contains the fragment file.
|
||||
/// </summary>
|
||||
public ShaderFile Fragment;
|
||||
public ShaderFile[] Fragment;
|
||||
|
||||
/// <summary>
|
||||
/// Creating the collection with vertex and fragment files.
|
||||
|
|
@ -44,6 +44,14 @@ namespace SM.OGL.Shaders
|
|||
/// <param name="fragment"></param>
|
||||
/// <param name="geometry"></param>
|
||||
public ShaderFileCollection(ShaderFile vertex, ShaderFile fragment, ShaderFile geometry = default)
|
||||
{
|
||||
Vertex = new []{vertex};
|
||||
if (geometry != null) Geometry = new[] {geometry};
|
||||
else Geometry = default;
|
||||
Fragment = new []{fragment};
|
||||
}
|
||||
|
||||
public ShaderFileCollection(ShaderFile[] vertex, ShaderFile[] fragment, ShaderFile[] geometry = default)
|
||||
{
|
||||
Vertex = vertex;
|
||||
Geometry = geometry;
|
||||
|
|
@ -56,9 +64,15 @@ namespace SM.OGL.Shaders
|
|||
/// <param name="shader"></param>
|
||||
internal void Append(GenericShader shader)
|
||||
{
|
||||
Vertex.Compile(shader, ShaderType.VertexShader);
|
||||
Geometry?.Compile(shader, ShaderType.GeometryShader);
|
||||
Fragment.Compile(shader, ShaderType.FragmentShader);
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -67,9 +81,15 @@ namespace SM.OGL.Shaders
|
|||
/// <param name="shader"></param>
|
||||
internal void Detach(GenericShader shader)
|
||||
{
|
||||
GL.DetachShader(shader, Vertex);
|
||||
if (Geometry != null) GL.DetachShader(shader, Geometry);
|
||||
GL.DetachShader(shader, Fragment);
|
||||
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()}'");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -354,7 +354,7 @@ namespace SM.OGL.Shaders
|
|||
|
||||
#region Matrix2
|
||||
|
||||
public void SetMatrix2(ref Matrix2 matrix, bool transpose = false)
|
||||
public void SetMatrix2(Matrix2 matrix, bool transpose = false)
|
||||
{
|
||||
GL.UniformMatrix2(Location, transpose, ref matrix);
|
||||
}
|
||||
|
|
@ -383,7 +383,7 @@ namespace SM.OGL.Shaders
|
|||
|
||||
#region Matrix3
|
||||
|
||||
public void SetMatrix3(ref Matrix3 matrix, bool transpose = false)
|
||||
public void SetMatrix3(Matrix3 matrix, bool transpose = false)
|
||||
{
|
||||
GL.UniformMatrix3(Location, transpose, ref matrix);
|
||||
}
|
||||
|
|
@ -485,7 +485,7 @@ namespace SM.OGL.Shaders
|
|||
{
|
||||
Parent.NextTexture = texturePos + 1;
|
||||
GL.ActiveTexture(TextureUnit.Texture0 + texturePos);
|
||||
GL.BindTexture(TextureTarget.Texture2D, texture);
|
||||
GL.BindTexture(texture.Target, texture);
|
||||
SetUniform1(texturePos);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace SM.OGL.Shaders
|
|||
public string Name { get; internal set; }
|
||||
public UniformCollection Parent { get; internal set; }
|
||||
public GenericShader ParentShader { get; internal set; }
|
||||
public int Length => storedUniforms.Count;
|
||||
|
||||
public Dictionary<string, Uniform> this[int index] => Get(index);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace SM.OGL.Shaders
|
|||
}
|
||||
catch (KeyNotFoundException)
|
||||
{
|
||||
GLCustomActions.AtWarning?.Invoke("Uniform '" + KeyString + key + "' was not found. Tried to recreate it.");
|
||||
GLCustomActions.AtWarning?.Invoke("Uniform '" + KeyString + key + "' at '" + ParentShader.GetType().Name + "' was not found. Tried to recreate it.");
|
||||
var u = new Uniform(GL.GetUniformLocation(ParentShader, KeyString + key), this);
|
||||
Add(key, u);
|
||||
return u;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue