Separated atlases from Font class

First use of shared_ptr, yay!


Former-commit-id: 4c22341fba5674746d5299cf0e8dbf6dc31d5362
This commit is contained in:
Lynix
2015-01-07 23:46:26 +01:00
parent b61ff3a0d1
commit b6c5668232
7 changed files with 522 additions and 253 deletions

View File

@@ -8,11 +8,10 @@
#define NAZARA_FONT_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/GuillotineBinPack.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/AbstractFontAtlas.hpp>
#include <memory>
#include <unordered_map>
@@ -24,7 +23,7 @@ struct NAZARA_API NzFontParams
class NzFont;
class NzFontData;
struct NzFontGlyph; // TEMP
struct NzFontGlyph;
using NzFontConstRef = NzResourceRef<const NzFont>;
using NzFontLoader = NzResourceLoader<NzFont, NzFontParams>;
@@ -32,31 +31,12 @@ using NzFontRef = NzResourceRef<NzFont>;
class NAZARA_API NzFont : public NzResource, NzNonCopyable
{
friend NzAbstractFontAtlas;
friend NzFontLoader;
public:
struct Atlas
{
NzGuillotineBinPack binPack;
NzImage image;
};
struct Glyph
{
NzRecti aabb;
NzRectui atlasRect;
bool flipped;
bool valid;
int advance;
unsigned int atlasIndex;
};
struct SizeInfo
{
unsigned int lineHeight;
float underlinePosition;
float underlineThickness;
};
struct Glyph;
struct SizeInfo;
NzFont();
NzFont(NzFont&& font) = default;
@@ -71,14 +51,12 @@ class NAZARA_API NzFont : public NzResource, NzNonCopyable
bool ExtractGlyph(unsigned int characterSize, char32_t character, nzUInt32 style, NzFontGlyph* glyph) const;
const Atlas& GetAtlas(unsigned int atlasIndex) const;
unsigned int GetAtlasCount() const;
const NzAbstractFontAtlas* GetAtlas() const;
unsigned int GetCachedGlyphCount(unsigned int characterSize, nzUInt32 style) const;
unsigned int GetCachedGlyphCount() const;
NzString GetFamilyName() const;
int GetKerning(unsigned int characterSize, char32_t first, char32_t second) const;
const Glyph& GetGlyph(unsigned int characterSize, nzUInt32 style, char32_t character) const;
unsigned int GetMaxAtlasSize() const;
unsigned int GetMinimumStepSize() const;
const SizeInfo& GetSizeInfo(unsigned int characterSize) const;
NzString GetStyleName() const;
@@ -93,41 +71,50 @@ class NAZARA_API NzFont : public NzResource, NzNonCopyable
bool OpenFromMemory(const void* data, std::size_t size, const NzFontParams& params = NzFontParams());
bool OpenFromStream(NzInputStream& stream, const NzFontParams& params = NzFontParams());
void SetMaxAtlasSize(unsigned int maxAtlasSize);
void SetAtlas(std::shared_ptr<NzAbstractFontAtlas> atlas);
void SetMinimumStepSize(unsigned int minimumSizeStep);
NzFont& operator=(NzFont&& font) = default;
static unsigned int GetDefaultMaxAtlasSize();
static void SetDefaultMaxAtlasSize(unsigned int maxAtlasSize);
enum ModicationCode
{
ModificationCode_GlyphCacheCleared,
ModificationCode_KerningCacheCleared,
ModificationCode_SizeInfoCacheCleared
};
struct Glyph
{
NzRecti aabb;
NzRectui atlasRect;
bool flipped;
bool valid;
int advance;
unsigned int layerIndex;
};
struct SizeInfo
{
unsigned int lineHeight;
float underlinePosition;
float underlineThickness;
};
private:
using GlyphMap = std::unordered_map<char32_t, Glyph>;
struct QueuedGlyph
{
char32_t codepoint;
NzImage image;
GlyphMap* map;
};
nzUInt64 ComputeKey(unsigned int characterSize, nzUInt32 style) const;
unsigned int GetRealMaxAtlasSize() const;
unsigned int InsertRect(NzRectui* rect, bool* flipped) const;
void OnAtlasCleared();
const Glyph& PrecacheGlyph(GlyphMap& glyphMap, unsigned int characterSize, bool bold, char32_t character) const;
void ProcessGlyphQueue() const;
std::shared_ptr<NzAbstractFontAtlas> m_atlas;
std::unique_ptr<NzFontData> m_data;
mutable std::unordered_map<nzUInt64, std::unordered_map<nzUInt64, int>> m_kerningCache;
mutable std::unordered_map<nzUInt64, GlyphMap> m_glyphes;
mutable std::unordered_map<nzUInt64, SizeInfo> m_sizeInfoCache;
mutable std::vector<Atlas> m_atlases;
mutable std::vector<QueuedGlyph> m_glyphQueue;
unsigned int m_maxAtlasSize;
unsigned int m_minimumSizeStep;
static NzFontLoader::LoaderList s_loaders;
static unsigned int s_maxAtlasSize;
};
#endif // NAZARA_FONT_HPP