Drawable Points
Drawable Points
#include <easy3d/viewer/drawable_points.h>
#include <easy3d/viewer/camera.h>
#include <easy3d/viewer/shader_program.h>
#include <easy3d/viewer/shader_manager.h>
#include <easy3d/viewer/texture.h>
#include <easy3d/viewer/setting.h>
#include <easy3d/viewer/opengl.h>
#include <easy3d/viewer/opengl_error.h>
#include <easy3d/viewer/clipping_plane.h>
#include <easy3d/util/logging.h>
namespace easy3d {
case SPHERE:
#if 0
if (use_texture_ && texture_)
_draw_spheres_with_texture_sprite(camera,
with_storage_buffer);
else
_draw_spheres_sprite(camera, with_storage_buffer);
#else
if (use_texture_ && texture_)
_draw_spheres_with_texture_geometry(camera,
with_storage_buffer);
else
_draw_spheres_geometry(camera, with_storage_buffer);
#endif
break;
case SURFEL:
if (use_texture_ && texture_)
_draw_surfels_with_texture(camera, with_storage_buffer);
else
_draw_surfels(camera, with_storage_buffer);
break;
}
}
ShaderProgram *program =
ShaderManager::get_program("points/points_plain_color");
if (!program) {
std::vector<ShaderProgram::Attribute> attributes;
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::POSITION,
"vtx_position"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::COLOR,
"vtx_color"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::NORMAL,
"vtx_normal"));
program =
ShaderManager::create_program_from_files("points/points_plain_color",
attributes);
}
if (!program)
return;
glPointSize(point_size());
program->bind();
program->set_uniform("MVP", MVP)
->set_uniform("lighting", normal_buffer() && lighting())
->set_uniform("two_sides_lighting", lighting_two_sides())
->set_uniform("wLightPos", wLightPos)
->set_uniform("wCamPos", wCamPos)
->set_uniform("per_vertex_color", per_vertex_color() &&
color_buffer())
->set_uniform("default_color", default_color())
->set_uniform("distinct_back_color", distinct_back_color())
->set_uniform("backside_color", back_color())
->set_block_uniform("Material", "ambient", material().ambient)
->set_block_uniform("Material", "specular", material().specular)
->set_block_uniform("Material", "shininess",
&material().shininess);
if (setting::clipping_plane)
setting::clipping_plane->set_program(program);
gl_draw(with_storage_buffer);
program->release();
}
ShaderProgram *program =
ShaderManager::get_program("points/points_spheres_sprite_color");
if (!program) {
std::vector<ShaderProgram::Attribute> attributes;
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::POSITION,
"vtx_position"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::COLOR,
"vtx_color"));
program =
ShaderManager::create_program_from_files("points/points_spheres_sprite_color",
attributes);
}
if (!program)
return;
easy3d_debug_log_gl_error;
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); // starting from GL3.2, using
GL_PROGRAM_POINT_SIZE
program->bind();
program->set_uniform("perspective", camera->type() ==
Camera::PERSPECTIVE)
->set_uniform("MV", camera->modelViewMatrix())
->set_uniform("PROJ", camera->projectionMatrix())
->set_uniform("screen_width", camera->screenWidth());
if (setting::clipping_plane)
setting::clipping_plane->set_program(program);
gl_draw(with_storage_buffer);
program->release();
ShaderProgram *program =
ShaderManager::get_program("points/points_spheres_geometry_color");
if (!program) {
std::vector<ShaderProgram::Attribute> attributes;
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::POSITION,
"vtx_position"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::COLOR,
"vtx_color"));
program =
ShaderManager::create_program_from_files("points/points_spheres_geometry_color",
attributes,
std::vector<std::string>(), true);
}
if (!program)
return;
easy3d_debug_log_gl_error;
program->bind();
program->set_uniform("perspective", camera->type() ==
Camera::PERSPECTIVE)
->set_uniform("MV", camera->modelViewMatrix())
->set_uniform("PROJ", camera->projectionMatrix());
if (setting::clipping_plane)
setting::clipping_plane->set_program(program);
gl_draw(with_storage_buffer);
program->release();
}
ShaderProgram *program =
ShaderManager::get_program("points/points_plain_texture");
if (!program) {
std::vector<ShaderProgram::Attribute> attributes;
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::POSITION,
"vtx_position"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::TEXCOORD,
"vtx_texcoord"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::NORMAL,
"vtx_normal"));
program =
ShaderManager::create_program_from_files("points/points_plain_texture",
attributes);
}
if (!program)
return;
glPointSize(point_size());
program->bind();
program->set_uniform("MVP", MVP)
->set_uniform("lighting", normal_buffer() && lighting())
->set_uniform("two_sides_lighting", lighting_two_sides())
->set_uniform("wLightPos", wLightPos)
->set_uniform("wCamPos", wCamPos)
->set_uniform("distinct_back_color", distinct_back_color())
->set_uniform("backside_color", back_color())
->set_block_uniform("Material", "ambient", material().ambient)
->set_block_uniform("Material", "specular", material().specular)
->set_block_uniform("Material", "shininess",
&material().shininess)
->set_uniform("highlight", highlight())
->set_uniform("hightlight_id_min", highlight_range_.first)
->set_uniform("hightlight_id_max", highlight_range_.second)
->bind_texture("textureID", texture()->id(), 0);
if (setting::clipping_plane)
setting::clipping_plane->set_program(program);
gl_draw(with_storage_buffer);
program->release_texture();
program->release();
}
ShaderProgram *program =
ShaderManager::get_program("points/points_spheres_geometry_texture");
if (!program) {
std::vector<ShaderProgram::Attribute> attributes;
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::POSITION,
"vtx_position"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::TEXCOORD,
"vtx_texcoord"));
program =
ShaderManager::create_program_from_files("points/points_spheres_geometry_texture
", attributes,
std::vector<std::string>(), true);
}
if (!program)
return;
easy3d_debug_log_gl_error;
program->bind();
program->set_uniform("perspective", camera->type() ==
Camera::PERSPECTIVE)
->set_uniform("MV", camera->modelViewMatrix())
->set_uniform("PROJ", camera->projectionMatrix());
program->set_uniform("highlight", highlight())
->set_uniform("hightlight_id_min", highlight_range_.first)
->set_uniform("hightlight_id_max", highlight_range_.second);
if (setting::clipping_plane)
setting::clipping_plane->set_program(program);
program->release();
}
ShaderProgram *program =
ShaderManager::get_program("points/points_surfel_color");
if (!program) {
std::vector<ShaderProgram::Attribute> attributes;
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::POSITION,
"vtx_position"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::NORMAL,
"vtx_normal"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::COLOR,
"vtx_color"));
program =
ShaderManager::create_program_from_files("points/points_surfel_color",
attributes,
std::vector<std::string>(), true);
}
if (!program)
return;
easy3d_debug_log_gl_error;
program->bind();
program->set_uniform("MVP", MVP)
->set_uniform("per_vertex_color", per_vertex_color() &&
color_buffer())
->set_uniform("default_color", default_color());
program->set_uniform("highlight", highlight())
->set_uniform("hightlight_id_min", highlight_range_.first)
->set_uniform("hightlight_id_max", highlight_range_.second);
if (setting::clipping_plane)
setting::clipping_plane->set_program(program);
gl_draw(with_storage_buffer);
program->release();
}
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::POSITION,
"vtx_position"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::NORMAL,
"vtx_normal"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::TEXCOORD,
"vtx_texcoord"));
program =
ShaderManager::create_program_from_files("points/points_surfel_texture",
attributes,
std::vector<std::string>(), true);
}
if (!program)
return;
easy3d_debug_log_gl_error;
program->bind();
program->set_uniform("MVP", MVP);
program->set_uniform("highlight", highlight())
->set_uniform("hightlight_id_min", highlight_range_.first)
->set_uniform("hightlight_id_max", highlight_range_.second);
if (setting::clipping_plane)
setting::clipping_plane->set_program(program);
program->release();
}