Graphics/TextSprite: Inlined some methods

Former-commit-id: 8c6633867e25b86b5b641662c804c446478fe56c
This commit is contained in:
Lynix
2015-06-16 22:54:29 +02:00
parent 8ade9fa65e
commit 54b0339025
3 changed files with 133 additions and 158 deletions

View File

@@ -25,36 +25,31 @@ using NzTextSpriteRef = NzObjectRef<NzTextSprite>;
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<typename... Args> 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);

View File

@@ -5,6 +5,123 @@
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
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<typename... Args>
NzTextSpriteRef NzTextSprite::New(Args&&... args)
{