pawengine/kitty.h

116 lines
3.8 KiB
C

#ifndef INCLUDE_KITTY
#define INCLUDE_KITTY
#include "image.h"
#include "vulkan.h"
#include <vulkan/vulkan.h>
enum AttatchType {
CAT_ATTATCH_IMAGE,
CAT_ATTATCH_UBO,
CAT_ATTATCH_UBO_ARRAY,
};
struct Attatchment {
enum AttatchType type;
union {
struct {
const char *path;
uchar *pixels;
struct IVec2 dims;
VkDeviceSize size;
VkImage image;
VkImageView view;
VkSampler sampler;
struct GpuPointer memory;
} image;
struct {
uint32_t size;
VkBuffer buffer[MAX_FRAMES_IN_FLIGHT];
struct GpuPointer memory[MAX_FRAMES_IN_FLIGHT];
} ubo;
struct {
uint32_t size;
uint32_t count;
VkBuffer buffer[MAX_FRAMES_IN_FLIGHT];
struct GpuPointer memory[MAX_FRAMES_IN_FLIGHT];
} ubo_array;
};
};
dyn_array_define(da_Attatchment, struct Attatchment);
struct Kitty {
VkPipeline pipeline;
VkPipelineLayout pipeline_layout;
const char *vertex_path;
const char *fragment_path;
struct VertexBuffer vertex_buffer;
struct InstanceBuffer instance_buffer;
struct IndexBuffer index_buffer;
struct da_Attatchment attatchments;
uint32_t push_constant_size;
void *next_push_constant;
VkDescriptorPool descriptor_pool;
VkDescriptorSetLayout descriptor_set_layout;
VkDescriptorSet descriptor_sets[MAX_FRAMES_IN_FLIGHT];
};
struct Kitty *kitty_make();
void kitty_set_vertex_shader(struct Kitty *thingy, const char *path);
void kitty_set_fragment_shader(struct Kitty *thingy, const char *path);
// 'data' can be freed after 'kitty_finalise' is called, ownership is not
// transferred
void kitty_set_vertex_buffer(struct Kitty *thingy, void *data, uint32_t count,
int vertex_size);
void kitty_add_vertex_buffer_format(struct Kitty *thingy, enum VkFormat format);
// 'data' can be freed after 'kitty_finalise' is called, ownership is not
// transferred
void kitty_add_index_buffer(struct Kitty *kitty, void *data, uint32_t count);
// 'data' can be freed after 'kitty_finalise' is called, ownership is not
// transferred
void kitty_add_instance_buffer(struct Kitty *kitty, void *data, uint32_t count,
int element_size);
void kitty_add_instance_buffer_format(struct Kitty *kitty,
enum VkFormat format);
void kitty_set_push_constant_size(struct Kitty *thingy, uint32_t size);
// the returned number can be used in 'kitty_set_next_ubo' to update the content
// of the buffer
int kitty_attatch_ubo(struct Kitty *thingy, uint32_t size);
// the returned number can be used in 'kitty_set_next_ubo' to update the content
// of the buffer
int kitty_attatch_ubo_array(struct Kitty *thingy, uint32_t size,
uint32_t count);
void kitty_attatch_image(struct Kitty *thingy, const char *path);
void kitty_finalise(struct Vk *state, struct Kitty *thingy);
void kitty_set_next_push_constant(struct Kitty *thingy, void *data);
void kitty_set_next_ubo(struct Vk *state, struct Kitty *thingy, int index,
void *data);
void kitty_draw(struct Vk *state, uint32_t image_index, struct Kitty *thingy);
void free_kitty(struct Vk *state, struct Kitty *kitty);
void kitty_create_layout_bindings(struct Kitty *kitty, struct Vk *state);
void kitty_create_pipeline(struct Kitty *kitty, struct Vk *state);
void kitty_create_descriptor_pool(struct Kitty *kitty, struct Vk *state);
void kitty_create_image_attatchments(struct Kitty *kitty, struct Vk *state);
void kitty_create_ubo_attatchments(struct Kitty *kitty, struct Vk *state);
void kitty_create_ubo_array_attatchments(struct Kitty *kitty, struct Vk *state);
void kitty_create_descriptor_sets(struct Kitty *kitty, struct Vk *state);
void kitty_create_vertex_buffer(struct Kitty *kitty, struct Vk *state);
void kitty_create_instance_buffer(struct Kitty *kitty, struct Vk *state);
#endif // INCLUDE_KITTY