248 lines
4.7 KiB
C
248 lines
4.7 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"
|
|
|
|
#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 DrawCommandStruct {
|
|
uint32_t vertex_count;
|
|
uint32_t instance_count;
|
|
uint32_t first_vertex;
|
|
uint32_t first_instance;
|
|
} DrawCommand;
|
|
|
|
typedef struct DispatchCommandStruct {
|
|
uint32_t x;
|
|
uint32_t y;
|
|
uint32_t z;
|
|
} DispatchCommand;
|
|
|
|
typedef struct FontStruct {
|
|
VkDeviceAddress symbol_list;
|
|
uint32_t num_symbols;
|
|
uint32_t width;
|
|
uint32_t height;
|
|
} Font;
|
|
|
|
typedef struct SymbolInfoStruct {
|
|
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;
|
|
uint32_t* charmap;
|
|
uint32_t num_symbols;
|
|
uint32_t index;
|
|
} FontStorage;
|
|
|
|
typedef struct TextureStorageStruct {
|
|
VmaAllocation image_memory;
|
|
VkImage image;
|
|
VkImageView view;
|
|
VkSampler sampler;
|
|
uint32_t index;
|
|
} TextureStorage;
|
|
|
|
typedef struct UIStringStruct {
|
|
vec2 pos;
|
|
vec4 color;
|
|
float size;
|
|
uint32_t offset;
|
|
uint32_t length;
|
|
uint32_t id;
|
|
} UIString;
|
|
|
|
typedef struct UIDrawableStruct {
|
|
vec2 pos;
|
|
vec2 size;
|
|
vec4 color;
|
|
uint32_t type;
|
|
uint32_t code;
|
|
uint32_t id;
|
|
} UIDrawable;
|
|
|
|
typedef struct UILayerStruct {
|
|
VkDeviceAddress strings;
|
|
VkDeviceAddress codes;
|
|
|
|
VkDeviceAddress drawables;
|
|
|
|
DrawCommand draw;
|
|
DispatchCommand dispatch_strings;
|
|
|
|
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;
|
|
|
|
UIDrawable* drawables_buffer;
|
|
UIString* strings_buffer;
|
|
uint32_t* codes_buffer;
|
|
|
|
UILayer data;
|
|
} UILayerStorage;
|
|
|
|
typedef struct UIContainerStruct {
|
|
vec2 pos;
|
|
vec2 size;
|
|
} UIContainer;
|
|
|
|
typedef struct UIContainerStorageStruct {
|
|
VkBuffer container;
|
|
|
|
VmaAllocation container_memory;
|
|
|
|
VkDeviceAddress address;
|
|
|
|
UIContainer data;
|
|
|
|
uint32_t id;
|
|
uint32_t layer_count;
|
|
UILayerStorage* layers;
|
|
} UIContainerStorage;
|
|
|
|
typedef struct UIContextStruct {
|
|
VkDeviceAddress font_infos;
|
|
vec2 screen;
|
|
vec2 scale;
|
|
} UIContext;
|
|
|
|
typedef struct UIContextStorageStruct {
|
|
VkDeviceAddress address;
|
|
|
|
VkBuffer context;
|
|
|
|
VmaAllocation context_memory;
|
|
|
|
VkBuffer font_infos;
|
|
VmaAllocation font_infos_memory;
|
|
|
|
VkDescriptorSet textures;
|
|
VkDescriptorSet samplers;
|
|
VkDescriptorSet font_samplers;
|
|
VkDescriptorSet font_textures;
|
|
VkDescriptorSetLayout samplers_layout;
|
|
VkDescriptorSetLayout textures_layout;
|
|
VkDescriptorPool fonts_pool;
|
|
VkDescriptorPool textures_pool;
|
|
|
|
GraphicsPipeline pipeline;
|
|
ComputePipeline string_pipeline;
|
|
|
|
uint32_t max_fonts;
|
|
uint32_t max_textures;
|
|
char** font_slots;
|
|
char** texture_slots;
|
|
|
|
uint32_t max_containers;
|
|
UIContainerStorage* containers;
|
|
|
|
UIContext data;
|
|
} UIContextStorage;
|
|
|
|
VkResult create_ui_context(
|
|
uint32_t max_fonts,
|
|
uint32_t max_textures,
|
|
uint32_t max_containers,
|
|
RenderContext* gpu,
|
|
UIContextStorage* memory);
|
|
|
|
VkResult load_font(
|
|
const char* ttf_file,
|
|
uint32_t size,
|
|
VkBool32 antialias,
|
|
FT_Library library,
|
|
RenderContext* gpu,
|
|
UIContextStorage* context,
|
|
uint32_t* index,
|
|
FontStorage* memory);
|
|
|
|
VkResult load_texture(
|
|
const char* png_path,
|
|
RenderContext* gpu,
|
|
UIContextStorage* context,
|
|
uint32_t* index,
|
|
TextureStorage* memory);
|
|
|
|
typedef struct UILayerInputStruct {
|
|
uint32_t num_strings;
|
|
uint32_t num_codes;
|
|
uint32_t num_drawables;
|
|
|
|
UIString* strings;
|
|
uint32_t* codes;
|
|
UIDrawable* drawables;
|
|
|
|
uint32_t font;
|
|
} UILayerInput;
|
|
|
|
typedef struct UIContainerInputStruct {
|
|
uint32_t id;
|
|
vec2 pos;
|
|
vec2 size;
|
|
|
|
uint32_t layer_count;
|
|
UILayerInput* layers;
|
|
} UIContainerInput;
|
|
|
|
VkResult create_container(
|
|
UIContainerInput* container,
|
|
RenderContext* gpu,
|
|
UIContextStorage* context);
|
|
|
|
VkResult create_layer(
|
|
uint32_t index,
|
|
UILayerInput* input,
|
|
RenderContext* gpu,
|
|
UIContainerStorage* container);
|
|
|
|
VkResult map_string(
|
|
const char * text,
|
|
uint32_t* buffer,
|
|
uint32_t offset,
|
|
uint32_t* charmap,
|
|
uint32_t charmap_size);
|
|
|
|
#endif
|