108 lines
3.2 KiB
C#
108 lines
3.2 KiB
C#
using StgSharp.Graphics;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace StgSharp.Graphics.GL.ShaderEdit
|
|
{
|
|
public class ShaderGenerator
|
|
{
|
|
private List<string> codeList;
|
|
private List<ShaderFunction> usedShaderFunctions;
|
|
|
|
public Uniform<T> DefineUniform<T>() where T : struct
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
public class ShaderFunction
|
|
{
|
|
private string name;
|
|
private List<string> codeList;
|
|
private List<ShaderParameter> inputList;
|
|
private ShaderParameter outPut;
|
|
|
|
public int ParameterCount
|
|
{
|
|
get { return inputList.Count; }
|
|
}
|
|
|
|
public void EmitCall(ShaderFunction function, ShaderParameter outPut, params ShaderParameter[] inputParams)
|
|
{
|
|
if (inputParams.Length != function.ParameterCount)
|
|
{
|
|
throw new ArgumentException("Provided parameters does not match function's parameter list.");
|
|
}
|
|
if (!ShaderParameter.IsSameType(outPut, function.outPut))
|
|
{
|
|
throw new Exception("Provided parameters does not match function's parameter list.");
|
|
}
|
|
for (int i = 0; i < inputParams.Length; i++)
|
|
{
|
|
if (!ShaderParameter.IsSameType(function.inputList[i], inputParams[i]))
|
|
{
|
|
throw new Exception("Provided parameters does not match function's parameter list.");
|
|
}
|
|
}
|
|
string codeLine = "";
|
|
if (outPut != ShaderParameter.Void)
|
|
{
|
|
codeLine += $"{outPut.name} = ";
|
|
}
|
|
codeLine += $"{function.name}(";
|
|
foreach (ShaderParameter inputParam in inputParams)
|
|
{
|
|
codeLine += inputParam.name;
|
|
}
|
|
codeLine += ");\n";
|
|
codeList.Add(codeLine);
|
|
}
|
|
}
|
|
|
|
public class ShaderParameter
|
|
{
|
|
internal readonly InternalShaderType type;
|
|
internal readonly string name;
|
|
internal readonly bool isReadOnly;
|
|
|
|
public ShaderParameter(string name, InternalShaderType type)
|
|
{
|
|
this.name = name;
|
|
this.type = type;
|
|
isReadOnly = false;
|
|
}
|
|
|
|
public static readonly ShaderParameter Void = new ShaderParameter("", InternalShaderType.Void);
|
|
|
|
public static bool IsSameType(ShaderParameter param1, ShaderParameter param2)
|
|
{
|
|
if (param1.type != InternalShaderType.Struct)
|
|
{
|
|
return param1.type == param2.type;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("Struct is currently not supported.");
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum InternalShaderType
|
|
{
|
|
#pragma warning disable CS1591
|
|
Struct, Void,
|
|
Int, UInt,
|
|
Float, Double,
|
|
Vector2, Vector3, Vector4,
|
|
VectorD2, VectorD3, VectorD4,
|
|
Matrix2x2, Matrix2x3, Matrix2x4,
|
|
Matrix3x2, Matrix3x3, Matrix3x4,
|
|
Matrix4x2, Matrix4x3, Matrix4x4,
|
|
#pragma warning restore CS1591
|
|
}
|
|
} |