/**
 * @file descriptor_builder.h
 * @author Piotr Krygier (everyonecancode@gmail.com)
 * @brief
 * @version 0.1
 * @date 2024-03-01
 *
 * @copyright Copyright (c) 2024
 *
 */

#ifndef DESCRIPTOR_BUILDER_H
#define DESCRIPTOR_BUILDER_H

#include <stdint.h>
#include <vulkan/vulkan_core.h>

#include "graphics_context.h"

struct descriptor_set_handle_t;
struct descriptor_set_list_t;

rse_err_t descriptor_pool_add_type(struct graphics_context_t* context, VkDescriptorType type, uint32_t count);

rse_err_t descriptor_pool_initialize(struct graphics_context_t* context);

rse_err_t descriptor_create_new_set(struct graphics_context_t* context, rse_id_t* set_id);

rse_err_t descriptor_add_layout(struct descriptor_set_layout_bindings_t* layout_bindings,
                                uint32_t binding,
                                VkDescriptorType type,
                                uint32_t descriptor_count,
                                VkShaderStageFlags shader_stages);

rse_err_t descriptor_set_finish(struct graphics_context_t* context,
                                struct descriptor_set_layout_bindings_t* layout_bindings,
                                rse_id_t set_id);

rse_err_t descriptor_build_sets(struct graphics_context_t* context);

/**
 * @brief Add descriptor set to provided list
 *
 * @param descriptor_set_handle Handle for given descriptor set
 * @param binding Descriptors binding
 * @param type Type of descriptors
 * @param descriptor_count Number of descriptors in this set
 * @param shader_stages In what stages this descriptors will be used
 * @return rse_err_t RSE_ERROR_NO_ERROR on success, error code on failure
 */
rse_err_t descriptor_add_set(struct descriptor_set_handle_t* descriptor_set_handle,
                             uint32_t binding,
                             VkDescriptorType type,
                             uint32_t descriptor_count,
                             VkShaderStageFlags shader_stages);

rse_err_t descriptor_attach_images(struct graphics_context_t* context,
                                   rse_id_t descriptor_set_id,
                                   rse_id_t* texture_ids,
                                   size_t images_count,
                                   VkSampler sampler,
                                   uint32_t binding);

rse_err_t descriptor_attach_buffer(struct graphics_context_t* context,
                                   rse_id_t descriptor_set_id,
                                   struct vulkan_buffer_t* buffer,
                                   uint32_t binding,
                                   VkDescriptorType type);

void destroy_descriptors(struct graphics_context_t* context);

#endif  // !DESCRIPTOR_BUILDER_H
