// DR. ROBOTNIK'S RING RACERS //----------------------------------------------------------------------------- // Copyright (C) 2024 by Ronald "Eidolon" Kinard // Copyright (C) 2024 by Kart Krew // // This program is free software distributed under the // terms of the GNU General Public License, version 2. // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- #ifndef __SRB2_HWR2_PASS_RESOURCE_MANAGERS_HPP__ #define __SRB2_HWR2_PASS_RESOURCE_MANAGERS_HPP__ #include #include #include #include #include "../rhi/rhi.hpp" namespace srb2::hwr2 { class FramebufferManager final { rhi::Handle main_color_; std::array, 2> post_colors_; rhi::Handle wipe_start_color_; rhi::Handle wipe_end_color_; std::size_t post_index_ = 0; std::size_t width_ = 0; std::size_t height_ = 0; bool first_postprocess_ = true; public: FramebufferManager(); virtual ~FramebufferManager(); void prepass(rhi::Rhi& rhi); void transfer(rhi::Rhi& rhi); void graphics(rhi::Rhi& rhi); void postpass(rhi::Rhi& rhi); /// @brief Swap the current and previous postprocess FB textures. Use between pass prepass phases to alternate. void swap_post() noexcept { post_index_ = post_index_ == 0 ? 1 : 0; first_postprocess_ = false; } void reset_post() noexcept { first_postprocess_ = true; } rhi::Handle main_color() const noexcept { return main_color_; } rhi::Handle current_post_color() const noexcept { return post_colors_[post_index_]; } rhi::Handle previous_post_color() const noexcept { if (first_postprocess_) { return main_color(); } return post_colors_[1 - post_index_]; }; rhi::Handle wipe_start_color() const noexcept { return wipe_start_color_; } rhi::Handle wipe_end_color() const noexcept { return wipe_end_color_; } std::size_t width() const noexcept { return width_; } std::size_t height() const noexcept { return height_; } }; class MainPaletteManager final { rhi::Handle palette_; rhi::Handle lighttable_; rhi::Handle encore_lighttable_; rhi::Handle default_colormap_; std::unordered_map> colormaps_; std::unordered_map> lighttables_; std::vector colormaps_to_upload_; std::vector lighttables_to_upload_; void upload_palette(rhi::Rhi& rhi); void upload_lighttables(rhi::Rhi& rhi); void upload_default_colormap(rhi::Rhi& rhi); void upload_colormaps(rhi::Rhi& rhi); public: MainPaletteManager(); virtual ~MainPaletteManager(); void prepass(rhi::Rhi& rhi); void transfer(rhi::Rhi& rhi); void graphics(rhi::Rhi& rhi); void postpass(rhi::Rhi& rhi); rhi::Handle palette() const noexcept { return palette_; } rhi::Handle lighttable() const noexcept { return lighttable_; } rhi::Handle encore_lighttable() const noexcept { return encore_lighttable_; } rhi::Handle default_colormap() const noexcept { return default_colormap_; } rhi::Handle find_or_create_colormap(rhi::Rhi& rhi, srb2::NotNull colormap); rhi::Handle find_colormap(srb2::NotNull colormap) const; rhi::Handle find_or_create_extra_lighttable(rhi::Rhi& rhi, srb2::NotNull lighttable); rhi::Handle find_extra_lighttable(srb2::NotNull lighttable) const; }; class CommonResourcesManager final { bool init_ = false; rhi::Handle black_; rhi::Handle white_; rhi::Handle transparent_; public: CommonResourcesManager(); virtual ~CommonResourcesManager(); void prepass(rhi::Rhi& rhi); void transfer(rhi::Rhi& rhi); void graphics(rhi::Rhi& rhi); void postpass(rhi::Rhi& rhi); rhi::Handle black() const noexcept { return black_; } rhi::Handle white() const noexcept { return white_; } rhi::Handle transparent() const noexcept { return transparent_; } }; } // namespace srb2::hwr2 #endif // __SRB2_HWR2_PASS_RESOURCE_MANAGERS_HPP__