/* Copyright (c) 2019-2025, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 the "License"; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include "common/error.h" #include "common/glm_common.h" #include "common/helpers.h" namespace vkb { namespace field { /** * @brief Base Field Interface class */ struct Base { std::string label; Base(const std::string &label) : label{label} {} virtual ~Base() = default; virtual const std::string to_string() = 0; }; /** * @brief Static Field Implementation * * To be used for values that do not change often. */ template struct Static : public Base { T value; Static(const std::string &label, const T &value) : Base(label), value{value} {} virtual ~Static() = default; const std::string to_string() override { return vkb::to_string(value); } }; /** * @brief Dynamic Field Implementation * * To be used for values that change frequently. */ template struct Dynamic : public Base { T &value; Dynamic(const std::string &label, T &value) : Base(label), value{value} {} virtual ~Dynamic() = default; const std::string to_string() override { return vkb::to_string(value); } }; /** * @brief Vector Field Implementation * * To be used for values that have an X, Y and Z value. */ template struct Vector final : public Static { T x, y, z; Vector(const std::string &label, const glm::vec3 &vec) : Vector(label, vec.x, vec.y, vec.z) {} Vector(const std::string &label, T x, T y, T z) : Static(label, x), x{x}, y{y}, z{z} {} virtual ~Vector() = default; const std::string to_string() override { return "x: " + vkb::to_string(x) + " " + "y: " + vkb::to_string(y) + " " + "z: " + vkb::to_string(z); } }; /** * @brief MinMax Field Implementation * * To be used for numbers that change a lot, keeping track of the high/low values. */ template struct MinMax final : public Dynamic { T min, max; MinMax(const std::string &label, T &value) : Dynamic(label, value), min{value}, max{value} { static_assert(std::is_arithmetic::value, "MinMax must be templated to a numeric type."); } virtual ~MinMax() = default; const std::string to_string() override { if (Dynamic::value > max) { max = Dynamic::value; } if (Dynamic::value < min) { min = Dynamic::value; } if (min == 0) { min = Dynamic::value; } return "current: " + vkb::to_string(Dynamic::value) + " min: " + vkb::to_string(min) + " max: " + vkb::to_string(max); } }; } // namespace field /** * @brief Manages the debug information */ class DebugInfo { public: const std::vector> &get_fields() const; /** * @brief Calculates the field label with the most amount of characters * @returns The length of the longest label */ float get_longest_label() const; /** * @brief Constructs and inserts a new field of type C * * Replaces the field if it is of type static. */ template