@@ -276,7 +276,6 @@ void OpenGLWidget::renderScene() {
276
276
// for every program (key) a vector with objects is stored
277
277
for (const auto & obj_group : object_tree) {
278
278
glUseProgram (obj_group.first );
279
- size_t instance_count = 0 ;
280
279
281
280
for (const size_t & obj_idx : obj_group.second ) {
282
281
const ObjectInfo& obj = scene_info[obj_idx];
@@ -296,18 +295,17 @@ void OpenGLWidget::renderScene() {
296
295
}
297
296
298
297
if (obj.enabled ) {
299
- if (obj.number_instances > 0 ) { // instanced rendering
298
+ if (obj.drawInstanced ) { // instanced rendering
300
299
glDrawElementsInstancedBaseVertexBaseInstance (
301
300
obj.gl_draw_mode , static_cast <GLint>(obj.number_elements ), GL_UNSIGNED_SHORT,
302
301
(void *)(obj.offset ), static_cast <GLsizei>(obj.number_instances ),
303
- static_cast <GLint>(obj.base_index ), static_cast <GLint>(instance_count ));
302
+ static_cast <GLint>(obj.base_index ), static_cast <GLint>(obj. base_instance ));
304
303
} else { // direct rendering with elements
305
304
glDrawElementsBaseVertex (obj.gl_draw_mode , static_cast <GLint>(obj.number_elements ),
306
305
GL_UNSIGNED_SHORT, (void *)(obj.offset ),
307
306
static_cast <GLint>(obj.base_index ));
308
307
}
309
308
}
310
- instance_count += obj.number_instances ;
311
309
}
312
310
}
313
311
@@ -380,13 +378,21 @@ void OpenGLWidget::recalculateOrbitPositions() {
380
378
std::vector<glm::mat4> transformations;
381
379
transformations.reserve (problem_instance.getSatellites ().size () + problem_instance.scheduled_communications .size ());
382
380
glm::mat4 scale = glm::inverse (glm::scale (glm::vec3 (zoom))); // ignore zoom
381
+ size_t instance_count = 0 ;
383
382
383
+ auto infos = getObjectInfo (" satellites" );
384
+ for (const auto & obj_info : infos)
385
+ obj_info->base_instance = instance_count;
384
386
for (const Satellite& o : problem_instance.getSatellites ()) {
385
387
glm::vec3 position = o.cartesian_coordinates (sim_time) / real_world_scale;
386
388
glm::mat4 translation = glm::translate (position);
387
389
transformations.push_back (translation * scale);
390
+ instance_count++;
388
391
}
389
392
393
+ infos = getObjectInfo (" communications_arrowhead" );
394
+ for (const auto & obj_info : infos)
395
+ obj_info->base_instance = instance_count;
390
396
for (const auto & c : problem_instance.scheduled_communications ) {
391
397
glm::vec3 sat1 = problem_instance.getSatellites ()[c.first ].cartesian_coordinates (sim_time) / real_world_scale;
392
398
glm::vec3 sat2 = problem_instance.getSatellites ()[c.second ].cartesian_coordinates (sim_time) / real_world_scale;
@@ -398,8 +404,12 @@ void OpenGLWidget::recalculateOrbitPositions() {
398
404
glm::mat4 rotation = glm::rotate (angle, axis);
399
405
400
406
transformations.push_back (translation * rotation * scale);
407
+ instance_count++;
401
408
}
402
409
410
+ infos = getObjectInfo (" orientation_arrowhead" );
411
+ for (const auto & obj_info : infos)
412
+ obj_info->base_instance = instance_count;
403
413
for (const auto & s : problem_instance.getSatellites ()) {
404
414
glm::vec3 position = s.cartesian_coordinates (sim_time) / real_world_scale;
405
415
TimelineEvent<glm::vec3> last_orientation = satellite_orientations[&s].previousEvent (sim_time, false );
@@ -429,12 +439,13 @@ void OpenGLWidget::recalculateOrbitPositions() {
429
439
430
440
glm::mat4 translation = glm::translate (glm::vec3 (position + direction_vector));
431
441
transformations.push_back (translation * scale * rotation);
442
+ instance_count++;
432
443
}
433
444
434
445
// push data to VBO
435
446
if (transformations.size () != 0 ) {
436
447
size_t size_transformation = sizeof (transformations[0 ]) * transformations.size ();
437
- glBindBuffer (GL_ARRAY_BUFFER, vbo_transformations); // set active
448
+ glBindBuffer (GL_ARRAY_BUFFER, vbo_transformations); // set active
438
449
glBufferData (GL_ARRAY_BUFFER, size_transformation, &transformations[0 ], GL_STREAM_DRAW); // push data
439
450
}
440
451
}
@@ -483,7 +494,7 @@ std::vector<Object> OpenGLWidget::createLines() {
483
494
all_lines.push_back (communication_line);
484
495
}
485
496
edgescene_com_start = problem_instance.islCount ();
486
- edgescene_com_end = edgescene_com_start + problem_instance.scheduled_communications .size () - 1 ;
497
+ edgescene_com_end = edgescene_com_start + problem_instance.scheduled_communications .size ();
487
498
488
499
// build satellite orientations
489
500
for (auto const & satellite : problem_instance.getSatellites ()) {
@@ -652,6 +663,7 @@ void OpenGLWidget::prepareInstanceScene(const PhysicalInstance& instance) {
652
663
Object satellites = OpenGLPrimitives::createSatellite ();
653
664
satellites.name = " satellites" ;
654
665
satellites.gl_program = satellite_prog;
666
+ satellites.drawInstanced = true ;
655
667
// for each satellite in instance we need one copy of the satellite object
656
668
for (int i = 0 ; i < problem_instance.getSatellites ().size (); i++) {
657
669
satellites.object_transformations .push_back (glm::mat4 (1 .f ));
@@ -668,6 +680,7 @@ void OpenGLWidget::prepareInstanceScene(const PhysicalInstance& instance) {
668
680
Object cone = OpenGLPrimitives::createCone (0 .006f , 0 .03f , glm::vec3 (.55f , .1f , 1 .f ));
669
681
cone.name = " communications_arrowhead" ;
670
682
cone.gl_program = satellite_prog;
683
+ cone.drawInstanced = true ;
671
684
for (int i = 0 ; i < problem_instance.scheduled_communications .size (); i++) {
672
685
cone.object_transformations .push_back (glm::mat4 (1 .f ));
673
686
}
@@ -677,6 +690,7 @@ void OpenGLWidget::prepareInstanceScene(const PhysicalInstance& instance) {
677
690
cone = OpenGLPrimitives::createCone (0 .005f , 0 .012f , glm::vec3 (1 .f ));
678
691
cone.name = " orientation_arrowhead" ;
679
692
cone.gl_program = satellite_prog;
693
+ cone.drawInstanced = true ;
680
694
for (int i = 0 ; i < problem_instance.getSatellites ().size (); i++) {
681
695
cone.object_transformations .push_back (glm::mat4 (1 .f ));
682
696
}
@@ -916,7 +930,7 @@ void OpenGLWidget::buildGUI() {
916
930
917
931
static bool hide_comms = false ;
918
932
if (ImGui::Checkbox (" Hide scheduled communications" , &hide_comms)) {
919
- for (size_t i = edgescene_com_start; i <= edgescene_com_end; i++) {
933
+ for (size_t i = edgescene_com_start; i < edgescene_com_end; i++) {
920
934
scene[EDGES_SUBSCENE].setEnabled (i, !hide_comms);
921
935
}
922
936
auto infos = getObjectInfo (" communications_arrowhead" );
@@ -927,7 +941,7 @@ void OpenGLWidget::buildGUI() {
927
941
928
942
static bool hide_orientations = false ;
929
943
if (ImGui::Checkbox (" Hide satellite orientations" , &hide_orientations)) {
930
- for (size_t i = edgescene_com_end + 1 ; i < scene[EDGES_SUBSCENE].objectCount (); i++) {
944
+ for (size_t i = edgescene_com_end; i < scene[EDGES_SUBSCENE].objectCount (); i++) {
931
945
scene[EDGES_SUBSCENE].setEnabled (i, !hide_orientations);
932
946
}
933
947
auto infos = getObjectInfo (" orientation_arrowhead" );
0 commit comments