diff --git a/include/Nazara/Graphics/TextSprite.hpp b/include/Nazara/Graphics/TextSprite.hpp index 606ae51c5..3eebe9d10 100644 --- a/include/Nazara/Graphics/TextSprite.hpp +++ b/include/Nazara/Graphics/TextSprite.hpp @@ -25,36 +25,31 @@ using NzTextSpriteRef = NzObjectRef; class NAZARA_GRAPHICS_API NzTextSprite : public NzInstancedRenderable { public: - NzTextSprite(); - NzTextSprite(const NzTextSprite& sprite); + inline NzTextSprite(); + inline NzTextSprite(const NzTextSprite& sprite); ~NzTextSprite() = default; void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override; - void Clear(); + inline void Clear(); - NzTextSprite* Clone() const; - NzTextSprite* Create() const; + inline const NzColor& GetColor() const; + inline const NzMaterialRef& GetMaterial() const; + inline float GetScale() const; - const NzColor& GetColor() const; - NzMaterial* GetMaterial() const; - float GetScale() const; - - void InvalidateVertices(); - bool IsDrawable() const; - - void SetColor(const NzColor& color); - void SetDefaultMaterial(); - void SetMaterial(NzMaterial* material); - void SetScale(float scale); + inline void SetColor(const NzColor& color); + inline void SetDefaultMaterial(); + inline void SetMaterial(NzMaterialRef material); + inline void SetScale(float scale); void Update(const NzAbstractTextDrawer& drawer); - NzTextSprite& operator=(const NzTextSprite& text); + inline NzTextSprite& operator=(const NzTextSprite& text); template static NzTextSpriteRef New(Args&&... args); private: + inline void InvalidateVertices(); void MakeBoundingVolume() const override; void OnAtlasInvalidated(const NzAbstractAtlas* atlas); void OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* oldLayer, NzAbstractImage* newLayer); diff --git a/include/Nazara/Graphics/TextSprite.inl b/include/Nazara/Graphics/TextSprite.inl index 85d23d517..a940ff212 100644 --- a/include/Nazara/Graphics/TextSprite.inl +++ b/include/Nazara/Graphics/TextSprite.inl @@ -5,6 +5,123 @@ #include #include +inline NzTextSprite::NzTextSprite() : +m_color(NzColor::White), +m_scale(1.f) +{ + SetDefaultMaterial(); +} + +inline NzTextSprite::NzTextSprite(const NzTextSprite& sprite) : +NzInstancedRenderable(sprite), +m_renderInfos(sprite.m_renderInfos), +m_localVertices(sprite.m_localVertices), +m_color(sprite.m_color), +m_material(sprite.m_material), +m_localBounds(sprite.m_localBounds), +m_scale(sprite.m_scale) +{ + for (auto it = sprite.m_atlases.begin(); it != sprite.m_atlases.end(); ++it) + { + const NzAbstractAtlas* atlas = it->first; + AtlasSlots& slots = m_atlases[atlas]; + + slots.clearSlot.Connect(atlas->OnAtlasCleared, this, &NzTextSprite::OnAtlasInvalidated); + slots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &NzTextSprite::OnAtlasLayerChange); + slots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &NzTextSprite::OnAtlasInvalidated); + } +} + +inline void NzTextSprite::Clear() +{ + m_atlases.clear(); + m_boundingVolume.MakeNull(); + m_localVertices.clear(); + m_renderInfos.clear(); +} + +inline const NzColor& NzTextSprite::GetColor() const +{ + return m_color; +} + +inline const NzMaterialRef& NzTextSprite::GetMaterial() const +{ + return m_material; +} + +inline float NzTextSprite::GetScale() const +{ + return m_scale; +} + +inline void NzTextSprite::SetColor(const NzColor& color) +{ + m_color = color; + + InvalidateVertices(); +} + +inline void NzTextSprite::SetDefaultMaterial() +{ + NzMaterialRef material = NzMaterial::New(); + material->Enable(nzRendererParameter_Blend, true); + material->Enable(nzRendererParameter_DepthWrite, false); + material->Enable(nzRendererParameter_FaceCulling, false); + material->EnableLighting(false); + material->SetDstBlend(nzBlendFunc_InvSrcAlpha); + material->SetSrcBlend(nzBlendFunc_SrcAlpha); + + SetMaterial(material); +} + +inline void NzTextSprite::SetMaterial(NzMaterialRef material) +{ + m_material = std::move(material); +} + +inline void NzTextSprite::SetScale(float scale) +{ + m_scale = scale; + + InvalidateVertices(); +} + +inline void NzTextSprite::InvalidateVertices() +{ + InvalidateInstanceData(0); +} + +inline NzTextSprite& NzTextSprite::operator=(const NzTextSprite& text) +{ + NzInstancedRenderable::operator=(text); + + m_atlases.clear(); + + m_color = text.m_color; + m_material = text.m_material; + m_renderInfos = text.m_renderInfos; + m_localBounds = text.m_localBounds; + m_localVertices = text.m_localVertices; + m_scale = text.m_scale; + + // Connect to the slots of the new atlases + for (auto it = text.m_atlases.begin(); it != text.m_atlases.end(); ++it) + { + const NzAbstractAtlas* atlas = it->first; + AtlasSlots& slots = m_atlases[atlas]; + + slots.clearSlot.Connect(atlas->OnAtlasCleared, this, &NzTextSprite::OnAtlasInvalidated); + slots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &NzTextSprite::OnAtlasLayerChange); + slots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &NzTextSprite::OnAtlasInvalidated); + } + + InvalidateBoundingVolume(); + InvalidateVertices(); + + return *this; +} + template NzTextSpriteRef NzTextSprite::New(Args&&... args) { diff --git a/src/Nazara/Graphics/TextSprite.cpp b/src/Nazara/Graphics/TextSprite.cpp index 609d37dd1..bcc318a55 100644 --- a/src/Nazara/Graphics/TextSprite.cpp +++ b/src/Nazara/Graphics/TextSprite.cpp @@ -11,35 +11,11 @@ #include #include -NzTextSprite::NzTextSprite() : -m_color(NzColor::White), -m_scale(1.f) -{ - SetDefaultMaterial(); -} - -NzTextSprite::NzTextSprite(const NzTextSprite& sprite) : -NzInstancedRenderable(sprite), -m_renderInfos(sprite.m_renderInfos), -m_localVertices(sprite.m_localVertices), -m_color(sprite.m_color), -m_material(sprite.m_material), -m_localBounds(sprite.m_localBounds), -m_scale(sprite.m_scale) -{ - for (auto it = sprite.m_atlases.begin(); it != sprite.m_atlases.end(); ++it) - { - const NzAbstractAtlas* atlas = it->first; - AtlasSlots& slots = m_atlases[atlas]; - - slots.clearSlot.Connect(atlas->OnAtlasCleared, this, &NzTextSprite::OnAtlasInvalidated); - slots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &NzTextSprite::OnAtlasLayerChange); - slots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &NzTextSprite::OnAtlasInvalidated); - } -} - void NzTextSprite::AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const { + if (!m_material) + return; + for (auto& pair : m_renderInfos) { NzTexture* overlay = pair.first; @@ -53,81 +29,6 @@ void NzTextSprite::AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const In } } -void NzTextSprite::Clear() -{ - m_atlases.clear(); - m_boundingVolume.MakeNull(); - m_localVertices.clear(); - m_renderInfos.clear(); -} - -NzTextSprite* NzTextSprite::Clone() const -{ - return new NzTextSprite(*this); -} - -NzTextSprite* NzTextSprite::Create() const -{ - return new NzTextSprite; -} - -const NzColor& NzTextSprite::GetColor() const -{ - return m_color; -} - -NzMaterial* NzTextSprite::GetMaterial() const -{ - return m_material; -} - -float NzTextSprite::GetScale() const -{ - return m_scale; -} - -void NzTextSprite::InvalidateVertices() -{ - InvalidateInstanceData(0); -} - -bool NzTextSprite::IsDrawable() const -{ - return m_material != nullptr; -} - -void NzTextSprite::SetColor(const NzColor& color) -{ - m_color = color; - - InvalidateVertices(); -} - -void NzTextSprite::SetDefaultMaterial() -{ - NzMaterialRef material = NzMaterial::New(); - material->Enable(nzRendererParameter_Blend, true); - material->Enable(nzRendererParameter_DepthWrite, false); - material->Enable(nzRendererParameter_FaceCulling, false); - material->EnableLighting(false); - material->SetDstBlend(nzBlendFunc_InvSrcAlpha); - material->SetSrcBlend(nzBlendFunc_SrcAlpha); - - SetMaterial(material); -} - -void NzTextSprite::SetMaterial(NzMaterial* material) -{ - m_material = material; -} - -void NzTextSprite::SetScale(float scale) -{ - m_scale = scale; - - InvalidateInstanceData(0); -} - void NzTextSprite::Update(const NzAbstractTextDrawer& drawer) { m_atlases.clear(); @@ -142,15 +43,7 @@ void NzTextSprite::Update(const NzAbstractTextDrawer& drawer) { NzFont* font = drawer.GetFont(i); const NzAbstractAtlas* atlas = font->GetAtlas().get(); - - #if NAZARA_GRAPHICS_SAFE - if ((atlas->GetStorage() & nzDataStorage_Hardware) == 0) - { - // Cet atlas ne nous donnera pas de texture, nous ne pouvons pas l'utiliser - NazaraError("Font " + NzString::Pointer(font) + " uses a non-hardware atlas which cannot be used by text sprites"); - return; - } - #endif + NazaraAssert(atlas->GetStorage() & nzDataStorage_Hardware, "Font uses a non-hardware atlas which cannot be used by text sprites"); if (m_atlases.find(atlas) == m_atlases.end()) { @@ -243,36 +136,6 @@ void NzTextSprite::Update(const NzAbstractTextDrawer& drawer) clearOnFail.Reset(); } -NzTextSprite& NzTextSprite::operator=(const NzTextSprite& text) -{ - NzInstancedRenderable::operator=(text); - - m_atlases.clear(); - - m_color = text.m_color; - m_material = text.m_material; - m_renderInfos = text.m_renderInfos; - m_localBounds = text.m_localBounds; - m_localVertices = text.m_localVertices; - m_scale = text.m_scale; - - // Connect to the slots of the new atlases - for (auto it = text.m_atlases.begin(); it != text.m_atlases.end(); ++it) - { - const NzAbstractAtlas* atlas = it->first; - AtlasSlots& slots = m_atlases[atlas]; - - slots.clearSlot.Connect(atlas->OnAtlasCleared, this, &NzTextSprite::OnAtlasInvalidated); - slots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &NzTextSprite::OnAtlasLayerChange); - slots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &NzTextSprite::OnAtlasInvalidated); - } - - InvalidateBoundingVolume(); - InvalidateVertices(); - - return *this; -} - void NzTextSprite::MakeBoundingVolume() const { NzRectf bounds(m_localBounds);