SwapChainSupportDetails QuerySwapChainSupport(PhysicalDevice device) { return(new SwapChainSupportDetails { Capabilities = device.GetSurfaceCapabilities(this.surface), Formats = device.GetSurfaceFormats(this.surface), PresentModes = device.GetSurfacePresentModes(this.surface) }); }
protected virtual void CreateSwapchain() { // surface format var surfaceFormats = physicalDevice.GetSurfaceFormats(surface); if (surfaceFormats.Length == 1 && surfaceFormats[0].Format == Format.Undefined) { backBufferFormat = Format.B8G8R8A8UNorm; } else { backBufferFormat = surfaceFormats[0].Format; } SurfaceCapabilities surfaceCapabilities; physicalDevice.GetSurfaceCapabilities(surface, out surfaceCapabilities); // Buffer count uint desiredImageCount = surfaceCapabilities.MinImageCount + 1; if (surfaceCapabilities.MaxImageCount > 0 && desiredImageCount > surfaceCapabilities.MaxImageCount) { desiredImageCount = surfaceCapabilities.MaxImageCount; } // Transform SurfaceTransformFlags preTransform; if ((surfaceCapabilities.SupportedTransforms & SurfaceTransformFlags.Identity) != 0) { preTransform = SurfaceTransformFlags.Identity; } else { preTransform = surfaceCapabilities.CurrentTransform; } // Present mode var presentModes = physicalDevice.GetSurfacePresentModes(surface); var swapChainPresentMode = PresentMode.Fifo; if (presentModes.Contains(PresentMode.Mailbox)) { swapChainPresentMode = PresentMode.Mailbox; } else if (presentModes.Contains(PresentMode.Immediate)) { swapChainPresentMode = PresentMode.Immediate; } // Create swapchain var swapchainCreateInfo = new SwapchainCreateInfo { StructureType = StructureType.SwapchainCreateInfo, Surface = surface, ImageSharingMode = SharingMode.Exclusive, ImageExtent = new Extent2D((uint)form.ClientSize.Width, (uint)form.ClientSize.Height), ImageArrayLayers = 1, ImageFormat = backBufferFormat, ImageColorSpace = ColorSpace.SRgbNonlinear, ImageUsage = ImageUsageFlags.ColorAttachment, PresentMode = swapChainPresentMode, CompositeAlpha = CompositeAlphaFlags.Opaque, MinImageCount = desiredImageCount, PreTransform = preTransform, Clipped = true // OldSwapchain = }; swapchain = device.CreateSwapchain(ref swapchainCreateInfo); // Initialize swapchain image layout backBuffers = device.GetSwapchainImages(swapchain); foreach (var image in backBuffers) { SetImageLayout(image, ImageAspectFlags.Color, ImageLayout.Undefined, ImageLayout.PresentSource); } Flush(); }