// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Graphics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_GRAPHICS_FORWARDPIPELINEPASS_HPP #define NAZARA_GRAPHICS_FORWARDPIPELINEPASS_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Nz { class AbstractViewer; class ElementRendererRegistry; class FrameGraph; class FramePass; class FramePipeline; class Light; class NAZARA_GRAPHICS_API ForwardPipelinePass : public FramePipelinePass { public: ForwardPipelinePass(FramePipeline& owner, ElementRendererRegistry& elementRegistry, AbstractViewer* viewer); ForwardPipelinePass(const ForwardPipelinePass&) = delete; ForwardPipelinePass(ForwardPipelinePass&&) = delete; ~ForwardPipelinePass() = default; inline void InvalidateCommandBuffers(); inline void InvalidateElements(); void Prepare(RenderFrame& renderFrame, const Frustumf& frustum, const std::vector& visibleRenderables, const std::vector& visibleLights, std::size_t visibilityHash); void RegisterMaterialInstance(const MaterialInstance& material); FramePass& RegisterToFrameGraph(FrameGraph& frameGraph, std::size_t colorBufferIndex, std::size_t depthBufferIndex, bool hasDepthPrepass); void UnregisterMaterialInstance(const MaterialInstance& material); ForwardPipelinePass& operator=(const ForwardPipelinePass&) = delete; ForwardPipelinePass& operator=(ForwardPipelinePass&&) = delete; static constexpr std::size_t MaxLightCountPerDraw = 3; private: struct MaterialPassEntry { std::size_t usedCount = 1; NazaraSlot(MaterialInstance, OnMaterialInstancePipelineInvalidated, onMaterialInstancePipelineInvalidated); NazaraSlot(MaterialInstance, OnMaterialInstanceShaderBindingInvalidated, onMaterialInstanceShaderBindingInvalidated); }; using LightKey = std::array; struct LightKeyHasher { inline std::size_t operator()(const LightKey& lightKey) const; }; struct LightDataUbo { std::shared_ptr renderBuffer; std::size_t offset = 0; UploadPool::Allocation* allocation = nullptr; }; struct LightPerElementData { RenderBufferView lightUniformBuffer; std::array shadowMaps; std::size_t lightCount; }; struct LightUboPool { std::vector> lightUboBuffers; }; struct RenderableLight { const Light* light; std::size_t lightIndex; float contributionScore; }; std::size_t m_forwardPassIndex; std::size_t m_lastVisibilityHash; std::shared_ptr m_lightUboPool; std::vector> m_elementRendererData; std::vector m_renderStates; std::vector m_renderElements; std::unordered_map m_materialInstances; std::unordered_map m_lightPerRenderElement; std::unordered_map m_lightBufferPerLights; std::vector m_lightDataBuffers; std::vector m_renderableLights; RenderQueue m_renderQueue; RenderQueueRegistry m_renderQueueRegistry; AbstractViewer* m_viewer; ElementRendererRegistry& m_elementRegistry; FramePipeline& m_pipeline; bool m_rebuildCommandBuffer; bool m_rebuildElements; }; } #include #endif // NAZARA_GRAPHICS_FORWARDPIPELINEPASS_HPP