本文整理汇总了C++中Font::GetAtlas方法的典型用法代码示例。如果您正苦于以下问题:C++ Font::GetAtlas方法的具体用法?C++ Font::GetAtlas怎么用?C++ Font::GetAtlas使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Font
的用法示例。
在下文中一共展示了Font::GetAtlas方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void TextSprite::Update(const AbstractTextDrawer& drawer)
{
CallOnExit clearOnFail([this]()
{
Clear();
});
// Mark every atlas as unused...
for (auto& pair : m_atlases)
pair.second.used = false;
// ... until they are marked as used by the drawer
std::size_t fontCount = drawer.GetFontCount();
for (std::size_t i = 0; i < fontCount; ++i)
{
Font* font = drawer.GetFont(i);
const AbstractAtlas* atlas = font->GetAtlas().get();
NazaraAssert(atlas->GetStorage() & DataStorage_Hardware, "Font uses a non-hardware atlas which cannot be used by text sprites");
auto it = m_atlases.find(atlas);
if (it == m_atlases.end())
{
it = m_atlases.insert(std::make_pair(atlas, AtlasSlots())).first;
AtlasSlots& atlasSlots = it->second;
atlasSlots.clearSlot.Connect(atlas->OnAtlasCleared, this, &TextSprite::OnAtlasInvalidated);
atlasSlots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &TextSprite::OnAtlasLayerChange);
atlasSlots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &TextSprite::OnAtlasInvalidated);
}
it->second.used = true;
}
// Remove unused atlas slots
auto atlasIt = m_atlases.begin();
while (atlasIt != m_atlases.end())
{
if (!atlasIt->second.used)
m_atlases.erase(atlasIt++);
else
++atlasIt;
}
std::size_t glyphCount = drawer.GetGlyphCount();
m_localVertices.resize(glyphCount * 4);
// Reset glyph count for every texture to zero
for (auto& pair : m_renderInfos)
pair.second.count = 0;
// Count glyph count for each texture
Texture* lastTexture = nullptr;
unsigned int* count = nullptr;
for (std::size_t i = 0; i < glyphCount; ++i)
{
const AbstractTextDrawer::Glyph& glyph = drawer.GetGlyph(i);
Texture* texture = static_cast<Texture*>(glyph.atlas);
if (lastTexture != texture)
{
auto it = m_renderInfos.find(texture);
if (it == m_renderInfos.end())
it = m_renderInfos.insert(std::make_pair(texture, RenderIndices{0U, 0U})).first;
count = &it->second.count;
lastTexture = texture;
}
(*count)++;
}
// Attributes indices and reinitialize glyph count to zero to use it as a counter in the next loop
// This is because the 1st glyph can use texture A, the 2nd glyph can use texture B and the 3th glyph C can use texture A again
// so we need a counter to know where to write informations
// also remove unused render infos
unsigned int index = 0;
auto infoIt = m_renderInfos.begin();
while (infoIt != m_renderInfos.end())
{
RenderIndices& indices = infoIt->second;
if (indices.count == 0)
m_renderInfos.erase(infoIt++); //< No glyph uses this texture, remove from indices
else
{
indices.first = index;
index += indices.count;
indices.count = 0;
++infoIt;
}
}
lastTexture = nullptr;
RenderIndices* indices = nullptr;
for (unsigned int i = 0; i < glyphCount; ++i)
{
const AbstractTextDrawer::Glyph& glyph = drawer.GetGlyph(i);
Texture* texture = static_cast<Texture*>(glyph.atlas);
if (lastTexture != texture)
//.........这里部分代码省略.........