Copyright Matus Chochlik. Distributed under the Boost Software License, Version 1.0. See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
#ifndef OGLPLUS_EXAMPLE_RESOURCES_HPP // NOLINT(llvm-header-guard)
#define OGLPLUS_EXAMPLE_RESOURCES_HPP
namespace eagine::oglp {
template <typename ApiTraits>
class basic_shape {
public:
basic_shape(
basic_gl_api<ApiTraits>& glapi,
memory::buffer& scratch_space,
const std::shared_ptr<shapes::generator>& base_gen,
std::initializer_list<shapes::vertex_attrib_variant> attribs,
: _gl_api{glapi}
, _buffers{attribs.size() + 1} {
shape_generator gen(_gl_api, base_gen);
_gl_api.gen_vertex_arrays() >> _vao;
_gl_api.bind_vertex_array(_vao);
_gl_api.gen_buffers(_buffers);
gen.index_setup(glapi, _buffers[0], draw_var, scratch_space);
_attrib_map.reserve(attribs.size());
const auto attrib_var = *(attribs.begin() + i);
_attrib_map[attrib_var] = i + 1;
gen.attrib_setup(
_gl_api,
_vao,
_buffers[i + 1],
attrib_var,
scratch_space);
}
_ops.resize(
std_size(gen.operation_count(draw_var)));
gen.instructions(_gl_api, draw_var,
cover(_ops));
}
basic_shape(basic_shape&&) noexcept = default;
basic_shape(const basic_shape&) = delete;
auto operator=(basic_shape&&) = delete;
auto operator=(const basic_shape&) = delete;
~basic_shape() noexcept {}
auto attrib_location(shapes::vertex_attrib_variant attrib_var) const noexcept
if(auto pos = _attrib_map.find(attrib_var); pos != _attrib_map.end()) {
limit_cast<gl_types::int_type>(pos->second)};
}
return {};
}
private:
basic_gl_api<ApiTraits>& _gl_api;
flat_map<shapes::vertex_attrib_variant, std::size_t> _attrib_map;
std::vector<oglp::shape_draw_operation> _ops;
gl_object_name_vector<buffer_tag> _buffers;
};
template <typename ApiTraits>
class basic_baked_program {
public:
basic_baked_program(basic_gl_api<ApiTraits>& glapi) noexcept
: _gl_api{glapi} {}
private:
basic_gl_api<ApiTraits>& _gl_api;
};
}
class surface_program {
public:
void init(execution_context&, video_context&);
void clean_up(video_context&);
void prepare_frame(video_context&, orbiting_camera& camera, float t);
private:
};
class halo_program {
public:
void init(execution_context&, video_context&);
void clean_up(video_context&);
void prepare_frame(video_context&, orbiting_camera& camera, float t);
private:
};
class shape_geometry {
public:
shape_geometry(std::shared_ptr<shapes::generator> gen)
: _gen{std::move(gen)} {}
void init(execution_context&, video_context&);
void clean_up(video_context&);
void draw(execution_context&, video_context&);
static auto position_loc() noexcept {
}
static auto normal_loc() noexcept {
}
private:
std::shared_ptr<shapes::generator> _gen;
oglp::owned_buffer_name _positions;
oglp::owned_buffer_name _normals;
oglp::owned_buffer_name _indices;
std::vector<oglp::shape_draw_operation> _ops;
};
}
#endif