#ifndef RT_GFX_H #define RT_GFX_H /* graphics system. this is the interface of the rendering code. * * we need (at least) three different renderers: * - world cell renderer (for world & dungeon environments) * - character renderer (for animated models) * - object renderer (for static models) */ #include #include "runtime/runtime.h" #ifdef __cplusplus extern "C" { #endif typedef union { float v[4]; struct { float r; float g; float b; float a; }; } rt_color; /* NOTE(kevin): When you add a value here, you need to handle them in * framegraph_processor.c : ParseFramegraph * and in the render target and texture functions of all renderers. */ typedef enum { RT_PIXEL_FORMAT_INVALID, RT_PIXEL_FORMAT_R8G8B8A8_UNORM, RT_PIXEL_FORMAT_B8G8R8A8_UNORM, RT_PIXEL_FORMAT_R8G8B8A8_SRGB, RT_PIXEL_FORMAT_B8G8R8A8_SRGB, RT_PIXEL_FORMAT_R8G8B8_UNORM, RT_PIXEL_FORMAT_B8G8R8_UNORM, RT_PIXEL_FORMAT_R8G8B8_SRGB, RT_PIXEL_FORMAT_B8G8R8_SRGB, RT_PIXEL_FORMAT_DEPTH24_STENCIL8, RT_PIXEL_FORMAT_DEPTH32, /* Special value indicating whichever format the swapchain uses */ RT_PIXEL_FORMAT_SWAPCHAIN, RT_PIXEL_FORMAT_count, } rt_pixel_format; /* In renderer_api.h -> Not necessary for almost all gfx usage */ typedef struct rt_renderer_init_info_s rt_renderer_init_info; RT_DLLEXPORT void rtRegisterRendererCVars(void); RT_DLLEXPORT rt_result rtInitGFX(rt_renderer_init_info *renderer_info); RT_DLLEXPORT void rtShutdownGFX(void); RT_DLLEXPORT void rtBeginGFXFrame(unsigned int frame_id); RT_DLLEXPORT void rtEndGFXFrame(unsigned int frame_id); /* ********************************************************************* * Framegraph API * * The framegraph is used to organize and schedule the work for a frame. * *********************************************************************/ /* Special value for the .width and .height fields of rt_render_target_info * to indicate that these should be set to the width or height of the swapchain, respectively. */ #define RT_RENDER_TARGET_SIZE_SWAPCHAIN 0 /* 32 bit string hashes */ typedef uint32_t rt_render_target_id; typedef uint32_t rt_render_pass_id; typedef struct { rt_render_target_id id; rt_pixel_format format; uint32_t width; uint32_t height; uint32_t sample_count; /* For debug purposes, can be 0 */ rt_relptr name; uint32_t name_len; } rt_render_target_info; typedef enum { RT_RENDER_TARGET_READ_SAMPLED, RT_RENDER_TARGET_READ_DIRECT, RT_RENDER_TARGET_READ_count, } rt_render_target_read_mode; typedef struct { rt_render_target_id render_target; rt_render_target_read_mode mode; } rt_render_target_read; typedef enum { /* Clears the render target with the clear value before executing the pass */ RT_RENDER_TARGET_WRITE_CLEAR = 0x01, /* Discards the written values after the pass has finished executing */ RT_RENDER_TARGET_WRITE_DISCARD = 0x02, } rt_render_target_write_flags; typedef struct { rt_render_target_id render_target; union { rt_color color; struct { float depth; int32_t stencil; } depth_stencil; } clear; rt_render_target_write_flags flags; } rt_render_target_write; typedef enum { RT_RENDER_PASS_TYPE_GRAPHICS, RT_RENDER_PASS_TYPE_COMPUTE, } rt_render_pass_type; typedef struct { rt_render_pass_id id; /* For debug purposes, can be 0 */ rt_relptr name; uint32_t name_len; rt_render_pass_type type; /* list of rt_render_target_reads */ rt_relptr read_render_targets; /* list of rt_render_target_writes */ rt_relptr write_render_targets; uint32_t read_render_target_count; uint32_t write_render_target_count; } rt_render_pass_info; typedef struct { rt_relptr render_targets; rt_relptr render_passes; uint32_t render_target_count; uint32_t render_pass_count; rt_relptr names; uint32_t names_size; } rt_framegraph_info; typedef void rt_render_pass_prepare_fn(rt_render_pass_id id, const rt_render_target_write *writes, uint32_t write_count, const rt_render_target_read *reads, uint32_t read_count); typedef void rt_render_pass_execute_fn(rt_render_pass_id id, const rt_render_target_write *writes, uint32_t write_count, const rt_render_target_read *reads, uint32_t read_count); typedef void rt_render_pass_finalize_fn(rt_render_pass_id id, const rt_render_target_write *writes, uint32_t write_count, const rt_render_target_read *reads, uint32_t read_count); typedef struct { rt_render_pass_prepare_fn *Prepare; rt_render_pass_execute_fn *Execute; rt_render_pass_finalize_fn *Finalize; } rt_render_pass_bind_fns; typedef struct rt_framegraph_s rt_framegraph; RT_DLLEXPORT rt_framegraph *rtCreateFramegraph(const rt_framegraph_info *info); RT_DLLEXPORT void rtDestroyFramegraph(rt_framegraph *framegraph); RT_DLLEXPORT void rtBindRenderPass(rt_framegraph *framegraph, rt_render_pass_id pass, const rt_render_pass_bind_fns *bind_fns); RT_DLLEXPORT void rtExecuteFramegraph(rt_framegraph *framegraph, unsigned int frame_id); /* Utility to turn a string into a usable render target id. */ RT_DLLEXPORT rt_render_target_id rtCalculateRenderTargetID(const char *name, size_t len); /* Utility to turn a string into a usable render pass id. */ RT_DLLEXPORT rt_render_pass_id rtCalculateRenderPassID(const char *name, size_t len); #ifdef __cplusplus } #endif #endif