Move billboard state into LabelDrawableSettings

This commit is contained in:
Georg Hagen
2025-01-05 23:44:01 +01:00
parent 92b9fb597f
commit 6cfd760034
3 changed files with 13 additions and 15 deletions

View File

@@ -63,11 +63,11 @@ namespace OpenVulkano
} }
else else
{ {
labelSettings.hasRoundedCorners = i % 2 == 0 ? 0 : 1; labelSettings.hasRoundedCorners = i & 1;
labelSettings.hasArrow = i % 2 == 0 ? 1 : 0; labelSettings.hasArrow = i % 2 == 0;
} }
bool isBillboard = i % 2 == 0 ? 1 : 0; labelSettings.isBillboard = i % 2 == 0;
LabelDrawable& label = m_drawablesPool.emplace_back(textDrawable.GetAtlasData(), labelSettings, isBillboard); LabelDrawable& label = m_drawablesPool.emplace_back(textDrawable.GetAtlasData(), labelSettings);
label.AddText(texts[i]); label.AddText(texts[i]);
if (i == 2) if (i == 2)
{ {
@@ -88,8 +88,7 @@ namespace OpenVulkano
m_camController.SetPosition({ 0, 0, 10 }); m_camController.SetPosition({ 0, 0, 10 });
m_camController.SetBoostFactor(5); m_camController.SetBoostFactor(5);
std::shared_ptr<UI::PerformanceInfo> m_perfInfo = std::shared_ptr<UI::PerformanceInfo> m_perfInfo = std::make_shared<UI::PerformanceInfo>();
std::make_shared<UI::PerformanceInfo>();
m_ui.AddElement(m_perfInfo); m_ui.AddElement(m_perfInfo);
GetGraphicsAppManager()->GetRenderer()->SetActiveUi(&m_ui); GetGraphicsAppManager()->GetRenderer()->SetActiveUi(&m_ui);
} }

View File

@@ -68,8 +68,8 @@ namespace OpenVulkano::Scene
} }
} }
LabelDrawable::LabelDrawable(const std::shared_ptr<AtlasData>& atlasData, const LabelDrawableSettings& settings, const bool isBillboard) LabelDrawable::LabelDrawable(const std::shared_ptr<AtlasData>& atlasData, const LabelDrawableSettings& settings)
: Drawable(DrawEncoder::GetDrawEncoder<LabelDrawable>(), DrawPhase::MAIN), m_atlasData(atlasData), m_isBillboard(isBillboard) : Drawable(DrawEncoder::GetDrawEncoder<LabelDrawable>(), DrawPhase::MAIN), m_atlasData(atlasData)
{ {
if (atlasData->glyphs.empty() || !atlasData->texture.size) if (atlasData->glyphs.empty() || !atlasData->texture.size)
{ {
@@ -99,7 +99,7 @@ namespace OpenVulkano::Scene
textDrawable.GetConfig().backgroundColor.a = 0; // do not render glyph's background textDrawable.GetConfig().backgroundColor.a = 0; // do not render glyph's background
double lineHeight = m_atlasData->meta.lineHeight; double lineHeight = m_atlasData->meta.lineHeight;
textDrawable.GenerateText(text, m_position); textDrawable.GenerateText(text, m_position);
textDrawable.SetShader(GetTextShader(m_atlasData->meta.atlasType, m_isBillboard)); textDrawable.SetShader(GetTextShader(m_atlasData->meta.atlasType, IsBillboard()));
m_bbox.Grow(textDrawable.GetBoundingBox()); m_bbox.Grow(textDrawable.GetBoundingBox());
// update position for next text entry // update position for next text entry
m_position.y = m_bbox.GetMin().y - lineHeight; m_position.y = m_bbox.GetMin().y - lineHeight;

View File

@@ -23,8 +23,9 @@ namespace OpenVulkano::Scene
float cornerRadius = 0.05f; float cornerRadius = 0.05f;
float arrowLength = 0.5f; float arrowLength = 0.5f;
float arrowWidth = 0.2f; float arrowWidth = 0.2f;
int32_t hasRoundedCorners = false; bool hasRoundedCorners = false;
int32_t hasArrow = false; bool hasArrow = false;
bool isBillboard = false;
}; };
struct LabelUniformData struct LabelUniformData
@@ -43,8 +44,7 @@ namespace OpenVulkano::Scene
class LabelDrawable final : public Drawable class LabelDrawable final : public Drawable
{ {
public: public:
LabelDrawable(const std::shared_ptr<AtlasData>& atlasData, LabelDrawable(const std::shared_ptr<AtlasData>& atlasData, const LabelDrawableSettings& settings = LabelDrawableSettings());
const LabelDrawableSettings& settings = LabelDrawableSettings(), bool isBillboard = false);
void AddText(const std::string& text, const TextConfig& config = TextConfig()); void AddText(const std::string& text, const TextConfig& config = TextConfig());
void SetLabelSettings(const LabelDrawableSettings& settings); void SetLabelSettings(const LabelDrawableSettings& settings);
void SetPosition(const Math::Vector3f& pos) { m_position = pos; } void SetPosition(const Math::Vector3f& pos) { m_position = pos; }
@@ -52,7 +52,7 @@ namespace OpenVulkano::Scene
[[nodiscard]] LabelDrawableSettings& GetSettings() { return m_settings; } [[nodiscard]] LabelDrawableSettings& GetSettings() { return m_settings; }
[[nodiscard]] UniformBuffer* GetLabelBuffer() { return &m_labelBuffer; } [[nodiscard]] UniformBuffer* GetLabelBuffer() { return &m_labelBuffer; }
[[nodiscard]] Math::Vector3f& GetPosition() { return m_position; } [[nodiscard]] Math::Vector3f& GetPosition() { return m_position; }
[[nodiscard]] bool IsBillboard() const { return m_isBillboard; } [[nodiscard]] bool IsBillboard() const { return m_settings.isBillboard; }
[[nodiscard]] const Math::AABB& GetBoundingBox() const { return m_bbox; } [[nodiscard]] const Math::AABB& GetBoundingBox() const { return m_bbox; }
std::optional<RayHit> Intersect(const Ray& ray) const override; std::optional<RayHit> Intersect(const Ray& ray) const override;
@@ -66,6 +66,5 @@ namespace OpenVulkano::Scene
std::shared_ptr<AtlasData> m_atlasData; std::shared_ptr<AtlasData> m_atlasData;
Math::Vector3f m_position = { 0, 0, 0 }; Math::Vector3f m_position = { 0, 0, 0 };
Math::AABB m_bbox; Math::AABB m_bbox;
bool m_isBillboard;
}; };
} }