Mandrill 2025.6.0
Loading...
Searching...
No Matches
Mandrill::App Class Referenceabstract

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ App()

App::App ( const std::string &  title,
uint32_t  width = 1280,
uint32_t  height = 720 
)

Create a new Mandrill app.

Parameters
titleTitle to be shown in the window frame
widthWidth of window
heightHeight of window

Member Function Documentation

◆ appCursorPosCallback()

virtual void Mandrill::App::appCursorPosCallback ( GLFWwindow *  pWindow,
double  xPos,
double  yPos 
)
protectedpure virtual

Virtual function for app to override. Just invoke baseCursorPosCallback() to get standard keybindings. See baseCursorPosCallback() for more details.

Parameters
pWindowThe window that received the event
xPosThe new cursor x-coordinate, relative to the left edge of the content area.
yPosThe new cursor y-coordinate, relative to the top edge of the content area.

◆ appGUI()

virtual void Mandrill::App::appGUI ( ImGuiContext *  pContext)
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.

Parameters
pContextCurrent ImGUI context

◆ appKeyCallback()

virtual void Mandrill::App::appKeyCallback ( GLFWwindow *  pWindow,
int  key,
int  scancode,
int  action,
int  mods 
)
protectedpure virtual

Virtual function for app to override. Just invoke baseKeyCallback() to get standard keybindings. See baseKeyCallback() for more details.

Parameters
pWindowThe window that received the event
keyThe keyboard key that was pressed or released
scancodeThe system-specific scancode of the key
actionGLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT. Future releases may add more actions
modsBit field describing which modifier keys were held down

◆ appMouseButtonCallback()

virtual void Mandrill::App::appMouseButtonCallback ( GLFWwindow *  pWindow,
int  button,
int  action,
int  mods 
)
protectedpure virtual

Virtual function for app to override. Just invoke baseMouseButtonCallback() to get standard keybindings. See baseMouseButtonCallback() for more details.

Parameters
pWindowThe window that received the event
buttonThe mouse button that was pressed or released.
actionOne of GLFW_PRESS or GLFW_RELEASE. Future releases may add more actions.
modsBit field describing which modifier keys were held down.

◆ baseCursorPosCallback()

void App::baseCursorPosCallback ( GLFWwindow *  pWindow,
double  xPos,
double  yPos 
)
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.

Parameters
pWindowThe window that received the event
xPosThe new cursor x-coordinate, relative to the left edge of the content area.
yPosThe new cursor y-coordinate, relative to the top edge of the content area.

◆ baseGUI() [1/2]

void App::baseGUI ( ptr< Device pDevice,
ptr< Swapchain pSwapchain,
ptr< Pipeline pPipeline 
)
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.

Parameters
pDeviceCurrently active device
pSwapchainSwapchain that should be recreated on changes
pPiplinePipeline that should be recreated

◆ baseGUI() [2/2]

void App::baseGUI ( ptr< Device pDevice,
ptr< Swapchain pSwapchain,
std::vector< ptr< Pipeline > >  pPipelines 
)
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.

Parameters
pDeviceCurrently active device
pSwapchainSwapchain that should be recreated on changes
pPipelinesPipelines that should be recreated

◆ baseKeyCallback() [1/2]

void App::baseKeyCallback ( GLFWwindow *  pWindow,
int  key,
int  scancode,
int  action,
int  mods,
ptr< Device pDevice,
ptr< Swapchain pSwapchain,
ptr< Pipeline pPipeline 
)
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.

Parameters
pWindowThe window that received the event
keyThe keyboard key that was pressed or released
scancodeThe system-specific scancode of the key
actionGLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT. Future releases may add more actions
modsBit field describing which modifier keys were held down
pDeviceCurrently active device
pSwapchainSwapchain that should be recreated on changes
pPipelinePipeline that should be recreated

◆ baseKeyCallback() [2/2]

void App::baseKeyCallback ( GLFWwindow *  pWindow,
int  key,
int  scancode,
int  action,
int  mods,
ptr< Device pDevice,
ptr< Swapchain pSwapchain,
std::vector< ptr< Pipeline > >  pPipelines 
)
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.

Parameters
pWindowThe window that received the event
keyThe keyboard key that was pressed or released
scancodeThe system-specific scancode of the key
actionGLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT. Future releases may add more actions
modsBit field describing which modifier keys were held down
pDeviceCurrently active device
pSwapchainSwapchain that should be recreated on changes
pPipelinesPipelines that should be recreated

◆ baseMouseButtonCallback()

void App::baseMouseButtonCallback ( GLFWwindow *  pWindow,
int  button,
int  action,
int  mods,
ptr< Camera pCamera 
)
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.

Parameters
pWindowThe window that received the event
buttonThe mouse button that was pressed or released.
actionOne of GLFW_PRESS or GLFW_RELEASE. Future releases may add more actions.
modsBit field describing which modifier keys were held down.
pCameraCurrent active camera to handle mouse capture for.

◆ createGUI()

void App::createGUI ( ptr< Device pDevice,
ptr< Pass pPass 
)
protected

Create a GUI for the application.

This initializes all the resources for ImGUI.

Parameters
pDeviceDevice to use for resource allocations
pPassPass to use for rendering the GUI

◆ destroyGUI()

void App::destroyGUI ( ptr< Device pDevice)
protected

Destroy the GUI for the application.

This will clean-up all the allocated resources of ImGUI.

Parameters
pDeviceDevice that was used for resources allocations

◆ getCursorDelta()

glm::vec2 Mandrill::App::getCursorDelta ( ) const
inlineprotected

Get how the mouse cursor moved since last frame.

Returns
A vec2 containing the change in x and y position since last frame

◆ keyboardCapturedByGUI()

bool Mandrill::App::keyboardCapturedByGUI ( ) const
inlineprotected

Check if keyboard inputs are currently captured by the GUI.

Returns
True of keyboard events are intended for GUI, false otherwise

◆ mouseCapturedByGUI()

bool Mandrill::App::mouseCapturedByGUI ( ) const
inlineprotected

Check if mouse inputs are currently captured by the GUI.

Returns
True if mouse movements are intended for GUI, false otherwise

◆ render()

virtual void Mandrill::App::render ( )
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.

◆ renderGUI()

void App::renderGUI ( VkCommandBuffer  cmd) const
protected

Render the GUI by writing the state to a command buffer.

Call this while populating command buffer.

Parameters
cmdCommand buffer to write to

◆ run()

void App::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:

int main() { SampleApp app = SampleApp(); app.run(); return 0; }

◆ update()

virtual void Mandrill::App::update ( float  delta)
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.

Parameters
deltaTime passed since last frame

The documentation for this class was generated from the following files: