9 #ifndef OGLPLUS_EXAMPLE_RESOURCES_HPP // NOLINT(llvm-header-guard)
10 #define OGLPLUS_EXAMPLE_RESOURCES_HPP
22 namespace eagine::oglp {
24 template <
typename ApiTraits>
28 basic_gl_api<ApiTraits>& glapi,
29 memory::buffer& scratch_space,
30 const std::shared_ptr<shapes::generator>& base_gen,
31 std::initializer_list<shapes::vertex_attrib_variant> attribs,
34 , _buffers{attribs.size() + 1} {
35 shape_generator gen(_gl_api, base_gen);
37 _gl_api.gen_vertex_arrays() >> _vao;
38 _gl_api.bind_vertex_array(_vao);
40 _gl_api.gen_buffers(_buffers);
42 gen.index_setup(glapi, _buffers[0], draw_var, scratch_space);
44 _attrib_map.reserve(attribs.size());
46 const auto attrib_var = *(attribs.begin() + i);
47 _attrib_map[attrib_var] = i + 1;
57 _ops.resize(
std_size(gen.operation_count(draw_var)));
58 gen.instructions(_gl_api, draw_var,
cover(_ops));
61 basic_shape(basic_shape&&) noexcept = default;
62 basic_shape(const basic_shape&) = delete;
63 auto operator=(basic_shape&&) = delete;
64 auto operator=(const basic_shape&) = delete;
66 ~basic_shape() noexcept {}
68 auto attrib_location(shapes::vertex_attrib_variant attrib_var)
const noexcept
70 if(
auto pos = _attrib_map.find(attrib_var); pos != _attrib_map.end()) {
72 limit_cast<gl_types::int_type>(pos->second)};
78 basic_gl_api<ApiTraits>& _gl_api;
79 flat_map<shapes::vertex_attrib_variant, std::size_t> _attrib_map;
80 std::vector<oglp::shape_draw_operation> _ops;
82 gl_object_name_vector<buffer_tag> _buffers;
85 template <
typename ApiTraits>
86 class basic_baked_program {
88 basic_baked_program(basic_gl_api<ApiTraits>& glapi) noexcept
92 basic_gl_api<ApiTraits>& _gl_api;
101 class surface_program {
103 void init(execution_context&, video_context&);
104 void clean_up(video_context&);
105 void prepare_frame(video_context&, orbiting_camera& camera,
float t);
119 void init(execution_context&, video_context&);
120 void clean_up(video_context&);
121 void prepare_frame(video_context&, orbiting_camera& camera,
float t);
136 class shape_geometry {
138 shape_geometry(std::shared_ptr<shapes::generator> gen)
139 : _gen{std::move(gen)} {}
141 void init(execution_context&, video_context&);
142 void clean_up(video_context&);
143 void draw(execution_context&, video_context&);
145 static auto position_loc() noexcept {
149 static auto normal_loc() noexcept {
154 std::shared_ptr<shapes::generator> _gen;
157 oglp::owned_buffer_name _positions;
158 oglp::owned_buffer_name _normals;
159 oglp::owned_buffer_name _indices;
161 std::vector<oglp::shape_draw_operation> _ops;