Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed May 20, 2024
1 parent 01ab43e commit e0af219
Show file tree
Hide file tree
Showing 45 changed files with 13,105 additions and 3,142 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
if not exist ../out/example_1.dll exit 1
if not exist ../out/example_2.dll exit 1
if not exist ../out/example_3.dll exit 1
if not exist ../out/example_4.dll exit 1
if not exist ../out/pilot_light.exe exit 1
if not exist ../out/pl_graphics_ext.dll exit 1
if not exist ../out/pl_image_ext.dll exit 1
Expand Down Expand Up @@ -117,6 +118,7 @@ jobs:
test -f ./out/example_1.dylib || exit 1
test -f ./out/example_2.dylib || exit 1
test -f ./out/example_3.dylib || exit 1
test -f ./out/example_4.dylib || exit 1
test -f ./out/pl_stats_ext.dylib || exit 1
test -f ./out/pl_image_ext.dylib || exit 1
test -f ./out/pl_debug_ext.dylib || exit 1
Expand Down Expand Up @@ -192,6 +194,7 @@ jobs:
test -f ./out/example_1.so || exit 1
test -f ./out/example_2.so || exit 1
test -f ./out/example_3.so || exit 1
test -f ./out/example_4.so || exit 1
test -f ./out/pl_graphics_ext.so || exit 1
test -f ./out/pl_image_ext.so || exit 1
test -f ./out/pl_stats_ext.so || exit 1
Expand Down
488 changes: 397 additions & 91 deletions apps/app.c

Large diffs are not rendered by default.

299 changes: 0 additions & 299 deletions apps/helper_windows.h

This file was deleted.

20 changes: 16 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,27 @@ Demonstrates:
* loading APIs
* hot reloading

## Example 2 - UI Library (example_2.c)
## Example 2 - Drawing Extension 2D (example_2.c)
Demonstrates:
* loading APIs
* hot reloading
* loading extensions
* UI library
* minimal use of graphics extension
* drawing extension (2D)

## Example 3 - 3D Debug Drawing (example_3.c)
## Example 3 - UI Extension (example_3.c)
Demonstrates:
* loading APIs
* hot reloading
* loading extensions
* minimal use of graphics extension
* drawing extension (2D)
* UI extension

## Example 4 - Drawing Extension 3D (example_4.c)
Demonstrates:
* loading APIs
* hot reloading
* loading extensions
* 3D debug drawing extension
* minimal use of graphics extension
* drawing extension (3D)
18 changes: 11 additions & 7 deletions examples/example_0.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/*
Index of this file:
// [SECTION] includes
// [SECTION] apis
// [SECTION] pl_app_load
// [SECTION] pl_app_shutdown
// [SECTION] pl_app_resize
Expand All @@ -18,7 +19,12 @@ Index of this file:

#include <stdio.h>
#include "pilotlight.h"
#include "pl_ui.h"

//-----------------------------------------------------------------------------
// [SECTION] apis
//-----------------------------------------------------------------------------

const plIOI* gptIO = NULL;

//-----------------------------------------------------------------------------
// [SECTION] pl_app_load
Expand All @@ -34,10 +40,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, void* pAppData)
// between extensions & the runtime
const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY);

// retrieve the UI context (provided by the runtime) and
// set it (required to use plIO for "talking" with runtime)
plUiContext* ptUIContext = ptDataRegistry->get_data("context");
pl_set_context(ptUIContext);
// retrieve the IO API required to use plIO for "talking" with runtime)
gptIO = ptApiRegistry->first(PL_API_IO);

// return optional application memory
return NULL;
Expand Down Expand Up @@ -71,7 +75,7 @@ PL_EXPORT void
pl_app_update(void* pAppData)
{

pl_new_frame(); // must be called once at the beginning of a frame
gptIO->new_frame(); // must be called once at the beginning of a frame

static int iIteration = 0;

Expand All @@ -80,7 +84,7 @@ pl_app_update(void* pAppData)
// shutdown main event loop after 50 iterations
if(iIteration == 50)
{
plIO* ptIO = pl_get_io();
plIO* ptIO = gptIO->get_io();
ptIO->bRunning = false;
}
}
24 changes: 8 additions & 16 deletions examples/example_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Index of this file:
#include <stdio.h>
#include <string.h> // memset
#include "pilotlight.h"
#include "pl_ui.h"
#include "pl_os.h" // window api

//-----------------------------------------------------------------------------
Expand All @@ -38,6 +37,7 @@ typedef struct _plAppData
// [SECTION] apis
//-----------------------------------------------------------------------------

const plIOI* gptIO = NULL;
const plWindowI* gptWindows = NULL;

//-----------------------------------------------------------------------------
Expand All @@ -54,21 +54,16 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// between extensions & the runtime
const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY);

// retrieve the UI context (provided by the runtime) and
// set it (required to use plIO for "talking" with runtime & keyboard/mouse input)
plUiContext* ptUIContext = ptDataRegistry->get_data("context");
pl_set_context(ptUIContext);

// load required apis (NULL if not available)
gptIO = ptApiRegistry->first(PL_API_IO);
gptWindows = ptApiRegistry->first(PL_API_WINDOW);

// if "ptAppData" is a valid pointer, then this function is being called
// during a hot reload.
if(ptAppData)
{
printf("Hot reload!\n");

// re-retrieve the windows API since we are now in
// a different dll/so
gptWindows = ptApiRegistry->first(PL_API_WINDOW);

// return the same memory again
return ptAppData;
}
Expand All @@ -78,9 +73,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
ptAppData = malloc(sizeof(plAppData));
memset(ptAppData, 0, sizeof(plAppData));

// load required apis (NULL if not available)
gptWindows = ptApiRegistry->first(PL_API_WINDOW);

// use window API to create a window
const plWindowDesc tWindowDesc = {
.pcName = "Example 1",
Expand Down Expand Up @@ -117,7 +109,7 @@ PL_EXPORT void
pl_app_resize(plAppData* ptAppData)
{
// perform any operations required during a window resize
plIO* ptIO = pl_get_io();
plIO* ptIO = gptIO->get_io();
printf("resize to %d, %d\n", (int)ptIO->afMainViewportSize[0], (int)ptIO->afMainViewportSize[1]);
}

Expand All @@ -129,10 +121,10 @@ PL_EXPORT void
pl_app_update(plAppData* ptAppData)
{

pl_new_frame(); // must be called once at the beginning of a frame
gptIO->new_frame(); // must be called once at the beginning of a frame

// check for key press
if(pl_is_key_pressed(PL_KEY_P, true))
if(gptIO->is_key_pressed(PL_KEY_P, true))
{
printf("P key pressed!\n");
}
Expand Down
99 changes: 35 additions & 64 deletions examples/example_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
- demonstrates loading APIs
- demonstrates loading extensions
- demonstrates hot reloading
- demonstrates UI library
- demonstrates minimal use of graphics extension
- demonstrates drawing extension (2D)
*/

/*
Expand All @@ -31,10 +31,10 @@ Index of this file:
#include "pl_memory.h"
#define PL_MATH_INCLUDE_FUNCTIONS
#include "pl_math.h"
#include "pl_ui.h"

// extensions
#include "pl_graphics_ext.h"
#include "pl_draw_ext.h"

//-----------------------------------------------------------------------------
// [SECTION] structs
Expand All @@ -49,10 +49,10 @@ typedef struct _plAppData
bool bShowUiDemo;

// drawing
plFontAtlas tFontAtlas;
plDrawList tAppDrawlist;
plDrawLayer* ptFGLayer;
plDrawLayer* ptBGLayer;
plFontAtlas tFontAtlas;
plDrawList2D* ptDrawlist;
plDrawLayer2D* ptFGLayer;
plDrawLayer2D* ptBGLayer;

// graphics & sync objects
plGraphics tGraphics;
Expand All @@ -65,9 +65,11 @@ typedef struct _plAppData
// [SECTION] apis
//-----------------------------------------------------------------------------

const plIOI* gptIO = NULL;
const plWindowI* gptWindows = NULL;
const plGraphicsI* gptGfx = NULL;
const plDeviceI* gptDevice = NULL;
const plDrawI* gptDraw = NULL;

//-----------------------------------------------------------------------------
// [SECTION] pl_app_load
Expand All @@ -83,10 +85,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// between extensions & the runtime
const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY);

// retrieve the UI context (provided by the runtime) and
// set it (required to use plIO for "talking" with runtime & keyboard/mouse input)
pl_set_context(ptDataRegistry->get_data("ui"));

// retrieve the memory context (provided by the runtime) and
// set it to allow for memory tracking when using PL_ALLOC/PL_FREE
pl_set_memory_context(ptDataRegistry->get_data(PL_CONTEXT_MEMORY));
Expand All @@ -102,9 +100,11 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// re-retrieve the apis since we are now in
// a different dll/so
gptWindows = ptApiRegistry->first(PL_API_WINDOW);
gptGfx = ptApiRegistry->first(PL_API_GRAPHICS);
gptDevice = ptApiRegistry->first(PL_API_DEVICE);
gptIO = ptApiRegistry->first(PL_API_IO);
gptWindows = ptApiRegistry->first(PL_API_WINDOW);
gptGfx = ptApiRegistry->first(PL_API_GRAPHICS);
gptDevice = ptApiRegistry->first(PL_API_DEVICE);
gptDraw = ptApiRegistry->first(PL_API_DRAW);

return ptAppData;
}
Expand Down Expand Up @@ -132,11 +132,14 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// load graphics extension (provides graphics & device apis)
ptExtensionRegistry->load("pl_graphics_ext", NULL, NULL, false);
ptExtensionRegistry->load("pl_draw_ext", NULL, NULL, true);

// load required apis (NULL if not available)
gptIO = ptApiRegistry->first(PL_API_IO);
gptWindows = ptApiRegistry->first(PL_API_WINDOW);
gptGfx = ptApiRegistry->first(PL_API_GRAPHICS);
gptDevice = ptApiRegistry->first(PL_API_DEVICE);
gptDraw = ptApiRegistry->first(PL_API_DRAW);

// use window API to create a window
const plWindowDesc tWindowDesc = {
Expand All @@ -154,17 +157,15 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
};
gptGfx->initialize(ptAppData->ptWindow, &tGraphicsDesc, &ptAppData->tGraphics);

// setup ui
pl_add_default_font(&ptAppData->tFontAtlas); // Proggy.ttf w/ 13 pt
pl_build_font_atlas(&ptAppData->tFontAtlas); // generates font atlas data
gptGfx->setup_ui(&ptAppData->tGraphics, ptAppData->tGraphics.tMainRenderPass); // prepares any graphics backend specifics
gptGfx->create_font_atlas(&ptAppData->tFontAtlas); // creates font atlas texture
pl_set_default_font(&ptAppData->tFontAtlas.sbtFonts[0]); // sets default font to use for UI rendering
// setup draw
gptDraw->initialize(&ptAppData->tGraphics);
gptDraw->add_default_font(&ptAppData->tFontAtlas);
gptDraw->build_font_atlas(&ptAppData->tFontAtlas);

// register our app drawlist
pl_register_drawlist(&ptAppData->tAppDrawlist);
ptAppData->ptFGLayer = pl_request_layer(&ptAppData->tAppDrawlist, "foreground layer");
ptAppData->ptBGLayer = pl_request_layer(&ptAppData->tAppDrawlist, "background layer");
ptAppData->ptDrawlist = gptDraw->request_2d_drawlist();
ptAppData->ptFGLayer = gptDraw->request_2d_layer(ptAppData->ptDrawlist, "foreground layer");
ptAppData->ptBGLayer = gptDraw->request_2d_layer(ptAppData->ptDrawlist, "background layer");

// create timeline semaphores to syncronize GPU work submission
for(uint32_t i = 0; i < PL_FRAMES_IN_FLIGHT; i++)
Expand All @@ -181,12 +182,10 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
PL_EXPORT void
pl_app_shutdown(plAppData* ptAppData)
{
// cleanup
gptGfx->destroy_font_atlas(&ptAppData->tFontAtlas); // backend specific cleanup
pl_cleanup_font_atlas(&ptAppData->tFontAtlas);

// ensure GPU is finished before cleanup
gptDevice->flush_device(&ptAppData->tGraphics.tDevice);
gptDraw->cleanup_font_atlas(&ptAppData->tFontAtlas);
gptDraw->cleanup();
gptGfx->cleanup(&ptAppData->tGraphics);
gptWindows->destroy_window(ptAppData->ptWindow);
pl_cleanup_profile_context();
Expand Down Expand Up @@ -214,6 +213,9 @@ pl_app_update(plAppData* ptAppData)
{
pl_begin_profile_frame();

gptIO->new_frame();
gptDraw->new_frame();

// for convience
plGraphics* ptGraphics = &ptAppData->tGraphics;

Expand All @@ -225,45 +227,15 @@ pl_app_update(plAppData* ptAppData)
return;
}

pl_new_frame(); // must be called once at the beginning of a frame

// create a UI window
if(pl_begin_window("Pilot Light", NULL, false))
{

const float pfRatios[] = {1.0f};
pl_layout_row(PL_UI_LAYOUT_ROW_TYPE_DYNAMIC, 0.0f, 1, pfRatios);
if(pl_collapsing_header("Information"))
{
pl_text("Pilot Light %s", PILOTLIGHT_VERSION);
pl_text("Pilot Light UI %s", PL_UI_VERSION);
pl_text("Pilot Light DS %s", PL_DS_VERSION);
pl_end_collapsing_header();
}

if(pl_collapsing_header("User Interface"))
{
pl_checkbox("UI Demo", &ptAppData->bShowUiDemo);
pl_end_collapsing_header();
}
pl_end_window();
}

if(ptAppData->bShowUiDemo)
pl_show_demo_window(&ptAppData->bShowUiDemo);

// drawing API usage
pl_add_circle(ptAppData->ptFGLayer, (plVec2){120.0f, 120.0f}, 50.0f, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 0, 1.0f);
pl_add_circle_filled(ptAppData->ptBGLayer, (plVec2){100.0f, 100.0f}, 25.0f, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 24);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~UI & drawing prep~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gptDraw->add_circle(ptAppData->ptFGLayer, (plVec2){120.0f, 120.0f}, 50.0f, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 0, 1.0f);
gptDraw->add_circle_filled(ptAppData->ptBGLayer, (plVec2){100.0f, 100.0f}, 25.0f, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 24);

// build UI render data (and submits layers in correct order)
pl_render();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~drawing prep~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// submit our draw layers
pl_submit_layer(ptAppData->ptBGLayer);
pl_submit_layer(ptAppData->ptFGLayer);
gptDraw->submit_2d_layer(ptAppData->ptBGLayer);
gptDraw->submit_2d_layer(ptAppData->ptFGLayer);

//~~~~~~~~~~~~~~~~~~~~~~~~begin recording command buffer~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -283,9 +255,8 @@ pl_app_update(plAppData* ptAppData)
plRenderEncoder tEncoder = gptGfx->begin_render_pass(ptGraphics, &tCommandBuffer, ptGraphics->tMainRenderPass);

// submit drawlists
gptGfx->draw_lists(ptGraphics, tEncoder, 1, pl_get_draw_list(NULL));
gptGfx->draw_lists(ptGraphics, tEncoder, 1, pl_get_debug_draw_list(NULL));
gptGfx->draw_lists(ptGraphics, tEncoder, 1, &ptAppData->tAppDrawlist);
plIO* ptIO = gptIO->get_io();
gptDraw->submit_2d_drawlist(ptAppData->ptDrawlist, tEncoder, ptIO->afMainViewportSize[0], ptIO->afMainViewportSize[1], 1);

// end render pass
gptGfx->end_render_pass(&tEncoder);
Expand Down
Loading

0 comments on commit e0af219

Please sign in to comment.