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