28.10.2020

SM.Core:
+ Particle System
+ scriptable system for scripts

~ Moved Texts- and Particles-namespace to SM.Base.Drawing
~ Changed how you tell the stopwatch to pause. (From method to property)
~ Fixed Randomize.GetFloat(min, max)
~ Now automaticly adds the DrawingBase.Transformation to DrawContext.ModelMatrix. No need to change DrawContext.Instances[0], anymore.

SM.OGL:
+ "one-file-shader"-support

SM2D:
+ DrawParticles (Control for Texture and Color not there yet)

~ Changed coordnate system to upper-right as (1,1)
~ Changed default shader to "one-file-shader"
This commit is contained in:
Michel Fedde 2020-10-28 18:19:15 +01:00
parent 03b3942732
commit beb9c19081
45 changed files with 580 additions and 190 deletions

View file

@ -1,5 +1,7 @@
#region usings
using System;
using System.Linq;
using OpenTK.Graphics.OpenGL4;
using SM.OGL.Mesh;
@ -24,6 +26,46 @@ namespace SM.OGL.Shaders
/// </summary>
protected UniformCollection Uniforms;
protected GenericShader(string combinedData)
{
int firstPos = combinedData.IndexOf("//# region ", StringComparison.Ordinal);
string header = combinedData.Substring(0, firstPos);
int regionAmount = combinedData.Split(new string[] {"//# region "}, StringSplitOptions.None).Length - 1;
int pos = firstPos + 10;
string vertex = "";
string geometry = "";
string fragment = "";
for (int i = 0; i < regionAmount; i++)
{
int posOfBreak = combinedData.IndexOf("\n", pos, StringComparison.Ordinal);
string name = combinedData.Substring(pos, posOfBreak - pos).Trim();
int nextPos = i == regionAmount - 1 ? combinedData.Length : combinedData.IndexOf("//# region ", posOfBreak, StringComparison.Ordinal);
string data = header + combinedData.Substring(posOfBreak, nextPos - posOfBreak);
pos = nextPos + 10;
switch (name)
{
case "vertex":
vertex = data.Replace("vmain()", "main()");
break;
case "geometry":
geometry = data.Replace("gmain()", "main()");
break;
case "fragment":
fragment = data.Replace("fmain()", "main()");
break;
}
}
Console.WriteLine();
ShaderFileFiles = new ShaderFileCollection(vertex,fragment, geometry);
}
protected GenericShader(string vertex, string fragment) : this(new ShaderFileCollection(vertex, fragment)){}
/// <inheritdoc />
@ -47,8 +89,7 @@ namespace SM.OGL.Shaders
Name(GetType().Name);
ShaderFileFiles.Detach(this);
Uniforms = new UniformCollection();
Uniforms.ParentShader = this;
Uniforms = new UniformCollection {ParentShader = this};
Uniforms.Import(this);
GLDebugging.CheckGLErrors($"A error occured at shader creation for '{GetType()}': %code%");

View file

@ -31,8 +31,8 @@ namespace SM.OGL.Shaders
/// </summary>
/// <param name="vertex">The vertex source file.</param>
/// <param name="fragment">The fragment source file.</param>
public ShaderFileCollection(string vertex, string fragment) : this(new ShaderFile(vertex),
new ShaderFile(fragment))
public ShaderFileCollection(string vertex, string fragment, string geometry = "") : this(new ShaderFile(vertex),
new ShaderFile(fragment), geometry != "" ? new ShaderFile(geometry) : null)
{
}