roleplay/client/include/ui.h

261 lines
5.1 KiB
C

#ifndef PIPELINE_H
#define PIPELINE_H
#include "vulkan/vulkan_core.h"
#include "cglm/types.h"
#include "vk_mem_alloc.h"
#include "gpu.h"
2024-10-16 20:29:19 -06:00
#include "ft2build.h"
#include FT_FREETYPE_H
#define ANCHOR_TOP_LEFT 0
#define ANCHOR_TOP_RIGHT 1
#define ANCHOR_BOTTOM_LEFT 2
#define ANCHOR_BOTTOM_RIGHT 3
#define ANCHOR_CENTER 4
#define DRAWABLE_TYPE_RECT 0
#define DRAWABLE_TYPE_GLYPH 1
#define DRAWABLE_TYPE_IMAGE 2
2024-10-24 20:49:59 -06:00
typedef struct UIPushConstantStruct {
VkDeviceAddress layer;
float time;
uint32_t pad;
2024-10-24 20:49:59 -06:00
} UIPushConstant;
2024-10-22 18:22:18 -06:00
typedef struct GPUFontStruct {
2024-10-18 18:34:31 -06:00
VkDeviceAddress symbol_list;
uint32_t num_symbols;
uint32_t width;
uint32_t height;
2024-10-22 18:22:18 -06:00
} GPUFont;
2024-10-22 18:22:18 -06:00
typedef struct GPUSymbolStruct {
2024-10-20 22:39:12 -06:00
float top;
float left;
float width;
float height;
2024-10-22 20:24:34 -06:00
vec2 advance;
2024-10-22 18:22:18 -06:00
} GPUSymbol;
2024-10-22 18:22:18 -06:00
typedef struct FontStruct {
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;
char* family;
char* style;
2024-10-22 18:22:18 -06:00
} Font;
2024-10-22 18:22:18 -06:00
typedef struct TextureStruct {
2024-10-21 09:20:50 -06:00
VmaAllocation image_memory;
VkImage image;
VkImageView view;
VkSampler sampler;
char* path;
2024-10-22 18:22:18 -06:00
} Texture;
2024-10-21 09:20:50 -06:00
2024-10-22 18:22:18 -06:00
typedef struct GPUStringStruct {
2024-10-18 16:15:00 -06:00
vec2 pos;
vec4 color;
float size;
uint32_t offset;
uint32_t length;
uint32_t font;
uint32_t id;
2024-10-22 18:22:18 -06:00
} GPUString;
2024-10-18 16:15:00 -06:00
2024-10-22 18:22:18 -06:00
typedef struct GPUDrawableStruct {
vec2 pos;
vec2 size;
vec4 color[4];
uint32_t type;
uint32_t var;
uint32_t id;
2024-10-22 18:22:18 -06:00
} GPUDrawable;
2024-10-22 18:22:18 -06:00
typedef struct GPULayerStruct {
DrawCommand draw;
DispatchCommand dispatch_strings;
uint32_t max_drawables;
uint32_t max_codes;
uint32_t max_strings;
uint32_t num_drawables;
VkDeviceAddress strings;
VkDeviceAddress codes;
VkDeviceAddress drawables;
VkDeviceAddress container;
2024-10-22 18:22:18 -06:00
} GPULayer;
2024-10-22 18:22:18 -06:00
typedef struct LayerStruct {
2024-10-26 18:25:44 -06:00
VkBuffer strings[MAX_FRAMES_IN_FLIGHT];
VkBuffer codes[MAX_FRAMES_IN_FLIGHT];
VkBuffer drawables[MAX_FRAMES_IN_FLIGHT];
VkBuffer layer[MAX_FRAMES_IN_FLIGHT];
2024-10-26 18:25:44 -06:00
VmaAllocation strings_memory[MAX_FRAMES_IN_FLIGHT];
VmaAllocation drawables_memory[MAX_FRAMES_IN_FLIGHT];
VmaAllocation codes_memory[MAX_FRAMES_IN_FLIGHT];
VmaAllocation layer_memory[MAX_FRAMES_IN_FLIGHT];
2024-10-26 18:25:44 -06:00
VkDeviceAddress address[MAX_FRAMES_IN_FLIGHT];
2024-10-22 18:22:18 -06:00
GPUDrawable* drawables_buffer;
GPUString* strings_buffer;
uint32_t* codes_buffer;
2024-10-22 18:22:18 -06:00
GPULayer data;
} Layer;
typedef struct LayerInputStruct {
uint32_t num_strings;
uint32_t num_codes;
uint32_t num_drawables;
uint32_t max_codes;
uint32_t max_strings;
uint32_t max_drawables;
2024-10-22 18:22:18 -06:00
GPUString* strings;
uint32_t* codes;
GPUDrawable* drawables;
} LayerInput;
2024-10-22 18:22:18 -06:00
typedef struct GPUContainerStruct {
vec2 offset;
vec2 size;
uint32_t anchor;
2024-10-24 20:49:59 -06:00
VkDeviceAddress context;
2024-10-22 18:22:18 -06:00
} GPUContainer;
2024-10-22 18:22:18 -06:00
typedef struct ContainerStruct {
VkBuffer container[MAX_FRAMES_IN_FLIGHT];
VmaAllocation container_memory[MAX_FRAMES_IN_FLIGHT];
VkDeviceAddress address[MAX_FRAMES_IN_FLIGHT];
2024-10-22 18:22:18 -06:00
GPUContainer data;
uint32_t id;
uint32_t layer_count;
2024-10-22 18:22:18 -06:00
Layer* layers;
} Container;
2024-10-22 18:22:18 -06:00
typedef struct ContainerInputStruct {
uint32_t id;
2024-10-22 18:22:18 -06:00
uint32_t anchor;
vec2 offset;
vec2 size;
uint32_t layer_count;
2024-10-22 18:22:18 -06:00
LayerInput* layers;
} ContainerInput;
2024-10-22 18:22:18 -06:00
typedef struct GPUUIContextStruct {
VkDeviceAddress font_infos;
2024-10-21 09:20:50 -06:00
vec2 screen;
vec2 extent;
vec2 scale;
2024-10-22 18:22:18 -06:00
} GPUUIContext;
2024-10-22 18:22:18 -06:00
typedef struct UIContext {
VkDeviceAddress address;
VkBuffer context;
VmaAllocation context_memory;
VkBuffer font_infos;
VmaAllocation font_infos_memory;
2024-10-21 10:09:52 -06:00
VkDescriptorSet textures;
VkDescriptorSet samplers;
VkDescriptorSet font_samplers;
VkDescriptorSet font_textures;
2024-10-21 10:09:52 -06:00
VkDescriptorSetLayout samplers_layout;
VkDescriptorSetLayout textures_layout;
VkDescriptorPool fonts_pool;
2024-10-21 10:09:52 -06:00
VkDescriptorPool textures_pool;
GraphicsPipeline pipeline;
ComputePipeline string_pipeline;
uint32_t max_fonts;
uint32_t max_textures;
2024-10-22 18:22:18 -06:00
Font* fonts;
Texture* texture_slots;
2024-10-21 14:05:27 -06:00
uint32_t max_containers;
2024-10-22 18:22:18 -06:00
Container* containers;
2024-10-21 14:05:27 -06:00
2024-10-22 18:22:18 -06:00
GPUUIContext data;
2024-10-22 18:31:34 -06:00
FT_Library freetype;
2024-10-22 18:22:18 -06:00
} UIContext;
VkResult create_ui_context(
2024-10-18 16:15:00 -06:00
uint32_t max_fonts,
2024-10-21 10:09:52 -06:00
uint32_t max_textures,
2024-10-21 14:05:27 -06:00
uint32_t max_containers,
RenderContext* gpu,
2024-10-22 18:22:18 -06:00
UIContext* context);
VkResult load_font(
2024-10-22 18:31:34 -06:00
uint32_t index,
const char* ttf_file,
uint32_t size,
VkBool32 antialias,
RenderContext* gpu,
2024-10-22 18:31:34 -06:00
UIContext* context);
2024-10-21 09:20:50 -06:00
VkResult load_texture(
const char* png_path,
RenderContext* gpu,
2024-10-22 18:22:18 -06:00
UIContext* context,
uint32_t* index);
2024-10-21 09:20:50 -06:00
VkResult create_container(
2024-10-22 18:22:18 -06:00
ContainerInput* container,
RenderContext* gpu,
2024-10-22 18:22:18 -06:00
UIContext* context);
VkResult create_layer(
uint32_t index,
2024-10-22 18:22:18 -06:00
LayerInput* input,
RenderContext* gpu,
2024-10-22 18:22:18 -06:00
Container* container);
2024-10-21 13:31:42 -06:00
VkResult map_string(
const char * text,
uint32_t* buffer,
uint32_t offset,
2024-10-22 18:31:34 -06:00
uint32_t font,
UIContext* context);
VkResult update_ui_context_resolution(
UIContext* ui,
RenderContext* gpu);
VkResult update_ui_string(
char* string,
uint32_t container_index,
uint32_t layer_index,
uint32_t string_index,
UIContext* ui,
RenderContext* gpu);
#endif