Compare commits

...

1 Commits

Author SHA1 Message Date
Caleb Cornett 4f89325d29 Add support for custom Video shaders 2022-10-01 03:10:28 -04:00
1 changed files with 32 additions and 2 deletions

View File

@ -22,6 +22,10 @@ namespace MoonWorks.Graphics
private readonly List<WeakReference<GraphicsResource>> resources = new List<WeakReference<GraphicsResource>>();
private static bool usingCustomVideoShaders;
private static string customVideoVertexShaderFilepath;
private static string customVideoFragmentShaderFilepath;
public GraphicsDevice(
Backend preferredBackend,
bool debugMode
@ -38,8 +42,24 @@ namespace MoonWorks.Graphics
Conversions.BoolToByte(debugMode)
);
VideoVertexShader = new ShaderModule(this, GetEmbeddedResource("MoonWorks.Shaders.FullscreenVert.spv"));
VideoFragmentShader = new ShaderModule(this, GetEmbeddedResource("MoonWorks.Shaders.YUV2RGBAFrag.spv"));
Stream videoVertexShaderStream;
Stream videoFragmentShaderStream;
if (!usingCustomVideoShaders)
{
videoVertexShaderStream = GetEmbeddedResource("MoonWorks.Shaders.FullscreenVert.spv");
videoFragmentShaderStream = GetEmbeddedResource("MoonWorks.Shaders.YUV2RGBAFrag.spv");
}
else
{
videoVertexShaderStream = File.Open(customVideoVertexShaderFilepath, FileMode.Open, FileAccess.Read);
videoFragmentShaderStream = File.Open(customVideoFragmentShaderFilepath, FileMode.Open, FileAccess.Read);
}
VideoVertexShader = new ShaderModule(this, videoVertexShaderStream);
VideoFragmentShader = new ShaderModule(this, videoFragmentShaderStream);
videoVertexShaderStream.Close();
videoFragmentShaderStream.Close();
VideoPipeline = new GraphicsPipeline(
this,
@ -148,6 +168,16 @@ namespace MoonWorks.Graphics
return typeof(GraphicsDevice).Assembly.GetManifestResourceStream(name);
}
/// <summary>
/// Use this ONLY for platforms with non-standard graphics APIs where the shader code can't be embedded into the assembly!
/// </summary>
public static void UseCustomVideoShaders(string vertexShaderFilePath, string fragmentShaderFilePath)
{
usingCustomVideoShaders = true;
customVideoVertexShaderFilepath = vertexShaderFilePath;
customVideoFragmentShaderFilepath = fragmentShaderFilePath;
}
protected virtual void Dispose(bool disposing)
{
if (!IsDisposed)