Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Engine.h
Go to the documentation of this file.
1#pragma once
2
8#include "Tick.h"
9
14#include <openxr/openxr.h>
15#include <vector>
16#include <vulkan/vulkan_core.h>
17#include <future>
18#include <atomic>
20#ifdef ENABLE_TRACY
21#include "tracy/TracyVulkan.hpp"
22#endif
23
24namespace EngineCore {
25class Ticker;
26class MeshLoader;
27class GameModule;
28class World;
29class RenderProcess;
30class MaterialShader;
31class DataBuffer;
32class PhysicsEngine;
33}
34
35namespace EngineCore {
36 class Engine {
37 public:
38 Engine() = default;
39 ~Engine();
40
47 void initRenderDoc();
48
55 void run(std::unique_ptr<GameModule> module);
56
64 std::shared_ptr<InputHandler> getInputHandler();
65
66 const std::unique_ptr<AssetManager>& getAssetManager() const;
67
68 private:
69 double gameTime = 0.0f;
70 public:
71
77 double getDeltaTimeSeconds();
78
83 double getGlobalTimeSeconds();
84
90 [[nodiscard]] ApplicationContext* getContext() const { return applicationContext; }
91
92 private:
94
95 std::unique_ptr<AssetManager> assetManager;
96 std::shared_ptr<InputHandler> inputHandler;
97
98 // Game reference
99 std::unique_ptr<GameModule> module;
100
101 // debug messenger for vulkan debug layer
102 VkDebugUtilsMessengerEXT debugMessenger = nullptr;
103
105 uint64_t frameCounter = 0;
106 void createInputManager();
107 public:
115 [[nodiscard]] uint32_t getRenderableSceneObjectCount() const;
116
121 [[nodiscard]] Renderer* getRenderer() const;
122
127 [[nodiscard]] Input::XrInputHandler* getXrInputHandler() const { return xrInputHandler; }
128
133 [[nodiscard]] Headset* getHeadset() const { return headset; }
134 private:
135
137
138 // command pool for all commands
139
140 std::vector<VkCommandBuffer> commandBuffers;
141
142 // frame time counter
143 uint32_t currentFrame = 0;
144
145 uint32_t textureCount = 0;
146 uint32_t meshCount = 0;
147
148 // virtual reality
149 bool isXrSessionRunning = false;
150
151 // function
152 void initWindow();
153
154 PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT = nullptr;
156
157 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo);
158
159 static VkBool32 debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
160 VkDebugUtilsMessageTypeFlagsEXT messageType,
161 const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData);
162
164
167 Headset* headset = nullptr;
168 Renderer* renderer = nullptr;
169
170 // Async frame completion for pipelined rendering
171 // This allows xrWaitFrame(N+1) to overlap with GPU work from frame N
172 std::future<void> frameCompletionFuture_;
173 std::atomic<bool> previousFrameXrComplete_{true};
174
175 // Named thread pool for XR frame operations (shows up properly in Tracy)
176 std::unique_ptr<NamedThreadPool> xrFrameThreadPool_;
177
185 void completeFrameAsync(VkFence graphicsFence, bool presentMirror);
186
190 void createStartupScene();
191
195 void initVulkan();
196
202
203#ifdef ENABLE_TRACY
204 std::vector<TracyVkCtx> tracyVulkanContext;
205#endif
206
207
208 public:
216
217 const std::unique_ptr<SceneManager>& getSceneManager() const { return sceneManager; }
218 private:
219
220 void calculateFrameTime( double& lastTime );
226 void fixLoadingAssets() const;
232 void update( double & gameTime );
233
239
243 void mainLoop();
244
248 void cleanup();
249
251
254 void initStartupScene();
255
256 public:
265 template <typename T>
266 void loadScene() {
267 sceneManager->loadScene<T>();
268 }
269
275
276 private:
277 std::unique_ptr<SceneManager> sceneManager;
278
279 void createAssetManager();
280
281 void initAssets();
282
284 void createPhysicsWorld();
285 void destroyPhysicsWorld();
287 };
288
296 public:
297 virtual ~EngineManager() = default;
298
304 static EngineManager& getInstance();
305
312
316 void setEngine(Engine* engineInstance);
317
318 protected:
320
321 EngineManager() = default;
322 EngineManager(const EngineManager&) = delete;
324 };
325
326
327}
The application context is the core class which stores the basic openxr and vulkan objects.
EngineManager & operator=(const EngineManager &)=delete
void setEngine(Engine *engineInstance)
set the content pointer for this singleton
Definition Engine.cpp:1144
EngineCore::Engine * getEngineModule()
gets the pointer to the engine object
Definition Engine.cpp:1140
virtual ~EngineManager()=default
EngineManager(const EngineManager &)=delete
static EngineManager & getInstance()
gets a reference to the engine manager
Definition Engine.cpp:1135
EngineCore::Engine * engine
Definition Engine.h:319
void initVulkan()
Initialisation of all vulkan related resources.
Definition Engine.cpp:292
std::shared_ptr< InputHandler > inputHandler
Definition Engine.h:96
std::unique_ptr< AssetManager > assetManager
Definition Engine.h:95
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo)
Definition Engine.cpp:219
const std::unique_ptr< AssetManager > & getAssetManager() const
Definition Engine.cpp:103
Headset * headset
Definition Engine.h:167
bool checkValidationLayerSupport()
Definition Engine.cpp:262
void fixLoadingAssets() const
When assets have been requested but are not loaded yet the static mesh data is in a limbo where it ha...
Definition Engine.cpp:388
int isMirrorViewMinimized()
Definition Engine.cpp:527
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT
Definition Engine.h:154
MeshComponent * leftHand
Definition Engine.h:253
std::future< void > frameCompletionFuture_
Definition Engine.h:172
void loadScene()
Triggers the load of a new scene. Will be executed once the current frame has finished processing.
Definition Engine.h:266
MeshComponent * rightHand
Definition Engine.h:252
bool descriptorDataIsDirty
Definition Engine.h:136
void tryCreateApplicationContext()
will try to create a window and if there is no openxr runtime detected it will wait 5 seconds and try...
Definition Engine.cpp:353
void createAssetManager()
Definition Engine.cpp:1116
void completeFrameAsync(VkFence graphicsFence, bool presentMirror)
Runs on background thread: waits for GPU fence, ends XR frame, presents mirror This allows CPU work t...
Definition Engine.cpp:532
std::atomic< bool > previousFrameXrComplete_
Definition Engine.h:173
std::vector< VkCommandBuffer > commandBuffers
Definition Engine.h:140
static VkBool32 debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData)
Definition Engine.cpp:233
void cleanup()
Cleanup of pointers for vulkan and subsystems.
Definition Engine.cpp:987
VkDebugUtilsMessengerEXT debugMessenger
Definition Engine.h:102
Renderer * renderer
Definition Engine.h:168
Renderer * getRenderer() const
Getter for the renderer.
Definition Engine.cpp:126
const std::unique_ptr< SceneManager > & getSceneManager() const
Definition Engine.h:217
void createPhysicsWorld()
PHYSICS.
Definition Engine.cpp:1124
void calculateFrameTime(double &lastTime)
Definition Engine.cpp:380
double getGlobalTimeSeconds()
Gets the time since the beginning of the simulation (sum of all delta times)
Definition Engine.cpp:112
void update(double &gameTime)
Definition Engine.cpp:412
void mainLoop()
Main engine loop where the rendering and game steps happen.
Definition Engine.cpp:567
uint32_t currentFrame
Definition Engine.h:143
uint32_t textureCount
Definition Engine.h:145
ApplicationContext * getContext() const
Gets the application context which stores the vulkan instance the device and queues.
Definition Engine.h:90
ApplicationContext * applicationContext
Definition Engine.h:165
PhysicsEngine * physicsEngine
Definition Engine.h:286
std::unique_ptr< SceneManager > sceneManager
Definition Engine.h:277
bool isXrSessionRunning
Definition Engine.h:149
double getDeltaTimeSeconds()
gets the time between frames
Definition Engine.cpp:107
void processResourceLoadingPipelines()
Collects and processes the pipelines which have finished and dispatches the new steps....
Definition Engine.cpp:404
MirrorView * mirrorView
Definition Engine.h:166
Input::XrInputHandler * xrInputHandler
Definition Engine.h:104
void processMirrorWindowEvents()
processes glfw window events like key presses or window events
Definition Engine.cpp:374
PhysicsEngine * getPhysicsEngine() const
Getter for the pointer to the physics engine.
Definition Engine.cpp:1111
void createInputManager()
Definition Engine.cpp:117
void initializePlogDebugger()
Definition Engine.cpp:1091
uint32_t getRenderableSceneObjectCount() const
Counts the amount of entities which have renderable components.
Definition Engine.cpp:122
std::unique_ptr< GameModule > module
Definition Engine.h:99
uint32_t meshCount
Definition Engine.h:146
void captureRenderdocFrame()
Captures a frame for render doc if the define RENDERDOC_ENABLED is set.
Definition Engine.cpp:508
void run(std::unique_ptr< GameModule > module)
Runs the engine. Is the entry point for this module.
Definition Engine.cpp:73
Input::XrInputHandler * getXrInputHandler() const
Getter for the XR input handler.
Definition Engine.h:127
void initStartupScene()
Definition Engine.cpp:1104
void createVulkanDebugMessenger()
Definition Engine.cpp:146
double gameTime
Definition Engine.h:69
void initRenderDoc()
Initialization point for software driven captures.
Definition Engine.cpp:62
void createStartupScene()
Creates the initial scene the engine loads before an actual level is loaded.
Definition Engine.cpp:287
Headset * getHeadset() const
Getter for the VR headset.
Definition Engine.h:133
std::shared_ptr< InputHandler > getInputHandler()
Gets a shared handle to the input handler. This is used for any type of input.
Definition Engine.cpp:96
void destroyPhysicsWorld()
Definition Engine.cpp:1129
std::unique_ptr< NamedThreadPool > xrFrameThreadPool_
Definition Engine.h:176
double deltaTimeSeconds
Definition Engine.h:93
uint64_t frameCounter
Definition Engine.h:105
A component which can be attached as many times to an actor as one wants. It makes it possible to ren...
This class houses the components needed to display a vr image on the desktop.
Definition MirrorView.h:21
The physics engine manages creating and destroying physics objects for the physics simulation.
The render process class consolidates all the resources that needs to be duplicated for each frame th...
Log category system implementation.