17.09.2020
+ Generic Scene + Generic Camera + Generic Window + Contexts for drawing and updateing + very basic 2D-implermention
This commit is contained in:
parent
9889366317
commit
589d131246
25 changed files with 383 additions and 78 deletions
8
SMCode/SM.Base/Shader/Files/default.frag
Normal file
8
SMCode/SM.Base/Shader/Files/default.frag
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#version 330
|
||||
uniform vec4 Tint;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
void main() {
|
||||
color = vec4(1,1,1,1) + Tint;
|
||||
}
|
||||
9
SMCode/SM.Base/Shader/Files/default.vert
Normal file
9
SMCode/SM.Base/Shader/Files/default.vert
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#version 330
|
||||
layout(location = 0) in vec3 aPos;
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 ModelMatrix;
|
||||
|
||||
void main() {
|
||||
gl_Position = MVP * ModelMatrix * vec4(aPos, 1);
|
||||
}
|
||||
32
SMCode/SM.Base/Shader/InstanceShader.cs
Normal file
32
SMCode/SM.Base/Shader/InstanceShader.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.StaticObjects;
|
||||
using SM.OGL.Shaders;
|
||||
|
||||
namespace SM.Base.Shader
|
||||
{
|
||||
public class InstanceShader : GenericShader
|
||||
{
|
||||
protected override bool AutoCompile { get; } = true;
|
||||
|
||||
public Action<UniformCollection, DrawContext> SetUniform;
|
||||
|
||||
public InstanceShader(string vertex, string fragment, Action<UniformCollection, DrawContext> setUniform) : base(
|
||||
new ShaderFileCollection(vertex, fragment))
|
||||
{
|
||||
SetUniform = setUniform;
|
||||
}
|
||||
public void Draw(DrawContext context)
|
||||
{
|
||||
GL.UseProgram(this);
|
||||
|
||||
SetUniform.Invoke(Uniforms, context);
|
||||
|
||||
DrawObject(context.Mesh, true);
|
||||
|
||||
GL.UseProgram(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
SMCode/SM.Base/Shader/Shaders.cs
Normal file
18
SMCode/SM.Base/Shader/Shaders.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System.IO;
|
||||
using System.Reflection;
|
||||
using SM.OGL.Shaders;
|
||||
|
||||
namespace SM.Base.Shader
|
||||
{
|
||||
public class Shaders
|
||||
{
|
||||
public static InstanceShader Default = new InstanceShader(new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("SM.Base.Shader.Files.default.vert")).ReadToEnd(),
|
||||
new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("SM.Base.Shader.Files.default.frag")).ReadToEnd(),
|
||||
((u, context) =>
|
||||
{
|
||||
u["MVP"].SetMatrix4(context.View * context.World);
|
||||
u["ModelMatrix"].SetMatrix4(context.ModelMatrix);
|
||||
u["Tint"].SetUniform4(1,1,1,1);
|
||||
}));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue