Go to the documentation of this file.
9 #ifndef EAGINE_SHAPES_GEN_BASE_HPP
10 #define EAGINE_SHAPES_GEN_BASE_HPP
12 #include "../assert.hpp"
13 #include "../compare.hpp"
14 #include "../integer_range.hpp"
15 #include "../interface.hpp"
16 #include "../math/primitives.hpp"
17 #include "../span.hpp"
18 #include "../types.hpp"
92 return {attrib, index};
243 return _caps.
has(cap);
247 return has(attrib) ? 1U : 0U;
255 EAGINE_ASSERT(vav.has_valid_index());
272 EAGINE_UNREACHABLE(
"Generator failed to get byte attribute values.");
276 EAGINE_UNREACHABLE(
"Generator failed to get int16 attribute values.");
280 EAGINE_UNREACHABLE(
"Generator failed to get int32 attribute values.");
284 EAGINE_UNREACHABLE(
"Generator failed to get uint16 attribute values.");
288 EAGINE_UNREACHABLE(
"Generator failed to get uint32 attribute values.");
292 EAGINE_UNREACHABLE(
"Generator failed to get float attribute values.");
311 : _attr_bits(attr_bits) {}
329 static inline auto operator+(
330 std::unique_ptr<generator>&& l,
331 std::unique_ptr<generator>&& r) noexcept
332 -> std::array<std::unique_ptr<generator>, 2> {
333 return {{std::move(l), std::move(r)}};
336 template <std::size_t N, std::size_t... I>
337 static inline auto _add_to_array(
338 std::array<std::unique_ptr<generator>, N>&& l,
339 std::unique_ptr<generator>&& r,
340 std::index_sequence<I...>) noexcept
341 -> std::array<std::unique_ptr<generator>, N + 1> {
342 return {{std::move(l[I])..., std::move(r)}};
345 template <std::
size_t N>
346 static inline auto operator+(
347 std::array<std::unique_ptr<generator>, N>&& l,
348 std::unique_ptr<generator>&& r) noexcept
349 -> std::array<std::unique_ptr<generator>, N + 1> {
350 return _add_to_array(
351 std::move(l), std::move(r), std::make_index_sequence<N>());
357 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
358 #include <eagine/shapes/gen_base.inl>
361 #endif // EAGINE_SHAPES_GEN_BASE_HPP
auto values_per_vertex(vertex_attrib_variant vav) -> span_size_t override
Returns the number of values per vertex for the specified variant.
Definition: gen_base.hpp:259
virtual auto is_enabled(generator_capability cap) noexcept -> bool=0
Indicates if the specified generator capability is enabled.
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
auto has(vertex_attrib_kind attrib) noexcept
Tests if the specified attribute is supported by this generator.
Definition: gen_base.hpp:41
bitfield< vertex_attrib_kind > vertex_attrib_bits
Alias for vertex_attrib_kind bitfield type.
Definition: vertex_attrib.hpp:85
Basic template for spheres in N-dimensional space.
Definition: primitives.hpp:122
auto draw_variant(span_size_t index) -> drawing_variant
Returns the identifier of the drawing variant at the specified index.
Definition: gen_base.hpp:131
Basic template for lines in N-dimensional space.
Definition: primitives.hpp:19
Common code is placed in this namespace.
Definition: eagine.hpp:21
void indices(drawing_variant, span< std::uint8_t > dest) override
Fetches the index data for the specified drawing variant.
virtual auto bounding_sphere() -> math::sphere< float, true >
Returns the bounding sphere for the generated shape.
auto variant_name(vertex_attrib_variant) -> string_view override
Returns the name of the specified attribute variant.
Definition: gen_base.hpp:250
auto operation_count()
Returns the number of drawing instructions for the default variant.
Definition: gen_base.hpp:179
void attrib_values(vertex_attrib_variant, span< std::int16_t >) override
Fetches the vertex attribute data for the specified variant as integers.
Definition: gen_base.hpp:275
virtual auto is_attrib_normalized(vertex_attrib_variant vav) -> bool=0
Indicates if the specified variant attribute values should be normalized.
virtual auto values_per_vertex(vertex_attrib_variant) -> span_size_t=0
Returns the number of values per vertex for the specified variant.
void attrib_values(vertex_attrib_variant, span< std::uint32_t >) override
Fetches the vertex attribute data for the specified variant as integers.
Definition: gen_base.hpp:287
Interface for shape loaders or generators.
Definition: gen_base.hpp:35
Primary template for conditionally valid values.
Definition: decl.hpp:49
constexpr auto has(bit_type bit) const noexcept
Tests if the specified bit is set.
Definition: bitfield.hpp:70
virtual void instructions(drawing_variant, span< draw_operation > dest)=0
Fetches the drawing operations for the specified drawing variant.
static auto attrib_values_per_vertex(vertex_attrib_kind attr) noexcept -> span_size_t
Gets the default number of values per vertex for an attribute kind.
Definition: vertex_attrib.hpp:258
auto is_enabled(generator_capability cap) noexcept -> bool final
Indicates if the specified generator capability is enabled.
Definition: gen_base.hpp:242
basic_span< T, T *, S > span
Default alias for basic memory spans with native pointer type.
Definition: span.hpp:415
virtual auto attribute_variants(vertex_attrib_kind) -> span_size_t=0
Returns the count of shape attribute variants.
auto ray_intersection(const math::line< float, true > &ray) -> optionally_valid< float >
Returns the parameter for the nearest intersection with a ray.
Definition: gen_base.hpp:217
Class designating an vertex attribute variant in a shape generator.
Definition: vertex_attrib.hpp:104
auto primitive_restart() noexcept -> bool
Indicates if primitive restart is enabled.
Definition: gen_base.hpp:68
auto attrib_bits() noexcept -> vertex_attrib_bits final
Returns the set of vertex attributes supported by this generator.
Definition: gen_base.hpp:229
bitfield< generator_capability > generator_capabilities
Alias for generator_capability bitfield type.
Definition: gen_capabilities.hpp:32
virtual auto variant_name(vertex_attrib_variant vav) -> string_view=0
Returns the name of the specified attribute variant.
Base template for abstract interfaces, implements common functionality.
Definition: interface.hpp:18
virtual void indices(drawing_variant, span< std::uint8_t > dest)=0
Fetches the index data for the specified drawing variant.
auto enable(generator_capability cap, bool value) noexcept -> bool final
Enables or disables the specified generator capability.
Definition: gen_base.hpp:233
auto strips_allowed() noexcept -> bool
Indicates if element strips are enabled.
Definition: gen_base.hpp:58
Common base implementation of the shape generator interface.
Definition: gen_base.hpp:227
void indices(span< std::uint16_t > dest)
Fetches the index data for the default drawing variant.
Definition: gen_base.hpp:163
auto disable(generator_capability cap) noexcept
Disables the specified generator capability.
Definition: gen_base.hpp:50
auto is_attrib_normalized(vertex_attrib_variant) -> bool override
Indicates if the specified variant attribute values should be normalized.
Definition: gen_base.hpp:267
generator_capability
Shape generator capability bit enumeration.
Definition: gen_capabilities.hpp:21
virtual auto attrib_type(vertex_attrib_variant vav) -> attrib_data_type=0
Returns the attribute data type for the specified variant.
virtual auto vertex_count() -> span_size_t=0
Returns the shaped vertex count.
@ element_strips
Line or triangle strips should be generated if possible.
span_size_t drawing_variant
Alias for shape drawing variant index type.
Definition: gen_base.hpp:31
@ primitive_restart
Primitive restart functionality should be used if possible.
auto ray_intersection(drawing_variant var, const math::line< float, true > &ray) -> optionally_valid< float >
Returns the parameter for the nearest intersection with a ray.
Definition: gen_base.hpp:209
@ element_fans
Line or triangle fanst should be generated if possible.
Base class for shape generators re-calculating the center.
Definition: gen_base.hpp:320
auto index_type() -> index_data_type
Returns the index data type for the default draw variant.
Definition: gen_base.hpp:139
void attrib_values(vertex_attrib_variant vav, span< float > dest) override
Fetches the vertex attribute data for the specified variant as floats.
virtual void ray_intersections(drawing_variant, span< const math::line< float, true >> rays, span< optionally_valid< float >> intersections)
Calculates the intersections of the shape geometry with a ray.
void attrib_values(vertex_attrib_variant, span< byte >) override
Fetches the vertex attribute data for the specified variant as bytes.
Definition: gen_base.hpp:271
void attrib_values(vertex_attrib_variant, span< float >) override
Fetches the vertex attribute data for the specified variant as floats.
Definition: gen_base.hpp:291
vertex_attrib_kind
Shape vertex attribute kind enumeration.
Definition: vertex_attrib.hpp:25
auto fans_allowed() noexcept -> bool
Indicates if element fans are enabled.
Definition: gen_base.hpp:63
virtual auto enable(generator_capability cap, bool value=true) noexcept -> bool=0
Enables or disables the specified generator capability.
void ray_intersections(span< const math::line< float, true >> rays, span< optionally_valid< float >> intersections)
Calculates the intersections of the shape geometry with a ray.
Definition: gen_base.hpp:201
virtual void attrib_values(vertex_attrib_variant, span< byte > dest)=0
Fetches the vertex attribute data for the specified variant as bytes.
attrib_data_type
Shape vertex attribute data type enumeration.
Definition: drawing.hpp:67
void instructions(span< draw_operation > dest)
Fetches the drawing operations for the default drawing variant.
Definition: gen_base.hpp:187
void attrib_values(vertex_attrib_variant, span< std::int32_t >) override
Fetches the vertex attribute data for the specified variant as integers.
Definition: gen_base.hpp:279
auto attribute_variants(vertex_attrib_kind attrib) -> span_size_t override
Returns the count of shape attribute variants.
Definition: gen_base.hpp:246
auto value_count(vertex_attrib_variant vav) -> span_size_t
Returns the total number of values for the specified attribute variant.
Definition: gen_base.hpp:99
auto attrib_type(vertex_attrib_variant) -> attrib_data_type override
Returns the attribute data type for the specified variant.
Definition: gen_base.hpp:263
auto draw_variant_count() -> span_size_t override
Returns the count of possible shape draw variants.
Definition: gen_base.hpp:295
integer_range(B, E) -> integer_range< std::common_type_t< B, E >>
Deduction guide for integer_range.
void indices(span< std::uint32_t > dest)
Fetches the index data for the default drawing variant.
Definition: gen_base.hpp:171
void indices(span< std::uint8_t > dest)
Fetches the index data for the default drawing variant.
Definition: gen_base.hpp:155
void attrib_values(vertex_attrib_variant, span< std::uint16_t >) override
Fetches the vertex attribute data for the specified variant as integers.
Definition: gen_base.hpp:283
virtual auto attrib_bits() noexcept -> vertex_attrib_bits=0
Returns the set of vertex attributes supported by this generator.
index_data_type
Shape element index type enumeration.
Definition: drawing.hpp:111
virtual auto draw_variant_count() -> span_size_t=0
Returns the count of possible shape draw variants.
auto find_variant(vertex_attrib_kind attrib, string_view name) -> vertex_attrib_variant
Finds attribute variant by kind and name.
Definition: gen_base.hpp:82
auto index_count()
Returns the index count for the default drawing variant.
Definition: gen_base.hpp:147