Kohi Game Engine
vulkan_image.h File Reference

The implementation of the Vulkan image, which can be thought of as a texture. More...

#include "vulkan_types.h"
#include <vulkan/vulkan_core.h>

Go to the source code of this file.

Functions

void vulkan_image_create (vulkan_context *context, ktexture_type type, u32 width, u32 height, u16 layer_count, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags memory_flags, b32 create_view, VkImageAspectFlags view_aspect_flags, const char *name, u32 mip_levels, vulkan_image *out_image)
 Creates a new Vulkan image. More...
 
void vulkan_image_destroy (vulkan_context *context, vulkan_image *image)
 Destroys the given image. More...
 
void vulkan_image_recreate (vulkan_context *context, vulkan_image *image)
 Destroys and recrates internal image and view resources based on current create infos which are cached on the provided image. If changing properties (i.e. resizing), modify those create infos first. More...
 
void vulkan_image_transition_layout (vulkan_context *context, vulkan_command_buffer *command_buffer, vulkan_image *image, VkFormat format, VkImageLayout old_layout, VkImageLayout new_layout)
 Transitions the provided image from old_layout to new_layout. More...
 
b8 vulkan_image_mipmaps_generate (vulkan_context *context, vulkan_image *image, vulkan_command_buffer *command_buffer)
 Generates mipmaps for the given image based on mip_levels set in the image. mip_levels must be > 1 for this to succeed. More...
 
void vulkan_image_copy_from_buffer (vulkan_context *context, vulkan_image *image, VkBuffer buffer, u64 offset, vulkan_command_buffer *command_buffer)
 Copies data in buffer to provided image. More...
 
void vulkan_image_copy_to_buffer (vulkan_context *context, vulkan_image *image, VkBuffer buffer, vulkan_command_buffer *command_buffer)
 Copies data in the provided image to the given buffer. More...
 
void vulkan_image_copy_region_to_buffer (vulkan_context *context, vulkan_image *image, VkBuffer buffer, u32 x, u32 y, u32 width, u32 height, vulkan_command_buffer *command_buffer)
 Copies a single pixel's data from the given image to the provided buffer. More...
 

Detailed Description

The implementation of the Vulkan image, which can be thought of as a texture.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
1.0
Date
2022-01-11

Function Documentation

◆ vulkan_image_copy_from_buffer()

void vulkan_image_copy_from_buffer ( vulkan_context context,
vulkan_image image,
VkBuffer  buffer,
u64  offset,
vulkan_command_buffer command_buffer 
)

Copies data in buffer to provided image.

Parameters
contextThe Vulkan context.
imageThe image to copy the buffer's data to.
bufferThe buffer whose data will be copied.
offsetThe offset in bytes from the beginning of the buffer.
command_bufferA pointer to the command buffer to be used for this operation.

◆ vulkan_image_copy_region_to_buffer()

void vulkan_image_copy_region_to_buffer ( vulkan_context context,
vulkan_image image,
VkBuffer  buffer,
u32  x,
u32  y,
u32  width,
u32  height,
vulkan_command_buffer command_buffer 
)

Copies a single pixel's data from the given image to the provided buffer.

Parameters
contextThe Vulkan context.
imageThe image to copy the image's data from.
bufferThe buffer to copy to.
xThe x-coordinate start of the pixel region to copy.
yThe y-coordinate start of the pixel region to copy.
widthThe width in pixels of the region to copy.
heightThe height in pixels of the region to copy.
command_bufferThe command buffer to be used for the copy.

◆ vulkan_image_copy_to_buffer()

void vulkan_image_copy_to_buffer ( vulkan_context context,
vulkan_image image,
VkBuffer  buffer,
vulkan_command_buffer command_buffer 
)

Copies data in the provided image to the given buffer.

Parameters
contextThe Vulkan context.
imageThe image to copy the image's data from.
bufferThe buffer to copy to.
command_bufferThe command buffer to be used for the copy.

◆ vulkan_image_create()

void vulkan_image_create ( vulkan_context context,
ktexture_type  type,
u32  width,
u32  height,
u16  layer_count,
VkFormat  format,
VkImageTiling  tiling,
VkImageUsageFlags  usage,
VkMemoryPropertyFlags  memory_flags,
b32  create_view,
VkImageAspectFlags  view_aspect_flags,
const char *  name,
u32  mip_levels,
vulkan_image out_image 
)

Creates a new Vulkan image.

Parameters
contextA pointer to the Vulkan context.
typeThe type of texture. Provides hints to creation.
widthThe width of the image. For cubemaps, this is for each side of the cube.
heightThe height of the image. For cubemaps, this is for each side of the cube.
formatThe format of the image.
tilingThe image tiling mode.
usageThe image usage.
memory_flagsMemory flags for the memory used by the image.
create_viewIndicates if a view should be created with the image.
view_aspect_flagsAspect flags to be used when creating the view, if applicable.
nameA name for the image.
mip_levelsThe number of mip map levels to use. Default is 1.
out_imageA pointer to hold the newly-created image.

◆ vulkan_image_destroy()

void vulkan_image_destroy ( vulkan_context context,
vulkan_image image 
)

Destroys the given image.

Parameters
contextA pointer to the Vulkan context.
imageA pointer to the image to be destroyed.

◆ vulkan_image_mipmaps_generate()

b8 vulkan_image_mipmaps_generate ( vulkan_context context,
vulkan_image image,
vulkan_command_buffer command_buffer 
)

Generates mipmaps for the given image based on mip_levels set in the image. mip_levels must be > 1 for this to succeed.

Parameters
contextA pointer to the Vulkan context.
imageA pointer to the image to generate mips for.
command_bufferA pointer to the command buffer to be used for this operation.
Returns
True on success; otherwise false.

◆ vulkan_image_recreate()

void vulkan_image_recreate ( vulkan_context context,
vulkan_image image 
)

Destroys and recrates internal image and view resources based on current create infos which are cached on the provided image. If changing properties (i.e. resizing), modify those create infos first.

Parameters
contextA pointer to the Vulkan context.
imageA pointer to the image to be recreated.

◆ vulkan_image_transition_layout()

void vulkan_image_transition_layout ( vulkan_context context,
vulkan_command_buffer command_buffer,
vulkan_image image,
VkFormat  format,
VkImageLayout  old_layout,
VkImageLayout  new_layout 
)

Transitions the provided image from old_layout to new_layout.

Parameters
contextA pointer to the Vulkan context.
command_bufferA pointer to the command buffer to be used.
imageA pointer to the image whose layout will be transitioned.
formatThe image format.
old_layoutThe old layout.
new_layoutThe new layout.