sandbox
Loading...
Searching...
No Matches
vertex_stream.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_MODELS_VERTEX_STREAM_HPP_
3#define LIBSBX_MODELS_VERTEX_STREAM_HPP_
4
5#include <array>
6#include <cstdint>
7#include <optional>
8#include <string_view>
9
10#include <libsbx/utility/enum.hpp>
11
12#include <libsbx/reflection/description.hpp>
13
14namespace sbx::models {
15
16enum class vertex_stream : std::uint8_t {
17 none = 0,
18 color = utility::bit_v<0>,
19 custom0 = utility::bit_v<1>,
20 custom1 = utility::bit_v<2>,
21 custom2 = utility::bit_v<3>,
22 custom3 = utility::bit_v<4>
23}; // enum class vertex_stream
24
25inline constexpr auto operator|(const vertex_stream lhs, const vertex_stream rhs) -> vertex_stream {
26 return static_cast<vertex_stream>(static_cast<std::uint8_t>(lhs) | static_cast<std::uint8_t>(rhs));
27}
28
29inline constexpr auto vertex_stream_count = std::size_t{5u};
30
31inline constexpr auto vertex_stream_element_size = std::uint32_t{16u};
32
34 vertex_stream value;
35 std::string_view name;
36 std::string_view push_name;
37 std::string_view define;
38}; // struct vertex_stream_descriptor
39
40inline constexpr auto vertex_stream_descriptors = std::array<vertex_stream_descriptor, vertex_stream_count>{
41 vertex_stream_descriptor{vertex_stream::color, "color", "color_buffer", "VERTEX_STREAM_COLOR"},
42 vertex_stream_descriptor{vertex_stream::custom0, "custom0", "custom0_buffer", "VERTEX_STREAM_CUSTOM0"},
43 vertex_stream_descriptor{vertex_stream::custom1, "custom1", "custom1_buffer", "VERTEX_STREAM_CUSTOM1"},
44 vertex_stream_descriptor{vertex_stream::custom2, "custom2", "custom2_buffer", "VERTEX_STREAM_CUSTOM2"},
45 vertex_stream_descriptor{vertex_stream::custom3, "custom3", "custom3_buffer", "VERTEX_STREAM_CUSTOM3"}
46};
47
48inline constexpr auto vertex_stream_index(const vertex_stream stream) -> std::optional<std::uint32_t> {
49 for (auto i = std::uint32_t{0u}; i < static_cast<std::uint32_t>(vertex_stream_descriptors.size()); ++i) {
50 if (vertex_stream_descriptors[i].value == stream) {
51 return i;
52 }
53 }
54
55 return std::nullopt;
56}
57
58} // namespace sbx::models
59
60template<>
61struct sbx::utility::is_bit_field<sbx::models::vertex_stream> : std::true_type { };
62
63template<>
64struct sbx::reflection::description<sbx::models::vertex_stream> {
65
66 static constexpr auto name() -> std::string_view {
67 return "vertex_stream";
68 }
69
70 static constexpr auto enumerators() {
71 return std::make_tuple(
72 enumerator{"none", sbx::models::vertex_stream::none},
73 enumerator{"color", sbx::models::vertex_stream::color},
74 enumerator{"custom0", sbx::models::vertex_stream::custom0},
75 enumerator{"custom1", sbx::models::vertex_stream::custom1},
76 enumerator{"custom2", sbx::models::vertex_stream::custom2},
77 enumerator{"custom3", sbx::models::vertex_stream::custom3}
78 );
79 }
80
81}; // struct sbx::reflection::description<sbx::graphics::vertex_stream>
82
83#endif // LIBSBX_MODELS_VERTEX_STREAM_HPP_
Definition: vertex_stream.hpp:33
Definition: description.hpp:16
Definition: enumerator.hpp:10
Definition: enum.hpp:29