Example #1
0
        /// <summary>
        /// Create a new managed `SwapChain` object. Native object will only be created with a call to the 'Create` method.
        /// </summary>
        /// <param name="_presentableQueue">Presentable queue.</param>
        /// <param name="width">Swapchain x dimension.</param>
        /// <param name="height">Swapchain y dimension.</param>
        /// <param name="format">Swapchain's images format.</param>
        /// <param name="presentMode">a present mode supported by the engine as returned by the `GetSurfacePresentModes` method of the `PhysicalDevice`</param>
        public SwapChain(PresentQueue _presentableQueue, uint width = 800, uint height = 600, VkFormat format = VkFormat.B8g8r8a8Unorm,
                         VkPresentModeKHR presentMode = VkPresentModeKHR.FifoKHR)
            : base(_presentableQueue.dev)
        {
            presentQueue = _presentableQueue;
            createInfos  = VkSwapchainCreateInfoKHR.New();

            VkSurfaceFormatKHR[] formats = Dev.phy.GetSurfaceFormats(presentQueue.Surface);
            for (int i = 0; i < formats.Length; i++)
            {
                if (formats[i].format == format)
                {
                    createInfos.imageFormat     = format;
                    createInfos.imageColorSpace = formats[i].colorSpace;
                    break;
                }
            }
            if (createInfos.imageFormat == VkFormat.Undefined)
            {
                throw new Exception("Invalid format for swapchain: " + format);
            }

            VkPresentModeKHR[] presentModes = Dev.phy.GetSurfacePresentModes(presentQueue.Surface);
            for (int i = 0; i < presentModes.Length; i++)
            {
                if (presentModes[i] == presentMode)
                {
                    createInfos.presentMode = presentMode;
                    break;
                }
            }
            if (createInfos.presentMode != presentMode)
            {
                throw new Exception("Invalid presentMode for swapchain: " + presentMode);
            }

            createInfos.surface          = presentQueue.Surface;
            createInfos.imageExtent      = new VkExtent2D(width, height);
            createInfos.imageArrayLayers = 1;
            createInfos.imageUsage       = IMAGES_USAGE;
            createInfos.imageSharingMode = VkSharingMode.Exclusive;
            createInfos.compositeAlpha   = VkCompositeAlphaFlagsKHR.OpaqueKHR;
            createInfos.presentMode      = presentMode;
            createInfos.clipped          = 1;
        }
Example #2
0
 /// <summary>
 /// Override this method to create additional queue. Dedicated queue of the requested type will be selected first, created queues may excess
 /// available physical queues.
 /// </summary>
 protected virtual void createQueues()
 {
     presentQueue = new PresentQueue(dev, VkQueueFlags.Graphics, hSurf);
 }