Holidays 12.10. -> 25.10.2020
~ Moved code around in files. SM.Base: + PostProcessing-system + OnInitialization() for Scenes. + Shader-Extensions + Added option to not react while unfocused to the window. + Added Screenshots to the window. + Connected the log system to the SM.OGL-action system. ~ Replaced IShader with abstract MaterialShader. ~ When a log compression folder doesn't exist, it will create one. SM.OGL: + Added support for UniformArrays + Added ShaderPreProcessing + Added Shader Extensions. + Added Debug actions. + SM.OGL settings ~ Framebuffer Size is automaticly changed, when the window and scale is set. SM2D: + Added easy shader drawing.
This commit is contained in:
parent
2c00dbd31a
commit
03b3942732
102 changed files with 2683 additions and 1398 deletions
|
|
@ -1,30 +1,37 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.OGL.Shaders
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains/Represents a file used in shaders.
|
||||
/// Contains/Represents a file used in shaders.
|
||||
/// </summary>
|
||||
public class ShaderFile : GLObject
|
||||
{
|
||||
private string _data;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Shader;
|
||||
|
||||
/// <summary>
|
||||
/// Contains overrides, that can be used to import values from the CPU to the shader before it is been send to the GPU.
|
||||
/// </summary>
|
||||
public Dictionary<string, string> StringOverrides = new Dictionary<string, string>();
|
||||
/// <summary>
|
||||
/// Contains other shader files to allow access to their functions.
|
||||
/// Contains other shader files to allow access to their functions.
|
||||
/// </summary>
|
||||
public List<ShaderFile> GLSLExtensions = new List<ShaderFile>();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a file.
|
||||
/// Gets/Sets the name for this shader file.
|
||||
/// </summary>
|
||||
public new string Name;
|
||||
|
||||
/// <summary>
|
||||
/// Contains overrides, that can be used to import values from the CPU to the shader before it is been send to the GPU.
|
||||
/// </summary>
|
||||
public Dictionary<string, string> StringOverrides = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a file.
|
||||
/// </summary>
|
||||
/// <param name="data">The source file.</param>
|
||||
public ShaderFile(string data)
|
||||
|
|
@ -32,11 +39,28 @@ namespace SM.OGL.Shaders
|
|||
_data = data;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Shader;
|
||||
|
||||
|
||||
private void GenerateSource()
|
||||
{
|
||||
foreach (KeyValuePair<string, string> kvp in StringOverrides)
|
||||
_data = _data.Replace("//! " + kvp.Key, kvp.Value);
|
||||
if (!GLSettings.ShaderPreProcessing) return;
|
||||
|
||||
if (_data.Contains("//#"))
|
||||
{
|
||||
var commandSplits = _data.Split(new[] {"//#"}, StringSplitOptions.RemoveEmptyEntries);
|
||||
for (var i = 1; i < commandSplits.Length; i++)
|
||||
{
|
||||
var split = commandSplits[i].Split('\r', '\n')[0].Trim();
|
||||
var cmdArgs = split.Split(new[] {' '}, 2);
|
||||
|
||||
ShaderPreProcess.Actions[cmdArgs[0]]?.Invoke(this, cmdArgs[1]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var kvp in StringOverrides)
|
||||
_data = _data.Replace("//!" + kvp.Key, kvp.Value);
|
||||
}
|
||||
|
||||
internal void Compile(GenericShader shader, ShaderType type)
|
||||
|
|
@ -49,7 +73,11 @@ namespace SM.OGL.Shaders
|
|||
GL.ShaderSource(_id, _data);
|
||||
GL.CompileShader(_id);
|
||||
}
|
||||
|
||||
GL.AttachShader(shader, _id);
|
||||
GLDebugging.CheckGLErrors($"Error at loading shader file: '{shader.GetType()}', '{type}', %code%");
|
||||
|
||||
for (var i = 0; i < GLSLExtensions.Count; i++) GLSLExtensions[i].Compile(shader, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue