Class VulkanRenderModuleSwapChain

java.lang.Object
io.codetoil.curved_spacetime.render.vulkan.VulkanRenderModuleSwapChain

public class VulkanRenderModuleSwapChain extends Object
The swap chain: the queue of images the GPU renders into and the surface presents.

Its configuration is negotiated rather than chosen. The image count, extent, and pixel format are all clamped to what the surface reports it can do, so the requested values are treated as preferences. Present mode follows the vsync setting: FIFO waits for the display's refresh, immediate does not.

A swap chain is tied to the surface's dimensions, so resizing a window invalidates it and it must be rebuilt.

  • Field Details

    • vulkanModuleLogicalDevice

      protected final VulkanModuleLogicalDevice vulkanModuleLogicalDevice
      The device this swap chain was created on.
    • vulkanRenderModuleImageViews

      protected final VulkanRenderModuleImageView[] vulkanRenderModuleImageViews
      One view per swap chain image, through which the images are rendered into.
    • vulkanSurfaceFormat

      protected final VulkanRenderModuleSwapChain.VulkanSurfaceFormat vulkanSurfaceFormat
      The pixel format and colour space agreed with the surface.
    • vulkanSwapChainExtent

      protected final org.lwjgl.vulkan.VkExtent2D vulkanSwapChainExtent
      The swap chain images' dimensions, allocated off-heap and freed by cleanup().
    • vkSwapChain

      protected final long vkSwapChain
      The underlying Vulkan swap chain handle.
    • logger

      protected final Logger logger
      The logger this swap chain writes its diagnostics to.
    • currentFrame

      protected int currentFrame
      Which image in the chain is currently being drawn.
  • Constructor Details

    • VulkanRenderModuleSwapChain

      public VulkanRenderModuleSwapChain(VulkanModuleLogicalDevice vulkanModuleLogicalDevice, VulkanRenderModuleSurface surface, RenderModuleWindow renderModuleWindow, int requestedImages, boolean vsync, Logger logger)
      Creates a swap chain against the given surface.

      The requested image count is clamped to the surface's supported range, and the extent to its supported bounds, so the resulting swap chain may differ from what was asked for.

      Parameters:
      vulkanModuleLogicalDevice - the device to create the swap chain on
      surface - the surface to present to
      renderModuleWindow - the window supplying the fallback extent
      requestedImages - how many images are wanted, subject to surface limits
      vsync - whether to wait for the display's refresh when presenting
      logger - the logger to write swap chain diagnostics to
      Throws:
      AssertionError - if the swap chain or its image views cannot be created
  • Method Details

    • cleanup

      public void cleanup()
      Destroys the image views and the swap chain, and frees the extent.
    • getVulkanSurfaceFormat

      public VulkanRenderModuleSwapChain.VulkanSurfaceFormat getVulkanSurfaceFormat()
      Returns the pixel format and colour space this swap chain presents in.
      Returns:
      the negotiated surface format
    • getVulkanLogicalDevice

      public VulkanModuleLogicalDevice getVulkanLogicalDevice()
      Returns the device this swap chain was created on.
      Returns:
      the owning logical device
    • getCurrentFrame

      public int getCurrentFrame()
      Returns which image in the chain is currently being drawn.
      Returns:
      the current frame index
    • getVulkanSwapChainExtent

      public org.lwjgl.vulkan.VkExtent2D getVulkanSwapChainExtent()
      Returns the swap chain images' dimensions.
      Returns:
      the extent, owned by this object and freed by cleanup()
    • getVulkanImageViews

      public VulkanRenderModuleImageView[] getVulkanImageViews()
      Returns the views through which the swap chain images are rendered into.
      Returns:
      one image view per swap chain image, owned by this object