Commit 2af1b035 authored by Florian Oetke's avatar Florian Oetke
Browse files

moved ui rendering to own renderer instance [fixes #38]

parent 14a8106c
......@@ -43,7 +43,10 @@ namespace mirrage {
renderer::make_pass_factory<renderer::Debug_draw_pass_factory>(),
renderer::make_pass_factory<renderer::Blit_pass_factory>(),
renderer::make_pass_factory<renderer::Gui_pass_factory>())))
, _global_render(_renderer_factory->create_renderer<renderer::Gui_pass_factory>())
, _render_pass_mask(_renderer_factory->all_passes_mask())
{
util::erase_fast(_render_pass_mask, renderer::render_pass_id_of<renderer::Gui_pass_factory>());
}
Game_engine::~Game_engine()
......@@ -51,6 +54,11 @@ namespace mirrage {
screens().clear(); // destroy all screens before the engine
}
void Game_engine::_on_post_frame(util::Time) { _renderer_factory->finish_frame(); }
void Game_engine::_on_post_frame(util::Time dt)
{
_global_render->update(dt);
_global_render->draw();
_renderer_factory->finish_frame();
}
} // namespace mirrage
......@@ -29,14 +29,18 @@ namespace mirrage {
int argc,
char** argv,
char** env);
~Game_engine();
~Game_engine() override;
auto renderer_factory() noexcept -> auto& { return *_renderer_factory; }
auto global_render() noexcept -> auto& { return *_global_render; }
auto render_pass_mask() noexcept -> auto& { return _render_pass_mask; }
protected:
void _on_post_frame(util::Time) override;
private:
std::unique_ptr<renderer::Deferred_renderer_factory> _renderer_factory;
std::unique_ptr<renderer::Deferred_renderer> _global_render;
renderer::Render_pass_mask _render_pass_mask;
};
} // namespace mirrage
......@@ -11,7 +11,7 @@ namespace mirrage {
Meta_system::Meta_system(Game_engine& engine)
: _entities(engine.assets(), this)
, _renderer(engine.renderer_factory().create_renderer(_entities))
, _renderer(engine.renderer_factory().create_renderer(_entities, engine.render_pass_mask()))
, _model_loading(std::make_unique<renderer::Loading_system>(_entities, engine.assets()))
, _nims(std::make_unique<systems::Nim_system>(_entities))
{
......
......@@ -272,8 +272,6 @@ namespace mirrage::asset {
PHYSFS_unmount(append_file(PHYSFS_getBaseDir(), "..").c_str());
PHYSFS_unmount(mirrage::asset::pwd().c_str());
print_dir_recursiv("/", 0, [](auto&& path) { LOG(plog::fatal) << path; });
_reload_dispatchers();
}
......
......@@ -34,6 +34,7 @@ namespace mirrage::renderer {
struct Camera_state {
public:
Camera_state(glm::vec4 viewport);
Camera_state(const Camera_comp&, const ecs::components::Transform_comp&, glm::vec4 viewport);
Camera_state(const Camera_comp&, glm::vec3 position, glm::quat orientation, glm::vec4 viewport);
......
......@@ -10,6 +10,7 @@
#include <mirrage/graphic/profiler.hpp>
#include <mirrage/utils/min_max.hpp>
#include <mirrage/utils/small_vector.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/vec3.hpp>
......@@ -100,6 +101,7 @@ namespace mirrage::renderer {
return std::unique_ptr<Render_pass_factory>(new T(std::forward<Args>(args)...));
}
using Render_pass_mask = std::vector<Render_pass_id>; // util::small_vector<Render_pass_id, 32>;
// shared among all Deferred_renderers in all screens
class Deferred_renderer_factory {
......@@ -109,7 +111,18 @@ namespace mirrage::renderer {
std::vector<std::unique_ptr<Render_pass_factory>>);
~Deferred_renderer_factory();
auto create_renderer(ecs::Entity_manager&) -> std::unique_ptr<Deferred_renderer>;
auto create_renderer(util::maybe<ecs::Entity_manager&> = util::nothing,
Render_pass_mask = Render_pass_mask{}) -> std::unique_ptr<Deferred_renderer>;
template <class... Passes>
auto create_renderer(util::maybe<ecs::Entity_manager&> ecs = util::nothing,
Render_pass_mask passes = Render_pass_mask{render_pass_id_of<Passes>()...})
-> std::unique_ptr<Deferred_renderer>
{
return create_renderer(ecs, passes);
}
auto all_passes_mask() const noexcept -> auto& { return _all_passes_mask; }
void queue_commands(vk::CommandBuffer);
auto queue_temporary_command_buffer() -> vk::CommandBuffer;
......@@ -155,6 +168,7 @@ namespace mirrage::renderer {
vk::UniqueSampler _model_material_sampler;
vk::UniqueDescriptorSetLayout _model_desc_set_layout;
std::unique_ptr<Asset_loaders> _asset_loaders;
Render_pass_mask _all_passes_mask;
void _present();
auto _rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t> gqueue) -> int;
......@@ -168,8 +182,8 @@ namespace mirrage::renderer {
class Deferred_renderer {
public:
Deferred_renderer(Deferred_renderer_factory&,
std::vector<std::unique_ptr<Render_pass_factory>>&,
ecs::Entity_manager&,
std::vector<Render_pass_factory*>,
util::maybe<ecs::Entity_manager&>,
Engine&);
Deferred_renderer(const Deferred_renderer&) = delete;
auto operator=(const Deferred_renderer&) -> Deferred_renderer& = delete;
......@@ -235,10 +249,10 @@ namespace mirrage::renderer {
private:
friend class Deferred_renderer_factory;
Engine* _engine;
Deferred_renderer_factory* _factory;
ecs::Entity_manager* _entity_manager;
graphic::Descriptor_pool _descriptor_set_pool;
Engine* _engine;
Deferred_renderer_factory* _factory;
util::maybe<ecs::Entity_manager&> _entity_manager;
graphic::Descriptor_pool _descriptor_set_pool;
std::unique_ptr<GBuffer> _gbuffer;
Global_uniforms _global_uniforms;
......@@ -256,11 +270,12 @@ namespace mirrage::renderer {
graphic::Image_descriptor_set_layout _noise_descriptor_set_layout;
graphic::DescriptorSet _noise_descriptor_set;
std::vector<Render_pass_factory*> _pass_factories;
std::vector<std::unique_ptr<Render_pass>> _passes;
Camera_comp::Pool* _cameras;
util::maybe<Camera_state> _active_camera;
Frame_data _frame_data;
util::maybe<Camera_comp::Pool&> _cameras;
util::maybe<Camera_state> _active_camera;
Frame_data _frame_data;
void _write_global_uniform_descriptor_set();
void _update_global_uniforms(vk::CommandBuffer, const Camera_state& camera);
......
......@@ -39,8 +39,12 @@ namespace std {
namespace mirrage::renderer {
class Animation_pass_factory;
class Animation_pass : public Render_pass {
public:
using Factory = Animation_pass_factory;
Animation_pass(Deferred_renderer&, ecs::Entity_manager&);
void update(util::Time dt) override;
......@@ -84,7 +88,12 @@ namespace mirrage::renderer {
class Animation_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool&)
auto id() const noexcept -> Render_pass_id override
{
return render_pass_id_of<Animation_pass_factory>();
}
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t>, int) -> int override;
......
......@@ -7,8 +7,12 @@
namespace mirrage::renderer {
class Blit_pass_factory;
class Blit_pass : public Render_pass {
public:
using Factory = Blit_pass_factory;
Blit_pass(Deferred_renderer&, graphic::Texture_2D& src);
void update(util::Time dt) override;
......@@ -28,8 +32,12 @@ namespace mirrage::renderer {
class Blit_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool& write_first_pp_buffer)
-> std::unique_ptr<Render_pass> override;
auto id() const noexcept -> Render_pass_id override { return render_pass_id_of<Blit_pass_factory>(); }
auto create_pass(Deferred_renderer&,
util::maybe<ecs::Entity_manager&>,
Engine&,
bool& write_first_pp_buffer) -> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t> graphics_queue, int current_score)
-> int override;
......
......@@ -7,8 +7,12 @@
namespace mirrage::renderer {
class Bloom_pass_factory;
class Bloom_pass : public Render_pass {
public:
using Factory = Bloom_pass_factory;
Bloom_pass(Deferred_renderer&, graphic::Render_target_2D& src);
......@@ -46,7 +50,12 @@ namespace mirrage::renderer {
class Bloom_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool& write_first_pp_buffer)
auto id() const noexcept -> Render_pass_id override
{
return render_pass_id_of<Bloom_pass_factory>();
}
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t> graphics_queue, int current_score)
......
......@@ -8,8 +8,12 @@
namespace mirrage::renderer {
class Debug_draw_pass_factory;
class Debug_draw_pass : public Render_pass {
public:
using Factory = Debug_draw_pass_factory;
Debug_draw_pass(Deferred_renderer&, graphic::Render_target_2D& src);
void update(util::Time dt) override;
......@@ -26,7 +30,12 @@ namespace mirrage::renderer {
class Debug_draw_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool& write_first_pp_buffer)
auto id() const noexcept -> Render_pass_id override
{
return render_pass_id_of<Debug_draw_pass_factory>();
}
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t> graphics_queue, int current_score)
......
......@@ -18,10 +18,14 @@ namespace mirrage::renderer {
};
static_assert(sizeof(Deferred_push_constants) <= 4096, "Too large for push constants!");
class Deferred_pass_factory;
// populates linear-depth, albedo/matId, matData, writes the direct lighting results
// to the target color-Buffer and just the diffuse lighting to the other color-Buffer
class Deferred_pass : public Render_pass {
public:
using Factory = Deferred_pass_factory;
Deferred_pass(Deferred_renderer&,
ecs::Entity_manager&,
graphic::Render_target_2D& color_target,
......@@ -47,7 +51,12 @@ namespace mirrage::renderer {
class Deferred_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool&)
auto id() const noexcept -> Render_pass_id override
{
return render_pass_id_of<Deferred_pass_factory>();
}
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t>, int) -> int override;
......
......@@ -4,8 +4,12 @@
namespace mirrage::renderer {
class Frustum_culling_pass_factory;
class Frustum_culling_pass : public Render_pass {
public:
using Factory = Frustum_culling_pass_factory;
Frustum_culling_pass(Deferred_renderer&, ecs::Entity_manager&);
......@@ -21,7 +25,12 @@ namespace mirrage::renderer {
class Frustum_culling_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool&)
auto id() const noexcept -> Render_pass_id override
{
return render_pass_id_of<Frustum_culling_pass_factory>();
}
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t>, int) -> int override;
......
......@@ -7,11 +7,15 @@
namespace mirrage::renderer {
class Gen_mipmap_pass_factory;
/**
* @brief Generates mipmaps for depth and normal (mat_data) buffer
*/
class Gen_mipmap_pass : public Render_pass {
public:
using Factory = Gen_mipmap_pass_factory;
Gen_mipmap_pass(Deferred_renderer&);
......@@ -34,7 +38,12 @@ namespace mirrage::renderer {
class Gen_mipmap_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool&)
auto id() const noexcept -> Render_pass_id override
{
return render_pass_id_of<Gen_mipmap_pass_factory>();
}
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t>, int) -> int override;
......
......@@ -7,8 +7,12 @@
namespace mirrage::renderer {
class Gi_pass_factory;
class Gi_pass : public Render_pass {
public:
using Factory = Gi_pass_factory;
Gi_pass(Deferred_renderer&, graphic::Render_target_2D& in_out, graphic::Render_target_2D& diffuse_in);
......@@ -130,7 +134,9 @@ namespace mirrage::renderer {
class Gi_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool&)
auto id() const noexcept -> Render_pass_id override { return render_pass_id_of<Gi_pass_factory>(); }
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t>, int) -> int override;
......
......@@ -12,8 +12,12 @@
namespace mirrage::renderer {
class Gui_pass_factory;
class Gui_pass : public Render_pass, public gui::Gui_renderer_interface {
public:
using Factory = Gui_pass_factory;
Gui_pass(Deferred_renderer&, Engine&);
......@@ -82,7 +86,11 @@ namespace mirrage::renderer {
class Gui_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool&)
auto id() const noexcept -> Render_pass_id override { return render_pass_id_of<Gui_pass_factory>(); }
auto requires_gbuffer() const noexcept -> bool override { return false; }
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t>, int) -> int override;
......
......@@ -26,8 +26,12 @@ namespace mirrage::renderer {
Shadowmap(Shadowmap&& rhs) noexcept;
};
class Shadowmapping_pass_factory;
class Shadowmapping_pass : public Render_pass {
public:
using Factory = Shadowmapping_pass_factory;
Shadowmapping_pass(Deferred_renderer&, ecs::Entity_manager&);
void update(util::Time dt) override;
......@@ -51,7 +55,12 @@ namespace mirrage::renderer {
class Shadowmapping_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool&)
auto id() const noexcept -> Render_pass_id override
{
return render_pass_id_of<Shadowmapping_pass_factory>();
}
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t>, int) -> int override;
......
......@@ -7,8 +7,12 @@
namespace mirrage::renderer {
class Ssao_pass_factory;
class Ssao_pass : public Render_pass {
public:
using Factory = Ssao_pass_factory;
Ssao_pass(Deferred_renderer&);
void update(util::Time dt) override;
......@@ -38,7 +42,9 @@ namespace mirrage::renderer {
class Ssao_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool&)
auto id() const noexcept -> Render_pass_id override { return render_pass_id_of<Ssao_pass_factory>(); }
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t>, int) -> int override;
......
......@@ -12,8 +12,12 @@ namespace mirrage::renderer {
glm::mat4 fov_reprojection{}; // fov_reprojection[3].xy = offset
};
class Taa_pass_factory;
class Taa_pass : public Render_pass {
public:
using Factory = Taa_pass_factory;
Taa_pass(Deferred_renderer&, graphic::Render_target_2D& write, graphic::Texture_2D& read);
......@@ -47,7 +51,9 @@ namespace mirrage::renderer {
class Taa_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool&)
auto id() const noexcept -> Render_pass_id override { return render_pass_id_of<Taa_pass_factory>(); }
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t>, int) -> int override;
......
......@@ -7,8 +7,12 @@
namespace mirrage::renderer {
class Tone_mapping_pass_factory;
class Tone_mapping_pass : public Render_pass {
public:
using Factory = Tone_mapping_pass_factory;
Tone_mapping_pass(Deferred_renderer&,
graphic::Render_target_2D& src,
graphic::Render_target_2D& target);
......@@ -63,7 +67,12 @@ namespace mirrage::renderer {
class Tone_mapping_pass_factory : public Render_pass_factory {
public:
auto create_pass(Deferred_renderer&, ecs::Entity_manager&, Engine&, bool&)
auto id() const noexcept -> Render_pass_id override
{
return render_pass_id_of<Tone_mapping_pass_factory>();
}
auto create_pass(Deferred_renderer&, util::maybe<ecs::Entity_manager&>, Engine&, bool&)
-> std::unique_ptr<Render_pass> override;
auto rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t>, int) -> int override;
......
......@@ -3,6 +3,7 @@
#include <mirrage/ecs/entity_handle.hpp>
#include <mirrage/utils/maybe.hpp>
#include <mirrage/utils/ranges.hpp>
#include <mirrage/utils/reflection.hpp>
#include <mirrage/utils/str_id.hpp>
#include <mirrage/utils/units.hpp>
......@@ -132,15 +133,22 @@ namespace mirrage::renderer {
virtual auto name() const noexcept -> const char* = 0;
};
using Render_pass_id = util::type_uid_t;
class Render_pass_factory {
public:
Render_pass_factory();
virtual ~Render_pass_factory() = default;
virtual auto id() const noexcept -> Render_pass_id = 0;
virtual auto create_pass(Deferred_renderer&,
ecs::Entity_manager&,
util::maybe<ecs::Entity_manager&>,
Engine&,
bool& write_first_pp_buffer) -> std::unique_ptr<Render_pass> = 0;
virtual auto requires_gbuffer() const noexcept -> bool { return true; }
virtual auto rank_device(vk::PhysicalDevice,
util::maybe<std::uint32_t> graphics_queue,
int current_score) -> int
......@@ -157,4 +165,16 @@ namespace mirrage::renderer {
}
};
template <class T>
auto render_pass_id_of()
{
if constexpr(std::is_base_of_v<Render_pass_factory, T>)
return util::type_uid_of<T>();
else {
static_assert(std::is_base_of_v<Render_pass_factory, T::Factory>,
"T is not a renderpass, nor its factory.");
return util::type_uid_of<T::Factory>();
}
}
} // namespace mirrage::renderer
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment