Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan hoffstadt committed Apr 24, 2024
1 parent 865c297 commit 45f2186
Show file tree
Hide file tree
Showing 5 changed files with 633 additions and 190 deletions.
74 changes: 37 additions & 37 deletions apps/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ typedef struct plAppData_t

// views
uint32_t uSceneHandle0;
uint32_t uSceneHandle1;
// uint32_t uSceneHandle1;
uint32_t uViewHandle0;
uint32_t uViewHandle1;
uint32_t uViewHandle2;
// uint32_t uViewHandle1;
// uint32_t uViewHandle2;

// drawing
plDrawLayer* ptDrawLayer;
Expand Down Expand Up @@ -220,10 +220,10 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// create offscreen view (temporary API)
ptAppData->uSceneHandle0 = gptRenderer->create_scene();
ptAppData->uSceneHandle1 = gptRenderer->create_scene();
// ptAppData->uSceneHandle1 = gptRenderer->create_scene();
ptAppData->uViewHandle0 = gptRenderer->create_view(ptAppData->uSceneHandle0, (plVec2){ptIO->afMainViewportSize[0] , ptIO->afMainViewportSize[1]});
ptAppData->uViewHandle1 = gptRenderer->create_view(ptAppData->uSceneHandle0, (plVec2){500.0f, 500.0f});
ptAppData->uViewHandle2 = gptRenderer->create_view(ptAppData->uSceneHandle1, (plVec2){500.0f, 500.0f});
// ptAppData->uViewHandle1 = gptRenderer->create_view(ptAppData->uSceneHandle0, (plVec2){500.0f, 500.0f});
// ptAppData->uViewHandle2 = gptRenderer->create_view(ptAppData->uSceneHandle1, (plVec2){500.0f, 500.0f});

// temporary draw layer for submitting fullscreen quad of offscreen render
ptAppData->ptDrawLayer = pl_request_layer(pl_get_draw_list(NULL), "draw layer");
Expand All @@ -239,18 +239,18 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptCamera->set_pitch_yaw(gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tCullCamera), 0.0f, PL_PI);
gptCamera->update(gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tCullCamera));

plComponentLibrary* ptSecondaryComponentLibrary = gptRenderer->get_component_library(ptAppData->uSceneHandle1);
ptAppData->tMainCamera2 = gptEcs->create_perspective_camera(ptSecondaryComponentLibrary, "secondary camera", (plVec3){-3.265f, 2.967f, 0.311f}, PL_PI_3, 1.0f, 0.01f, 400.0f);
gptCamera->set_pitch_yaw(gptEcs->get_component(ptSecondaryComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera2), -0.535f, 1.737f);
gptCamera->update(gptEcs->get_component(ptSecondaryComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera2));
// plComponentLibrary* ptSecondaryComponentLibrary = gptRenderer->get_component_library(ptAppData->uSceneHandle1);
// ptAppData->tMainCamera2 = gptEcs->create_perspective_camera(ptSecondaryComponentLibrary, "secondary camera", (plVec3){-3.265f, 2.967f, 0.311f}, PL_PI_3, 1.0f, 0.01f, 400.0f);
// gptCamera->set_pitch_yaw(gptEcs->get_component(ptSecondaryComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera2), -0.535f, 1.737f);
// gptCamera->update(gptEcs->get_component(ptSecondaryComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera2));

// load models
pl_begin_profile_frame();

pl_begin_profile_sample("load skyboxes");
const plMat4 tTransform0 = pl_mat4_translate_xyz(2.0f, 1.0f, 0.0f);
gptRenderer->load_skybox_from_panorama(ptAppData->uSceneHandle0, "../data/glTF-Sample-Environments-main/ennis.jpg", 1024);
gptRenderer->load_skybox_from_panorama(ptAppData->uSceneHandle1, "../data/glTF-Sample-Environments-main/ennis.jpg", 1024);
// gptRenderer->load_skybox_from_panorama(ptAppData->uSceneHandle1, "../data/glTF-Sample-Environments-main/ennis.jpg", 1024);
pl_end_profile_sample();

plModelLoaderData tLoaderData0 = {0};
Expand All @@ -263,20 +263,20 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptModelLoader->free_data(&tLoaderData0);
pl_end_profile_sample();

pl_begin_profile_sample("load models 1");
gptModelLoader->load_gltf(ptSecondaryComponentLibrary, "../data/glTF-Sample-Assets-main/Models/CesiumMan/glTF/CesiumMan.gltf", NULL, &tLoaderData0);
gptModelLoader->load_stl(ptSecondaryComponentLibrary, "../data/pilotlight-assets-master/meshes/monkey.stl", (plVec4){1.0f, 0.0f, 0.0f, 0.80f}, &tTransform0, &tLoaderData0);
gptRenderer->add_drawable_objects_to_scene(ptAppData->uSceneHandle1, tLoaderData0.uOpaqueCount, tLoaderData0.atOpaqueObjects, tLoaderData0.uTransparentCount, tLoaderData0.atTransparentObjects);
gptModelLoader->free_data(&tLoaderData0);
pl_end_profile_sample();
// pl_begin_profile_sample("load models 1");
// gptModelLoader->load_gltf(ptSecondaryComponentLibrary, "../data/glTF-Sample-Assets-main/Models/CesiumMan/glTF/CesiumMan.gltf", NULL, &tLoaderData0);
// gptModelLoader->load_stl(ptSecondaryComponentLibrary, "../data/pilotlight-assets-master/meshes/monkey.stl", (plVec4){1.0f, 0.0f, 0.0f, 0.80f}, &tTransform0, &tLoaderData0);
// gptRenderer->add_drawable_objects_to_scene(ptAppData->uSceneHandle1, tLoaderData0.uOpaqueCount, tLoaderData0.atOpaqueObjects, tLoaderData0.uTransparentCount, tLoaderData0.atTransparentObjects);
// gptModelLoader->free_data(&tLoaderData0);
// pl_end_profile_sample();

pl_begin_profile_sample("finalize scene 0");
gptRenderer->finalize_scene(ptAppData->uSceneHandle0);
pl_end_profile_sample();

pl_begin_profile_sample("finalize scene 1");
gptRenderer->finalize_scene(ptAppData->uSceneHandle1);
pl_end_profile_sample();
// pl_begin_profile_sample("finalize scene 1");
// gptRenderer->finalize_scene(ptAppData->uSceneHandle1);
// pl_end_profile_sample();

pl_end_profile_frame();

Expand Down Expand Up @@ -372,10 +372,10 @@ pl_app_update(plAppData* ptAppData)

// handle input
plComponentLibrary* ptMainComponentLibrary = gptRenderer->get_component_library(ptAppData->uSceneHandle0);
plComponentLibrary* ptSecondaryComponentLibrary = gptRenderer->get_component_library(ptAppData->uSceneHandle1);
// plComponentLibrary* ptSecondaryComponentLibrary = gptRenderer->get_component_library(ptAppData->uSceneHandle1);

plCameraComponent* ptCamera = gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera);
plCameraComponent* ptCamera2 = gptEcs->get_component(ptSecondaryComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera2);
// plCameraComponent* ptCamera2 = gptEcs->get_component(ptSecondaryComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera2);
plCameraComponent* ptCullCamera = gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tCullCamera);

static const float fCameraTravelSpeed = 4.0f;
Expand Down Expand Up @@ -404,12 +404,12 @@ pl_app_update(plAppData* ptAppData)
}

gptCamera->update(ptCamera);
gptCamera->update(ptCamera2);
// gptCamera->update(ptCamera2);
gptCamera->update(ptCullCamera);

// run ecs system
gptRenderer->run_ecs(ptAppData->uSceneHandle0);
gptRenderer->run_ecs(ptAppData->uSceneHandle1);
// gptRenderer->run_ecs(ptAppData->uSceneHandle1);

// new ui frame
pl_new_frame();
Expand All @@ -432,7 +432,7 @@ pl_app_update(plAppData* ptAppData)
plCommandBuffer tCommandBuffer = gptGfx->begin_command_recording(ptGraphics, &tBeginInfo0);

gptRenderer->update_scene(tCommandBuffer, ptAppData->uSceneHandle0);
gptRenderer->update_scene(tCommandBuffer, ptAppData->uSceneHandle1);
// gptRenderer->update_scene(tCommandBuffer, ptAppData->uSceneHandle1);
gptGfx->end_command_recording(ptGraphics, &tCommandBuffer);

const plSubmitInfo tSubmitInfo0 = {
Expand All @@ -451,14 +451,14 @@ pl_app_update(plAppData* ptAppData)
.ptCullCamera = ptAppData->bFrustumCulling ? ptCamera : NULL
};

plViewOptions tViewOptions2 = {
.bShowAllBoundingBoxes = ptAppData->bDrawAllBoundingBoxes,
.bShowVisibleBoundingBoxes = ptAppData->bDrawVisibleBoundingBoxes,
.bShowOrigin = false,
.bCullStats = false,
.ptViewCamera = ptCamera2,
.ptCullCamera = ptCamera2
};
// plViewOptions tViewOptions2 = {
// .bShowAllBoundingBoxes = ptAppData->bDrawAllBoundingBoxes,
// .bShowVisibleBoundingBoxes = ptAppData->bDrawVisibleBoundingBoxes,
// .bShowOrigin = false,
// .bCullStats = false,
// .ptViewCamera = ptCamera2,
// .ptCullCamera = ptCamera2
// };

if(ptAppData->bFrustumCulling && ptAppData->bFreezeCullCamera)
tViewOptions.ptCullCamera = ptCullCamera;
Expand All @@ -473,8 +473,8 @@ pl_app_update(plAppData* ptAppData)
};
tCommandBuffer = gptGfx->begin_command_recording(ptGraphics, &tBeginInfo1);
gptRenderer->render_scene(tCommandBuffer, ptAppData->uSceneHandle0, ptAppData->uViewHandle0, tViewOptions);
gptRenderer->render_scene(tCommandBuffer, ptAppData->uSceneHandle0, ptAppData->uViewHandle1, tViewOptions2);
gptRenderer->render_scene(tCommandBuffer, ptAppData->uSceneHandle1, ptAppData->uViewHandle2, tViewOptions2);
// gptRenderer->render_scene(tCommandBuffer, ptAppData->uSceneHandle0, ptAppData->uViewHandle1, tViewOptions2);
// gptRenderer->render_scene(tCommandBuffer, ptAppData->uSceneHandle1, ptAppData->uViewHandle2, tViewOptions2);

gptGfx->end_command_recording(ptGraphics, &tCommandBuffer);

Expand Down Expand Up @@ -579,8 +579,8 @@ pl_app_update(plAppData* ptAppData)

// add full screen quad for offscreen render
pl_add_image(ptAppData->ptDrawLayer, gptRenderer->get_view_texture_id(ptAppData->uSceneHandle0, ptAppData->uViewHandle0), (plVec2){0}, (plVec2){ptIO->afMainViewportSize[0], ptIO->afMainViewportSize[1]});
pl_add_image(ptAppData->ptDrawLayer, gptRenderer->get_view_texture_id(ptAppData->uSceneHandle0, ptAppData->uViewHandle1), (plVec2){0}, (plVec2){500.0f, 500.0f});
pl_add_image(ptAppData->ptDrawLayer, gptRenderer->get_view_texture_id(ptAppData->uSceneHandle1, ptAppData->uViewHandle2), (plVec2){0.0f, 500.0f}, (plVec2){500.0f, 1000.0f});
// pl_add_image(ptAppData->ptDrawLayer, gptRenderer->get_view_texture_id(ptAppData->uSceneHandle0, ptAppData->uViewHandle1), (plVec2){0}, (plVec2){500.0f, 500.0f});
// pl_add_image(ptAppData->ptDrawLayer, gptRenderer->get_view_texture_id(ptAppData->uSceneHandle1, ptAppData->uViewHandle2), (plVec2){0.0f, 500.0f}, (plVec2){500.0f, 1000.0f});
pl_submit_layer(ptAppData->ptDrawLayer);

plRenderEncoder tEncoder = gptGfx->begin_render_pass(ptGraphics, &tCommandBuffer, ptGraphics->tMainRenderPass);
Expand Down
Loading

0 comments on commit 45f2186

Please sign in to comment.