Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ void main()
SDL_GPUVertexAttribute vertexAttributes[2]{};
SDL_GPUVertexBufferDescription vertexBufferDesctiptions[1]{};

/**
* @brief Initialize the application: create window, compile shaders, create GPU pipeline and resources, and
* initialize ImGui.
*
* @param argc Number of command-line arguments provided to the application.
* @param argv Command-line argument vector provided to the application.
* @return SDL_AppResult SDL_APP_CONTINUE to proceed with the main loop, SDL_APP_SUCCESS to request termination.
*/
virtual SDL_AppResult init(int argc, char** argv) override
{
// create a window
Expand Down Expand Up @@ -216,6 +224,17 @@ void main()
return SDL_APP_CONTINUE;
}

/**
* @brief Advance the application by one frame: update ImGui, handle UI for vertex editing and live shader
* recompilation, record GPU commands to render the triangle and ImGui, and submit the GPU command buffer.
*
* Performs per-frame UI updates (including draggable vertex positions and a multiline shader editor), uploads
* vertex data when modified, recompiles and replaces the vertex shader and graphics pipeline on shader edits,
* acquires a GPU command buffer and the swapchain texture, executes a render pass that draws the triangle and ImGui
* draw lists, and submits the command buffer.
*
* @return SDL_AppResult SDL_APP_CONTINUE to continue the main loop.
*/
virtual SDL_AppResult iterate() override
{
ImGui_ImplSDLGPU3_NewFrame();
Expand Down Expand Up @@ -346,6 +365,14 @@ void main()
return SDL_APP_CONTINUE;
}

/**
* @brief Cleanly shuts down the application and releases GPU and UI resources.
*
* Performs final cleanup: shuts down ImGui SDL/SDLGPU backends, destroys the ImGui context,
* releases the vertex buffer, shaders, and graphics pipeline, and destroys the SDL window.
*
* @param result The application's exit result code provided by the SDL app framework.
*/
virtual void quit(SDL_AppResult result) override
{
ImGui_ImplSDL3_Shutdown();
Expand Down
31 changes: 31 additions & 0 deletions sdl_wrapper/sdl_callback_implement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import sdl_wrapper;

extern sopho::App* create_app();

/**
* @brief Initializes the SDL video subsystem, constructs the application, and invokes its initialization.
*
* @param appstate Pointer to storage that will receive the created sopho::App* on success.
* @param argc Program argument count forwarded to the application's init.
* @param argv Program argument vector forwarded to the application's init.
* @return SDL_AppResult Result returned by the application's init, or SDL_APP_FAILURE if application creation failed.
*/
SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv)
{
SDL_Init(SDL_INIT_VIDEO);
Expand All @@ -18,18 +26,41 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv)
return app->init(argc, argv);
}

/**
* @brief Invoke the application's per-frame iterate handler.
*
* @param appstate Pointer to the sopho::App instance previously stored in SDL_AppInit.
* @return SDL_AppResult The result of the application's iterate call indicating the application's requested next
* action.
*/
SDL_AppResult SDL_AppIterate(void* appstate)
{
auto* app = static_cast<sopho::App*>(appstate);
return app->iterate();
}

/**
* @brief Dispatches an SDL event to the stored application instance.
*
* @param appstate Opaque pointer previously set by SDL_AppInit; must point to a `sopho::App` instance.
* @param event Pointer to the SDL event to deliver to the application.
* @return SDL_AppResult Result returned by the application's event handler.
*/
SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
{
auto* app = static_cast<sopho::App*>(appstate);
return app->event(event);
}

/**
* @brief Shuts down the application and releases its instance.
*
* Invokes the application's quit handler with the provided result and destroys
* the stored application instance.
*
* @param appstate Pointer to the sopho::App instance previously stored by SDL_AppInit.
* @param result Result code describing why the application is quitting.
*/
void SDL_AppQuit(void* appstate, SDL_AppResult result)
{
auto* app = static_cast<sopho::App*>(appstate);
Expand Down