SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
InputAssembler.h
1#pragma once
2
3#include "spark/render/Export.h"
4#include "spark/render/IndexBuffer.h"
5#include "spark/render/VertexBuffer.h"
6
7#include <algorithm>
8#include <format>
9#include <vector>
10
11namespace spark::render
12{
16 enum class PrimitiveTopology
17 {
19 PointList = 0x00010001,
20
22 LineList = 0x00020001,
23
25 TriangleList = 0x00040001,
26
28 LineStrip = 0x00020002,
29
31 TriangleStrip = 0x00040002
32 };
33
34 class SPARK_RENDER_EXPORT IInputAssembler
35 {
36 public:
37 virtual ~IInputAssembler() noexcept = default;
38
43 [[nodiscard]] std::vector<const IVertexBufferLayout*> vertexBufferLayouts() const noexcept { return genericVertexBufferLayouts(); }
44
50 [[nodiscard]] virtual const IVertexBufferLayout& vertexBufferLayout(unsigned int binding) const = 0;
51
56 [[nodiscard]] virtual const IIndexBufferLayout& indexBufferLayout() const = 0;
57
62 [[nodiscard]] virtual PrimitiveTopology topology() const noexcept = 0;
63
64 private:
66 [[nodiscard]] virtual std::vector<const IVertexBufferLayout*> genericVertexBufferLayouts() const noexcept = 0;
67 };
68
74 template <typename VertexBufferLayoutType, typename IndexBufferLayoutType>
76 {
77 public:
78 using VertexBufferLayout = VertexBufferLayoutType;
79 using IndexBufferLayout = IndexBufferLayoutType;
80
81 public:
83 [[nodiscard]] virtual std::vector<const VertexBufferLayoutType*> vertexBufferLayouts() const noexcept = 0;
84
86 [[nodiscard]] const VertexBufferLayoutType& vertexBufferLayout(unsigned binding) const override = 0;
87
89 [[nodiscard]] const IndexBufferLayoutType& indexBufferLayout() const override = 0;
90
91 private:
92 [[nodiscard]] std::vector<const IVertexBufferLayout*> genericVertexBufferLayouts() const noexcept override
93 {
94 auto tmp = vertexBufferLayouts();
95 std::vector<const IVertexBufferLayout*> vertex_buffer_layouts_vector;
96 vertex_buffer_layouts_vector.reserve(tmp.size());
97 std::ranges::transform(tmp,
98 std::back_inserter(vertex_buffer_layouts_vector),
99 [](const auto& vertex_buffer_layout) { return static_cast<const IVertexBufferLayout*>(vertex_buffer_layout); });
100 return vertex_buffer_layouts_vector;
101 }
102 };
103}
104
105template <>
106struct std::formatter<spark::render::PrimitiveTopology> : std::formatter<std::string_view>
107{
108 static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
109
110 static constexpr auto format(const spark::render::PrimitiveTopology topology, auto& ctx)
111 {
112 switch (topology)
113 {
114 case spark::render::PrimitiveTopology::PointList:
115 return std::format_to(ctx.out(), "PointList");
116 case spark::render::PrimitiveTopology::LineList:
117 return std::format_to(ctx.out(), "LineList");
118 case spark::render::PrimitiveTopology::TriangleList:
119 return std::format_to(ctx.out(), "TriangleList");
120 case spark::render::PrimitiveTopology::LineStrip:
121 return std::format_to(ctx.out(), "LineStrip");
122 case spark::render::PrimitiveTopology::TriangleStrip:
123 return std::format_to(ctx.out(), "TriangleStrip");
124 }
125 return std::format_to(ctx.out(), "Unknown");
126 }
127};
Describes the layout of an index buffer.
Definition IndexBuffer.h:24
Definition InputAssembler.h:35
std::vector< const IVertexBufferLayout * > vertexBufferLayouts() const noexcept
Gets all vertex buffers layouts in the input assembly.
Definition InputAssembler.h:43
virtual const IIndexBufferLayout & indexBufferLayout() const =0
Gets the index buffer layout.
virtual const IVertexBufferLayout & vertexBufferLayout(unsigned int binding) const =0
Gets the vertex buffer layout for the given binding.
virtual PrimitiveTopology topology() const noexcept=0
Gets the topology of the input assembly.
Describes the layout of a vertex buffer.
Definition VertexBuffer.h:14
Represents a the input assembler state of a IRenderPipeline.
Definition InputAssembler.h:76
virtual std::vector< const VertexBufferLayoutType * > vertexBufferLayouts() const noexcept=0
Gets all vertex buffers layouts in the input assembly.