Tech ENABLE_GL_CORE_PROFILE - Fixed rendering of circle cursor with dashed lines in GLGizmoPainterBase
This commit is contained in:
parent
8f40270f93
commit
3928c5c01c
2 changed files with 33 additions and 20 deletions
|
@ -182,7 +182,12 @@ void GLGizmoPainterBase::render_cursor_circle()
|
|||
const float cnv_inv_height = 1.0f / cnv_height;
|
||||
|
||||
const Vec2d center = m_parent.get_local_mouse_position();
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
const float zoom = float(wxGetApp().plater()->get_camera().get_zoom());
|
||||
const float radius = m_cursor_radius * zoom;
|
||||
#else
|
||||
const float radius = m_cursor_radius * float(wxGetApp().plater()->get_camera().get_zoom());
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
#else
|
||||
const float cnv_half_width = 0.5f * float(cnv_size.get_width());
|
||||
const float cnv_half_height = 0.5f * float(cnv_size.get_height());
|
||||
|
@ -220,44 +225,45 @@ void GLGizmoPainterBase::render_cursor_circle()
|
|||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (!m_circle.is_initialized() || std::abs(m_old_cursor_radius - radius) > EPSILON) {
|
||||
m_old_cursor_radius = radius;
|
||||
m_circle.reset();
|
||||
#else
|
||||
if (!m_circle.is_initialized() || !m_old_center.isApprox(center) || std::abs(m_old_cursor_radius - radius) > EPSILON) {
|
||||
m_old_cursor_radius = radius;
|
||||
m_old_center = center;
|
||||
m_circle.reset();
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
||||
GLModel::Geometry init_data;
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
const unsigned int StepsCount = (unsigned int)(2 * (4 + int(252 * (zoom - 1.0f) / (250.0f - 1.0f))));
|
||||
const float StepSize = 2.0f * float(PI) / float(StepsCount);
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P2 };
|
||||
#else
|
||||
static const unsigned int StepsCount = 32;
|
||||
static const float StepSize = 2.0f * float(PI) / float(StepsCount);
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P4 };
|
||||
#else
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2 };
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
init_data.color = { 0.0f, 1.0f, 0.3f, 1.0f };
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
init_data.reserve_vertices(2 * StepsCount);
|
||||
init_data.reserve_indices(2 * StepsCount);
|
||||
#else
|
||||
init_data.reserve_vertices(StepsCount);
|
||||
init_data.reserve_indices(StepsCount);
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
||||
// vertices + indices
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
float perimeter = 0.0f;
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
||||
for (unsigned int i = 0; i < StepsCount; ++i) {
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (i % 2 != 0) continue;
|
||||
|
||||
const float angle_i = float(i) * StepSize;
|
||||
const unsigned int j = (i + 1) % StepsCount;
|
||||
const float angle_j = float(j) * StepSize;
|
||||
const Vec2d v_i(2.0f * ((center.x() + ::cos(angle_i) * radius) * cnv_inv_width - 0.5f), -2.0f * ((center.y() + ::sin(angle_i) * radius) * cnv_inv_height - 0.5f));
|
||||
const Vec2d v_j(2.0f * ((center.x() + ::cos(angle_j) * radius) * cnv_inv_width - 0.5f), -2.0f * ((center.y() + ::sin(angle_j) * radius) * cnv_inv_height - 0.5f));
|
||||
init_data.add_vertex(Vec4f(v_i.x(), v_i.y(), 0.0f, perimeter));
|
||||
perimeter += (v_j - v_i).norm();
|
||||
init_data.add_vertex(Vec4f(v_j.x(), v_j.y(), 0.0f, perimeter));
|
||||
init_data.add_line(i * 2 + 0, i * 2 + 1);
|
||||
const Vec2d v_i(::cos(angle_i), ::sin(angle_i));
|
||||
const Vec2d v_j(::cos(angle_j), ::sin(angle_j));
|
||||
init_data.add_vertex(Vec2f(v_i.x(), v_i.y()));
|
||||
init_data.add_vertex(Vec2f(v_j.x(), v_j.y()));
|
||||
const size_t vcount = init_data.vertices_count();
|
||||
init_data.add_line(vcount - 2, vcount - 1);
|
||||
#else
|
||||
const float angle = float(i) * StepSize;
|
||||
init_data.add_vertex(Vec2f(2.0f * ((center.x() + ::cos(angle) * radius) * cnv_inv_width - 0.5f),
|
||||
|
@ -276,14 +282,19 @@ void GLGizmoPainterBase::render_cursor_circle()
|
|||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
if (shader != nullptr) {
|
||||
shader->start_using();
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
const Transform3d view_model_matrix = Geometry::translation_transform(Vec3d(2.0f * (center.x() * cnv_inv_width - 0.5f), -2.0f * (center.y() * cnv_inv_height - 0.5f), 0.0)) *
|
||||
Geometry::scale_transform(Vec3d(2.0f * radius * cnv_inv_width, 2.0f * radius * cnv_inv_height, 1.0f));
|
||||
shader->set_uniform("view_model_matrix", view_model_matrix);
|
||||
#else
|
||||
shader->set_uniform("view_model_matrix", Transform3d::Identity());
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
shader->set_uniform("projection_matrix", Transform3d::Identity());
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
const std::array<int, 4>& viewport = wxGetApp().plater()->get_camera().get_viewport();
|
||||
shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3])));
|
||||
shader->set_uniform("width", 0.25f);
|
||||
shader->set_uniform("dash_size", 0.01f);
|
||||
shader->set_uniform("gap_size", 0.0075f);
|
||||
shader->set_uniform("gap_size", 0.0f);
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
m_circle.render();
|
||||
shader->stop_using();
|
||||
|
|
|
@ -210,7 +210,9 @@ protected:
|
|||
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
GLModel m_circle;
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
Vec2d m_old_center{ Vec2d::Zero() };
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
float m_old_cursor_radius{ 0.0f };
|
||||
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue