// SONIC ROBO BLAST 2 //----------------------------------------------------------------------------- // Copyright (C) 2023 by Ronald "Eidolon" Kinard // // 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_TWODEE_HPP__ #define __SRB2_HWR2_PASS_TWODEE_HPP__ #include #include #include #include #include #include #include "../cxxutil.hpp" #include "pass.hpp" #include "pass_resource_managers.hpp" #include "twodee.hpp" namespace srb2::hwr2 { class TwodeePass; /// @brief Shared structures to allow multiple 2D instances to share the same atlases struct TwodeePassData; /// @brief Hash map key for caching pipelines struct TwodeePipelineKey { Draw2dBlend blend; bool lines; bool operator==(const TwodeePipelineKey& r) const noexcept { return !(blend != r.blend || lines != r.lines); } bool operator!=(const TwodeePipelineKey& r) const noexcept { return !(*this == r); } }; struct MergedTwodeeCommandFlatTexture { lumpnum_t lump; bool operator==(const MergedTwodeeCommandFlatTexture& rhs) const noexcept { return lump == rhs.lump; } bool operator!=(const MergedTwodeeCommandFlatTexture& rhs) const noexcept { return !(*this == rhs); } }; struct MergedTwodeeCommand { TwodeePipelineKey pipeline_key = {}; rhi::Handle binding_set = {}; std::optional> texture; const uint8_t* colormap; uint32_t index_offset = 0; uint32_t elements = 0; }; struct MergedTwodeeCommandList { rhi::Handle vbo {}; uint32_t vbo_size = 0; rhi::Handle ibo {}; uint32_t ibo_size = 0; std::vector cmds; }; std::shared_ptr make_twodee_pass_data(); struct TwodeePass final : public Pass { Twodee* ctx_ = nullptr; std::variant, rhi::Handle> out_color_; std::shared_ptr data_; std::shared_ptr flat_manager_; rhi::Handle us_1; rhi::Handle us_2; std::vector cmd_lists_; std::vector, std::size_t>> vbos_; std::vector, std::size_t>> ibos_; bool rebuild_atlases_ = false; rhi::Handle render_pass_; rhi::Handle output_; uint32_t output_width_ = 0; uint32_t output_height_ = 0; TwodeePass(); virtual ~TwodeePass(); virtual void prepass(rhi::Rhi& rhi) override; virtual void transfer(rhi::Rhi& rhi, rhi::Handle ctx) override; virtual void graphics(rhi::Rhi& rhi, rhi::Handle ctx) override; virtual void postpass(rhi::Rhi& rhi) override; }; } // namespace srb2::hwr2 template <> struct std::hash { std::size_t operator()(const srb2::hwr2::TwodeePipelineKey& v) const { std::size_t hash = 0; srb2::hash_combine(hash, v.blend, v.lines); return hash; } }; #endif // __SRB2_HWR2_PASS_TWODEE_HPP__