#ifndef RT_RENCOM_RENDERER_API_H
#define RT_RENCOM_RENDERER_API_H

#include <runtime/runtime.h>
#include <stdbool.h>

#include "renderer.h"
#include "render_resource.h"
#include "command_list.h"

typedef struct rt_physical_resource_manager_i rt_physical_resource_manager_i;

typedef rt_physical_resource_manager_i rt_render_device_get_physical_resource_manager_fn(void *o);
typedef rt_result rt_render_device_submit_command_list_fn(void *o, rt_render_command_list *list);

/* Interface for the render device.
 * The device is responsible for executing command lists. */
typedef struct {
    void *o;
    rt_render_device_get_physical_resource_manager_fn *GetPhysicalResourceManager;
    rt_render_device_submit_command_list_fn *SubmitCommandList;
} rt_render_device_i;

typedef bool rt_physical_resource_manager_is_present_fn(void *o, rt_render_resource_handle h);
typedef void rt_physical_resource_manager_destroy_fn(void *o, rt_render_resource_handle h);
typedef rt_result rt_physical_resource_manager_create_buffer_fn(void *o, rt_render_resource_handle h, const rt_render_buffer_desc *desc);
typedef rt_result rt_physical_resource_manager_create_texture2d_fn(void *o, rt_render_resource_handle h, const rt_render_texture2d_desc *desc);

/* Interface for the physical resource manager.
 * The physical resource manager maps render resources to actual gpu memory (=api objects like VkImage)
 */
struct rt_physical_resource_manager_i {
    void *o;
    rt_physical_resource_manager_is_present_fn *IsPresent;
    rt_physical_resource_manager_destroy_fn *Destroy;
    rt_physical_resource_manager_create_buffer_fn *CreateBuffer;
    rt_physical_resource_manager_create_texture2d_fn *CreateTexture2D;
};

typedef struct {
    rt_result result;
    rt_render_device_i device;
} rt_render_backend_init_result;

typedef void rt_render_backend_register_cvars_fn(void);
typedef rt_render_backend_init_result rt_render_backend_init_fn(const rt_renderer_window_info *info);
typedef void rt_render_backend_shutdown_fn(void);

/* Public renderer interface */
typedef struct {
    rt_render_backend_register_cvars_fn *RegisterCVARs;
    rt_render_backend_init_fn *Init;
    rt_render_backend_shutdown_fn *Shutdown;
} rt_render_backend_api;

extern rt_render_backend_api g_render_backend;
extern rt_render_device_i g_device_i;

#endif
