Graphics/TextSprite: Update to Renderable

Still WIP as it appears to randomly crash


Former-commit-id: 2397ba7e556f7ed72b5fc8752704c3b212fa9fc1
This commit is contained in:
Lynix
2015-06-11 14:14:57 +02:00
parent 35f6e0d376
commit 3b5551ed7a
4 changed files with 81 additions and 105 deletions

View File

@@ -9,21 +9,27 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
#include <Nazara/Graphics/Renderable.hpp>
#include <Nazara/Utility/AbstractAtlas.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
#include <memory>
#include <set>
class NAZARA_API NzTextSprite : public NzSceneNode
class NzTextSprite;
using NzTextSpriteConstRef = NzObjectRef<const NzTextSprite>;
using NzTextSpriteLibrary = NzObjectLibrary<NzTextSprite>;
using NzTextSpriteRef = NzObjectRef<NzTextSprite>;
class NAZARA_API NzTextSprite : public NzRenderable
{
public:
NzTextSprite();
NzTextSprite(const NzTextSprite& sprite);
~NzTextSprite() = default;
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
void Clear();
@@ -32,7 +38,6 @@ class NAZARA_API NzTextSprite : public NzSceneNode
const NzColor& GetColor() const;
NzMaterial* GetMaterial() const;
nzSceneNodeType GetSceneNodeType() const override;
void InvalidateVertices();
bool IsDrawable() const;
@@ -45,14 +50,13 @@ class NAZARA_API NzTextSprite : public NzSceneNode
NzTextSprite& operator=(const NzTextSprite& text);
template<typename... Args> static NzTextSpriteRef New(Args&&... args);
private:
void InvalidateNode() override;
void MakeBoundingVolume() const override;
void OnAtlasInvalidated(const NzAbstractAtlas* atlas);
void OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* oldLayer, NzAbstractImage* newLayer);
void Register() override;
void Unregister() override;
void UpdateVertices() const;
void UpdateData(InstanceData* instanceData) const override;
struct RenderIndices
{
@@ -69,12 +73,15 @@ class NAZARA_API NzTextSprite : public NzSceneNode
std::unordered_map<const NzAbstractAtlas*, AtlasSlots> m_atlases;
mutable std::unordered_map<NzTexture*, RenderIndices> m_renderInfos;
mutable std::vector<NzVertexStruct_XY_Color> m_localVertices;
mutable std::vector<NzVertexStruct_XYZ_Color_UV> m_vertices;
mutable std::vector<NzVertexStruct_XY_Color_UV> m_localVertices;
NzColor m_color;
NzMaterialRef m_material;
NzRectui m_localBounds;
mutable bool m_verticesUpdated;
static NzTextSpriteLibrary::LibraryMap s_library;
};
#include <Nazara/Graphics/TextSprite.inl>
#endif // NAZARA_TEXTSPRITE_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
template<typename... Args>
NzTextSpriteRef NzTextSprite::New(Args&&... args)
{
std::unique_ptr<NzTextSprite> object(new NzTextSprite(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -28,6 +28,11 @@ struct NzVertexStruct_XY_UV : NzVertexStruct_XY
NzVector2f uv;
};
struct NzVertexStruct_XY_Color_UV : NzVertexStruct_XY_Color
{
NzVector2f uv;
};
/******************************* Structures 3D *******************************/
struct NzVertexStruct_XYZ