Tech ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - Use vertex attributes and matrices in shaders.

Shader: flat - Camera target
This commit is contained in:
enricoturri1966 2022-02-28 12:39:00 +01:00
parent 5b1c9a34d6
commit d0511b332b

View File

@ -5777,54 +5777,58 @@ void GLCanvas3D::_render_view_toolbar() const
#if ENABLE_SHOW_CAMERA_TARGET #if ENABLE_SHOW_CAMERA_TARGET
void GLCanvas3D::_render_camera_target() void GLCanvas3D::_render_camera_target()
{ {
static const double half_length = 5.0; static const float half_length = 5.0f;
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
glsafe(::glLineWidth(2.0f)); glsafe(::glLineWidth(2.0f));
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
const Vec3d& target = wxGetApp().plater()->get_camera().get_target(); const Vec3f& target = wxGetApp().plater()->get_camera().get_target().cast<float>();
bool target_changed = !m_camera_target.target.isApprox(target); bool target_changed = !m_camera_target.target.isApprox(target.cast<double>());
m_camera_target.target = target; m_camera_target.target = target.cast<double>();
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
if (!m_camera_target.axis[i].is_initialized() || target_changed) { if (!m_camera_target.axis[i].is_initialized() || target_changed) {
m_camera_target.axis[i].reset(); m_camera_target.axis[i].reset();
GLModel::InitializationData init_data; GLModel::Geometry init_data;
GLModel::InitializationData::Entity entity; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
entity.type = GLModel::PrimitiveType::Lines; init_data.color = (i == X) ? ColorRGBA::X() : ((i == Y) ? ColorRGBA::Y() : ColorRGBA::Z());
entity.positions.reserve(2); init_data.reserve_vertices(2);
init_data.reserve_indices(2);
// vertices
if (i == X) { if (i == X) {
entity.positions.emplace_back(target.x() - half_length, target.y(), target.z()); init_data.add_vertex(Vec3f(target.x() - half_length, target.y(), target.z()));
entity.positions.emplace_back(target.x() + half_length, target.y(), target.z()); init_data.add_vertex(Vec3f(target.x() + half_length, target.y(), target.z()));
} }
else if (i == Y) { else if (i == Y) {
entity.positions.emplace_back(target.x(), target.y() - half_length, target.z()); init_data.add_vertex(Vec3f(target.x(), target.y() - half_length, target.z()));
entity.positions.emplace_back(target.x(), target.y() + half_length, target.z()); init_data.add_vertex(Vec3f(target.x(), target.y() + half_length, target.z()));
} }
else { else {
entity.positions.emplace_back(target.x(), target.y(), target.z() - half_length); init_data.add_vertex(Vec3f(target.x(), target.y(), target.z() - half_length));
entity.positions.emplace_back(target.x(), target.y(), target.z() + half_length); init_data.add_vertex(Vec3f(target.x(), target.y(), target.z() + half_length));
}
entity.normals.reserve(2);
for (size_t j = 0; j < 2; ++j) {
entity.normals.emplace_back(Vec3f::UnitZ());
} }
entity.indices.reserve(2); // indices
entity.indices.emplace_back(0); init_data.add_ushort_line(0, 1);
entity.indices.emplace_back(1);
init_data.entities.emplace_back(entity); m_camera_target.axis[i].init_from(std::move(init_data));
m_camera_target.axis[i].init_from(init_data);
m_camera_target.axis[i].set_color(-1, (i == X) ? ColorRGBA::X() : (i == Y) ? ColorRGBA::Y() : ColorRGBA::Z());
} }
} }
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
const Transform3d matrix = wxGetApp().plater()->get_camera().get_projection_view_matrix();
shader->set_uniform("projection_view_model_matrix", matrix);
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
m_camera_target.axis[i].render(); m_camera_target.axis[i].render();
} }