rework API for text rendering

This commit is contained in:
ohyzha
2024-08-04 00:10:59 +03:00
parent dcf6e72f96
commit 232ad0a938
8 changed files with 122 additions and 129 deletions

View File

@@ -63,39 +63,20 @@ namespace OpenVulkano
auto& resourceLoader = ResourceLoader::GetInstance();
const std::string fontPath = resourceLoader.GetResourcePath("Roboto-Regular.ttf");
const std::string atlasPath = (fs::path(fontPath).parent_path() / "roboto-regular-atlas.png").string();
m_nodesPool.resize(N);
m_drawablesPool.resize(N);
m_uniBuffers.resize(N);
for (int i = 0; i < N; i++)
{
m_uniBuffers[i].Init(sizeof(TextConfig), &texts[i].second, 3);
}
m_shader.AddShaderProgram(OpenVulkano::ShaderProgramType::VERTEX, "Shader/text");
m_shader.AddShaderProgram(OpenVulkano::ShaderProgramType::FRAGMENT, "Shader/text");
m_shader.AddVertexInputDescription(OpenVulkano::Vertex::GetVertexInputDescription());
m_shader.AddDescriptorSetLayoutBinding(Texture::DESCRIPTOR_SET_LAYOUT_BINDING);
m_shader.AddDescriptorSetLayoutBinding(UniformBuffer::DESCRIPTOR_SET_LAYOUT_BINDING);
m_shader.alphaBlend = true;
m_shader.cullMode = CullMode::NONE;
Charset charset = Charset::ASCII;
for (unicode_t c = 0x0410; c <= 0x041F; c++)
{
// some unicode values
charset.add(c);
}
m_atlasGenerator.GenerateAtlas(fontPath, atlasPath, charset);
m_atlasGenerator.GenerateAtlas(fontPath, charset);
for (int i = 0; i < texts.size(); i++)
{
TextDrawable* t = new TextDrawable();
t->SetFontAtlasGenerator(&m_atlasGenerator);
t->SetConfig(texts[i].second);
t->SetUniformBuffer(&m_uniBuffers[i]);
t->SetShader(&m_shader);
TextDrawable* t = new TextDrawable(&m_atlasGenerator, texts[i].second);
t->GenerateText(texts[i].first);
m_drawablesPool[i] = t;
m_nodesPool[i].Init();
@@ -131,9 +112,7 @@ namespace OpenVulkano
private:
OpenVulkano::Scene::Scene m_scene;
PerspectiveCamera m_cam;
std::vector<UniformBuffer> m_uniBuffers;
OpenVulkano::FreeCamCameraController m_camController;
Shader m_shader;
FontAtlasGenerator m_atlasGenerator;
std::vector<SimpleDrawable*> m_drawablesPool;
std::vector<Node> m_nodesPool;