OGLplus  (0.59.0) a C++ wrapper for rendering APIs

generator.hpp
Go to the documentation of this file.
1 
9 #ifndef OGLPLUS_SHAPES_GENERATOR_HPP
10 #define OGLPLUS_SHAPES_GENERATOR_HPP
11 
12 #include "../gl_api.hpp"
13 #include "../math/primitives.hpp"
14 #include "drawing.hpp"
15 #include <eagine/memory/buffer.hpp>
18 #include <eagine/span.hpp>
19 #include <memory>
20 
21 namespace eagine::oglp {
22 //------------------------------------------------------------------------------
27 private:
29  std::shared_ptr<generator> _gen{};
30 
31 public:
32  template <typename A>
33  shape_generator(const basic_gl_api<A>&, std::shared_ptr<generator>);
34 
35  template <typename A, typename Gen>
36  shape_generator(const basic_gl_api<A>& api, std::shared_ptr<Gen> gen)
37  : shape_generator(api, std::shared_ptr<generator>(std::move(gen))) {}
38 
39  auto find_variant(shapes::vertex_attrib_kind attrib, string_view name) const
41  return _gen->find_variant(attrib, name);
42  }
43 
44  auto find_variant_or(
46  string_view name,
48  if(auto found{find_variant(attrib, name)}) {
49  return found;
50  }
51  return {attrib, index};
52  }
53 
54  auto draw_variant_count() const -> span_size_t {
55  return _gen->draw_variant_count();
56  }
57 
58  auto draw_variant(span_size_t index) -> shapes::drawing_variant {
59  return _gen->draw_variant(index);
60  }
61 
62  auto vertex_count() const -> span_size_t {
63  return _gen->vertex_count();
64  }
65 
66  auto values_per_vertex(shapes::vertex_attrib_variant vav) const
67  -> span_size_t {
68  return _gen->values_per_vertex(vav);
69  }
70 
71  auto value_count(shapes::vertex_attrib_variant vav) const -> span_size_t {
72  return vertex_count() * values_per_vertex(vav);
73  }
74 
75  template <typename A>
76  auto attrib_type(
77  const basic_gl_api<A>& api,
79  return translate(api, _gen->attrib_type(vav));
80  }
81 
82  template <typename A>
83  auto is_attrib_normalized(
84  const basic_gl_api<A>& api,
86  return translate(api, _gen->is_attrib_normalized(vav));
87  }
88 
89  auto attrib_type_size(shapes::vertex_attrib_variant vav) const
90  -> span_size_t {
91  return type_size(_gen->attrib_type(vav));
92  }
93 
94  auto attrib_data_block_size(shapes::vertex_attrib_variant vav) const
95  -> span_size_t {
96  return value_count(vav) * attrib_type_size(vav);
97  }
98 
99  void attrib_data(shapes::vertex_attrib_variant, memory::block data) const;
100 
101  auto is_indexed() const -> bool {
102  return _gen->index_count() > 0;
103  }
104 
105  auto index_count() const -> span_size_t {
106  return _gen->index_count();
107  }
108 
109  auto index_count(shapes::drawing_variant dv) const -> span_size_t {
110  return _gen->index_count(dv);
111  }
112 
113  auto index_type_size() const -> span_size_t {
114  return type_size(_gen->index_type());
115  }
116 
117  auto index_type_size(shapes::drawing_variant dv) const -> span_size_t {
118  return type_size(_gen->index_type(dv));
119  }
120 
121  auto index_data_block_size() const -> span_size_t {
122  return index_count() * index_type_size();
123  }
124 
125  auto index_data_block_size(shapes::drawing_variant dv) const
126  -> span_size_t {
127  return index_count(dv) * index_type_size(dv);
128  }
129 
130  void index_data(shapes::drawing_variant, memory::block data) const;
131  void index_data(memory::block data) const {
132  return index_data(0, data);
133  }
134 
135  auto operation_count() const -> span_size_t {
136  return _gen->operation_count();
137  }
138 
139  auto operation_count(shapes::drawing_variant dv) const -> span_size_t {
140  return _gen->operation_count(dv);
141  }
142 
143  auto operation_count(span<const shapes::drawing_variant> dvs) const
144  -> span_size_t;
145 
146  template <typename A>
147  void attrib_setup(
148  const basic_gl_api<A>& api,
149  vertex_array_name vao,
150  buffer_name buf,
152  shapes::vertex_attrib_variant attrib_variant,
153  memory::buffer& temp) const;
154 
155  template <typename A>
156  void index_setup(
157  const basic_gl_api<A>& api,
158  buffer_name buf,
160  memory::buffer& temp) const;
161 
162  template <typename A>
163  void index_setup(
164  const basic_gl_api<A>& api,
165  buffer_name buf,
166  memory::buffer& temp) const {
167  return index_setup(api, buf, 0, temp);
168  }
169 
170  template <typename A>
171  void index_setup(
172  const basic_gl_api<A>& api,
173  buffer_name buf,
174  span<const shapes::drawing_variant> dvs,
175  memory::buffer& temp) const;
176 
177  template <typename A>
178  void instructions(
179  const basic_gl_api<A>&,
181  span<shape_draw_operation>) const;
182 
183  template <typename A>
184  void instructions(
185  const basic_gl_api<A>& api,
186  span<shape_draw_operation> dest) const {
187  return instructions(api, 0, dest);
188  }
189 
190  template <typename A>
191  void instructions(
192  const basic_gl_api<A>&,
193  span<const shapes::drawing_variant> dvs,
194  span<shape_draw_subset>,
195  span<shape_draw_operation>) const;
196 
197  auto bounding_sphere() const -> sphere {
198  return _gen->bounding_sphere();
199  }
200 
201  auto ray_intersection(const line& ray) const -> optionally_valid<float> {
202  return _gen->ray_intersection(ray);
203  }
204 
205  auto ray_intersection(const optionally_valid<line>& opt_ray) const
207  if(opt_ray) {
208  return ray_intersection(extract(opt_ray));
209  }
210  return {};
211  }
212 };
213 //------------------------------------------------------------------------------
214 } // namespace eagine::oglp
215 
216 #include <oglplus/shapes/generator.inl>
217 
218 #endif // OGLPLUS_SHAPES_GENERATOR_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
static auto translate(std::shared_ptr< generator > gen, std::array< float, 3 > d) noexcept
Constructs instances of translated_gen modifier.
Definition: translated.hpp:41
Basic template for spheres in N-dimensional space.
Definition: primitives.hpp:122
Basic template for lines in N-dimensional space.
Definition: primitives.hpp:19
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
Interface for shape loaders or generators.
Definition: gen_base.hpp:35
Primary template for conditionally valid values.
Definition: decl.hpp:49
Class designating an vertex attribute variant in a shape generator.
Definition: vertex_attrib.hpp:104
Class wrapping a generic shape loader/generator, adapting it for GL.
Definition: generator.hpp:26
Wrapper for true, false GL enums.
Definition: enum_types.hpp:17
Non-owning wrapper for C-API opaque handle types.
Definition: handle.hpp:26
Reallocatable owning byte buffer.
Definition: buffer.hpp:22
Typed enumeration for GL data type constants.
Definition: enum_types.hpp:568
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
span_size_t drawing_variant
Alias for shape drawing variant index type.
Definition: gen_base.hpp:31
vertex_attrib_kind
Shape vertex attribute kind enumeration.
Definition: vertex_attrib.hpp:25
Combined wrapper for the GL API operations and constants.
Definition: basic_gl_api.hpp:27
auto type_size(const basic_gl_api< A > &, shapes::attrib_data_type) noexcept -> span_size_t
Returns the byte size of a shape attribute data type.

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).