![]() |
Mandrill 2025.6.0
|
Base class for a Mandrill application. This class provides the basic functionality to create a window and handling user input. This class should be inherited by any application using Mandrill, and all the pure virtual functions have to be overriden. More...
#include <App.h>
Public Member Functions | |
App (const std::string &title, uint32_t width=1280, uint32_t height=720) | |
Create a new Mandrill app. | |
~App () | |
Destructor for app. | |
void | run () |
This is the main function of an application. A typical usecase would be to inherit App and then invoke the run() function. For a class SampleApp that inherits App this is how it could be used: | |
Protected Member Functions | |
virtual void | update (float delta)=0 |
Update scene objects. | |
virtual void | render ()=0 |
Render app. | |
virtual void | appGUI (ImGuiContext *pContext)=0 |
Draw application specific GUI of a Mandrill application. | |
void | createGUI (ptr< Device > pDevice, ptr< Pass > pPass) |
Create a GUI for the application. | |
void | destroyGUI (ptr< Device > pDevice) |
Destroy the GUI for the application. | |
void | baseGUI (ptr< Device > pDevice, ptr< Swapchain > pSwapchain, ptr< Pipeline > pPipeline) |
Draw the base GUI of a Mandrill application. | |
void | baseGUI (ptr< Device > pDevice, ptr< Swapchain > pSwapchain, std::vector< ptr< Pipeline > > pPipelines) |
Draw the base GUI of a Mandrill application. | |
void | renderGUI (VkCommandBuffer cmd) const |
Render the GUI by writing the state to a command buffer. | |
void | baseKeyCallback (GLFWwindow *pWindow, int key, int scancode, int action, int mods, ptr< Device > pDevice, ptr< Swapchain > pSwapchain, ptr< Pipeline > pPipeline) |
App keyboard callback function. This will handle keyboard commands associated with the base application menus. Read more in the GLFW documentation: https://www.glfw.org/docs/3.3/input_guide.html#input_key. | |
void | baseKeyCallback (GLFWwindow *pWindow, int key, int scancode, int action, int mods, ptr< Device > pDevice, ptr< Swapchain > pSwapchain, std::vector< ptr< Pipeline > > pPipelines) |
App keyboard callback function. This will handle keyboard commands associated with the base application menus. Read more in the GLFW documentation: https://www.glfw.org/docs/3.3/input_guide.html#input_key. | |
virtual void | appKeyCallback (GLFWwindow *pWindow, int key, int scancode, int action, int mods)=0 |
Virtual function for app to override. Just invoke baseKeyCallback() to get standard keybindings. See baseKeyCallback() for more details. | |
void | baseCursorPosCallback (GLFWwindow *pWindow, double xPos, double yPos) |
App cursor position callback function. This will handle track mouse movements and is required for getCursorDelta() to work. Read more in the GLFW documentation: https://www.glfw.org/docs/3.3/input_guide.html#input_mouse. | |
virtual void | appCursorPosCallback (GLFWwindow *pWindow, double xPos, double yPos)=0 |
Virtual function for app to override. Just invoke baseCursorPosCallback() to get standard keybindings. See baseCursorPosCallback() for more details. | |
void | baseMouseButtonCallback (GLFWwindow *pWindow, int button, int action, int mods, ptr< Camera > pCamera) |
App mouse button callback function. This will handle camera capturing the mouse cursor. Read more in the GLFW docutmentation: https://www.glfw.org/docs/3.3/input_guide.html#input_mouse. | |
virtual void | appMouseButtonCallback (GLFWwindow *pWindow, int button, int action, int mods)=0 |
Virtual function for app to override. Just invoke baseMouseButtonCallback() to get standard keybindings. See baseMouseButtonCallback() for more details. | |
glm::vec2 | getCursorDelta () const |
Get how the mouse cursor moved since last frame. | |
bool | keyboardCapturedByGUI () const |
Check if keyboard inputs are currently captured by the GUI. | |
bool | mouseCapturedByGUI () const |
Check if mouse inputs are currently captured by the GUI. | |
Protected Attributes | |
GLFWwindow * | mpWindow |
uint32_t | mWidth |
uint32_t | mHeight |
float | mTime = 0.0f |
Base class for a Mandrill application. This class provides the basic functionality to create a window and handling user input. This class should be inherited by any application using Mandrill, and all the pure virtual functions have to be overriden.
App::App | ( | const std::string & | title, |
uint32_t | width = 1280 , |
||
uint32_t | height = 720 |
||
) |
Create a new Mandrill app.
title | Title to be shown in the window frame |
width | Width of window |
height | Height of window |
|
protectedpure virtual |
Virtual function for app to override. Just invoke baseCursorPosCallback()
to get standard keybindings. See baseCursorPosCallback()
for more details.
pWindow | The window that received the event |
xPos | The new cursor x-coordinate, relative to the left edge of the content area. |
yPos | The new cursor y-coordinate, relative to the top edge of the content area. |
|
protectedpure virtual |
Draw application specific GUI of a Mandrill application.
Use this function to draw GUI that is specific to the application. This function gives access to the current ImGUI context being used by Mandrill. Make sure to set the context before interacting with ImGUI:
ImGui::SetCurrentContext(pContext);
This function should be overridden.
pContext | Current ImGUI context |
|
protectedpure virtual |
Virtual function for app to override. Just invoke baseKeyCallback()
to get standard keybindings. See baseKeyCallback()
for more details.
pWindow | The window that received the event |
key | The keyboard key that was pressed or released |
scancode | The system-specific scancode of the key |
action | GLFW_PRESS , GLFW_RELEASE or GLFW_REPEAT . Future releases may add more actions |
mods | Bit field describing which modifier keys were held down |
|
protectedpure virtual |
Virtual function for app to override. Just invoke baseMouseButtonCallback()
to get standard keybindings. See baseMouseButtonCallback()
for more details.
pWindow | The window that received the event |
button | The mouse button that was pressed or released. |
action | One of GLFW_PRESS or GLFW_RELEASE . Future releases may add more actions. |
mods | Bit field describing which modifier keys were held down. |
|
protected |
App cursor position callback function. This will handle track mouse movements and is required for getCursorDelta() to work. Read more in the GLFW documentation: https://www.glfw.org/docs/3.3/input_guide.html#input_mouse.
pWindow | The window that received the event |
xPos | The new cursor x-coordinate, relative to the left edge of the content area. |
yPos | The new cursor y-coordinate, relative to the top edge of the content area. |
|
protected |
Draw the base GUI of a Mandrill application.
This function will draw a menu bar and allow for basic features like showing framerate and taking screenshots. The menu also allows for controlling different aspects of the rendering context and therefore needs access to the device, swapchain, render pass and pipelines.
|
protected |
Draw the base GUI of a Mandrill application.
This function will draw a menu bar and allow for basic features like showing framerate and taking screenshots. The menu also allows for controlling different aspects of the rendering context and therefore needs access to the device, swapchain, render pass and pipelines.
pDevice | Currently active device |
pSwapchain | Swapchain that should be recreated on changes |
pPipelines | Pipelines that should be recreated |
|
protected |
App keyboard callback function. This will handle keyboard commands associated with the base application menus. Read more in the GLFW documentation: https://www.glfw.org/docs/3.3/input_guide.html#input_key.
pWindow | The window that received the event |
key | The keyboard key that was pressed or released |
scancode | The system-specific scancode of the key |
action | GLFW_PRESS , GLFW_RELEASE or GLFW_REPEAT . Future releases may add more actions |
mods | Bit field describing which modifier keys were held down |
pDevice | Currently active device |
pSwapchain | Swapchain that should be recreated on changes |
pPipeline | Pipeline that should be recreated |
|
protected |
App keyboard callback function. This will handle keyboard commands associated with the base application menus. Read more in the GLFW documentation: https://www.glfw.org/docs/3.3/input_guide.html#input_key.
pWindow | The window that received the event |
key | The keyboard key that was pressed or released |
scancode | The system-specific scancode of the key |
action | GLFW_PRESS , GLFW_RELEASE or GLFW_REPEAT . Future releases may add more actions |
mods | Bit field describing which modifier keys were held down |
pDevice | Currently active device |
pSwapchain | Swapchain that should be recreated on changes |
pPipelines | Pipelines that should be recreated |
|
protected |
App mouse button callback function. This will handle camera capturing the mouse cursor. Read more in the GLFW docutmentation: https://www.glfw.org/docs/3.3/input_guide.html#input_mouse.
pWindow | The window that received the event |
button | The mouse button that was pressed or released. |
action | One of GLFW_PRESS or GLFW_RELEASE . Future releases may add more actions. |
mods | Bit field describing which modifier keys were held down. |
pCamera | Current active camera to handle mouse capture for. |
|
protected |
Destroy the GUI for the application.
This will clean-up all the allocated resources of ImGUI.
pDevice | Device that was used for resources allocations |
|
inlineprotected |
Get how the mouse cursor moved since last frame.
|
inlineprotected |
Check if keyboard inputs are currently captured by the GUI.
|
inlineprotected |
Check if mouse inputs are currently captured by the GUI.
|
protectedpure virtual |
Render app.
This function is called once per run()
loop is used to populate the command buffer for rendering. Typical use case is to acquire a frame from the swapchain, populate the command buffer and then present the to the screen using a render pass.
This is an example:
void render() override { VkCommandBuffer cmd = mpSwapchain->acquireNextImage(); mpPass->frameBegin(cmd, glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
// Populate command buffer using cmd here...
mpPass->frameEnd(cmd); mpSwapchain->present(cmd, mpPass->getOutput()); }
This function should be overridden.
|
protected |
Render the GUI by writing the state to a command buffer.
Call this while populating command buffer.
cmd | Command buffer to write to |
void App::run | ( | ) |
|
protectedpure virtual |
Update scene objects.
This function is called once per run()
loop and can be used to update scene objects like meshes and cameras that should animate.
This function should be overridden.
delta | Time passed since last frame |