@@ -350,6 +350,8 @@ pl_app_shutdown(plAppData* ptAppData)
350350 gptScreenLog->cleanup ();
351351 if (ptAppData->ptView )
352352 gptRenderer->cleanup_view (ptAppData->ptView );
353+ if (ptAppData->ptSecondaryView )
354+ gptRenderer->cleanup_view (ptAppData->ptSecondaryView );
353355 if (ptAppData->ptScene )
354356 gptRenderer->cleanup_scene (ptAppData->ptScene );
355357 gptEcs->cleanup ();
@@ -411,7 +413,9 @@ pl_app_update(plAppData* ptAppData)
411413
412414 plCamera* ptCamera = (plCamera*)gptEcs->get_component (ptAppData->ptCompLibrary , gptCamera->get_ecs_type_key (), ptAppData->tMainCamera );
413415 plCamera* ptCullCamera = (plCamera*)gptEcs->get_component (ptAppData->ptCompLibrary , gptCamera->get_ecs_type_key (), ptAppData->tCullCamera );
416+ plCamera* ptSecondaryCamera = (plCamera*)gptEcs->get_component (ptAppData->ptCompLibrary , gptCamera->get_ecs_type_key (), ptAppData->tSecondaryCamera );
414417 gptCamera->update (ptCullCamera);
418+ gptCamera->update (ptSecondaryCamera);
415419
416420 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~selection stuff~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
417421
@@ -520,27 +524,48 @@ pl_app_update(plAppData* ptAppData)
520524 plLightComponent* ptLights = nullptr ;
521525 const uint32_t uLightCount = gptEcs->get_components (ptAppData->ptCompLibrary , gptRenderer->get_ecs_type_key_light (), (void **)&ptLights, nullptr );
522526 gptRenderer->debug_draw_lights (ptAppData->ptView , ptLights, uLightCount);
527+ gptRenderer->debug_draw_lights (ptAppData->ptSecondaryView , ptLights, uLightCount);
523528 }
524529
525530 if (ptAppData->bDrawAllBoundingBoxes )
531+ {
526532 gptRenderer->debug_draw_all_bound_boxes (ptAppData->ptView );
533+ gptRenderer->debug_draw_all_bound_boxes (ptAppData->ptSecondaryView );
534+ }
527535
528536 if (ptAppData->bShowSkybox )
537+ {
529538 gptRenderer->show_skybox (ptAppData->ptView );
539+ gptRenderer->show_skybox (ptAppData->ptSecondaryView );
540+ }
530541
531542 if (ptAppData->bShowGrid )
543+ {
532544 gptRenderer->show_grid (ptAppData->ptView );
545+ gptRenderer->show_grid (ptAppData->ptSecondaryView );
546+ }
533547
534548 if (ptAppData->bShowBVH )
549+ {
535550 gptRenderer->debug_draw_bvh (ptAppData->ptView );
551+ gptRenderer->debug_draw_bvh (ptAppData->ptSecondaryView );
552+ }
536553
537554 // render scene
538555 gptRenderer->prepare_scene (ptAppData->ptScene );
539556 gptRenderer->prepare_view (ptAppData->ptView , ptCamera);
557+ if (ptAppData->bSecondaryViewActive )
558+ gptRenderer->prepare_view (ptAppData->ptSecondaryView , ptSecondaryCamera);
559+
540560 plCamera* ptActiveCullCamera = ptCamera;
541561 if (ptAppData->bFreezeCullCamera )
542562 ptActiveCullCamera = ptCullCamera;
543563 gptRenderer->render_view (ptAppData->ptView , ptCamera, ptAppData->bFrustumCulling ? ptActiveCullCamera : nullptr );
564+
565+ if (ptAppData->bSecondaryViewActive )
566+ {
567+ gptRenderer->render_view (ptAppData->ptSecondaryView , ptSecondaryCamera, ptSecondaryCamera);
568+ }
544569 }
545570
546571 ImGui::DockSpaceOverViewport (0 , 0 , ImGuiDockNodeFlags_PassthruCentralNode);
@@ -617,7 +642,7 @@ pl_app_update(plAppData* ptAppData)
617642 if (ptAppData->ptScene )
618643 {
619644
620- plCamera* ptCamera = (plCamera*)gptEcs->get_component (ptAppData->ptCompLibrary , gptCamera->get_ecs_type_key (), ptAppData->tMainCamera );
645+ plCamera* ptCamera = (plCamera*)gptEcs->get_component (ptAppData->ptCompLibrary , gptCamera->get_ecs_type_key (), ptAppData->tMainCamera );
621646 if (ptAppData->bMainViewHovered )
622647 pl__camera_update_imgui (ptCamera);
623648
@@ -626,14 +651,30 @@ pl_app_update(plAppData* ptAppData)
626651 tContextSize.y / ImGui::GetWindowViewport ()->Size .y ,
627652 };
628653
654+ plVec2 tUvScale = gptRenderer->get_view_color_texture_max_uv (ptAppData->ptView );
629655
630656 ImTextureID tTexture = gptDearImGui->get_texture_id_from_bindgroup (ptAppData->ptDevice , gptRenderer->get_view_color_texture (ptAppData->ptView ));
631- ImGui::Image (tTexture, tContextSize);
657+ ImGui::Image (tTexture, tContextSize, ImVec2 ( 0 , 0 ), ImVec2 (tUvScale. x , tUvScale. y ) );
632658
633659 }
634660 }
635661 ImGui::End ();
636662
663+ if (ptAppData->bSecondaryViewActive )
664+ {
665+ plVec2 tUvScale = gptRenderer->get_view_color_texture_max_uv (ptAppData->ptSecondaryView );
666+ ImGui::SetNextWindowSizeConstraints (ImVec2 (200 .0f , 200 .0f ), ImVec2 (10000 .0f , 10000 .0f ));
667+ if (ImGui::Begin (" Secondary View" , &ptAppData->bSecondaryViewActive , ImGuiWindowFlags_NoDocking))
668+ {
669+ ImVec2 tContextSize = ImGui::GetContentRegionAvail ();
670+ gptCamera->set_aspect ((plCamera*)gptEcs->get_component (ptAppData->ptCompLibrary , gptCamera->get_ecs_type_key (), ptAppData->tSecondaryCamera ), tContextSize.x / tContextSize.y );
671+
672+ ImTextureID tTexture = gptDearImGui->get_texture_id_from_bindgroup (ptAppData->ptDevice , gptRenderer->get_view_color_texture (ptAppData->ptSecondaryView ));
673+ ImGui::Image (tTexture, tContextSize, ImVec2 (0 , 0 ), ImVec2 (tUvScale.x , tUvScale.y ));
674+ }
675+ ImGui::End ();
676+ }
677+
637678 if (ptAppData->bShowPlotDemo )
638679 ImPlot::ShowDemoWindow (&ptAppData->bShowPlotDemo );
639680
@@ -872,6 +913,7 @@ pl__show_editor_window(plAppData* ptAppData)
872913
873914 ImGui::Checkbox (" Show Debug Lights" , &ptAppData->bShowDebugLights );
874915 ImGui::Checkbox (" Show Bounding Boxes" , &ptAppData->bDrawAllBoundingBoxes );
916+ ImGui::Checkbox (" Secondary View" , &ptAppData->bSecondaryViewActive );
875917
876918 if (ptAppData->ptScene )
877919 {
@@ -892,8 +934,10 @@ pl__show_editor_window(plAppData* ptAppData)
892934 gptPhysics->reset ();
893935 gptEcs->reset_library (ptAppData->ptCompLibrary );
894936 gptRenderer->cleanup_view (ptAppData->ptView );
937+ gptRenderer->cleanup_view (ptAppData->ptSecondaryView );
895938 gptRenderer->cleanup_scene (ptAppData->ptScene );
896939 ptAppData->ptView = nullptr ;
940+ ptAppData->ptSecondaryView = nullptr ;
897941 ptAppData->ptScene = nullptr ;
898942 }
899943 }
@@ -996,6 +1040,7 @@ pl__show_editor_window(plAppData* ptAppData)
9961040 plIO* ptIO = gptIO->get_io ();
9971041
9981042 ptAppData->ptView = gptRenderer->create_view (ptAppData->ptScene , ptIO->tMainViewportSize );
1043+ ptAppData->ptSecondaryView = gptRenderer->create_view (ptAppData->ptScene , {500 .0f , 500 .0f });
9991044
10001045 plModelLoaderData tLoaderData0 = {0 };
10011046
@@ -1167,6 +1212,14 @@ pl__create_scene(plAppData* ptAppData)
11671212 gptCamera->set_pitch_yaw (ptCullCamera, 0 .0f , PL_PI );
11681213 gptCamera->update (ptCullCamera);
11691214
1215+ // create secondary camera
1216+ plCamera* ptSecondaryCamera = nullptr ;
1217+ ptAppData->tSecondaryCamera = gptCamera->create_perspective (ptAppData->ptCompLibrary , " secondary camera" , pl_create_vec3 (-4 .7f , 4 .2f , -3 .256f ), PL_PI_3 , 1 .0f , 0 .1f , 20 .0f , true , &ptSecondaryCamera);
1218+ gptCamera->set_pitch_yaw (ptSecondaryCamera, -0 .1f , 0 .911f );
1219+ gptCamera->update (ptSecondaryCamera);
1220+ plTransformComponent* ptSecondaryCameraTransform = (plTransformComponent* )gptEcs->add_component (ptAppData->ptCompLibrary , gptEcs->get_ecs_type_key_transform (), ptAppData->tSecondaryCamera );
1221+ ptSecondaryCameraTransform->tTranslation = pl_create_vec3 (-4 .7f , 4 .2f , -3 .256f );
1222+
11701223 // create lights
11711224 plLightComponent* ptLight = nullptr ;
11721225 gptRenderer->create_directional_light (ptAppData->ptCompLibrary , " direction light" , pl_create_vec3 (-0 .375f , -1 .0f , -0 .085f ), &ptLight);
0 commit comments