Mandrill 2025.6.0
Loading...
Searching...
No Matches
App.h
1#pragma once
2
3#include "Common.h"
4
5#include "Camera.h"
6#include "Device.h"
7#include "Pass.h"
8#include "Pipeline.h"
9#include "Swapchain.h"
10
11namespace Mandrill
12{
18 class MANDRILL_API App
19 {
20 public:
27 App(const std::string& title, uint32_t width = 1280, uint32_t height = 720);
28
32 ~App();
33
48 void run();
49
50 protected:
60 virtual void update(float delta) = 0;
61
86 virtual void render() = 0;
87
101 virtual void appGUI(ImGuiContext* pContext) = 0;
102
103 // virtual void onMouseEvent() = 0;
104
112 void createGUI(ptr<Device> pDevice, ptr<Pass> pPass);
113
120 void destroyGUI(ptr<Device> pDevice);
121
132 void baseGUI(ptr<Device> pDevice, ptr<Swapchain> pSwapchain, ptr<Pipeline> pPipeline);
133
144 void baseGUI(ptr<Device> pDevice, ptr<Swapchain> pSwapchain, std::vector<ptr<Pipeline>> pPipelines);
145
152 void renderGUI(VkCommandBuffer cmd) const;
153
166 void baseKeyCallback(GLFWwindow* pWindow, int key, int scancode, int action, int mods, ptr<Device> pDevice,
167 ptr<Swapchain> pSwapchain, ptr<Pipeline> pPipeline);
168
181 void baseKeyCallback(GLFWwindow* pWindow, int key, int scancode, int action, int mods, ptr<Device> pDevice,
182 ptr<Swapchain> pSwapchain, std::vector<ptr<Pipeline>> pPipelines);
183
193 virtual void appKeyCallback(GLFWwindow* pWindow, int key, int scancode, int action, int mods) = 0;
194
203 void baseCursorPosCallback(GLFWwindow* pWindow, double xPos, double yPos);
204
212 virtual void appCursorPosCallback(GLFWwindow* pWindow, double xPos, double yPos) = 0;
213
223 void baseMouseButtonCallback(GLFWwindow* pWindow, int button, int action, int mods, ptr<Camera> pCamera);
224
233 virtual void appMouseButtonCallback(GLFWwindow* pWindow, int button, int action, int mods) = 0;
234
239 glm::vec2 getCursorDelta() const
240 {
241 return {mCursorDeltaX, mCursorDeltaY};
242 }
243
249 {
250 return mKeyboardCapturedByGUI;
251 }
252
258 {
259 return mMouseCapturedByGUI;
260 }
261
262 // GLFW window
263 GLFWwindow* mpWindow;
264
265 protected:
266 // Screen resolution
267 uint32_t mWidth, mHeight;
268
269 // Time since application started in seconds
270 float mTime = 0.0f;
271
272 private:
281 void initGLFW(const std::string& title, uint32_t width, uint32_t height);
282
288 void initImGUI();
289
294 ImGuiContext* newFrameGUI();
295
300 void takeScreenshot(ptr<Swapchain> pSwapchain);
301
305 void toggleFullscreen();
306
310 void resetFramebufferSize();
311
320 static void keyCallbackEntry(GLFWwindow* pWindow, int key, int scancode, int action, int mods);
321
328 static void cursorPosCallbackEntry(GLFWwindow* pWindow, double xPos, double yPos);
329
337 static void mouseButtonCallbackEntry(GLFWwindow* pWindow, int button, int action, int mods);
338
339 // Time since last frame in seconds
340 float mDelta = 0.0f;
341
342 // Smoothed delta for GUI presentation
343 float mDeltaSmooth = 0.0f;
344
345 // Give new delta sample 5% weight
346 const float kSmoothingFactor = 0.05f;
347
348 // Screen mode
349 GLFWmonitor* mpMonitor;
350 GLFWvidmode mFullscreenMode;
351 bool mFullscreen = false;
352
353 // Mouse movement
354 float mCursorX = 0.0f, mCursorY = 0.0f;
355 float mCursorDeltaX = 0.0f, mCursorDeltaY = 0.0f;
356 float mCursorPrevX = 0.0f, mCursorPrevY = 0.0f;
357
358 // GUI
359 bool mCreatedGUI = false;
360 bool mShowMainMenu = true;
361 bool mShowFrameRate = false;
362 bool mShowHelp = false;
363 bool mShowAbout = false;
364
365 // Flags for GUI input capture
366 bool mKeyboardCapturedByGUI;
367 bool mMouseCapturedByGUI;
368
369 // Descriptor pool for ImGUI
370 VkDescriptorPool mDescriptorPool;
371
372 // Font for ImGUI
373 ImFont* mFont;
374 };
375} // namespace Mandrill
Base class for a Mandrill application. This class provides the basic functionality to create a window...
Definition App.h:19
virtual void render()=0
Render app.
bool mouseCapturedByGUI() const
Check if mouse inputs are currently captured by the GUI.
Definition App.h:257
virtual void appGUI(ImGuiContext *pContext)=0
Draw application specific GUI of a Mandrill application.
glm::vec2 getCursorDelta() const
Get how the mouse cursor moved since last frame.
Definition App.h:239
bool keyboardCapturedByGUI() const
Check if keyboard inputs are currently captured by the GUI.
Definition App.h:248
virtual void update(float delta)=0
Update scene objects.
virtual void appMouseButtonCallback(GLFWwindow *pWindow, int button, int action, int mods)=0
Virtual function for app to override. Just invoke baseMouseButtonCallback() to get standard keybindin...
virtual void appCursorPosCallback(GLFWwindow *pWindow, double xPos, double yPos)=0
Virtual function for app to override. Just invoke baseCursorPosCallback() to get standard keybindings...
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....