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

application/021_cel_shading/resources.cpp

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

#include "resources.hpp"
#include <eagine/embed.hpp>
//------------------------------------------------------------------------------
// program
//------------------------------------------------------------------------------
void cel_program::init(execution_context& ec, video_context& vc) {
auto& gl = vc.gl_api();
gl.create_program() >> prog;
const auto prog_src{embed(EAGINE_ID(prog), "cel_shading.oglpprog")};
gl.build_program(prog, prog_src.unpack(ec));
gl.use_program(prog);
gl.get_uniform_location(prog, "Projection") >> projection_loc;
gl.get_uniform_location(prog, "Modelview") >> modelview_loc;
}
//------------------------------------------------------------------------------
void cel_program::clean_up(video_context& vc) {
auto& gl = vc.gl_api();
gl.delete_program(std::move(prog));
}
//------------------------------------------------------------------------------
void cel_program::set_projection(video_context& vc, orbiting_camera& camera) {
if(camera.has_changed()) {
vc.gl_api().set_uniform(prog, projection_loc, camera.matrix(vc));
}
}
//------------------------------------------------------------------------------
void cel_program::set_modelview(execution_context& ec, video_context& vc) {
shp_turns += 0.1F * ec.state().frame_duration().value();
vc.gl_api().set_uniform(
prog,
modelview_loc,
oglp::matrix_rotation_x(turns_(shp_turns) / 1) *
oglp::matrix_rotation_y(turns_(shp_turns) / 2) *
oglp::matrix_rotation_z(turns_(shp_turns) / 3));
}
//------------------------------------------------------------------------------
void cel_program::bind_position_location(
video_context& vc,
vc.gl_api().bind_attrib_location(prog, loc, "Position");
}
//------------------------------------------------------------------------------
// geometry
//------------------------------------------------------------------------------
void icosahedron_geometry::init(execution_context& ec, video_context& vc) {
const auto& glapi = vc.gl_api();
const auto& gl = glapi;
oglp::shape_generator shape(
ops.resize(std_size(shape.operation_count()));
shape.instructions(glapi, cover(ops));
// vao
gl.gen_vertex_arrays() >> vao;
gl.bind_vertex_array(vao);
// positions
gl.gen_buffers() >> positions;
shape.attrib_setup(
glapi,
vao,
positions,
position_loc(),
ec.buffer());
// indices
gl.gen_buffers() >> indices;
shape.index_setup(glapi, indices, ec.buffer());
}
//------------------------------------------------------------------------------
void icosahedron_geometry::clean_up(video_context& vc) {
auto& gl = vc.gl_api();
gl.delete_buffers(std::move(indices));
gl.delete_buffers(std::move(positions));
gl.delete_vertex_arrays(std::move(vao));
}
//------------------------------------------------------------------------------
void icosahedron_geometry::draw(video_context& vc) {
draw_using_instructions(vc.gl_api(), view(ops));
}
//------------------------------------------------------------------------------
} // namespace eagine::application
Application harness / wrapper code is placed in this namespace.
Definition: eagine.hpp:72
#define EAGINE_ID(NAME)
Macro for constructing instances of eagine::identifier.
Definition: identifier.hpp:353
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
convertible_matrix_constructor< rotation_x< matrix< T, 4, 4, true, V > >> matrix_rotation_x
Alias for constructor of rotation along x-axis transformation matrix.
Definition: matrix_rotation.hpp:124
static constexpr auto view(T *addr, S size) noexcept -> const_span< T >
Creates a view starting at the specified pointer and specified length.
Definition: span.hpp:458
static constexpr auto std_size(T v) noexcept
Converts argument to std size type.
Definition: types.hpp:52
prog_var_location< EAGINE_ID_V(VertexAttr)> vertex_attrib_location
Alias for program vertex attribute location wrapper.
Definition: prog_var_loc.hpp:104
static constexpr auto turns_(T value) noexcept
Creates a tagged quantity in full turn units.
Definition: quantities.hpp:82
convertible_matrix_constructor< rotation_z< matrix< T, 4, 4, true, V > >> matrix_rotation_z
Alias for constructor of rotation along z-axis transformation matrix.
Definition: matrix_rotation.hpp:152
static auto unit_icosahedron(vertex_attrib_bits attr_bits)
Constructs instances of unit_icosahedron_gen.
Definition: icosahedron.hpp:71
void draw_using_instructions(const basic_gl_api< A > &api, span< const shape_draw_operation > ops) noexcept
Takes a sequence of draw operations from a shape generator and draws them.
convertible_matrix_constructor< rotation_y< matrix< T, 4, 4, true, V > >> matrix_rotation_y
Alias for constructor of rotation along y-axis transformation matrix.
Definition: matrix_rotation.hpp:138
static auto embed(identifier res_id, string_view src_path) noexcept -> embedded_resource
Triggers the embedding of data from a file on the specified path.
Definition: embed.hpp:105

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