Added Shader base and PixelShader

This commit is contained in:
Simon Lübeß
2020-12-04 19:02:42 +01:00
parent b12baf695a
commit 242d9e728c
6 changed files with 177 additions and 45 deletions
@@ -112,5 +112,7 @@ namespace GlitchyEngine.Renderer
public extern void SetVertexLayout(VertexLayout vertexLayout);
public extern void SetPrimitiveTopology(PrimitiveTopology primitiveTopology);
public extern void SetPixelShader(PixelShader pixelShader);
}
}
+54
View File
@@ -0,0 +1,54 @@
using System;
using System.IO;
namespace GlitchyEngine.Renderer
{
public struct ShaderDefine
{
public String Name;
public String Definition;
public this() => this = default;
public this(String name, String definition)
{
Name = name;
Definition = definition;
}
}
public abstract class Shader
{
protected GraphicsContext _context;
public GraphicsContext Context => _context;
public this(GraphicsContext context, String source, String entryPoint, ShaderDefine[] macros = null)
{
_context = context;
CompileFromSource(source, entryPoint);
}
public static mixin FromFile<T>(GraphicsContext context, String fileName, String entryPoint, ShaderDefine[] macros = null) where T : Shader
{
String fileContent = new String();
File.ReadAllText(fileName, fileContent, true);
T shader = new T(context, fileContent, entryPoint, macros);
delete fileContent;
shader
}
public abstract void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null);
}
public class PixelShader : Shader
{
public this(GraphicsContext context, String source, String entryPoint, ShaderDefine[] macros = null)
: base(context, source, entryPoint, macros) { }
public override extern void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null);
}
}