swapchain API revision
							parent
							
								
									1a07a71745
								
							
						
					
					
						commit
						d6e0feeecf
					
				|  | @ -1 +1 @@ | |||
| Subproject commit eaed76f4dcc60022b3f10997fb34eb8ead9ae7d7 | ||||
| Subproject commit 7c31601ab48ca0ccf3f475193643ca5f652bd509 | ||||
|  | @ -13,15 +13,18 @@ namespace MoonWorks.Graphics | |||
| 		public IntPtr Handle { get; } | ||||
| 
 | ||||
| 		// some state for debug validation | ||||
| 		GraphicsPipeline currentGraphicsPipeline = null; | ||||
| 		ComputePipeline currentComputePipeline = null; | ||||
| 		bool renderPassActive = false; | ||||
| 		GraphicsPipeline currentGraphicsPipeline; | ||||
| 		ComputePipeline currentComputePipeline; | ||||
| 		bool renderPassActive; | ||||
| 
 | ||||
| 		// called from RefreshDevice | ||||
| 		internal CommandBuffer(GraphicsDevice device, IntPtr handle) | ||||
| 		{ | ||||
| 			Device = device; | ||||
| 			Handle = handle; | ||||
| 			currentGraphicsPipeline = null; | ||||
| 			currentComputePipeline = null; | ||||
| 			renderPassActive = false; | ||||
| 		} | ||||
| 
 | ||||
| 		// FIXME: we can probably use the NativeMemory functions to not have to generate arrays here | ||||
|  | @ -815,7 +818,7 @@ namespace MoonWorks.Graphics | |||
| 			return new Texture( | ||||
| 				Device, | ||||
| 				texturePtr, | ||||
| 				Device.GetSwapchainFormat(window), | ||||
| 				window.SwapchainFormat, | ||||
| 				width, | ||||
| 				height | ||||
| 			); | ||||
|  |  | |||
|  | @ -10,6 +10,9 @@ namespace MoonWorks.Graphics | |||
| 		public IntPtr Handle { get; } | ||||
| 		public Backend Backend { get; } | ||||
| 
 | ||||
| 		private uint windowFlags; | ||||
| 		public SDL2.SDL.SDL_WindowFlags WindowFlags => (SDL2.SDL.SDL_WindowFlags) windowFlags; | ||||
| 
 | ||||
| 		// Built-in video pipeline | ||||
| 		private ShaderModule VideoVertexShader { get; } | ||||
| 		private ShaderModule VideoFragmentShader { get; } | ||||
|  | @ -20,22 +23,13 @@ namespace MoonWorks.Graphics | |||
| 		private readonly List<WeakReference<GraphicsResource>> resources = new List<WeakReference<GraphicsResource>>(); | ||||
| 
 | ||||
| 		public GraphicsDevice( | ||||
| 			IntPtr deviceWindowHandle, | ||||
| 			Backend preferredBackend, | ||||
| 			Refresh.PresentMode presentMode, | ||||
| 			bool debugMode | ||||
| 		) | ||||
| 		{ | ||||
| 			Backend = (Backend) Refresh.Refresh_SelectBackend((Refresh.Backend) preferredBackend, out uint flags); | ||||
| 
 | ||||
| 			var presentationParameters = new Refresh.PresentationParameters | ||||
| 			{ | ||||
| 				deviceWindowHandle = deviceWindowHandle, | ||||
| 				presentMode = presentMode | ||||
| 			}; | ||||
| 			Backend = (Backend) Refresh.Refresh_SelectBackend((Refresh.Backend) preferredBackend, out windowFlags); | ||||
| 
 | ||||
| 			Handle = Refresh.Refresh_CreateDevice( | ||||
| 				presentationParameters, | ||||
| 				Conversions.BoolToByte(debugMode) | ||||
| 			); | ||||
| 
 | ||||
|  | @ -60,6 +54,43 @@ namespace MoonWorks.Graphics | |||
| 			); | ||||
| 		} | ||||
| 
 | ||||
| 		public bool ClaimWindow(Window window, PresentMode presentMode) | ||||
| 		{ | ||||
| 			var success = Conversions.ByteToBool( | ||||
| 				Refresh.Refresh_ClaimWindow( | ||||
| 					Handle, | ||||
| 					window.Handle, | ||||
| 					(Refresh.PresentMode) presentMode | ||||
| 				) | ||||
| 			); | ||||
| 
 | ||||
| 			if (success) | ||||
| 			{ | ||||
| 				window.Claimed = true; | ||||
| 				window.SwapchainFormat = GetSwapchainFormat(window); | ||||
| 			} | ||||
| 
 | ||||
| 			return success; | ||||
| 		} | ||||
| 
 | ||||
| 		public void UnclaimWindow(Window window) | ||||
| 		{ | ||||
| 			Refresh.Refresh_UnclaimWindow( | ||||
| 				Handle, | ||||
| 				window.Handle | ||||
| 			); | ||||
| 			window.Claimed = false; | ||||
| 		} | ||||
| 
 | ||||
| 		public void SetPresentMode(Window window, PresentMode presentMode) | ||||
| 		{ | ||||
| 			Refresh.Refresh_SetSwapchainPresentMode( | ||||
| 				Handle, | ||||
| 				window.Handle, | ||||
| 				(Refresh.PresentMode) presentMode | ||||
| 			); | ||||
| 		} | ||||
| 
 | ||||
| 		public CommandBuffer AcquireCommandBuffer() | ||||
| 		{ | ||||
| 			return new CommandBuffer(this, Refresh.Refresh_AcquireCommandBuffer(Handle, 0)); | ||||
|  | @ -86,7 +117,7 @@ namespace MoonWorks.Graphics | |||
| 			Refresh.Refresh_Wait(Handle); | ||||
| 		} | ||||
| 
 | ||||
| 		public TextureFormat GetSwapchainFormat(Window window) | ||||
| 		private TextureFormat GetSwapchainFormat(Window window) | ||||
| 		{ | ||||
| 			return (TextureFormat) Refresh.Refresh_GetSwapchainFormat(Handle, window.Handle); | ||||
| 		} | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using SDL2; | ||||
| 
 | ||||
| namespace MoonWorks | ||||
|  | @ -10,29 +11,32 @@ namespace MoonWorks | |||
| 		public uint Width { get; private set; } | ||||
| 		public uint Height { get; private set; } | ||||
| 
 | ||||
| 		public bool Claimed { get; internal set; } | ||||
| 		public MoonWorks.Graphics.TextureFormat SwapchainFormat { get; internal set; } | ||||
| 
 | ||||
| 		private bool IsDisposed; | ||||
| 
 | ||||
| 		public Window(WindowCreateInfo windowCreateInfo) | ||||
| 		{ | ||||
| 			var windowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN; | ||||
| 		private static Dictionary<uint, Window> idLookup = new Dictionary<uint, Window>(); | ||||
| 
 | ||||
| 		public Window(WindowCreateInfo windowCreateInfo, SDL.SDL_WindowFlags flags) | ||||
| 		{ | ||||
| 			if (windowCreateInfo.ScreenMode == ScreenMode.Fullscreen) | ||||
| 			{ | ||||
| 				windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN; | ||||
| 				flags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN; | ||||
| 			} | ||||
| 			else if (windowCreateInfo.ScreenMode == ScreenMode.BorderlessWindow) | ||||
| 			{ | ||||
| 				windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP; | ||||
| 				flags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP; | ||||
| 			} | ||||
| 
 | ||||
| 			if (windowCreateInfo.SystemResizable) | ||||
| 			{ | ||||
| 				windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE; | ||||
| 				flags |= SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE; | ||||
| 			} | ||||
| 
 | ||||
| 			if (windowCreateInfo.StartMaximized) | ||||
| 			{ | ||||
| 				windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_MAXIMIZED; | ||||
| 				flags |= SDL.SDL_WindowFlags.SDL_WINDOW_MAXIMIZED; | ||||
| 			} | ||||
| 
 | ||||
| 			ScreenMode = windowCreateInfo.ScreenMode; | ||||
|  | @ -43,11 +47,13 @@ namespace MoonWorks | |||
| 				SDL.SDL_WINDOWPOS_UNDEFINED, | ||||
| 				(int) windowCreateInfo.WindowWidth, | ||||
| 				(int) windowCreateInfo.WindowHeight, | ||||
| 				windowFlags | ||||
| 				flags | ||||
| 			); | ||||
| 
 | ||||
| 			Width = windowCreateInfo.WindowWidth; | ||||
| 			Height = windowCreateInfo.WindowHeight; | ||||
| 
 | ||||
| 			idLookup.Add(SDL.SDL_GetWindowID(Handle), this); | ||||
| 		} | ||||
| 
 | ||||
| 		public void ChangeScreenMode(ScreenMode screenMode) | ||||
|  | @ -81,6 +87,11 @@ namespace MoonWorks | |||
| 			Height = height; | ||||
| 		} | ||||
| 
 | ||||
| 		internal static Window Lookup(uint windowID) | ||||
| 		{ | ||||
| 			return idLookup.ContainsKey(windowID) ? idLookup[windowID] : null; | ||||
| 		} | ||||
| 
 | ||||
| 		internal void SizeChanged(uint width, uint height) | ||||
| 		{ | ||||
| 			Width = width; | ||||
|  | @ -96,6 +107,7 @@ namespace MoonWorks | |||
| 					// dispose managed state (managed objects) | ||||
| 				} | ||||
| 
 | ||||
| 				idLookup.Remove(SDL.SDL_GetWindowID(Handle)); | ||||
| 				SDL.SDL_DestroyWindow(Handle); | ||||
| 
 | ||||
| 				IsDisposed = true; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue