// 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_SPRITECHAINRENDERER_HPP #define NAZARA_GRAPHICS_SPRITECHAINRENDERER_HPP #include #include #include #include #include #include #include #include #include namespace Nz { class RenderDevice; class RenderPipeline; class ShaderBinding; class Texture; class VertexDeclaration; class WorldInstance; struct SpriteChainRendererData : public ElementRendererData { struct DrawCall { const RenderBuffer* vertexBuffer; const RenderPipeline* renderPipeline; const ShaderBinding* shaderBinding; std::size_t firstIndex; std::size_t quadCount; Recti scissorBox; }; struct DrawCallIndices { std::size_t start; std::size_t count; }; std::unordered_map drawCallPerElement; std::vector drawCalls; std::vector> vertexBuffers; std::vector shaderBindings; }; class NAZARA_GRAPHICS_API SpriteChainRenderer final : public ElementRenderer { public: SpriteChainRenderer(RenderDevice& device, std::size_t maxVertexBufferSize = 32 * 1024); ~SpriteChainRenderer() = default; RenderElementPool& GetPool() override; std::unique_ptr InstanciateData() override; void Prepare(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, RenderFrame& currentFrame, std::size_t elementCount, const Pointer* elements, const RenderStates* renderStates) override; void PrepareEnd(RenderFrame& currentFrame, ElementRendererData& rendererData) override; void Render(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, std::size_t elementCount, const Pointer* elements) override; void Reset(ElementRendererData& rendererData, RenderFrame& currentFrame) override; private: void Flush(); void FlushDrawCall(); void FlushDrawData(); struct BufferCopy { RenderBuffer* targetBuffer; UploadPool::Allocation* allocation; std::size_t size; }; struct PendingData { std::size_t firstQuadIndex = 0; SpriteChainRendererData::DrawCall* currentDrawCall = nullptr; UploadPool::Allocation* currentAllocation = nullptr; UInt8* currentAllocationMemPtr = nullptr; const VertexDeclaration* currentVertexDeclaration = nullptr; RenderBuffer* currentVertexBuffer = nullptr; const MaterialInstance* currentMaterialInstance = nullptr; const RenderPipeline* currentPipeline = nullptr; const ShaderBinding* currentShaderBinding = nullptr; const Texture* currentTextureOverlay = nullptr; const WorldInstance* currentWorldInstance = nullptr; RenderBufferView currentLightData; Recti currentScissorBox = Recti(-1, -1, -1, -1); }; struct VertexBufferPool { std::vector> vertexBuffers; }; std::shared_ptr m_indexBuffer; std::shared_ptr m_vertexBufferPool; std::size_t m_maxVertexBufferSize; std::size_t m_maxVertexCount; std::vector m_pendingCopies; std::vector m_bindingCache; RenderElementPool m_spriteChainPool; PendingData m_pendingData; RenderDevice& m_device; }; } #include #endif // NAZARA_GRAPHICS_SPRITECHAINRENDERER_HPP