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"

Go to the source code of this file.

Functions

void vulkan_image_create (vulkan_context *context, texture_type type, u32 width, u32 height, 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_view_create (vulkan_context *context, texture_type type, VkFormat format, vulkan_image *image, VkImageAspectFlags aspect_flags)
 Creates a view for the given image. More...
 
void vulkan_image_transition_layout (vulkan_context *context, texture_type type, 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, texture_type type, 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, texture_type type, 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_pixel_to_buffer (vulkan_context *context, texture_type type, vulkan_image *image, VkBuffer buffer, u32 x, u32 y, vulkan_command_buffer *command_buffer)
 Copies a single pixel's data from the given image to the provided buffer. More...
 
void vulkan_image_destroy (vulkan_context *context, vulkan_image *image)
 Destroys the given image. 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,
texture_type  type,
vulkan_image image,
VkBuffer  buffer,
u64  offset,
vulkan_command_buffer command_buffer 
)

Copies data in buffer to provided image.

Parameters
contextThe Vulkan context.
typeThe type of texture. Provides hints to creation.
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_pixel_to_buffer()

void vulkan_image_copy_pixel_to_buffer ( vulkan_context context,
texture_type  type,
vulkan_image image,
VkBuffer  buffer,
u32  x,
u32  y,
vulkan_command_buffer command_buffer 
)

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

Parameters
contextThe Vulkan context.
typeThe type of texture. Provides hints to layer count.
imageThe image to copy the image's data from.
bufferThe buffer to copy to.
xThe x-coordinate of the pixel to copy.
yThe y-coordinate of the pixel 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,
texture_type  type,
vulkan_image image,
VkBuffer  buffer,
vulkan_command_buffer command_buffer 
)

Copies data in the provided image to the given buffer.

Parameters
contextThe Vulkan context.
typeThe type of texture. Provides hints to layer count.
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,
texture_type  type,
u32  width,
u32  height,
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_transition_layout()

void vulkan_image_transition_layout ( vulkan_context context,
texture_type  type,
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.
typeThe type of texture. Provides hints to creation.
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.

◆ vulkan_image_view_create()

void vulkan_image_view_create ( vulkan_context context,
texture_type  type,
VkFormat  format,
vulkan_image image,
VkImageAspectFlags  aspect_flags 
)

Creates a view for the given image.

Parameters
contextA pointer to the Vulkan context.
typeThe type of texture. Provides hints to creation.
formatThe image format.
imageA pointer to the image to associate the view with.
aspect_flagsAspect flags to be used when creating the view, if applicable.