@@ -190,15 +190,15 @@ void LightPathsLayer::slot_synchronize_camera()
190190
191191void LightPathsLayer::load_light_paths_data ()
192192{
193- m_index_offsets .clear ();
193+ m_path_terminator_vertex_indices .clear ();
194194 m_max_luminance = 0 .0f ;
195195 if (!m_light_paths.empty ())
196196 {
197- m_index_offsets .push_back (0 );
197+ m_path_terminator_vertex_indices .push_back (0 );
198198
199199 const auto & light_path_recorder = m_project.get_light_path_recorder ();
200200
201- GLsizei total_index_count = 0 ;
201+ m_total_triangle_count = 0 ;
202202
203203 // Vertex count * 4 since we will be adding two vertices for each point along the line and will
204204 // be adding each point twice for the beginning and end parts of each segment
@@ -301,10 +301,10 @@ void LightPathsLayer::load_light_paths_data()
301301 indices_scratch.begin (),
302302 indices_scratch.end ());
303303
304- total_index_count += 6 ;
304+ m_total_triangle_count += 6 ;
305305 prev = vert;
306306 }
307- m_index_offsets .push_back (total_index_count );
307+ m_path_terminator_vertex_indices .push_back (static_cast <GLsizei>(others_buffer. size ()) );
308308 }
309309
310310 // Add an empty vertex at the end to serve as last 'next'
@@ -359,6 +359,8 @@ void LightPathsLayer::init_gl(QSurfaceFormat format)
359359 m_max_luminance_loc = m_gl->glGetUniformLocation (m_shader_program, " u_max_luminance" );
360360 m_max_thickness_loc = m_gl->glGetUniformLocation (m_shader_program, " u_max_thickness" );
361361 m_min_thickness_loc = m_gl->glGetUniformLocation (m_shader_program, " u_min_thickness" );
362+ m_first_selected_loc = m_gl->glGetUniformLocation (m_shader_program, " u_first_selected" );
363+ m_last_selected_loc = m_gl->glGetUniformLocation (m_shader_program, " u_last_selected" );
362364
363365 const float z_near = 0 .01f ;
364366 const float z_far = 1000 .0f ;
@@ -510,8 +512,22 @@ void LightPathsLayer::render_scene(const GLfloat* gl_view_matrix) const
510512 if (!m_gl_initialized)
511513 return ;
512514
513- if (m_index_offsets. size () > 1 )
515+ if (m_total_triangle_count > 1 )
514516 {
517+ GLint first_selected;
518+ GLint last_selected;
519+ assert (m_selected_light_path_index >= -1 );
520+ if (m_selected_light_path_index == -1 )
521+ {
522+ first_selected = 0 ;
523+ last_selected = static_cast <GLint>(m_path_terminator_vertex_indices[m_path_terminator_vertex_indices.size () - 1 ]);
524+ }
525+ else
526+ {
527+ first_selected = static_cast <GLint>(m_path_terminator_vertex_indices[m_selected_light_path_index + 1 ]);
528+ last_selected = static_cast <GLint>(m_path_terminator_vertex_indices[m_selected_light_path_index + 2 ]);
529+ }
530+
515531 m_gl->glUseProgram (m_shader_program);
516532
517533 m_gl->glUniformMatrix4fv (
@@ -537,24 +553,18 @@ void LightPathsLayer::render_scene(const GLfloat* gl_view_matrix) const
537553 m_res_loc,
538554 (GLfloat)m_width,
539555 (GLfloat)m_height);
556+ m_gl->glUniform1i (
557+ m_first_selected_loc,
558+ first_selected);
559+ m_gl->glUniform1i (
560+ m_last_selected_loc,
561+ last_selected);
540562
541563 m_gl->glBindVertexArray (m_light_paths_vao);
542564
543- GLint first;
544- GLsizei count;
545- assert (m_selected_light_path_index >= -1 );
546- if (m_selected_light_path_index == -1 )
547- {
548- first = 0 ;
549- count = m_index_offsets[m_index_offsets.size () - 1 ] / 3 ;
550- }
551- else
552- {
553- first = static_cast <GLint>(m_index_offsets[m_selected_light_path_index]);
554- count = m_index_offsets[m_selected_light_path_index + 1 ] - first;
555- }
565+
556566 m_gl->glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, m_indices_ebo);
557- m_gl->glDrawElements (GL_TRIANGLES, count , GL_UNSIGNED_INT, reinterpret_cast < GLvoid*>(first * sizeof ( unsigned int ) ));
567+ m_gl->glDrawElements (GL_TRIANGLES, m_total_triangle_count , GL_UNSIGNED_INT, static_cast < const GLvoid*>(0 ));
558568 m_gl->glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0 );
559569 }
560570}
0 commit comments