// Copyright (C) 2022 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 namespace Nz { class AbstractViewer; class FrameGraph; class FramePipeline; class Light; class Material; class NAZARA_GRAPHICS_API ForwardPipelinePass : public FramePipelinePass { public: ForwardPipelinePass(FramePipeline& owner, AbstractViewer* viewer); ForwardPipelinePass(const ForwardPipelinePass&) = delete; ForwardPipelinePass(ForwardPipelinePass&&) = delete; ~ForwardPipelinePass(); 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 RegisterMaterial(const Material& material); void RegisterToFrameGraph(FrameGraph& frameGraph, std::size_t colorBufferIndex, std::size_t depthBufferIndex, bool hasDepthPrepass); void UnregisterMaterial(const Material& 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(MaterialPass, OnMaterialPassPipelineInvalidated, onMaterialPipelineInvalidated); NazaraSlot(MaterialPass, OnMaterialPassShaderBindingInvalidated, onMaterialShaderBindingInvalidated); }; 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 LightUboPool { std::vector> lightUboBuffers; }; std::size_t m_forwardPassIndex; std::size_t m_lastVisibilityHash; std::shared_ptr m_lightUboPool; std::vector> m_elementRendererData; std::vector> m_renderElements; std::vector m_renderStates; std::unordered_map m_materialPasses; 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; FramePipeline& m_pipeline; bool m_rebuildCommandBuffer; bool m_rebuildElements; }; } #include #endif // NAZARA_GRAPHICS_FORWARDPIPELINEPASS_HPP