Implement back text rendering (WIP)
This commit is contained in:
35
include/Nazara/Graphics/GuillotineTextureAtlas.hpp
Normal file
35
include/Nazara/Graphics/GuillotineTextureAtlas.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2017 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GUILLOTINETEXTUREATLAS_HPP
|
||||
#define NAZARA_GUILLOTINETEXTUREATLAS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Utility/GuillotineImageAtlas.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class RenderDevice;
|
||||
|
||||
class NAZARA_GRAPHICS_API GuillotineTextureAtlas : public GuillotineImageAtlas
|
||||
{
|
||||
public:
|
||||
inline GuillotineTextureAtlas(RenderDevice& renderDevice);
|
||||
~GuillotineTextureAtlas() = default;
|
||||
|
||||
DataStoreFlags GetStorage() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<AbstractImage> ResizeImage(const std::shared_ptr<AbstractImage>& oldImage, const Vector2ui& size) const override;
|
||||
|
||||
RenderDevice& m_renderDevice;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/GuillotineTextureAtlas.inl>
|
||||
|
||||
#endif // NAZARA_GUILLOTINETEXTUREATLAS_HPP
|
||||
16
include/Nazara/Graphics/GuillotineTextureAtlas.inl
Normal file
16
include/Nazara/Graphics/GuillotineTextureAtlas.inl
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (C) 2017 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 <Nazara/Graphics/GuillotineTextureAtlas.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline GuillotineTextureAtlas::GuillotineTextureAtlas(RenderDevice& renderDevice) :
|
||||
m_renderDevice(renderDevice)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
103
include/Nazara/Graphics/TextSprite.hpp
Normal file
103
include/Nazara/Graphics/TextSprite.hpp
Normal file
@@ -0,0 +1,103 @@
|
||||
// Copyright (C) 2017 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_TEXTSPRITE_HPP
|
||||
#define NAZARA_TEXTSPRITE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Renderer/RenderPipeline.hpp>
|
||||
#include <Nazara/Utility/AbstractAtlas.hpp>
|
||||
#include <Nazara/Utility/VertexDeclaration.hpp>
|
||||
#include <Nazara/Utility/VertexStruct.hpp>
|
||||
#include <array>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractTextDrawer;
|
||||
|
||||
class NAZARA_GRAPHICS_API TextSprite : public InstancedRenderable
|
||||
{
|
||||
public:
|
||||
TextSprite(std::shared_ptr<Material> material);
|
||||
TextSprite(const TextSprite&) = delete;
|
||||
TextSprite(TextSprite&&) noexcept = default;
|
||||
~TextSprite() = default;
|
||||
|
||||
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const override;
|
||||
|
||||
inline void Clear();
|
||||
|
||||
const std::shared_ptr<Material>& GetMaterial(std::size_t i) const;
|
||||
std::size_t GetMaterialCount() const;
|
||||
|
||||
inline void SetMaterial(std::shared_ptr<Material> 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<Texture*>()(key.texture) + key.renderOrder;
|
||||
}
|
||||
};
|
||||
|
||||
struct RenderIndices
|
||||
{
|
||||
unsigned int first;
|
||||
unsigned int count;
|
||||
};
|
||||
|
||||
std::unordered_map<const AbstractAtlas*, AtlasSlots> m_atlases;
|
||||
mutable std::unordered_map<RenderKey, RenderIndices, HashRenderKey> m_renderInfos;
|
||||
std::shared_ptr<Material> m_material;
|
||||
std::vector<RenderData> m_data;
|
||||
std::vector<VertexStruct_XYZ_Color_UV> m_vertices;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/TextSprite.inl>
|
||||
|
||||
#endif
|
||||
23
include/Nazara/Graphics/TextSprite.inl
Normal file
23
include/Nazara/Graphics/TextSprite.inl
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright (C) 2017 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 <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <cassert>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void TextSprite::Clear()
|
||||
{
|
||||
m_atlases.clear();
|
||||
m_vertices.clear();
|
||||
}
|
||||
|
||||
inline void TextSprite::SetMaterial(std::shared_ptr<Material> material)
|
||||
{
|
||||
m_material = std::move(material);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user