Add support for custom Video shaders

pull/28/head
Caleb Cornett 2022-10-01 03:10:28 -04:00
parent 66c6ceec04
commit 4f89325d29
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 readonly List<WeakReference<GraphicsResource>> resources = new List<WeakReference<GraphicsResource>>();
private static bool usingCustomVideoShaders;
private static string customVideoVertexShaderFilepath;
private static string customVideoFragmentShaderFilepath;
public GraphicsDevice( public GraphicsDevice(
Backend preferredBackend, Backend preferredBackend,
bool debugMode bool debugMode
@ -38,8 +42,24 @@ namespace MoonWorks.Graphics
Conversions.BoolToByte(debugMode) Conversions.BoolToByte(debugMode)
); );
VideoVertexShader = new ShaderModule(this, GetEmbeddedResource("MoonWorks.Shaders.FullscreenVert.spv")); Stream videoVertexShaderStream;
VideoFragmentShader = new ShaderModule(this, GetEmbeddedResource("MoonWorks.Shaders.YUV2RGBAFrag.spv")); 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( VideoPipeline = new GraphicsPipeline(
this, this,
@ -148,6 +168,16 @@ namespace MoonWorks.Graphics
return typeof(GraphicsDevice).Assembly.GetManifestResourceStream(name); 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) protected virtual void Dispose(bool disposing)
{ {
if (!IsDisposed) if (!IsDisposed)