// 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_TEXTSPRITE_HPP #define NAZARA_GRAPHICS_TEXTSPRITE_HPP #include #include #include #include #include #include #include #include namespace Nz { class AbstractTextDrawer; class NAZARA_GRAPHICS_API TextSprite : public InstancedRenderable { public: TextSprite(std::shared_ptr material = {}); TextSprite(const TextSprite&) = delete; TextSprite(TextSprite&&) noexcept = default; ~TextSprite() = default; void BuildElement(ElementRendererRegistry& registry, const ElementData& elementData, std::size_t passIndex, std::vector& elements) const override; inline void Clear(); const std::shared_ptr& GetMaterial(std::size_t i = 0) const override; std::size_t GetMaterialCount() const override; inline void SetMaterial(std::shared_ptr material); void Update(const AbstractTextDrawer& drawer, float scale = 1.f); TextSprite& operator=(const TextSprite&) = delete; TextSprite& operator=(TextSprite&&) noexcept = default; private: void OnAtlasInvalidated(const AbstractAtlas* atlas); void OnAtlasLayerChange(const AbstractAtlas* atlas, AbstractImage* oldLayer, AbstractImage* newLayer); struct AtlasSlots { bool used; NazaraSlot(AbstractAtlas, OnAtlasCleared, clearSlot); NazaraSlot(AbstractAtlas, OnAtlasLayerChange, layerChangeSlot); NazaraSlot(AbstractAtlas, OnAtlasRelease, releaseSlot); }; struct RenderData { }; struct RenderKey { Texture* texture; int renderOrder; bool operator==(const RenderKey& rhs) const { return texture == rhs.texture && renderOrder == rhs.renderOrder; } bool operator!=(const RenderKey& rhs) const { return !operator==(rhs); } }; struct HashRenderKey { std::size_t operator()(const RenderKey& key) const { // Since renderOrder will be very small, this will be enough return std::hash()(key.texture) + key.renderOrder; } }; struct RenderIndices { unsigned int first; unsigned int count; }; std::unordered_map m_atlases; mutable std::unordered_map m_renderInfos; std::shared_ptr m_material; std::vector m_data; std::vector m_vertices; Recti m_scissorBox; }; } #include #endif // NAZARA_GRAPHICS_TEXTSPRITE_HPP