#pragma once #include #include #include namespace mln { namespace gfx { class Backend { public: /// @brief The active graphics API/backend type. enum class Type : uint8_t { OpenGL, ///< The OpenGL API backend Metal, ///< The Metal API backend Vulkan, ///< The Vulkan API backend WebGPU, ///< The WebGPU API backend TYPE_MAX, ///< Not a valid backend type, used to determine the number ///< of available backends (ie for array allocation). }; #if MLN_RENDER_BACKEND_WEBGPU static constexpr Type DefaultType = Type::WebGPU; #elif MLN_RENDER_BACKEND_METAL static constexpr Type DefaultType = Type::Metal; #elif MLN_RENDER_BACKEND_VULKAN static constexpr Type DefaultType = Type::Vulkan; #else // assume MLN_RENDER_BACKEND_OPENGL static constexpr Type DefaultType = Type::OpenGL; #endif static void SetType(const Type value) { if (Value(value) != value) { abort(); // SetType must be called prior to any GetType calls. } } static Type GetType() { return Value(DefaultType); } static bool getEnableGPUExpressionEval() { return enableGPUExpressionEval; } static void setEnableGPUExpressionEval(bool value) { enableGPUExpressionEval = value; } template static std::unique_ptr Create(Args... args) { #if MLN_RENDER_BACKEND_WEBGPU return Create(std::forward(args)...); #elif MLN_RENDER_BACKEND_METAL return Create(std::forward(args)...); #elif MLN_RENDER_BACKEND_VULKAN return Create(std::forward(args)...); #else // assume MLN_RENDER_BACKEND_OPENGL return Create(std::forward(args)...); #endif } private: template static std::unique_ptr Create(Args...); static Type Value(Type value) { static const Type type = value; return type; } static bool enableGPUExpressionEval; }; } // namespace gfx } // namespace mln