#pragma once #include #include namespace mbgl { namespace gfx { class Shader; // Assert that a type is a valid shader for downcasting. // A valid shader must: // * Inherit gfx::Shader // * Have properly called DECLARE_SHADER_TYPEINFO in the class body // * Be a final class template inline constexpr bool is_shader_v = std::is_base_of_v && std::is_same_v< std::remove_cv_t, std::string_view> && std::is_final_v; /// @brief A shader is used as the base class for all programs across any supported /// backend API. Shaders are registered with a `gfx::ShaderRegistry` instance. class Shader { public: virtual ~Shader() = default; /// @brief Get the name of this shader /// @return Shader name virtual const std::string_view name() const noexcept = 0; /// @brief Downcast to a type /// @tparam T Derived type /// @return Type or nullptr if type info was not a match template, bool>* = nullptr> T* to() noexcept { if (name() != T::Name) { return nullptr; } return static_cast(this); } }; } // namespace gfx } // namespace mbgl