3#include "spark/render/Export.h"
4#include "spark/render/GraphicsAdapter.h"
5#include "spark/render/GraphicsDevice.h"
14namespace spark::render
19 enum class BackendType
39 [[nodiscard]]
virtual BackendType
type() const noexcept = 0;
51 [[nodiscard]] BackendType
type() const noexcept
override {
return BackendType::Rendering; }
57 [[nodiscard]] std::vector<const IGraphicsAdapter*>
adapters() const noexcept {
return genericAdapters(); }
64 SPARK_SUPPRESS_MSVC_WARNING(4324)
79 [[nodiscard]]
virtual std::vector<const IGraphicsAdapter*> genericAdapters() const noexcept = 0;
86 template <typename GraphicsDeviceType>
90 using device_type = GraphicsDeviceType;
91 using surface_type =
typename device_type::surface_type;
92 using adapter_type =
typename device_type::adapter_type;
93 using swap_chain_type =
typename device_type::swap_chain_type;
94 using command_queue_type =
typename device_type::command_queue_type;
95 using command_buffer_type =
typename device_type::command_buffer_type;
96 using frame_buffer_type =
typename device_type::frame_buffer_type;
97 using render_pass_type =
typename device_type::render_pass_type;
98 using pipeline_layout_type =
typename device_type::pipeline_layout_type;
99 using render_pipeline_type =
typename device_type::render_pipeline_type;
100 using shader_program_type =
typename device_type::shader_program_type;
101 using input_assembler_type =
typename device_type::input_assembler_type;
102 using rasterizer_type =
typename device_type::rasterizer_type;
107 [[nodiscard]]
virtual std::vector<const adapter_type*> adapters()
const noexcept = 0;
110 [[nodiscard]]
const adapter_type*
findAdapter(
const std::optional<lib::Uuid>&
id = std::nullopt)
const override = 0;
113 [[nodiscard]] device_type*
device(
const std::string& name)
noexcept override = 0;
116 [[nodiscard]]
const device_type*
device(
const std::string& name)
const noexcept override = 0;
124 virtual void registerDevice(std::string name, std::unique_ptr<device_type>&& device) = 0;
142 template <
typename Self,
typename... Args>
143 device_type*
createDevice(std::string name,
const adapter_type& adapter, std::unique_ptr<surface_type>&& surface, Args&&... args)
145 auto device = std::make_unique<device_type>(adapter, std::move(surface), std::forward<Args>(args)...);
146 auto* ptr = device.get();
147 static_cast<Self*
>(
this)->registerDevice(name, std::move(device));
152 [[nodiscard]] std::vector<const IGraphicsAdapter*> genericAdapters() const noexcept final
154 auto tmp = adapters();
155 std::vector<const IGraphicsAdapter*> result;
156 result.reserve(tmp.size());
157 std::ranges::transform(tmp, std::back_inserter(result), [](
const auto& adapter) {
return static_cast<const IGraphicsAdapter*
>(adapter); });
A class representing a SPARK application.
Definition Application.h:19
The base class for a backend.
Definition Backend.h:29
virtual BackendType type() const noexcept=0
Gets the type of the backend.
Represents a physical graphics adapter.
Definition GraphicsAdapter.h:37
Interface for a graphics device.
Definition GraphicsDevice.h:18
Describes a rendering backend. (backend with type BackendType::Rendering)
Definition Backend.h:46
virtual const IGraphicsAdapter * findAdapter(const std::optional< lib::Uuid > &id=std::nullopt) const =0
Finds a graphics adapter by unique id.
virtual IGraphicsDevice * device(const std::string &name) noexcept=0
Searches for a graphics device by name.
virtual const IGraphicsDevice * device(const std::string &name) const noexcept=0
Searches for a graphics device by name.
BackendType type() const noexcept override
Gets the type of the backend.
Definition Backend.h:51
std::vector< const IGraphicsAdapter * > adapters() const noexcept
Lists all available graphics adapters.
Definition Backend.h:57
Defines a back-end, that provides a device instance for a certain surface and graphics adapter.
Definition Backend.h:88
device_type * device(const std::string &name) noexcept override=0
Searches for a graphics device by name.
const adapter_type * findAdapter(const std::optional< lib::Uuid > &id=std::nullopt) const override=0
Finds a graphics adapter by unique id.
const device_type * device(const std::string &name) const noexcept override=0
Searches for a graphics device by name.
device_type * createDevice(std::string name, const adapter_type &adapter, std::unique_ptr< surface_type > &&surface, Args &&... args)
Creates a new graphics device.
Definition Backend.h:143
virtual void releaseDevice(const std::string &name)=0
Unregisters a graphics device.
virtual void registerDevice(std::string name, std::unique_ptr< device_type > &&device)=0
Registers a new graphics device.