give more meaningful names
This commit is contained in:
@@ -4,13 +4,14 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "Text.hpp"
|
||||
#include "TextDrawable.hpp"
|
||||
#include "Scene/Geometry.hpp"
|
||||
#include "Scene/Material.hpp"
|
||||
#include "Scene/Vertex.hpp"
|
||||
#include "Scene/UniformBuffer.hpp"
|
||||
#include "Scene/FontAtlasGenerator.hpp"
|
||||
#include "Base/Logger.hpp"
|
||||
#include "utf8.h"
|
||||
#include "fmt/core.h"
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
@@ -18,13 +19,13 @@ namespace OpenVulkano::Scene
|
||||
using namespace msdfgen;
|
||||
using namespace msdf_atlas;
|
||||
|
||||
Text::~Text()
|
||||
TextDrawable::~TextDrawable()
|
||||
{
|
||||
delete m_mesh;
|
||||
delete m_material;
|
||||
}
|
||||
|
||||
void Text::GenerateText(const std::string& text, const Math::Vector3f& pos)
|
||||
void TextDrawable::GenerateText(const std::string& text, const Math::Vector3f& pos)
|
||||
{
|
||||
if (!m_fontAtlasGenerator)
|
||||
{
|
||||
@@ -62,9 +63,11 @@ namespace OpenVulkano::Scene
|
||||
};
|
||||
|
||||
double cursorX = pos.x;
|
||||
for (size_t i = 0; i < text.size(); i++)
|
||||
auto begin = text.begin();
|
||||
auto end = text.end();
|
||||
for (size_t i = 0; begin != end; i++)
|
||||
{
|
||||
unicode_t c = text[i];
|
||||
unicode_t c = utf8::next(begin, end);
|
||||
if (symbols.find(c) != symbols.end())
|
||||
{
|
||||
Bbox glyphBaselineBbox, glyphAtlasBbox;
|
||||
@@ -86,41 +89,42 @@ namespace OpenVulkano::Scene
|
||||
double ax = cursorX + bearingX;
|
||||
double ay = pos.y - (h - bearingY);
|
||||
|
||||
m_material->texture = &info.texture;
|
||||
const Texture& atlasTex = m_fontAtlasGenerator->GetAtlas();
|
||||
m_material->texture = const_cast<Texture*>(&atlasTex);
|
||||
|
||||
m_mesh->vertices[vIdx].position.x = ax;
|
||||
m_mesh->vertices[vIdx].position.y = ay;
|
||||
m_mesh->vertices[vIdx].position.z = 1;
|
||||
m_mesh->vertices[vIdx].textureCoordinates.x = l / info.texture.resolution.x;
|
||||
m_mesh->vertices[vIdx].textureCoordinates.y = b / info.texture.resolution.y;
|
||||
m_mesh->vertices[vIdx].textureCoordinates.x = l / atlasTex.resolution.x;
|
||||
m_mesh->vertices[vIdx].textureCoordinates.y = b / atlasTex.resolution.y;
|
||||
|
||||
m_mesh->vertices[vIdx + 1].position.x = ax + w;
|
||||
m_mesh->vertices[vIdx + 1].position.y = ay;
|
||||
m_mesh->vertices[vIdx + 1].position.z = 1;
|
||||
m_mesh->vertices[vIdx + 1].textureCoordinates.x = r / info.texture.resolution.x;
|
||||
m_mesh->vertices[vIdx + 1].textureCoordinates.y = b / info.texture.resolution.y;
|
||||
m_mesh->vertices[vIdx + 1].textureCoordinates.x = r / atlasTex.resolution.x;
|
||||
m_mesh->vertices[vIdx + 1].textureCoordinates.y = b / atlasTex.resolution.y;
|
||||
|
||||
m_mesh->vertices[vIdx + 2].position.x = ax + w;
|
||||
m_mesh->vertices[vIdx + 2].position.y = ay + h;
|
||||
m_mesh->vertices[vIdx + 2].position.z = 1;
|
||||
m_mesh->vertices[vIdx + 2].textureCoordinates.x = r / info.texture.resolution.x;
|
||||
m_mesh->vertices[vIdx + 2].textureCoordinates.y = t / info.texture.resolution.y;
|
||||
m_mesh->vertices[vIdx + 2].textureCoordinates.x = r / atlasTex.resolution.x;
|
||||
m_mesh->vertices[vIdx + 2].textureCoordinates.y = t / atlasTex.resolution.y;
|
||||
|
||||
m_mesh->vertices[vIdx + 3].position.x = ax;
|
||||
m_mesh->vertices[vIdx + 3].position.y = ay + h;
|
||||
m_mesh->vertices[vIdx + 3].position.z = 1;
|
||||
m_mesh->vertices[vIdx + 3].textureCoordinates.x = l / info.texture.resolution.x;
|
||||
m_mesh->vertices[vIdx + 3].textureCoordinates.y = t / info.texture.resolution.y;
|
||||
|
||||
m_mesh->vertices[vIdx + 3].textureCoordinates.x = l / atlasTex.resolution.x;
|
||||
m_mesh->vertices[vIdx + 3].textureCoordinates.y = t / atlasTex.resolution.y;
|
||||
|
||||
m_mesh->SetIndices(indices, 6, 6 * i);
|
||||
// TODO: change to lower value(or ideally remove completely) to avoid overlapping and make less space between symbols
|
||||
// when setting for depth comparison operator will be available( <= )
|
||||
cursorX += info.glyphBox.advance +0.08;
|
||||
cursorX += info.glyphBox.advance + 0.08;
|
||||
}
|
||||
else
|
||||
{
|
||||
// throw ? replace with ? character (if available) ?
|
||||
Logger::RENDER->error(fmt::format("Could not find glyph for character", c));
|
||||
Logger::RENDER->error(fmt::format("Could not find glyph for character {}", c));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,11 +34,11 @@ namespace OpenVulkano::Scene
|
||||
//bool sdfMultiChannel = false;
|
||||
};
|
||||
|
||||
class Text : public SimpleDrawable
|
||||
class TextDrawable : public SimpleDrawable
|
||||
{
|
||||
public:
|
||||
Text() = default;
|
||||
~Text();
|
||||
TextDrawable() = default;
|
||||
~TextDrawable();
|
||||
void SetUniformBuffer(UniformBuffer* buffer) { m_uniBuffer = buffer; }
|
||||
void GenerateText(const std::string& text, const Math::Vector3f& pos = Math::Vector3f(0.f));
|
||||
void SetConfig(const TextConfig& cfg) { m_cfg = cfg; }
|
||||
Reference in New Issue
Block a user