@@ -84,7 +84,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
84
84
gptStarter = pl_get_api_latest (ptApiRegistry, plStarterI);
85
85
gptAnimation = pl_get_api_latest (ptApiRegistry, plAnimationI);
86
86
gptMesh = pl_get_api_latest (ptApiRegistry, plMeshI);
87
- gptShaderVariant = pl_get_api_latest (ptApiRegistry, plShaderVariantI );
87
+ gptShaderTools = pl_get_api_latest (ptApiRegistry, plShaderToolsI );
88
88
gptVfs = pl_get_api_latest (ptApiRegistry, plVfsI);
89
89
gptPak = pl_get_api_latest (ptApiRegistry, plPakI);
90
90
gptDateTime = pl_get_api_latest (ptApiRegistry, plDateTimeI);
@@ -140,7 +140,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
140
140
gptStarter = pl_get_api_latest (ptApiRegistry, plStarterI);
141
141
gptAnimation = pl_get_api_latest (ptApiRegistry, plAnimationI);
142
142
gptMesh = pl_get_api_latest (ptApiRegistry, plMeshI);
143
- gptShaderVariant = pl_get_api_latest (ptApiRegistry, plShaderVariantI );
143
+ gptShaderTools = pl_get_api_latest (ptApiRegistry, plShaderToolsI );
144
144
gptVfs = pl_get_api_latest (ptApiRegistry, plVfsI);
145
145
gptPak = pl_get_api_latest (ptApiRegistry, plPakI);
146
146
gptDateTime = pl_get_api_latest (ptApiRegistry, plDateTimeI);
@@ -164,6 +164,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
164
164
ptAppData->bShowPilotLightTool = true ;
165
165
ptAppData->bShowSkybox = true ;
166
166
ptAppData->bFrustumCulling = true ;
167
+ ptAppData->bVSync = true ;
167
168
168
169
gptConfig->load_from_disk (nullptr );
169
170
ptAppData->bShowEntityWindow = gptConfig->load_bool (" bShowEntityWindow" , false );
@@ -178,18 +179,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
178
179
// initialize APIs that require it
179
180
gptEcsTools->initialize ();
180
181
gptPhysics->initialize ({});
181
-
182
- // initialize shader compiler
183
- static plShaderOptions tDefaultShaderOptions = PL_ZERO_INIT;
184
- tDefaultShaderOptions.apcIncludeDirectories [0 ] = " /shaders/" ;
185
- tDefaultShaderOptions.apcDirectories [0 ] = " /shaders/" ;
186
- tDefaultShaderOptions.apcDirectories [1 ] = " /shader-temp/" ;
187
- tDefaultShaderOptions.pcCacheOutputDirectory = " /shader-temp/" ;
188
- tDefaultShaderOptions.tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT | PL_SHADER_FLAGS_INCLUDE_DEBUG | PL_SHADER_FLAGS_ALWAYS_COMPILE;
189
- gptShader->initialize (&tDefaultShaderOptions);
190
-
191
- // initialize job system
192
- gptJobs->initialize ({});
193
182
194
183
// create window (only 1 allowed currently)
195
184
plWindowDesc tWindowDesc = {
@@ -203,30 +192,51 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
203
192
gptWindows->create (tWindowDesc, &ptAppData->ptWindow );
204
193
gptWindows->show (ptAppData->ptWindow );
205
194
206
- // initialize graphics
207
- plGraphicsInit tGraphicsDesc = PL_ZERO_INIT;
208
- tGraphicsDesc.tFlags = PL_GRAPHICS_INIT_FLAGS_SWAPCHAIN_ENABLED | PL_GRAPHICS_INIT_FLAGS_VALIDATION_ENABLED;
209
- gptGfx->initialize (&tGraphicsDesc);
195
+ plStarterInit tStarterInit = {};
196
+ tStarterInit.tFlags = PL_STARTER_FLAGS_NONE;
197
+ tStarterInit.ptWindow = ptAppData->ptWindow ;
198
+
199
+ // extensions handled by starter
200
+ tStarterInit.tFlags |= PL_STARTER_FLAGS_GRAPHICS_EXT;
201
+ tStarterInit.tFlags |= PL_STARTER_FLAGS_PROFILE_EXT;
202
+ tStarterInit.tFlags |= PL_STARTER_FLAGS_STATS_EXT;
203
+ tStarterInit.tFlags |= PL_STARTER_FLAGS_CONSOLE_EXT;
204
+ tStarterInit.tFlags |= PL_STARTER_FLAGS_TOOLS_EXT;
205
+ tStarterInit.tFlags |= PL_STARTER_FLAGS_DRAW_EXT;
206
+ tStarterInit.tFlags |= PL_STARTER_FLAGS_UI_EXT;
207
+ tStarterInit.tFlags |= PL_STARTER_FLAGS_SCREEN_LOG_EXT;
208
+
209
+ // initial flags
210
+ tStarterInit.tFlags |= PL_STARTER_FLAGS_DEPTH_BUFFER;
211
+
212
+ // from a graphics standpoint, the starter extension is handling device, swapchain, renderpass
213
+ // etc. which we will get to in later examples
214
+ gptStarter->initialize (tStarterInit);
215
+
216
+ // initialize shader compiler
217
+ static plShaderOptions tDefaultShaderOptions = PL_ZERO_INIT;
218
+ tDefaultShaderOptions.apcIncludeDirectories [0 ] = " /shaders/" ;
219
+ tDefaultShaderOptions.apcDirectories [0 ] = " /shaders/" ;
220
+ tDefaultShaderOptions.apcDirectories [1 ] = " /shader-temp/" ;
221
+ tDefaultShaderOptions.pcCacheOutputDirectory = " /shader-temp/" ;
222
+ tDefaultShaderOptions.tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT | PL_SHADER_FLAGS_INCLUDE_DEBUG | PL_SHADER_FLAGS_ALWAYS_COMPILE;
223
+ gptShader->initialize (&tDefaultShaderOptions);
224
+
225
+ ptAppData->ptDevice = gptStarter->get_device ();
210
226
211
- ptAppData-> ptSurface = gptGfx-> create_surface (ptAppData-> ptWindow );
212
- ptAppData-> ptDevice = gptStarter-> create_device (ptAppData-> ptSurface );
227
+ // initialize job system
228
+ gptJobs-> initialize ({} );
213
229
214
- const plShaderVariantInit tShaderVariantInit = {
230
+ const plShaderToolsInit tShaderVariantInit = {
215
231
ptAppData->ptDevice
216
232
};
217
- gptShaderVariant->initialize (tShaderVariantInit);
218
-
219
- // create swapchain
220
- plSwapchainInit tSwapInit = PL_ZERO_INIT;
221
- tSwapInit.bVSync = true ;
222
- tSwapInit.tSampleCount = 1 ;
223
- ptAppData->ptSwap = gptGfx->create_swapchain (ptAppData->ptDevice , ptAppData->ptSurface , &tSwapInit);
233
+ gptShaderTools->initialize (tShaderVariantInit);
224
234
225
235
// setup reference renderer
226
236
plRendererSettings tRenderSettings = PL_ZERO_INIT;
227
237
tRenderSettings.ptDevice = ptAppData->ptDevice ;
228
238
tRenderSettings.uMaxTextureResolution = 1024 ;
229
- tRenderSettings.ptSwap = ptAppData-> ptSwap ;
239
+ tRenderSettings.ptSwap = gptStarter-> get_swapchain () ;
230
240
gptRenderer->initialize (tRenderSettings);
231
241
232
242
// initialize ecs component library
@@ -256,14 +266,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
256
266
257
267
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~setup draw extensions~~~~~~~~~~~~~~~~~~~~~~~~~~~~
258
268
259
- // initialize
260
- gptDraw->initialize (nullptr );
261
- gptDrawBackend->initialize (ptAppData->ptDevice );
262
-
263
- // create font atlas
264
- plFontAtlas* ptAtlas = gptDraw->create_font_atlas ();
265
- gptDraw->set_font_atlas (ptAtlas);
266
-
267
269
// create fonts
268
270
plFontRange tFontRange = PL_ZERO_INIT;
269
271
tFontRange.iFirstCodePoint = 0x0020 ;
@@ -276,7 +278,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
276
278
tFontConfig0.uVOverSampling = 1 ;
277
279
tFontConfig0.ptRanges = &tFontRange;
278
280
tFontConfig0.uRangeCount = 1 ;
279
- ptAppData->tDefaultFont = gptDraw->add_font_from_file_ttf (ptAtlas , tFontConfig0, " /fonts/Cousine-Regular.ttf" );
281
+ ptAppData->tDefaultFont = gptDraw->add_font_from_file_ttf (gptDraw-> get_current_font_atlas () , tFontConfig0, " /fonts/Cousine-Regular.ttf" );
280
282
281
283
plFontRange tIconRange = PL_ZERO_INIT;
282
284
tIconRange.iFirstCodePoint = ICON_MIN_FA;
@@ -290,30 +292,21 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
290
292
tFontConfig1.ptMergeFont = ptAppData->tDefaultFont ;
291
293
tFontConfig1.ptRanges = &tIconRange;
292
294
tFontConfig1.uRangeCount = 1 ;
293
- gptDraw->add_font_from_file_ttf (ptAtlas, tFontConfig1, " /fonts/fa-solid-900.otf" );
294
-
295
- // build font atlas
296
- plCommandBuffer* ptCmdBuffer = gptGfx->request_command_buffer (gptRenderer->get_command_pool ());
297
- gptDrawBackend->build_font_atlas (ptCmdBuffer, ptAtlas);
298
- gptGfx->return_command_buffer (ptCmdBuffer);
299
-
300
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~message extension~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
301
-
302
- gptScreenLog->initialize ({ptAppData->tDefaultFont });
303
-
304
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ui extension~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
305
-
306
- gptUI->initialize ();
295
+ gptDraw->add_font_from_file_ttf (gptDraw->get_current_font_atlas (), tFontConfig1, " /fonts/fa-solid-900.otf" );
296
+ gptStarter->set_default_font (ptAppData->tDefaultFont );
307
297
gptUI->set_default_font (ptAppData->tDefaultFont );
308
298
299
+ gptStarter->finalize ();
300
+
309
301
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~app stuff~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
310
302
311
303
// temporary draw layer for submitting fullscreen quad of offscreen render
312
304
ptAppData->ptDrawLayer = gptDraw->request_2d_layer (gptUI->get_draw_list ());
313
305
314
306
pl__find_models (ptAppData);
315
307
316
- gptDearImGui->initialize (ptAppData->ptDevice , ptAppData->ptSwap , gptRenderer->get_main_render_pass ());
308
+ gptDearImGui->initialize (ptAppData->ptDevice , gptStarter->get_swapchain (), gptStarter->get_render_pass ());
309
+ // ImGui::GetIO().ConfigFlags &= ~ImGuiBackendFlags_PlatformHasViewports;
317
310
ImPlot::SetCurrentContext ((ImPlotContext*)ptDataRegistry->get_data (" implot" ));
318
311
ImGuiIO& tImGuiIO = ImGui::GetIO ();
319
312
tImGuiIO.IniFilename = nullptr ;
@@ -351,26 +344,18 @@ pl_app_shutdown(plAppData* ptAppData)
351
344
352
345
gptConfig->save_to_disk (nullptr );
353
346
gptConfig->cleanup ();
354
-
355
- gptDrawBackend->cleanup_font_atlas (gptDraw->get_current_font_atlas ());
356
- gptUI->cleanup ();
357
347
gptEcsTools->cleanup ();
358
348
gptPhysics->cleanup ();
359
349
gptShader->cleanup ();
360
- gptConsole->cleanup ();
361
350
gptScreenLog->cleanup ();
362
- gptDrawBackend->cleanup ();
363
351
if (ptAppData->ptView )
364
352
gptRenderer->cleanup_view (ptAppData->ptView );
365
353
if (ptAppData->ptScene )
366
354
gptRenderer->cleanup_scene (ptAppData->ptScene );
367
355
gptEcs->cleanup ();
368
356
gptRenderer->cleanup ();
369
- gptShaderVariant->cleanup ();
370
- gptGfx->cleanup_swapchain (ptAppData->ptSwap );
371
- gptGfx->cleanup_surface (ptAppData->ptSurface );
372
- gptGfx->cleanup_device (ptAppData->ptDevice );
373
- gptGfx->cleanup ();
357
+ gptShaderTools->cleanup ();
358
+ gptStarter->cleanup ();
374
359
gptWindows->destroy (ptAppData->ptWindow );
375
360
pl_sb_free (ptAppData->sbtTestModels );
376
361
PL_FREE (ptAppData);
@@ -385,7 +370,7 @@ pl_app_resize(plWindow*, plAppData* ptAppData)
385
370
{
386
371
plIO* ptIO = gptIO->get_io ();
387
372
ptAppData->bResize = true ;
388
- gptRenderer ->resize ();
373
+ gptStarter ->resize ();
389
374
}
390
375
391
376
// -----------------------------------------------------------------------------
@@ -395,23 +380,19 @@ pl_app_resize(plWindow*, plAppData* ptAppData)
395
380
PL_EXPORT void
396
381
pl_app_update (plAppData* ptAppData)
397
382
{
398
- gptProfile->begin_frame ();
383
+ if (!gptStarter->begin_frame ())
384
+ return ;
385
+
399
386
pl_begin_cpu_sample (gptProfile, 0 , __FUNCTION__);
400
387
401
- gptIO->new_frame ();
402
388
gptResource->new_frame ();
403
389
404
390
// for convience
405
391
plIO* ptIO = gptIO->get_io ();
406
392
407
- if (!gptRenderer->begin_frame ())
408
- {
409
- pl_end_cpu_sample (gptProfile, 0 );
410
- gptProfile->end_frame ();
411
- return ;
412
- }
393
+ gptRenderer->begin_frame ();
413
394
414
- gptDearImGui->new_frame (ptAppData->ptDevice , gptRenderer-> get_main_render_pass ());
395
+ gptDearImGui->new_frame (ptAppData->ptDevice , gptStarter-> get_render_pass ());
415
396
416
397
if (ptAppData->bResize )
417
398
{
@@ -421,20 +402,8 @@ pl_app_update(plAppData* ptAppData)
421
402
ptAppData->bResize = false ;
422
403
}
423
404
424
- gptDrawBackend->new_frame ();
425
- gptUI->new_frame ();
426
-
427
405
// update statistics
428
- gptStats->new_frame ();
429
- static double * pdFrameTimeCounter = nullptr ;
430
- static double * pdMemoryCounter = nullptr ;
431
- if (!pdFrameTimeCounter)
432
- pdFrameTimeCounter = gptStats->get_counter (" frametime (ms)" );
433
- if (!pdMemoryCounter)
434
- pdMemoryCounter = gptStats->get_counter (" CPU memory" );
435
- *pdFrameTimeCounter = (double )ptIO->fDeltaTime * 1000.0 ;
436
- *pdMemoryCounter = (double )gptMemory->get_memory_usage ();
437
- gptShaderVariant->update_stats ();
406
+ gptShaderTools->update_stats ();
438
407
439
408
if (ptAppData->ptScene )
440
409
{
@@ -571,13 +540,6 @@ pl_app_update(plAppData* ptAppData)
571
540
gptRenderer->render_view (ptAppData->ptView , ptCamera, ptAppData->bFrustumCulling ? ptActiveCullCamera : nullptr );
572
541
}
573
542
574
- if (gptIO->is_key_pressed (PL_KEY_F1, false ))
575
- {
576
- gptConsole->open ();
577
- }
578
-
579
- gptConsole->update ();
580
-
581
543
ImGui::DockSpaceOverViewport (0 , 0 , ImGuiDockNodeFlags_PassthruCentralNode);
582
544
583
545
if (ImGui::BeginMainMenuBar ())
@@ -619,8 +581,6 @@ pl_app_update(plAppData* ptAppData)
619
581
if (ptAppData->bShowUiDemo )
620
582
pl__show_ui_demo_window (ptAppData);
621
583
622
- gptTools->update ();
623
-
624
584
if (ptAppData->bShowUiStyle )
625
585
gptUI->show_style_editor_window (&ptAppData->bShowUiStyle );
626
586
@@ -677,31 +637,11 @@ pl_app_update(plAppData* ptAppData)
677
637
if (ptAppData->bShowImGuiDemo )
678
638
ImGui::ShowDemoWindow (&ptAppData->bShowImGuiDemo );
679
639
680
- plRenderEncoder* ptRenderEncoder = nullptr ;
681
- plCommandBuffer* ptCommandBuffer = nullptr ;
682
- gptRenderer->begin_final_pass (&ptRenderEncoder, &ptCommandBuffer);
683
-
684
- // render ui
685
- pl_begin_cpu_sample (gptProfile, 0 , " render ui" );
686
-
687
- gptDearImGui->render (ptRenderEncoder, ptCommandBuffer);
688
-
689
- gptUI->end_frame ();
690
-
691
- float fWidth = ptIO->tMainViewportSize .x ;
692
- float fHeight = ptIO->tMainViewportSize .y ;
693
- gptDrawBackend->submit_2d_drawlist (gptUI->get_draw_list (), ptRenderEncoder, fWidth , fHeight , gptGfx->get_swapchain_info (ptAppData->ptSwap ).tSampleCount );
694
- gptDrawBackend->submit_2d_drawlist (gptUI->get_debug_draw_list (), ptRenderEncoder, fWidth , fHeight , gptGfx->get_swapchain_info (ptAppData->ptSwap ).tSampleCount );
695
- pl_end_cpu_sample (gptProfile, 0 );
696
-
697
- plDrawList2D* ptMessageDrawlist = gptScreenLog->get_drawlist (tLogOffset.x , tLogOffset.y , fWidth * 0 .2f , fHeight );
698
- gptDrawBackend->submit_2d_drawlist (ptMessageDrawlist, ptRenderEncoder, fWidth , fHeight , gptGfx->get_swapchain_info (ptAppData->ptSwap ).tSampleCount );
699
-
700
-
701
- gptRenderer->end_final_pass (ptRenderEncoder, ptCommandBuffer);
702
-
640
+ plRenderEncoder* ptRenderEncoder = gptStarter->begin_main_pass ();
641
+ gptDearImGui->render (ptRenderEncoder, gptGfx->get_encoder_command_buffer (ptRenderEncoder));
642
+ gptStarter->end_main_pass ();
703
643
pl_end_cpu_sample (gptProfile, 0 );
704
- gptProfile ->end_frame ();
644
+ gptStarter ->end_frame ();
705
645
}
706
646
707
647
// -----------------------------------------------------------------------------
@@ -1084,8 +1024,13 @@ pl__show_editor_window(plAppData* ptAppData)
1084
1024
if (ImGui::CollapsingHeader (ICON_FA_DICE_D6 " Graphics" ))
1085
1025
{
1086
1026
plRendererRuntimeOptions* ptRuntimeOptions = gptRenderer->get_runtime_options ();
1087
- if (ImGui::Checkbox (" VSync" , &ptRuntimeOptions->bVSync ))
1088
- ptRuntimeOptions->bReloadSwapchain = true ;
1027
+ if (ImGui::Checkbox (" VSync" , &ptAppData->bVSync ))
1028
+ {
1029
+ if (ptAppData->bVSync )
1030
+ gptStarter->activate_vsync ();
1031
+ else
1032
+ gptStarter->deactivate_vsync ();
1033
+ }
1089
1034
ImGui::Checkbox (" Show Origin" , &ptRuntimeOptions->bShowOrigin );
1090
1035
ImGui::Checkbox (" Show BVH" , &ptAppData->bShowBVH );
1091
1036
ImGui::Checkbox (" Show Skybox" , &ptAppData->bShowSkybox );
0 commit comments