@@ -34,6 +34,7 @@ Index of this file:
34
34
#include "pl_debug_ext.h"
35
35
#include "pl_ecs_ext.h"
36
36
#include "pl_resource_ext.h"
37
+ #include "pl_model_loader_ext.h"
37
38
#include "pl_ref_renderer_ext.h"
38
39
#include "pl_job_ext.h"
39
40
@@ -106,6 +107,7 @@ const plEcsI* gptEcs = NULL;
106
107
const plCameraI * gptCamera = NULL ;
107
108
const plResourceI * gptResource = NULL ;
108
109
const plRefRendererI * gptRenderer = NULL ;
110
+ const plModelLoaderI * gptModelLoader = NULL ;
109
111
const plJobI * gptJobs = NULL ;
110
112
111
113
//-----------------------------------------------------------------------------
@@ -126,20 +128,21 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
126
128
pl_set_profile_context (gptDataRegistry -> get_data ("profile" ));
127
129
128
130
// reload global apis
129
- gptWindows = ptApiRegistry -> first (PL_API_WINDOW );
130
- gptThreads = ptApiRegistry -> first (PL_API_THREADS );
131
- gptStats = ptApiRegistry -> first (PL_API_STATS );
132
- gptFile = ptApiRegistry -> first (PL_API_FILE );
133
- gptGfx = ptApiRegistry -> first (PL_API_GRAPHICS );
134
- gptDevice = ptApiRegistry -> first (PL_API_DEVICE );
135
- gptDebug = ptApiRegistry -> first (PL_API_DEBUG );
136
- gptImage = ptApiRegistry -> first (PL_API_IMAGE );
137
- gptStream = ptApiRegistry -> first (PL_API_DRAW_STREAM );
138
- gptEcs = ptApiRegistry -> first (PL_API_ECS );
139
- gptCamera = ptApiRegistry -> first (PL_API_CAMERA );
140
- gptResource = ptApiRegistry -> first (PL_API_RESOURCE );
141
- gptRenderer = ptApiRegistry -> first (PL_API_REF_RENDERER );
142
- gptJobs = ptApiRegistry -> first (PL_API_JOB );
131
+ gptWindows = ptApiRegistry -> first (PL_API_WINDOW );
132
+ gptThreads = ptApiRegistry -> first (PL_API_THREADS );
133
+ gptStats = ptApiRegistry -> first (PL_API_STATS );
134
+ gptFile = ptApiRegistry -> first (PL_API_FILE );
135
+ gptGfx = ptApiRegistry -> first (PL_API_GRAPHICS );
136
+ gptDevice = ptApiRegistry -> first (PL_API_DEVICE );
137
+ gptDebug = ptApiRegistry -> first (PL_API_DEBUG );
138
+ gptImage = ptApiRegistry -> first (PL_API_IMAGE );
139
+ gptStream = ptApiRegistry -> first (PL_API_DRAW_STREAM );
140
+ gptEcs = ptApiRegistry -> first (PL_API_ECS );
141
+ gptCamera = ptApiRegistry -> first (PL_API_CAMERA );
142
+ gptResource = ptApiRegistry -> first (PL_API_RESOURCE );
143
+ gptRenderer = ptApiRegistry -> first (PL_API_REF_RENDERER );
144
+ gptJobs = ptApiRegistry -> first (PL_API_JOB );
145
+ gptModelLoader = ptApiRegistry -> first (PL_API_MODEL_LOADER );
143
146
144
147
return ptAppData ;
145
148
}
@@ -170,23 +173,28 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
170
173
ptExtensionRegistry -> load ("pl_debug_ext" , NULL , NULL , true);
171
174
ptExtensionRegistry -> load ("pl_ecs_ext" , NULL , NULL , false);
172
175
ptExtensionRegistry -> load ("pl_resource_ext" , NULL , NULL , false);
176
+ ptExtensionRegistry -> load ("pl_model_loader_ext" , NULL , NULL , false);
173
177
ptExtensionRegistry -> load ("pl_ref_renderer_ext" , NULL , NULL , true);
174
178
175
179
// load apis
176
- gptWindows = ptApiRegistry -> first (PL_API_WINDOW );
177
- gptThreads = ptApiRegistry -> first (PL_API_THREADS );
178
- gptStats = ptApiRegistry -> first (PL_API_STATS );
179
- gptFile = ptApiRegistry -> first (PL_API_FILE );
180
- gptGfx = ptApiRegistry -> first (PL_API_GRAPHICS );
181
- gptDevice = ptApiRegistry -> first (PL_API_DEVICE );
182
- gptDebug = ptApiRegistry -> first (PL_API_DEBUG );
183
- gptImage = ptApiRegistry -> first (PL_API_IMAGE );
184
- gptStream = ptApiRegistry -> first (PL_API_DRAW_STREAM );
185
- gptEcs = ptApiRegistry -> first (PL_API_ECS );
186
- gptCamera = ptApiRegistry -> first (PL_API_CAMERA );
187
- gptResource = ptApiRegistry -> first (PL_API_RESOURCE );
188
- gptRenderer = ptApiRegistry -> first (PL_API_REF_RENDERER );
189
- gptJobs = ptApiRegistry -> first (PL_API_JOB );
180
+ gptWindows = ptApiRegistry -> first (PL_API_WINDOW );
181
+ gptThreads = ptApiRegistry -> first (PL_API_THREADS );
182
+ gptStats = ptApiRegistry -> first (PL_API_STATS );
183
+ gptFile = ptApiRegistry -> first (PL_API_FILE );
184
+ gptGfx = ptApiRegistry -> first (PL_API_GRAPHICS );
185
+ gptDevice = ptApiRegistry -> first (PL_API_DEVICE );
186
+ gptDebug = ptApiRegistry -> first (PL_API_DEBUG );
187
+ gptImage = ptApiRegistry -> first (PL_API_IMAGE );
188
+ gptStream = ptApiRegistry -> first (PL_API_DRAW_STREAM );
189
+ gptEcs = ptApiRegistry -> first (PL_API_ECS );
190
+ gptCamera = ptApiRegistry -> first (PL_API_CAMERA );
191
+ gptResource = ptApiRegistry -> first (PL_API_RESOURCE );
192
+ gptRenderer = ptApiRegistry -> first (PL_API_REF_RENDERER );
193
+ gptJobs = ptApiRegistry -> first (PL_API_JOB );
194
+ gptModelLoader = ptApiRegistry -> first (PL_API_MODEL_LOADER );
195
+
196
+ // initialize job system
197
+ gptJobs -> initialize (0 );
190
198
191
199
const plWindowDesc tWindowDesc = {
192
200
.pcName = "Pilot Light Example" ,
@@ -224,36 +232,52 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
224
232
ptAppData -> ptDrawLayer = pl_request_layer (pl_get_draw_list (NULL ), "draw layer" );
225
233
226
234
// create main camera
227
- plComponentLibrary * ptComponentLibrary = gptRenderer -> get_component_library ();
228
- ptAppData -> tMainCamera = gptEcs -> create_perspective_camera (ptComponentLibrary , "main camera" , (plVec3 ){0 , 0 , 5.0f }, PL_PI_3 , ptIO -> afMainViewportSize [0 ] / ptIO -> afMainViewportSize [1 ], 0.01f , 400.0f );
229
- gptCamera -> set_pitch_yaw (gptEcs -> get_component (ptComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera ), 0.0f , PL_PI );
230
- gptCamera -> update (gptEcs -> get_component (ptComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera ));
235
+ plComponentLibrary * ptMainComponentLibrary = gptRenderer -> get_component_library (ptAppData -> uSceneHandle0 );
236
+ ptAppData -> tMainCamera = gptEcs -> create_perspective_camera (ptMainComponentLibrary , "main camera" , (plVec3 ){0 , 0 , 5.0f }, PL_PI_3 , ptIO -> afMainViewportSize [0 ] / ptIO -> afMainViewportSize [1 ], 0.01f , 400.0f );
237
+ gptCamera -> set_pitch_yaw (gptEcs -> get_component (ptMainComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera ), 0.0f , PL_PI );
238
+ gptCamera -> update (gptEcs -> get_component (ptMainComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera ));
231
239
232
240
// create cull camera
233
- ptAppData -> tCullCamera = gptEcs -> create_perspective_camera (ptComponentLibrary , "cull camera" , (plVec3 ){0 , 0 , 5.0f }, PL_PI_3 , ptIO -> afMainViewportSize [0 ] / ptIO -> afMainViewportSize [1 ], 0.1f , 106.0f );
234
- gptCamera -> set_pitch_yaw (gptEcs -> get_component (ptComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tCullCamera ), 0.0f , PL_PI );
235
- gptCamera -> update (gptEcs -> get_component (ptComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tCullCamera ));
241
+ ptAppData -> tCullCamera = gptEcs -> create_perspective_camera (ptMainComponentLibrary , "cull camera" , (plVec3 ){0 , 0 , 5.0f }, PL_PI_3 , ptIO -> afMainViewportSize [0 ] / ptIO -> afMainViewportSize [1 ], 0.1f , 106.0f );
242
+ gptCamera -> set_pitch_yaw (gptEcs -> get_component (ptMainComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tCullCamera ), 0.0f , PL_PI );
243
+ gptCamera -> update (gptEcs -> get_component (ptMainComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tCullCamera ));
236
244
237
- ptAppData -> tMainCamera2 = gptEcs -> create_perspective_camera (ptComponentLibrary , "secondary camera" , (plVec3 ){-3.265f , 2.967f , 0.311f }, PL_PI_3 , 1.0f , 0.01f , 400.0f );
238
- gptCamera -> set_pitch_yaw (gptEcs -> get_component (ptComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera2 ), -0.535f , 1.737f );
239
- gptCamera -> update (gptEcs -> get_component (ptComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera2 ));
245
+ plComponentLibrary * ptSecondaryComponentLibrary = gptRenderer -> get_component_library (ptAppData -> uSceneHandle1 );
246
+ 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 );
247
+ gptCamera -> set_pitch_yaw (gptEcs -> get_component (ptSecondaryComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera2 ), -0.535f , 1.737f );
248
+ gptCamera -> update (gptEcs -> get_component (ptSecondaryComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera2 ));
240
249
241
250
// load models
242
251
pl_begin_profile_frame ();
243
- pl_begin_profile_sample ("load models" );
252
+
253
+ pl_begin_profile_sample ("load skyboxes" );
244
254
const plMat4 tTransform0 = pl_mat4_translate_xyz (2.0f , 1.0f , 0.0f );
245
255
gptRenderer -> load_skybox_from_panorama (ptAppData -> uSceneHandle0 , "../data/glTF-Sample-Environments-main/ennis.jpg" , 1024 );
246
256
gptRenderer -> load_skybox_from_panorama (ptAppData -> uSceneHandle1 , "../data/glTF-Sample-Environments-main/ennis.jpg" , 1024 );
247
- gptRenderer -> load_gltf (ptAppData -> uSceneHandle0 , "../data/glTF-Sample-Assets-main/Models/Sponza/glTF/Sponza.gltf" , NULL );
248
- gptRenderer -> load_gltf (ptAppData -> uSceneHandle0 , "../data/glTF-Sample-Assets-main/Models/CesiumMan/glTF/CesiumMan.gltf" , NULL );
249
- gptRenderer -> load_stl (ptAppData -> uSceneHandle0 , "../data/pilotlight-assets-master/meshes/monkey.stl" , (plVec4 ){1.0f , 1.0f , 0.0f , 0.80f }, & tTransform0 );
257
+ pl_end_profile_sample ();
250
258
251
- gptRenderer -> load_gltf (ptAppData -> uSceneHandle1 , "../data/glTF-Sample-Assets-main/Models/CesiumMan/glTF/CesiumMan.gltf" , NULL );
252
- gptRenderer -> load_stl (ptAppData -> uSceneHandle1 , "../data/pilotlight-assets-master/meshes/monkey.stl" , (plVec4 ){1.0f , 0.0f , 0.0f , 0.80f }, & tTransform0 );
259
+ plModelLoaderData tLoaderData0 = {0 };
260
+
261
+ pl_begin_profile_sample ("load models 0" );
262
+ gptModelLoader -> load_gltf (ptMainComponentLibrary , "../data/glTF-Sample-Assets-main/Models/Sponza/glTF/Sponza.gltf" , NULL , & tLoaderData0 );
263
+ gptModelLoader -> load_gltf (ptMainComponentLibrary , "../data/glTF-Sample-Assets-main/Models/CesiumMan/glTF/CesiumMan.gltf" , NULL , & tLoaderData0 );
264
+ gptModelLoader -> load_stl (ptMainComponentLibrary , "../data/pilotlight-assets-master/meshes/monkey.stl" , (plVec4 ){1.0f , 1.0f , 0.0f , 0.80f }, & tTransform0 , & tLoaderData0 );
265
+ gptRenderer -> add_drawable_objects_to_scene (ptAppData -> uSceneHandle0 , tLoaderData0 .uOpaqueCount , tLoaderData0 .atOpaqueObjects , tLoaderData0 .uTransparentCount , tLoaderData0 .atTransparentObjects );
266
+ gptModelLoader -> free_data (& tLoaderData0 );
253
267
pl_end_profile_sample ();
254
268
255
- pl_begin_profile_sample ("finalize scene" );
269
+ pl_begin_profile_sample ("load models 1" );
270
+ gptModelLoader -> load_gltf (ptSecondaryComponentLibrary , "../data/glTF-Sample-Assets-main/Models/CesiumMan/glTF/CesiumMan.gltf" , NULL , & tLoaderData0 );
271
+ gptModelLoader -> load_stl (ptSecondaryComponentLibrary , "../data/pilotlight-assets-master/meshes/monkey.stl" , (plVec4 ){1.0f , 0.0f , 0.0f , 0.80f }, & tTransform0 , & tLoaderData0 );
272
+ gptRenderer -> add_drawable_objects_to_scene (ptAppData -> uSceneHandle1 , tLoaderData0 .uOpaqueCount , tLoaderData0 .atOpaqueObjects , tLoaderData0 .uTransparentCount , tLoaderData0 .atTransparentObjects );
273
+ gptModelLoader -> free_data (& tLoaderData0 );
274
+ pl_end_profile_sample ();
275
+
276
+ pl_begin_profile_sample ("finalize scene 0" );
256
277
gptRenderer -> finalize_scene (ptAppData -> uSceneHandle0 );
278
+ pl_end_profile_sample ();
279
+
280
+ pl_begin_profile_sample ("finalize scene 1" );
257
281
gptRenderer -> finalize_scene (ptAppData -> uSceneHandle1 );
258
282
pl_end_profile_sample ();
259
283
@@ -276,6 +300,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
276
300
PL_EXPORT void
277
301
pl_app_shutdown (plAppData * ptAppData )
278
302
{
303
+ gptJobs -> cleanup ();
279
304
gptGfx -> destroy_font_atlas (& ptAppData -> tFontAtlas ); // backend specific cleanup
280
305
pl_cleanup_font_atlas (& ptAppData -> tFontAtlas );
281
306
gptRenderer -> cleanup ();
@@ -294,7 +319,7 @@ pl_app_resize(plAppData* ptAppData)
294
319
{
295
320
gptGfx -> resize (gptRenderer -> get_graphics ());
296
321
plIO * ptIO = pl_get_io ();
297
- gptCamera -> set_aspect (gptEcs -> get_component (gptRenderer -> get_component_library (), PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera ), ptIO -> afMainViewportSize [0 ] / ptIO -> afMainViewportSize [1 ]);
322
+ gptCamera -> set_aspect (gptEcs -> get_component (gptRenderer -> get_component_library (ptAppData -> uSceneHandle0 ), PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera ), ptIO -> afMainViewportSize [0 ] / ptIO -> afMainViewportSize [1 ]);
298
323
ptAppData -> bResize = true;
299
324
}
300
325
@@ -349,11 +374,12 @@ pl_app_update(plAppData* ptAppData)
349
374
* pdMemoryCounter = (double )pl_get_memory_context ()-> szMemoryUsage ;
350
375
351
376
// handle input
352
- plComponentLibrary * ptComponentLibrary = gptRenderer -> get_component_library ();
377
+ plComponentLibrary * ptMainComponentLibrary = gptRenderer -> get_component_library (ptAppData -> uSceneHandle0 );
378
+ plComponentLibrary * ptSecondaryComponentLibrary = gptRenderer -> get_component_library (ptAppData -> uSceneHandle1 );
353
379
354
- plCameraComponent * ptCamera = gptEcs -> get_component (ptComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera );
355
- plCameraComponent * ptCamera2 = gptEcs -> get_component (ptComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera2 );
356
- plCameraComponent * ptCullCamera = gptEcs -> get_component (ptComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tCullCamera );
380
+ plCameraComponent * ptCamera = gptEcs -> get_component (ptMainComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera );
381
+ plCameraComponent * ptCamera2 = gptEcs -> get_component (ptSecondaryComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tMainCamera2 );
382
+ plCameraComponent * ptCullCamera = gptEcs -> get_component (ptMainComponentLibrary , PL_COMPONENT_TYPE_CAMERA , ptAppData -> tCullCamera );
357
383
358
384
static const float fCameraTravelSpeed = 4.0f ;
359
385
static const float fCameraRotationSpeed = 0.005f ;
@@ -381,7 +407,8 @@ pl_app_update(plAppData* ptAppData)
381
407
gptCamera -> update (ptCullCamera );
382
408
383
409
// run ecs system
384
- gptRenderer -> run_ecs ();
410
+ gptRenderer -> run_ecs (ptAppData -> uSceneHandle0 );
411
+ gptRenderer -> run_ecs (ptAppData -> uSceneHandle1 );
385
412
386
413
// new ui frame
387
414
pl_new_frame ();
@@ -529,7 +556,7 @@ pl_app_update(plAppData* ptAppData)
529
556
gptDebug -> show_debug_windows (& ptAppData -> tDebugInfo );
530
557
531
558
if (ptAppData -> bShowEntityWindow )
532
- pl_show_ecs_window (gptEcs , gptRenderer -> get_component_library (), & ptAppData -> bShowEntityWindow );
559
+ pl_show_ecs_window (gptEcs , gptRenderer -> get_component_library (ptAppData -> uSceneHandle0 ), & ptAppData -> bShowEntityWindow );
533
560
534
561
if (ptAppData -> bShowUiDemo )
535
562
{
0 commit comments