roleplay/client/include/ui.h

169 lines
3.6 KiB
C

#ifndef PIPELINE_H
#define PIPELINE_H
#include "vulkan/vulkan_core.h"
#include "cglm/types.h"
#include "vk_mem_alloc.h"
#include "command.h"
#include "ft2build.h"
#include FT_FREETYPE_H
typedef struct ComputePipelineStruct {
VkPipelineLayout layout;
VkPipeline pipeline;
} ComputePipeline;
typedef struct GraphicsPipelineStruct {
VkPipelineLayout layout;
VkPipeline pipeline;
} GraphicsPipeline;
typedef struct ColoredRectStruct {
vec3 pos;
uint32_t padding0;
vec2 size;
vec4 color;
} ColoredRect;
typedef struct UIUniformStruct {
mat4 screen;
} UIUniform;
typedef struct StringStruct {
vec3 pos;
uint32_t padding0;
vec4 color;
float size;
uint32_t offset;
uint32_t length;
} String;
typedef struct DrawCommandStruct {
uint32_t vertex_count;
uint32_t instance_count;
uint32_t first_vertex;
uint32_t first_instance;
} DrawCommand;
typedef struct StringPointersStruct {
VkDeviceAddress strings;
VkDeviceAddress codes;
VkDeviceAddress characters;
VkDeviceAddress draw;
} StringPointers;
typedef struct CharacterStruct {
vec3 pos;
uint32_t padding0;
vec4 color;
float size;
uint32_t code;
} Character;
typedef struct FontUniformStruct {
uint32_t num_symbols;
uint32_t width;
uint32_t height;
VkDeviceAddress symbol_list;
} FontUniform;
typedef struct SymbolInfoStruct {
int32_t top;
uint32_t left;
uint32_t width;
uint32_t height;
uint32_t advance;
} SymbolInfo;
typedef struct FontStorageStruct {
VmaAllocation symbol_memory;
VmaAllocation uniform_memory;
VmaAllocation image_memory;
VkBuffer symbols;
VkBuffer uniform;
VkImage image;
VkImageView view;
VkSampler sampler;
} FontStorage;
typedef struct TextPointersMemoryStruct {
VmaAllocation pointers_memory;
VmaAllocation draw_memory;
VmaAllocation strings_memory;
VmaAllocation codes_memory;
VmaAllocation characters_memory;
VkBuffer pointers_buffer;
VkBuffer draw_buffer;
VkBuffer strings_buffer;
VkBuffer codes_buffer;
VkBuffer characters_buffer;
} TextPointersMemory;
typedef struct UILayerStruct {
VkDeviceAddress colored_rects;
uint32_t colored_rect_count;
VkDeviceAddress textured_rects;
uint32_t textured_rect_count;
VkDescriptorSet texture_array;
VkBuffer string_draw;
VkBuffer chars;
VkDeviceAddress string_pointers;
uint32_t string_count;
uint32_t chars_count;
VkDescriptorSet font;
} UILayer;
typedef struct UIContextStruct {
VkBuffer ui_descriptor_buffer;
VmaAllocation ui_descriptor_memory;
VkDescriptorSetLayout ui_descriptor_layout;
VkDescriptorPool ui_descriptor_pool;
VkDescriptorSet ui_descriptor_set;
VkDescriptorPool font_pool;
VkDescriptorSetLayout font_layout;
GraphicsPipeline ui_pipeline_rect;
GraphicsPipeline ui_pipeline_text;
ComputePipeline ui_compute_text;
} UIContext;
VkResult init_pipelines(
VkDevice device,
VmaAllocator allocator,
VkExtent2D swapchain_extent,
vec2 window_scale,
VkRenderPass render_pass,
UIContext* context);
VkResult load_font(
VkDevice device,
VmaAllocator allocator,
VkDescriptorSetLayout layout,
VkDescriptorPool pool,
VkCommandPool transfer_pool,
Queue transfer_queue,
FT_Library library,
const char* ttf_file,
uint32_t size,
VkBool32 antialias,
uint32_t** charmap,
FontStorage* memory,
VkDescriptorSet* font);
VkResult create_text_pointers(
uint32_t max_strings,
uint32_t max_characters,
VkDevice device,
VmaAllocator allocator,
VkCommandPool transfer_pool,
Queue transfer_queue,
TextPointersMemory* memory,
VkDeviceAddress* address);
#endif