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 torus_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),
"checker_torus.oglpprog")};
gl.build_program(prog, prog_src.unpack(ec));
gl.use_program(prog);
gl.get_uniform_location(prog, "Camera") >> camera_loc;
}
void torus_program::clean_up(video_context& vc) {
auto& gl = vc.gl_api();
gl.delete_program(std::move(prog));
}
void torus_program::set_projection(video_context& vc, orbiting_camera& camera) {
if(camera.has_changed()) {
auto& gl = vc.gl_api();
gl.set_uniform(prog, camera_loc, camera.matrix(vc.surface_aspect()));
}
}
void torus_program::bind_position_location(
video_context& vc,
auto& gl = vc.gl_api();
gl.bind_attrib_location(prog, loc, "Position");
}
void torus_program::bind_normal_location(
video_context& vc,
auto& gl = vc.gl_api();
gl.bind_attrib_location(prog, loc, "Normal");
}
void torus_program::bind_texcoord_location(
video_context& vc,
auto& gl = vc.gl_api();
gl.bind_attrib_location(prog, loc, "TexCoord");
}
void torus_geometry::init(execution_context& ec, video_context& vc) {
const auto& glapi = vc.gl_api();
const auto& gl = glapi;
oglp::shape_generator shape(
glapi,
auto draw_var = shape.draw_variant(0);
ops.resize(
std_size(shape.operation_count(draw_var)));
shape.instructions(glapi, draw_var,
cover(ops));
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() >> normals;
shape.attrib_setup(
glapi,
vao,
normals,
normal_loc(),
ec.buffer());
gl.gen_buffers() >> texcoords;
shape.attrib_setup(
glapi,
vao,
texcoords,
texcoord_loc(),
ec.buffer());
gl.gen_buffers() >> indices;
shape.index_setup(glapi, indices, draw_var, ec.buffer());
}
void torus_geometry::clean_up(video_context& vc) {
const auto& gl = vc.gl_api();
gl.delete_buffers(std::move(indices));
gl.delete_buffers(std::move(texcoords));
gl.delete_buffers(std::move(normals));
gl.delete_buffers(std::move(positions));
gl.delete_vertex_arrays(std::move(vao));
}
void torus_geometry::draw(execution_context&, video_context& ec) {
}
}