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

application/000_stencil_shadow/resources.hpp

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
#include <oglplus/gl.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,
shapes::drawing_variant draw_var) noexcept
: _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());
for(auto i : integer_range(attribs.size())) {
const auto attrib_var = *(attribs.begin() + i);
_attrib_map[attrib_var] = i + 1;
gen.attrib_setup(
_gl_api,
_vao,
_buffers[i + 1],
vertex_attrib_location{limit_cast<gl_types::int_type>(i)},
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;
};
} // namespace eagine::oglp
//------------------------------------------------------------------------------
// program
//------------------------------------------------------------------------------
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);
void bind_position_location(video_context&, oglp::vertex_attrib_location);
void bind_normal_location(video_context&, oglp::vertex_attrib_location);
private:
oglp::uniform_location _projection_loc;
};
//------------------------------------------------------------------------------
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);
void bind_position_location(video_context&, oglp::vertex_attrib_location);
void bind_normal_location(video_context&, oglp::vertex_attrib_location);
private:
oglp::uniform_location _projection_loc;
oglp::uniform_location _camera_pos_loc;
};
//------------------------------------------------------------------------------
// geometry
//------------------------------------------------------------------------------
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;
};
//------------------------------------------------------------------------------
} // namespace eagine::application
#endif
Application harness / wrapper code is placed in this namespace.
Definition: eagine.hpp:72
prog_var_location< EAGINE_ID_V(Uniform)> uniform_location
Alias for shader program uniform location wrapper.
Definition: prog_var_loc.hpp:115
gl_object_name< vertex_array_tag > vertex_array_name
Alias for GL vertex array object handle.
Definition: object_name.hpp:163
static constexpr auto cover(T *addr, S size) noexcept -> span_if_mutable< T >
Creates a span starting at the specified pointer and specified length.
Definition: span.hpp:465
static constexpr auto std_size(T v) noexcept
Converts argument to std size type.
Definition: types.hpp:52
gl_owned_object_name< vertex_array_tag > owned_vertex_array_name
Alias for owned GL vertex array object handle.
Definition: object_name.hpp:224
prog_var_location< EAGINE_ID_V(VertexAttr)> vertex_attrib_location
Alias for program vertex attribute location wrapper.
Definition: prog_var_loc.hpp:104
span_size_t drawing_variant
Alias for shape drawing variant index type.
Definition: gen_base.hpp:31
integer_range(B, E) -> integer_range< std::common_type_t< B, E >>
Deduction guide for integer_range.
gl_owned_object_name< program_tag > owned_program_name
Alias for owned GL program object handle.
Definition: object_name.hpp:188

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