#ifndef RT_GFX_BACKEND_H #define RT_GFX_BACKEND_H /* Backend functions and types. */ #include #include "gfx.h" #include "runtime.h" #include "resources.h" #ifdef __cplusplus extern "C" { #endif #ifdef _WIN32 struct HINSTANCE__; struct HWND__; #elif defined(RT_USE_XLIB) struct _XDisplay; #endif struct rt_renderer_init_info_s { #ifdef _WIN32 struct HINSTANCE__ *hInstance; struct HWND__ *hWnd; #elif defined(RT_USE_XLIB) struct _XDisplay *display; unsigned long window; #endif }; typedef struct { rt_resource_id vertex_shader; rt_resource_id fragment_shader; rt_resource_id compute_shader; rt_relptr texture_bindings; rt_relptr uniform_bindings; rt_relptr storage_bindings; uint16_t texture_binding_count; uint16_t uniform_binding_count; uint16_t storage_binding_count; } rt_pipeline_info; /* Attributes are used to bind buffers (or textures) to symbolic values. * For example, an attribute might be bound to "CELL_GRID", which would be * replaced with the (at the time of the invoke) grid buffer of the current * world cell. */ typedef enum { RT_ATTRIBUTE_VALUE_UNDEFINED, RT_ATTRIBUTE_VALUE_MATERIAL_ALBEDO, RT_ATTRIBUTE_VALUE_MATERIAL_NORMAL, RT_ATTRIBUTE_VALUE_count } rt_attribute_value; typedef struct { uint32_t index; rt_attribute_value value; } rt_attribute_binding; typedef enum { RT_SHADER_TYPE_INVALID, RT_SHADER_TYPE_VULKAN, RT_SHADER_TYPE_count, } rt_shader_type; typedef enum { RT_SHADER_STAGE_VERTEX, RT_SHADER_STAGE_FRAGMENT, RT_SHADER_STAGE_COMPUTE, RT_SHADER_STAGE_count, } rt_shader_stage; typedef struct { rt_shader_type type; rt_shader_stage stage; rt_relptr bytecode; size_t bytecode_length; } rt_shader_info; /* Handles for backend objects */ #define RT_GFX_HANDLE_MAX_VERSION 255 typedef struct { uint32_t version : 8; uint32_t index : 24; } rt_pipeline_handle; typedef void rt_register_renderer_cvars_fn(void); typedef rt_result rt_init_renderer_fn(const rt_renderer_init_info *info); typedef void rt_shutdown_renderer_fn(void); typedef rt_pipeline_handle rt_compile_pipeline_fn(const rt_pipeline_info *info); typedef void rt_destroy_pipeline_fn(rt_pipeline_handle handle); typedef struct { rt_register_renderer_cvars_fn *RegisterCVars; rt_init_renderer_fn *Init; rt_shutdown_renderer_fn *Shutdown; rt_compile_pipeline_fn *CompilePipeline; rt_destroy_pipeline_fn *DestroyPipeline; } rt_renderer_api; #define RT_RENDERER_API_FN(name) RT_DLLEXPORT rtRen##name #ifndef RT_DONT_DEFINE_RENDERER_GLOBAL extern rt_renderer_api g_renderer; #endif #ifdef __cplusplus } #endif #endif