/* Copyright (c) 2020-2025, Arm Limited and Contributors * Copyright (c) 2023-2025, Mobica Limited * Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. * * 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 "common/tags.h" #include "platform/platform.h" #include "plugin.h" namespace vkb { /** * @brief PluginBase is the base class that plugins inherit from. The class enforces the use of tags when creating new plugins. * For method information see Plugin */ template class PluginBase : public Plugin, public Tag { public: PluginBase(const std::string name, const std::string description, const std::vector &hooks = {}, std::vector> const &commands = {}, std::vector> const &options = {}); virtual ~PluginBase() = default; const std::vector &get_hooks() const override; bool has_tag(TagID id) const override; // hooks that can be implemented by plugins void on_update(float delta_time) override{}; void on_app_start(const std::string &app_id) override{}; void on_app_close(const std::string &app_id) override{}; void on_platform_close() override{}; void on_post_draw(RenderContext &context) override{}; void on_app_error(const std::string &app_id) override{}; void on_update_ui_overlay(vkb::Drawer &drawer) override{}; private: Tag *tags = reinterpret_cast *>(this); std::vector hooks; }; template PluginBase::PluginBase(const std::string name, const std::string description, const std::vector &hooks, std::vector> const &commands, std::vector> const &options) : Plugin(name, description, commands, options), hooks{hooks} { } template bool PluginBase::has_tag(TagID id) const { return tags->has_tag(id); } template const std::vector &PluginBase::get_hooks() const { return hooks; } } // namespace vkb