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"
void cubes_program::init(execution_context& ec, video_context& vc) {
auto& gl = vc.gl_api();
gl.create_program() >> prog;
gl.build_program(prog, prog_src.unpack(ec));
gl.use_program(prog);
gl.get_uniform_location(prog, "Camera") >> camera_loc;
gl.get_uniform_location(prog, "Center") >> center_loc;
gl.get_uniform_location(prog, "Time") >> time_loc;
gl.get_uniform_location(prog, "Edges") >> edges_loc;
}
void cubes_program::clean_up(video_context& vc) {
auto& gl = vc.gl_api();
gl.delete_program(std::move(prog));
}
void cubes_program::set_projection(video_context& vc, orbiting_camera& camera) {
if(camera.has_changed()) {
vc.gl_api().set_uniform(
prog, camera_loc, camera.matrix(vc.surface_aspect()));
}
}
void cubes_program::update(execution_context& ec, video_context& vc) {
const auto t = ec.state().frame_time().value();
const auto& glapi = vc.gl_api();
glapi.set_uniform(
prog,
center_loc,
glapi.set_uniform(prog, time_loc, t);
}
void cubes_program::bind_position_location(
video_context& vc,
vc.gl_api().bind_attrib_location(prog, loc, "Position");
}
void cubes_program::bind_pivot_location(
video_context& vc,
vc.gl_api().bind_attrib_location(prog, loc, "Pivot");
}
void cubes_program::bind_coord_location(
video_context& vc,
vc.gl_api().bind_attrib_location(prog, loc, "Coord");
}
void cubes_program::drawing_surface(video_context& vc) {
vc.gl_api().set_uniform(prog, edges_loc, 0.F);
}
void cubes_program::drawing_edges(video_context& vc) {
vc.gl_api().set_uniform(prog, edges_loc, 1.F);
}
void cubes_geometry::init(execution_context& ec, video_context& vc) {
const auto& glapi = vc.gl_api();
const auto& gl = glapi;
oglp::shape_generator shape(
glapi,
{1.F, 1.F, 1.F},
{10, 10, 10}))));
std::array<shapes::drawing_variant, 2> vars{
shape.draw_variant(0), shape.draw_variant(1)};
gl.gen_vertex_arrays() >> vao;
gl.bind_vertex_array(vao);
gl.gen_buffers() >> positions;
shape.attrib_setup(
glapi,
vao,
positions,
position_loc(),
ec.buffer());
gl.gen_buffers() >> pivots;
shape.attrib_setup(
glapi,
vao,
pivots,
pivot_loc(),
ec.buffer());
gl.gen_buffers() >> coords;
shape.attrib_setup(
glapi,
vao,
coords,
coord_loc(),
ec.buffer());
gl.gen_buffers() >> indices;
shape.index_setup(glapi, indices,
view(vars), ec.buffer());
}
void cubes_geometry::clean_up(video_context& vc) {
auto& gl = vc.gl_api();
gl.delete_buffers(std::move(indices));
gl.delete_buffers(std::move(coords));
gl.delete_buffers(std::move(pivots));
gl.delete_buffers(std::move(positions));
gl.delete_vertex_arrays(std::move(vao));
}
void cubes_geometry::draw_surface(video_context& vc) {
}
void cubes_geometry::draw_edges(video_context& vc) {
}
}