Add support for custom Video shaders #28
			
				
			
		
		
		
	|  | @ -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) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue