2024-10-09 14:31:30 -06:00
|
|
|
#ifndef PIPELINE_H
|
|
|
|
#define PIPELINE_H
|
|
|
|
|
|
|
|
#include "vulkan/vulkan_core.h"
|
|
|
|
#include "cglm/types.h"
|
2024-10-09 20:00:56 -06:00
|
|
|
#include "vk_mem_alloc.h"
|
2024-10-21 12:52:45 -06:00
|
|
|
#include "gpu.h"
|
2024-10-09 14:31:30 -06:00
|
|
|
|
2024-10-16 20:29:19 -06:00
|
|
|
#include "ft2build.h"
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
|
2024-10-22 17:48:37 -06:00
|
|
|
#define ANCHOR_TOP_LEFT 0
|
|
|
|
#define ANCHOR_TOP_RIGHT 1
|
|
|
|
#define ANCHOR_BOTTOM_LEFT 2
|
|
|
|
#define ANCHOR_BOTTOM_RIGHT 3
|
|
|
|
#define ANCHOR_CENTER 4
|
|
|
|
|
2024-11-10 16:36:01 -07:00
|
|
|
#define DRAWABLE_TYPE_RECT 0
|
|
|
|
#define DRAWABLE_TYPE_GLYPH 1
|
|
|
|
#define DRAWABLE_TYPE_IMAGE 2
|
2024-11-12 17:39:29 -07:00
|
|
|
#define DRAWABLE_TYPE_RECT_HSV 3
|
|
|
|
|
|
|
|
#define UI_EVENT_CURSOR (1 << 0)
|
|
|
|
#define UI_EVENT_SCROLL (1 << 1)
|
|
|
|
#define UI_EVENT_BUTTON (1 << 2)
|
2024-11-10 16:36:01 -07:00
|
|
|
|
2024-10-24 20:49:59 -06:00
|
|
|
typedef struct UIPushConstantStruct {
|
|
|
|
VkDeviceAddress layer;
|
|
|
|
float time;
|
2024-10-28 22:07:13 -06:00
|
|
|
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;
|
2024-10-14 13:33:14 -06:00
|
|
|
uint32_t num_symbols;
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
2024-10-22 18:22:18 -06:00
|
|
|
} GPUFont;
|
2024-10-13 22:18:37 -06:00
|
|
|
|
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-14 13:33:14 -06:00
|
|
|
|
2024-10-22 18:22:18 -06:00
|
|
|
typedef struct FontStruct {
|
2024-10-14 14:59:49 -06:00
|
|
|
VmaAllocation symbol_memory;
|
2024-10-14 01:00:10 -06:00
|
|
|
VmaAllocation image_memory;
|
2024-10-18 14:26:41 -06:00
|
|
|
VkBuffer symbols;
|
|
|
|
VkImage image;
|
|
|
|
VkImageView view;
|
|
|
|
VkSampler sampler;
|
2024-10-18 16:15:00 -06:00
|
|
|
uint32_t* charmap;
|
|
|
|
uint32_t num_symbols;
|
2024-10-18 14:26:41 -06:00
|
|
|
uint32_t index;
|
2024-10-21 14:15:47 -06:00
|
|
|
char* family;
|
|
|
|
char* style;
|
2024-10-22 18:22:18 -06:00
|
|
|
} Font;
|
2024-10-14 01:00:10 -06:00
|
|
|
|
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;
|
2024-10-21 14:15:47 -06:00
|
|
|
|
|
|
|
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;
|
2024-10-22 17:48:37 -06:00
|
|
|
uint32_t font;
|
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 {
|
2024-10-18 22:53:06 -06:00
|
|
|
vec2 pos;
|
|
|
|
vec2 size;
|
2024-11-12 11:56:57 -07:00
|
|
|
vec4 color[4];
|
2024-10-18 22:53:06 -06:00
|
|
|
uint32_t type;
|
2024-11-12 11:56:57 -07:00
|
|
|
uint32_t var;
|
2024-11-12 23:07:01 -07:00
|
|
|
uint32_t events;
|
2024-10-22 18:22:18 -06:00
|
|
|
} GPUDrawable;
|
2024-10-18 22:53:06 -06:00
|
|
|
|
2024-10-22 18:22:18 -06:00
|
|
|
typedef struct GPULayerStruct {
|
2024-10-18 22:53:06 -06:00
|
|
|
DrawCommand draw;
|
2024-10-18 14:26:41 -06:00
|
|
|
DispatchCommand dispatch_strings;
|
2024-10-18 22:53:06 -06:00
|
|
|
|
2024-10-20 21:59:28 -06:00
|
|
|
uint32_t max_drawables;
|
|
|
|
uint32_t max_codes;
|
|
|
|
uint32_t max_strings;
|
|
|
|
uint32_t num_drawables;
|
|
|
|
|
2024-10-29 16:12:01 -06:00
|
|
|
VkDeviceAddress strings;
|
|
|
|
VkDeviceAddress codes;
|
|
|
|
VkDeviceAddress drawables;
|
2024-10-20 21:59:28 -06:00
|
|
|
VkDeviceAddress container;
|
2024-10-22 18:22:18 -06:00
|
|
|
} GPULayer;
|
2024-10-13 15:44:33 -06:00
|
|
|
|
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-20 21:59:28 -06:00
|
|
|
|
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-20 21:59:28 -06:00
|
|
|
|
2024-10-26 18:25:44 -06:00
|
|
|
VkDeviceAddress address[MAX_FRAMES_IN_FLIGHT];
|
2024-10-20 21:59:28 -06:00
|
|
|
|
2024-10-22 18:22:18 -06:00
|
|
|
GPUDrawable* drawables_buffer;
|
|
|
|
GPUString* strings_buffer;
|
2024-10-21 13:39:12 -06:00
|
|
|
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;
|
|
|
|
|
2024-10-28 13:44:34 -06:00
|
|
|
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-20 21:59:28 -06:00
|
|
|
|
2024-10-22 18:22:18 -06:00
|
|
|
typedef struct GPUContainerStruct {
|
2024-10-21 21:57:05 -06:00
|
|
|
vec2 offset;
|
2024-10-20 21:59:28 -06:00
|
|
|
vec2 size;
|
2024-10-22 17:48:37 -06:00
|
|
|
uint32_t anchor;
|
2024-10-24 20:49:59 -06:00
|
|
|
|
|
|
|
VkDeviceAddress context;
|
2024-10-22 18:22:18 -06:00
|
|
|
} GPUContainer;
|
2024-10-20 21:59:28 -06:00
|
|
|
|
2024-11-13 12:19:06 -07:00
|
|
|
typedef struct UIContextStruct UIContext;
|
|
|
|
|
2024-11-17 19:27:42 -07:00
|
|
|
typedef bool (*ui_text_callback)(void* data, UIContext* ui, RenderContext* gpu, unsigned int codepoint);
|
2024-11-17 14:24:22 -07:00
|
|
|
typedef bool (*ui_key_callback)(void* data, UIContext* ui, RenderContext* gpu, int key, int action, int mods);
|
2024-11-17 19:27:42 -07:00
|
|
|
typedef bool (*ui_button_callback)(void* data, UIContext* ui, RenderContext* gpu, float x, float y, int button, int action, int mods);
|
|
|
|
typedef bool (*ui_scroll_callback)(void* data, UIContext* ui, RenderContext* gpu, double x, double y);
|
|
|
|
typedef bool (*ui_cursor_callback)(void* data, UIContext* ui, RenderContext* gpu, float x, float y);
|
2024-11-17 14:24:22 -07:00
|
|
|
typedef void (*ui_deselect_callback)(void* data, UIContext* ui, RenderContext* gpu);
|
2024-11-12 21:00:32 -07:00
|
|
|
|
|
|
|
typedef struct UICallbacksStruct {
|
2024-11-17 14:24:22 -07:00
|
|
|
uint32_t layer;
|
|
|
|
uint32_t element;
|
|
|
|
void* data;
|
|
|
|
|
|
|
|
ui_text_callback text;
|
2024-11-13 12:19:06 -07:00
|
|
|
ui_key_callback key;
|
|
|
|
ui_button_callback button;
|
|
|
|
ui_scroll_callback scroll;
|
|
|
|
ui_cursor_callback cursor;
|
|
|
|
ui_deselect_callback deselect;
|
2024-11-12 21:00:32 -07:00
|
|
|
} UICallbacks;
|
|
|
|
|
2024-10-22 18:22:18 -06:00
|
|
|
typedef struct ContainerStruct {
|
2024-10-28 22:07:13 -06:00
|
|
|
VkBuffer container[MAX_FRAMES_IN_FLIGHT];
|
2024-10-20 21:59:28 -06:00
|
|
|
|
2024-10-28 22:07:13 -06:00
|
|
|
VmaAllocation container_memory[MAX_FRAMES_IN_FLIGHT];
|
2024-10-20 21:59:28 -06:00
|
|
|
|
2024-10-28 22:07:13 -06:00
|
|
|
VkDeviceAddress address[MAX_FRAMES_IN_FLIGHT];
|
2024-10-20 21:59:28 -06:00
|
|
|
|
2024-10-22 18:22:18 -06:00
|
|
|
GPUContainer data;
|
|
|
|
|
|
|
|
uint32_t id;
|
2024-10-28 22:07:13 -06:00
|
|
|
uint32_t layer_count;
|
2024-10-22 18:22:18 -06:00
|
|
|
Layer* layers;
|
2024-11-12 21:00:32 -07:00
|
|
|
|
|
|
|
uint32_t callback_count;
|
|
|
|
UICallbacks* callbacks;
|
2024-10-22 18:22:18 -06:00
|
|
|
} Container;
|
2024-10-21 12:52:45 -06:00
|
|
|
|
2024-10-22 18:22:18 -06:00
|
|
|
typedef struct ContainerInputStruct {
|
2024-10-21 12:52:45 -06:00
|
|
|
uint32_t id;
|
2024-10-22 18:22:18 -06:00
|
|
|
uint32_t anchor;
|
|
|
|
vec2 offset;
|
|
|
|
vec2 size;
|
|
|
|
|
2024-10-21 12:52:45 -06:00
|
|
|
uint32_t layer_count;
|
2024-10-22 18:22:18 -06:00
|
|
|
LayerInput* layers;
|
2024-11-12 21:00:32 -07:00
|
|
|
|
|
|
|
uint32_t callback_count;
|
|
|
|
UICallbacks* callbacks;
|
2024-10-22 18:22:18 -06:00
|
|
|
} ContainerInput;
|
2024-10-20 21:59:28 -06:00
|
|
|
|
2024-10-22 18:22:18 -06:00
|
|
|
typedef struct GPUUIContextStruct {
|
2024-10-18 14:26:41 -06:00
|
|
|
VkDeviceAddress font_infos;
|
2024-10-21 09:20:50 -06:00
|
|
|
vec2 screen;
|
2024-10-22 17:48:37 -06:00
|
|
|
vec2 extent;
|
2024-10-20 21:59:28 -06:00
|
|
|
vec2 scale;
|
2024-10-22 18:22:18 -06:00
|
|
|
} GPUUIContext;
|
2024-10-13 20:27:09 -06:00
|
|
|
|
2024-11-13 12:19:06 -07:00
|
|
|
struct UIContextStruct {
|
2024-10-18 14:26:41 -06:00
|
|
|
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;
|
2024-10-18 14:26:41 -06:00
|
|
|
VkDescriptorSet font_samplers;
|
|
|
|
VkDescriptorSet font_textures;
|
2024-10-21 10:09:52 -06:00
|
|
|
VkDescriptorSetLayout samplers_layout;
|
|
|
|
VkDescriptorSetLayout textures_layout;
|
2024-10-18 14:26:41 -06:00
|
|
|
VkDescriptorPool fonts_pool;
|
2024-10-21 10:09:52 -06:00
|
|
|
VkDescriptorPool textures_pool;
|
2024-10-18 14:26:41 -06:00
|
|
|
|
2024-10-18 22:53:06 -06:00
|
|
|
GraphicsPipeline pipeline;
|
2024-10-18 14:26:41 -06:00
|
|
|
ComputePipeline string_pipeline;
|
2024-10-20 21:59:28 -06:00
|
|
|
|
2024-10-21 10:27:24 -06:00
|
|
|
uint32_t max_fonts;
|
|
|
|
uint32_t max_textures;
|
2024-10-21 14:15:47 -06:00
|
|
|
|
2024-10-22 18:22:18 -06:00
|
|
|
Font* fonts;
|
|
|
|
Texture* texture_slots;
|
2024-10-21 10:27:24 -06:00
|
|
|
|
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-11-12 17:39:29 -07:00
|
|
|
|
2024-11-12 21:00:32 -07:00
|
|
|
UICallbacks* active_callbacks;
|
|
|
|
uint32_t active_container;
|
2024-11-12 23:07:01 -07:00
|
|
|
uint32_t active_layer;
|
2024-11-12 21:00:32 -07:00
|
|
|
uint32_t active_element;
|
|
|
|
|
|
|
|
double cursor[2];
|
2024-11-13 12:19:06 -07:00
|
|
|
};
|
2024-10-18 14:26:41 -06:00
|
|
|
|
|
|
|
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,
|
2024-10-21 12:52:45 -06:00
|
|
|
RenderContext* gpu,
|
2024-10-22 18:22:18 -06:00
|
|
|
UIContext* context);
|
2024-10-17 11:06:09 -06:00
|
|
|
|
|
|
|
VkResult load_font(
|
2024-10-22 18:31:34 -06:00
|
|
|
uint32_t index,
|
2024-10-17 11:06:09 -06:00
|
|
|
const char* ttf_file,
|
|
|
|
uint32_t size,
|
|
|
|
VkBool32 antialias,
|
2024-10-21 12:52:45 -06:00
|
|
|
RenderContext* gpu,
|
2024-10-22 18:31:34 -06:00
|
|
|
UIContext* context);
|
2024-10-17 11:06:09 -06:00
|
|
|
|
2024-10-21 09:20:50 -06:00
|
|
|
VkResult load_texture(
|
2024-10-21 12:52:45 -06:00
|
|
|
const char* png_path,
|
|
|
|
RenderContext* gpu,
|
2024-10-22 18:22:18 -06:00
|
|
|
UIContext* context,
|
2024-10-21 14:15:47 -06:00
|
|
|
uint32_t* index);
|
2024-10-21 09:20:50 -06:00
|
|
|
|
2024-12-03 21:05:10 -07:00
|
|
|
VkResult load_container(
|
2024-10-22 18:22:18 -06:00
|
|
|
ContainerInput* container,
|
2024-10-21 12:52:45 -06:00
|
|
|
RenderContext* gpu,
|
2024-10-22 18:22:18 -06:00
|
|
|
UIContext* context);
|
2024-10-20 21:59:28 -06:00
|
|
|
|
2024-12-03 21:05:10 -07:00
|
|
|
VkResult unload_container(
|
|
|
|
uint32_t id,
|
|
|
|
RenderContext* gpu,
|
|
|
|
UIContext* context);
|
|
|
|
|
2024-10-18 14:26:41 -06:00
|
|
|
VkResult create_layer(
|
2024-10-21 13:11:59 -06:00
|
|
|
uint32_t index,
|
2024-10-22 18:22:18 -06:00
|
|
|
LayerInput* input,
|
2024-10-21 12:52:45 -06:00
|
|
|
RenderContext* gpu,
|
2024-10-22 18:22:18 -06:00
|
|
|
Container* container);
|
2024-10-20 21:59:28 -06:00
|
|
|
|
2024-10-21 13:31:42 -06:00
|
|
|
VkResult map_string(
|
2024-10-20 21:59:28 -06:00
|
|
|
const char * text,
|
|
|
|
uint32_t* buffer,
|
|
|
|
uint32_t offset,
|
2024-10-22 18:31:34 -06:00
|
|
|
uint32_t font,
|
|
|
|
UIContext* context);
|
2024-10-20 21:59:28 -06:00
|
|
|
|
2024-11-10 16:36:01 -07:00
|
|
|
VkResult update_ui_context_resolution(
|
|
|
|
UIContext* ui,
|
|
|
|
RenderContext* gpu);
|
|
|
|
|
|
|
|
VkResult update_ui_string(
|
2024-12-03 21:05:10 -07:00
|
|
|
const char* string,
|
2024-11-12 17:39:29 -07:00
|
|
|
uint32_t container_id,
|
2024-11-10 16:36:01 -07:00
|
|
|
uint32_t layer_index,
|
|
|
|
uint32_t string_index,
|
|
|
|
UIContext* ui,
|
|
|
|
RenderContext* gpu);
|
|
|
|
|
2024-11-12 21:00:32 -07:00
|
|
|
Container* context_container(uint32_t container_id, UIContext* ui);
|
|
|
|
|
2024-11-12 17:39:29 -07:00
|
|
|
bool ui_intersect(
|
|
|
|
double cursor[2],
|
|
|
|
RenderContext* gpu,
|
|
|
|
UIContext* ui,
|
2024-11-12 23:07:01 -07:00
|
|
|
uint32_t events,
|
2024-11-12 17:39:29 -07:00
|
|
|
uint32_t* container,
|
2024-11-12 23:07:01 -07:00
|
|
|
uint32_t* layer,
|
2024-11-12 17:39:29 -07:00
|
|
|
uint32_t* element,
|
|
|
|
vec2 position);
|
|
|
|
|
2024-11-12 23:07:01 -07:00
|
|
|
void set_active_element(uint32_t container, uint32_t layer, uint32_t element, UIContext* ui);
|
2024-11-12 21:00:32 -07:00
|
|
|
|
2024-11-13 12:19:06 -07:00
|
|
|
void clear_active_element(UIContext* ui, RenderContext* gpu);
|
2024-11-12 21:00:32 -07:00
|
|
|
|
|
|
|
void anchor_offset(RenderContext* gpu, Container* container, vec2 offset);
|
|
|
|
|
2024-10-09 14:31:30 -06:00
|
|
|
#endif
|