16.09.2020

~ Fixed shading import
~ Fixed "Plate" mesh
~ Move the dll files into "SMCode"
This commit is contained in:
Michel Fedde 2020-09-16 19:12:53 +02:00
parent 421d03f91d
commit 9889366317
27 changed files with 30 additions and 17 deletions

View file

@ -0,0 +1,50 @@
using System;
using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders
{
public class GenericShader : GLObject
{
protected ShaderFileCollection ShaderFileFiles;
protected UniformCollection Uniforms;
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Program;
public GenericShader(ShaderFileCollection shaderFileFiles)
{
ShaderFileFiles = shaderFileFiles;
}
public void Compile()
{
_id = GL.CreateProgram();
ShaderFileFiles.Append(this);
GL.LinkProgram(_id);
this.Name(GetType().Name);
ShaderFileFiles.Detach(this);
GL.GetProgram(_id, GetProgramParameterName.ActiveUniforms, out int uniformCount);
if (uniformCount < 1)
throw new Exception("[Critical] No uniforms has been found.");
Uniforms = new UniformCollection();
for (int i = 0; i < uniformCount; i++)
{
string key = GL.GetActiveUniform(_id, i, out _, out _);
int loc = GL.GetUniformLocation(_id, key);
if (key.StartsWith("[")) key = key.Split('[', ']')[0];
Uniforms.Add(key, loc);
}
}
public void DrawObject(Mesh.Mesh mesh, bool bindVAO = false)
{
if (bindVAO) GL.BindVertexArray(mesh);
GL.DrawArrays(mesh.PrimitiveType, 0, mesh.Vertex.Count);
}
}
}