Internals: Graphics Interface

Drawing Sprites / Shapes

void TS_VkBeginDrawPass()

start the drawing pass

void TS_VkDraw(float r, float g, float b, float alpha)

fill the render area with a color

Parameters
  • r – red component of the color

  • g – green component of the color

  • b – blue component of the color

  • alpha – transparency component of the color

void TS_VkEndDrawPass(float r, float g, float b, float alpha)

finish the drawing pass by rendering a solid color

Parameters
  • r – red component of the color (in RGBA)

  • g – green component of the color (in RGBA)

  • b – blue component of the color (in RGBA)

  • alpha – transparency component of the color (in RGBA)

void TS_VkAcquireNextImage()

acquire next vulkan image

void TS_VkCmdDrawRect(float r, float g, float b, float alpha, float x, float y, float width, float height)

draw a rectangle

Parameters
  • r – red component of the color (in RGBA)

  • g – green component of the color (in RGBA)

  • b – blue component of the color (in RGBA)

  • alpha – transparency component of the color (in RGBA)

  • x – x-position of the upper left corner of the rectangle

  • y – y-position of the upper left corner of the rectangle

  • width – size along the x-dimension

  • height – size along the y-dimension

void TS_VkCmdDrawSprite(const char *image_path, float r, float g, float b, float alpha, int region_x, int region_y, int region_width, int region_height, int cell_w, int cell_h, int cell_index_i, int cell_index_j, float position_x, float position_y, float scale_x, float scale_y)

draw a sprite

Parameters
  • image_path – path to image on disk

  • r – red component of the color (in RGBA)

  • g – green component of the color (in RGBA)

  • b – blue component of the color (in RGBA)

  • alpha – transparency component of the color (in RGBA)

  • region_x – x-coordinate of the top left corner of the subregion

  • region_y – y-coordinate of the top left corner of the subregion

  • region_width – size of the subregion along the x-dimension

  • region_height – size of the subregion along the x-dimension

  • cell_w – width of each cell of the grid

  • cell_h – height of each cell of the grid

  • cell_index_i – x-index of the cell

  • cell_index_j – y-index of the cell

  • position_x – x-coordinate of the top left corner of the sprite

  • position_y – y-coordinate of the top left corner of the sprite

  • scale_x – scale along the x-dimension

  • scale_y – scale along the y-dimension

void TS_VkCmdClearColorImage(float r, float g, float b, float alpha)

clear the render window with a color

clear an image with a color

Parameters
  • r – red component of the color (in RGBA)

  • g – green component of the color (in RGBA)

  • b – blue component of the color (in RGBA)

  • alpha – transparency component of the color (in RGBA)


Images / Textures

struct TS_Texture

Public Members

std::pair<vk::Image, vma::Allocation> img

image

vk::ImageView view

current view

uint32_t width

size along x-dimension

uint32_t height

size along y-dimension

std::string fname

file name

int TS_VkLoadTexture(const char *img)

load texture

Parameters

img – path to image on disk

void TS_VkUnloadTexture(const char *img)

unload texture

Parameters

img – texture path

std::pair<vk::Image, vma::Allocation> TS_VmaCreateImage(uint32_t width, uint32_t height, vk::Format fmt, vk::ImageTiling tiling, vk::Flags<vk::ImageUsageFlagBits> usage, vk::Flags<vk::MemoryPropertyFlagBits> properties, vma::AllocationCreateFlags allocFlags = vma::AllocationCreateFlags())

create a vma image

Parameters
  • width – size along x-dimension

  • height – size along y-dimension

  • fmt – vulkan format

  • tiling – vulkan image tiling

  • usage – vulkan image usage flags

  • properties – vulkan memory properties

  • allocFlags – [optional] vma allocation flags

Returns

pair where .first is the vulkan buffer, .second is the vma::Allcation object

void TS_VkCopyBufferToImage(vk::Buffer buf, vk::Image img, uint32_t wdth, uint32_t hght)

copy vulkan buffer to image

Parameters
  • buf – buffer

  • img – image

  • wdth – width of the TODO: buffer or image?

  • hght – height of the TODO: buffer or image?

void TS_VkTransitionImageLayout(vk::Image img, vk::ImageLayout oldLayout, vk::ImageLayout newLayout)

transition the layout of an image

Parameters
  • img – image

  • oldLayout – previous layout

  • newLayout – new layout


Initializing the State

To initialize the render state, use:

void TS_VkInit()

initialize the vulkan state

which, internally, calls the following functions:

vk::ImageView TS_VkCreateImageView(vk::Image img, vk::Format fmt, vk::ImageAspectFlagBits flags)

create vulkan image view

Parameters
  • img – vulkan image

  • fmt – vulkan format

  • flags – image aspect flags

Returns

created image view

std::pair<vk::Buffer, vma::Allocation> TS_VmaCreateBuffer(vk::DeviceSize size, vk::Flags<vk::BufferUsageFlagBits> usage, vk::Flags<vk::MemoryPropertyFlagBits> properties, vma::AllocationCreateFlags allocFlags = vma::AllocationCreateFlags())

create a vma buffer

Parameters
  • size – vulkan device size

  • usage – vulkan buffer usage flags

  • properties – vulkan memory properties

  • allocFlags – [optional] allocation flags

Returns

pair where .first is the vulkan buffer, .second is the vma::Allcation object

std::pair<vk::Image, vma::Allocation> TS_VmaCreateImage(uint32_t width, uint32_t height, vk::Format fmt, vk::ImageTiling tiling, vk::Flags<vk::ImageUsageFlagBits> usage, vk::Flags<vk::MemoryPropertyFlagBits> properties, vma::AllocationCreateFlags allocFlags = vma::AllocationCreateFlags())

create a vma image

Parameters
  • width – size along x-dimension

  • height – size along y-dimension

  • fmt – vulkan format

  • tiling – vulkan image tiling

  • usage – vulkan image usage flags

  • properties – vulkan memory properties

  • allocFlags – [optional] vma allocation flags

Returns

pair where .first is the vulkan buffer, .second is the vma::Allcation object

void TS_VkCreateInstance()

create vulkan instance

void TS_VkCreateSurface()

create vulkan surface

void TS_VkCreateDevice()

created device

void TS_VmaCreateAllocator()

create the vma allocator object

void TS_VmaCreateBuffers()

create the vma buffers

void TS_VkCreateSwapchain()

create the vulkan swapchain

void TS_VkCreateImageViews()

create the vulkan image views

void TS_VkCreateRenderPass()

create the vulkan render pass

void TS_VkSetupDepthStencil()

setup the vulkan depth stencil

vk::ShaderModule TS_VkCreateShaderModule(std::string code, shaderc_shader_kind kind, bool optimize = false)

initialize the vulkan shader module

void TS_VkCreateDescriptorSet()

create the vulkan descriptor set

void TS_VkCreateTrianglePipeline()

create the vulkan triangle pipeline

void TS_VkCreateFramebuffers()

create the vulkan framebuffer

void TS_VkCreateCommandPool()

create the vulkan command pool

void TS_VkAllocateCommandBuffers()

allocate the vulkan command buffer

void TS_VkCreateSemaphores()

create the vulkan semaphores

void TS_VkCreateFences()

create the vulkan fences

void TS_VkPopulateDebugMessengerCreateInfo(vk::DebugUtilsMessengerCreateInfoEXT &dbmci)

set the vulkan debug messenger

Parameters

dbmci – debug messenger create info


Shutting down the State

To shut down the render state, use:

void TS_VkQuit()

quit the vulkan state

which internally calls the following functions:

void TS_VkDestroyFences()

deallocate the vulkan fences

void TS_VkDestroySemaphores()

deallocate the vulkan semaphores

void TS_VkFreeCommandBuffers()

free the vulkan command buffers

void TS_VkDestroyCommandPool()

destroy the vulkan command pool

void TS_VkDestroyFramebuffers()

destroy the vulkan framebuffers

void TS_VkDestroyTrianglePipeline()

destroy the vulkan triangle pipeline

void TS_VkDestroyDescriptorSet()

destroy the vulkan descriptor set

void TS_VkDestroyRenderPass()

destroy the vulkan render pass

void TS_VkTeardownDepthStencil()

destroy the vulkan depth stencil

void TS_VkDestroyImageViews()

destroy the vulkan image view

void TS_VkDestroySwapchain()

destroy the vulkan swap chain

void TS_VkDestroySemaphores()

deallocate the vulkan semaphores

void TS_VmaDestroyBuffers()

destroy the vma buffer

void TS_VkDestroyTextures()

deallocate all vulkan textures

void TS_VmaDestroyAllocator()

destroy the vulkan allocator

void TS_VkDestroyDevice()

destroy the vulkan device

void TS_VkDestroySurface()

destroy the vulkan surface

void TS_VkDestroyDebugMessenger()

destroy the vulkan debug messenger

void TS_VkDestroyInstance()

destroy the vulkan instance


Selecting the Physical Device

void TS_VkSelectPhysicalDevice()

select the physical device


Check Supported Depth Format

vk::Bool32 TS_VkGetSupportedDepthFormat()

get vulkan supported depth format

Returns

true if format supported, false otherwise


Scratch Buffer

vk::CommandBuffer TS_VkBeginScratchBuffer()

begin vulkan scratch buffer

Returns

vulkan command buffer

void TS_VkSubmitScratchBuffer(vk::CommandBuffer &tmp)

submit vulkan scratch buffer

Parameters

tmp – command buffer


Scratch Buffer

void TS_VkResetCommandBuffer()

reset the vulkan command buffer

void TS_VkBeginCommandBuffer()

begin the vulkan command buffer


Vulkan Queues

void TS_VkQueueSubmit()

queue vulkan submit info

void TS_VkQueuePresent()

queue vulkan present

void TS_VkSelectQueueFamily()

select vulkan queue family