Class: Vulkan::Swapchain

Inherits:
Object
  • Object
show all
Includes:
Checks, Conversions, Finalizer
Defined in:
lib/vulkan/swapchain.rb

Constant Summary

Constants included from Conversions

Conversions::ACCESS_MASK_BITS, Conversions::BORDER_COLORS, Conversions::BUFFER_USAGE_BITS, Conversions::COMPARE_OPS, Conversions::DEPENDENCY_FLAG_BITS, Conversions::DESCRIPTOR_TYPES, Conversions::DYNAMIC_STATES, Conversions::FILTERS, Conversions::FORMAT_FEATURE_BITS, Conversions::IMAGE_ASPECT_BITS, Conversions::IMAGE_CREATE_BITS, Conversions::IMAGE_FORMATS, Conversions::IMAGE_TILING, Conversions::IMAGE_TYPES, Conversions::IMAGE_USAGE_BITS, Conversions::MEMORY_PROPERTIES, Conversions::PIPELINE_STAGE_BITS, Conversions::PRESENT_MODES, Conversions::SAMPLER_ADDRESS_MODES, Conversions::SAMPLER_MIPMAP_MODES, Conversions::SHADER_STAGE_BITS, Conversions::SHARING_MODES, Conversions::SURFACE_TRANSFORMS, Conversions::VERTEX_INPUT_RATES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Finalizer

#finalize_with, #hexaddr, included, #to_ptr

Methods included from Conversions

#array_of_pointers, #array_of_structures, #array_of_uint32s, #bool_to_vk, #buffer_usage_flags_to_syms, #const_to_symbol, #cstr_to_rbstr, #flags_to_symbols, #flags_to_syms, #num_to_samples, #present_mode_to_sym, #queue_family_to_index, #struct_to_hash, #sym_to_blend_factor, #sym_to_blend_op, #sym_to_border_color, #sym_to_color_component_bit, #sym_to_command_buffer_level, #sym_to_command_buffer_usage, #sym_to_compare_op, #sym_to_cull_mode, #sym_to_descriptor_type, #sym_to_dynamic_state, #sym_to_filter, #sym_to_front_face, #sym_to_image_format, #sym_to_image_layout, #sym_to_image_tiling, #sym_to_image_type, #sym_to_index_type, #sym_to_load_op, #sym_to_pipeline_bind_point, #sym_to_polygon_mode, #sym_to_present_mode, #sym_to_sampler_address_mode, #sym_to_sampler_mipmap_mode, #sym_to_samples, #sym_to_sharing_mode, #sym_to_store_op, #sym_to_subpass_contents, #sym_to_topology, #sym_to_val, #sym_to_vertex_input_rate, #syms_to_access_mask, #syms_to_buffer_usage_flags, #syms_to_dependency_flags, #syms_to_descriptor_set_layout_type_flags, #syms_to_flags, #syms_to_format_feature_flags, #syms_to_image_aspect_flags, #syms_to_image_create_flags, #syms_to_image_usage_flags, #syms_to_memory_properties, #syms_to_pipeline_stage_flags, #syms_to_shader_stage_flags, #syms_to_surface_transforms, #vk_make_version, #vk_parse_version

Methods included from Checks

#check_result

Constructor Details

#initialize(instance, device, surface:, surface_width:, surface_height:, app_config: {}, builder_class: Vulkan::SwapchainBuilder, image_usage: VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, image_array_layers: 1, sharing_mode: VK_SHARING_MODE_EXCLUSIVE, composite_alpha: VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, clipped: true, old_swapchain: nil) ⇒ Swapchain

Returns a new instance of Swapchain.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vulkan/swapchain.rb', line 12

def initialize(instance, device, surface:,
                                 surface_width:,
                                 surface_height:,
                                 app_config: {},
                                 builder_class: Vulkan::SwapchainBuilder,
                                 image_usage: VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
                                 image_array_layers: 1,
                                 sharing_mode: VK_SHARING_MODE_EXCLUSIVE,
                                 composite_alpha: VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
                                 clipped: true,
                                 old_swapchain: nil)
  @vk = Vulkan[instance, device]

  info = device.physical_device.swapchain_surface_info(surface)
  builder = builder_class.new(info, app_config)
  @extent = { width: builder.width(surface_width), height: builder.height(surface_height) }

  image_format = builder.format
  @format = image_format[:format]
  @color_space = image_format[:color_space]

  create_info = VkSwapchainCreateInfoKHR.malloc
  create_info.sType                 = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR
  create_info.surface               = surface.to_ptr
  create_info.minImageCount         = builder.image_count
  create_info.imageFormat           = @format
  create_info.imageColorSpace       = @color_space
  create_info.imageExtent.width     = @extent[:width]
  create_info.imageExtent.height    = @extent[:height]
  create_info.imageArrayLayers      = image_array_layers
  create_info.imageUsage            = image_usage
  create_info.imageSharingMode      = sharing_mode
  create_info.queueFamilyIndexCount = 0
  create_info.pQueueFamilyIndices   = nil
  create_info.preTransform          = syms_to_surface_transforms(builder.transformation)
  create_info.compositeAlpha        = composite_alpha
  create_info.presentMode           = sym_to_present_mode(builder.presentation_mode)
  create_info.clipped               = clipped ? VK_TRUE : VK_FALSE
  create_info.oldSwapchain          = old_swapchain

  swapchain = Vulkan.create_value("void *", nil)
  check_result @vk.vkCreateSwapchainKHR(device.to_ptr, create_info, nil, swapchain)
  @handle = swapchain.value
  finalize_with @vk, :vkDestroySwapchainKHR, device.to_ptr, @handle, nil

  image_count_p = Vulkan.create_value('uint32_t', 0)
  check_result @vk.vkGetSwapchainImagesKHR(device.to_ptr, @handle, image_count_p, nil)
  images_p = Vulkan.struct("images[#{image_count_p.value}]" => 'void *handle').malloc
  check_result @vk.vkGetSwapchainImagesKHR(device.to_ptr, @handle, image_count_p, images_p);
  @image_views = images_p.images.map { |i| ImageView.new(@vk, i.handle, sym_to_image_format(@format)) }

  @image_index_p = Vulkan.create_value('uint32_t', 0)
end

Instance Attribute Details

#color_spaceObject (readonly)

Returns the value of attribute color_space.



8
9
10
# File 'lib/vulkan/swapchain.rb', line 8

def color_space
  @color_space
end

#extentObject (readonly)

Returns the value of attribute extent.



7
8
9
# File 'lib/vulkan/swapchain.rb', line 7

def extent
  @extent
end

#formatObject (readonly)

Returns the value of attribute format.



9
10
11
# File 'lib/vulkan/swapchain.rb', line 9

def format
  @format
end

#image_viewsObject (readonly)

Returns the value of attribute image_views.



10
11
12
# File 'lib/vulkan/swapchain.rb', line 10

def image_views
  @image_views
end

Instance Method Details

#[](method_name) ⇒ Object



66
67
68
# File 'lib/vulkan/swapchain.rb', line 66

def [](method_name)
  send method_name
end

#heightObject



74
75
76
# File 'lib/vulkan/swapchain.rb', line 74

def height
  @extent[:height]
end

#next_image_index(semaphore: nil, fence: nil, timeout: 0xffffffffffffffff) ⇒ Object



82
83
84
85
# File 'lib/vulkan/swapchain.rb', line 82

def next_image_index(semaphore: nil, fence: nil, timeout: 0xffffffffffffffff)
  @vk.vkAcquireNextImageKHR(@vk.device, to_ptr, timeout, semaphore, fence, @image_index_p)
  @image_index_p.value
end

#sizeObject



78
79
80
# File 'lib/vulkan/swapchain.rb', line 78

def size
  image_views.size
end

#widthObject



70
71
72
# File 'lib/vulkan/swapchain.rb', line 70

def width
  @extent[:width]
end