roleplay/client/include/ui.h

231 lines
4.5 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"
2024-10-16 20:29:19 -06:00
#include "ft2build.h"
#include FT_FREETYPE_H
2024-10-14 19:42:38 -06:00
typedef struct ComputePipelineStruct {
VkPipelineLayout layout;
VkPipeline pipeline;
} ComputePipeline;
typedef struct GraphicsPipelineStruct {
VkPipelineLayout layout;
VkPipeline pipeline;
} GraphicsPipeline;
2024-10-15 11:44:59 -06:00
typedef struct DrawCommandStruct {
uint32_t vertex_count;
2024-10-15 11:44:59 -06:00
uint32_t instance_count;
uint32_t first_vertex;
2024-10-15 11:44:59 -06:00
uint32_t first_instance;
} DrawCommand;
typedef struct DispatchCommandStruct {
uint32_t x;
uint32_t y;
uint32_t z;
} DispatchCommand;
typedef struct FontStruct {
2024-10-18 18:34:31 -06:00
VkDeviceAddress symbol_list;
uint32_t num_symbols;
uint32_t width;
uint32_t height;
} Font;
typedef struct SymbolInfoStruct {
2024-10-20 22:39:12 -06:00
float top;
float left;
float width;
float height;
float advance;
} SymbolInfo;
typedef struct FontStorageStruct {
VmaAllocation symbol_memory;
VmaAllocation image_memory;
VkBuffer symbols;
VkImage image;
VkImageView view;
VkSampler sampler;
2024-10-18 16:15:00 -06:00
uint32_t* charmap;
uint32_t num_symbols;
uint32_t index;
} FontStorage;
2024-10-18 16:15:00 -06:00
typedef struct UIStringStruct {
vec2 pos;
vec4 color;
float size;
uint32_t offset;
uint32_t length;
} UIString;
typedef struct UIDrawableStruct {
vec2 pos;
vec2 size;
vec4 color;
uint32_t type;
uint32_t code;
} UIDrawable;
typedef struct UILayerStruct {
VkDeviceAddress strings;
2024-10-18 16:15:00 -06:00
VkDeviceAddress codes;
VkDeviceAddress drawables;
2024-10-18 16:15:00 -06:00
DrawCommand draw;
DispatchCommand dispatch_strings;
2024-10-18 18:34:31 -06:00
uint32_t font_index;
uint32_t max_drawables;
uint32_t max_codes;
uint32_t max_strings;
uint32_t num_drawables;
VkDeviceAddress container;
} UILayer;
typedef struct UIlayerStorageStruct {
VkBuffer strings;
VkBuffer codes;
VkBuffer drawables;
VkBuffer layer;
VmaAllocation strings_memory;
VmaAllocation drawables_memory;
VmaAllocation codes_memory;
VmaAllocation layer_memory;
VkDeviceAddress address;
UILayer data;
} UILayerStorage;
typedef struct UIContainerStruct {
vec2 pos;
vec2 size;
} UIContainer;
typedef struct UIContainerStorageStruct {
VkBuffer container;
VmaAllocation container_memory;
VkDeviceAddress address;
UIContainer data;
} UIContainerStorage;
typedef struct UIContextStruct {
VkDeviceAddress font_infos;
vec2 scale;
} UIContext;
typedef struct UIContextStorageStruct {
VkDeviceAddress address;
VkBuffer context;
VmaAllocation context_memory;
VkBuffer font_infos;
VmaAllocation font_infos_memory;
VkDescriptorSet font_samplers;
VkDescriptorSet font_textures;
VkDescriptorSetLayout font_samplers_layout;
VkDescriptorSetLayout font_textures_layout;
VkDescriptorPool fonts_pool;
GraphicsPipeline pipeline;
ComputePipeline string_pipeline;
UIContext data;
} UIContextStorage;
VkResult create_ui_context(
VkDevice device,
VmaAllocator allocator,
VkRenderPass render_pass,
2024-10-18 16:15:00 -06:00
uint32_t max_fonts,
VkExtent2D swapchain_extent,
vec2 window_scale,
VkCommandPool transfer_pool,
Queue transfer_queue,
UIContextStorage* memory);
VkResult load_font(
VkDevice device,
VmaAllocator allocator,
2024-10-18 18:34:31 -06:00
UIContextStorage* context,
2024-10-18 16:31:28 -06:00
uint32_t index,
VkCommandPool transfer_pool,
Queue transfer_queue,
FT_Library library,
const char* ttf_file,
uint32_t size,
VkBool32 antialias,
FontStorage* memory);
VkResult create_container(
float x,
float y,
float width,
float height,
VkDevice device,
VmaAllocator allocator,
VkCommandPool transfer_pool,
Queue transfer_queue,
UIContainerStorage* memory);
VkResult create_layer(
uint32_t max_strings,
uint32_t max_codes,
uint32_t max_drawables,
2024-10-18 18:34:31 -06:00
uint32_t font_index,
VkDevice device,
VmaAllocator allocator,
VkCommandPool transfer_pool,
Queue transfer_queue,
UIContainerStorage* container,
2024-10-18 16:15:00 -06:00
UILayerStorage* memory);
void set_ui_rect(
float x,
float y,
float width,
float height,
float r,
float g,
float b,
float a,
UIDrawable* drawable);
void set_ui_string(
float x,
float y,
float size,
float r,
float g,
float b,
float a,
uint32_t length,
uint32_t offset,
UIString* string);
VkResult set_ui_codes(
const char * text,
uint32_t* buffer,
uint32_t offset,
uint32_t* charmap,
uint32_t charmap_size);
#endif