From 2e4ecca19aadc09d5c3d927724f8004b6a0ff0b0 Mon Sep 17 00:00:00 2001 From: quou Date: Thu, 13 Feb 2025 23:32:28 +1100 Subject: refactoring; prep for shadows --- renderer.hpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 renderer.hpp (limited to 'renderer.hpp') diff --git a/renderer.hpp b/renderer.hpp new file mode 100644 index 0000000..29a9dd0 --- /dev/null +++ b/renderer.hpp @@ -0,0 +1,74 @@ +#ifndef renderer_hpp +#define renderer_hpp + +#include "camera.hpp" +#include "hashmap.hpp" +#include "lighting.hpp" +#include "video.hpp" + +enum { + FORWARD, + SHADOW_MAP_START, + SHADOW_MAP_END = SHADOW_MAP_START + Lighting::max_shadows, + drawlist_count = SHADOW_MAP_END }; + +struct Camera_Id : public Primitive_Id { + using Primitive_Id::Primitive_Id; +}; + +template<> +struct Hash_Function { + size_t operator()(Camera_Id id) const { + return id.index; + } +}; + +struct Model_Instance; +struct Renderer; + +struct Drawlist { + Model_Instance** models; + int count; + int cap; + Camera_Id camera; + Staged_Buffer vp; + + void render( + const Renderer& r, + Device* dev, + Arena* a, + const Lighting* l, + Render_Pass& pass + ); +}; + +struct Renderer { + static constexpr int max_cameras = 16; + Hash_Map cameras; + Drawlist drawlists[drawlist_count]; + int camera_count; + + Sampler_Id clamped_linear; + Texture_Id env_cubemap; + + void init(Arena* arena, Device* d); + void destroy(Device* d); + void set_camera(Camera_Id cam, int drawlist); + void render( + Device* dev, + Arena* a, + Texture_Id hdr_target, + const Lighting* l + ); + + void add_model(int drawlist, Model_Instance* m); + void rem_model(int drawlist, Model_Instance* m); + void default_model(Model_Instance* m); + + Camera_Id create_camera(); + Camera& get_camera(Camera_Id cam); + const Camera& get_camera(Camera_Id cam) const; + void destroy_camera(Camera_Id cam); +}; + +#endif -- cgit v1.2.3-54-g00ecf