Move GetDefaultShader logic into function

This commit is contained in:
Georg Hagen
2025-01-04 21:16:08 +01:00
parent c0e85d4fba
commit 47a904f572
2 changed files with 15 additions and 11 deletions

View File

@@ -207,16 +207,7 @@ namespace OpenVulkano::Scene
bmin.x = m_geometry.vertices[0].position.x;
m_bbox.Init(bmin, bmax);
if (!GetShader())
{
switch (m_atlasData->meta.atlasType)
{
case FontAtlasType::SDF: SetShader(&DEFAULT_SHADER_SDF); break;
case FontAtlasType::MSDF: SetShader(&DEFAULT_SHADER_MSDF); break;
default: Logger::RENDER->warn("No default shader for atlas type: {}", m_atlasData->meta.atlasType.GetName());
case FontAtlasType::BITMAP: SetShader(&DEFAULT_SHADER_BITMAP); break;
}
}
if (!GetShader()) SetShader(GetDefaultShader(m_atlasData->meta.atlasType));
}
void TextDrawable::SetAtlasData(const std::shared_ptr<AtlasData>& atlasData)
@@ -224,4 +215,15 @@ namespace OpenVulkano::Scene
if (!atlasData || !*atlasData) throw std::runtime_error("Cannot initialize text drawable with empty atlas data");
m_atlasData = atlasData;
}
Shader* TextDrawable::GetDefaultShader(const FontAtlasType type)
{
switch (type)
{
case FontAtlasType::SDF: return &DEFAULT_SHADER_SDF;
case FontAtlasType::MSDF: return &DEFAULT_SHADER_MSDF;
default: Logger::RENDER->warn("No default shader for atlas type: {}", type.GetName());
case FontAtlasType::BITMAP: return &DEFAULT_SHADER_BITMAP;
}
}
}

View File

@@ -49,10 +49,12 @@ namespace OpenVulkano::Scene
[[nodiscard]] Math::AABB& GetBoundingBox() { return m_bbox; }
[[nodiscard]] TextConfig& GetConfig() { return m_cfg; }
[[nodiscard]] const std::string& GetText() const { return m_text; }
[[nodiscard]] const std::shared_ptr<AtlasData> GetAtlasData() { return m_atlasData; }
[[nodiscard]] const std::shared_ptr<AtlasData>& GetAtlasData() { return m_atlasData; }
[[nodiscard]] Geometry* GetGeometry() { return &m_geometry; }
[[nodiscard]] Texture* GetTexture() { return &m_atlasData->texture; }
[[nodiscard]] UniformBuffer* GetUniformBuffer() { return &m_uniBuffer; }
[[nodiscard]] static Shader* GetDefaultShader(FontAtlasType type);
};
}