Chronos 0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
engine.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2024 Rahul Satish Vadhyar
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
21*/
22
30#pragma once
31
32#ifdef ENABLE_EDITOR
33// if the editor is enabled, then include the editorRenderer to get the
34// rendering functions and classes of the editor.
35#include "editorRenderer.hpp"
36#endif
37#include "swapchain.hpp"
38#include "objectManager.hpp"
39#include "textureManager.hpp"
40namespace Chronos {
41namespace Engine {
42
81 class Engine {
82 public:
97 Engine();
98
100
108
113 int width = 800;
114
119 int height = 600;
120
124 GLFWwindow* window;
125
132 float bgColor[3] = { 0.0f, 0.0f, 0.0f };
133
152 void drawFrame();
153
163 void resizeFrameBuffer();
164
200 void setPresentMode(std::string mode);
201
202#ifdef ENABLE_EDITOR
211 void setEditorAddElementsCallback(void (*)());
212#endif
220 ~Engine();
221
222 void changeMSAA(std::string);
223
224 std::vector<std::string> getAvailableMSAAModes();
225
234
244
251 VkCommandPool commandPool;
252
253 private:
254 bool changeMSAAFlag = false;
255 VkSampleCountFlagBits newMSAAMode;
256
257 void changeMSAASettings();
258
268 bool framebufferResized = false;
269
276 uint32_t currentFrame = 0;
277
284 VkInstance instance;
285
286#ifdef ENABLE_VULKAN_VALIDATION_LAYERS
295 VkDebugUtilsMessengerEXT debugMessenger;
296#endif
297
304 VkSurfaceKHR surface;
305
306 std::vector<VkSemaphore> imageAvailableSemaphores;
307 std::vector<VkSemaphore> renderFinishedSemaphores;
308 std::vector<VkFence> inFlightFences;
315 void initWindow();
316
332 void initVulkan();
333
348 void cleanup();
349
356 void createInstance();
357
358#ifdef ENABLE_VULKAN_VALIDATION_LAYERS
365 void setupDebugMessenger();
366#endif
370 void createSurface();
371
385 void createSyncObjects();
386
387 void changePresentMode();
388
389#ifdef ENABLE_EDITOR
391#endif
392#ifdef CHRONOS_PROFILING
393 public:
400 float getfps()
401 {
402 static float prevTime = 0.0f;
403 float current_time = static_cast<float>(glfwGetTime());
404 float fps = 1.0f / (current_time - prevTime);
405 prevTime = current_time;
406 return fps;
407 }
408
409 float getWaitTime() { return waitTime; }
410 float getUpdateTime() { return updateTime; }
411 float getCpuTime() { return cpuTime; }
412 float getTotalTime() { return totalTime; }
413 float getPresentTime() { return presentTime; }
414
415 private:
416 float waitTime = 0.0f;
417 float updateTime = 0.0f;
418 float cpuTime = 0.0f;
419 float totalTime = 0.0f;
420 float presentTime = 0.0f;
421
422#endif
423 };
424
425};
426};
This initializes, manages and destroys the logical and physical devices(GPU).
Definition device.hpp:47
uint32_t currentFrame
The current frame to be rendered to.
Definition engine.hpp:276
Chronos::Engine::Device device
This is the object that manages the device.
Definition engine.hpp:233
VkCommandPool commandPool
The command Pool.
Definition engine.hpp:251
void initVulkan()
The complicated process of initalizing the vulkan API is done here.
Definition engine.cpp:74
std::vector< VkSemaphore > imageAvailableSemaphores
Definition engine.hpp:306
VkInstance instance
The Vulkan instance.
Definition engine.hpp:284
void resizeFrameBuffer()
Tells the engine that the window has to be resized. This is called by GLFW.
Definition engine.cpp:56
void createSurface()
Creates the surface to render to.
Definition engine.cpp:395
std::vector< VkSemaphore > renderFinishedSemaphores
Definition engine.hpp:307
std::vector< VkFence > inFlightFences
Definition engine.hpp:308
void drawFrame()
Main draw call. Its responsible for drawing frames and resizing the window. To be added to the main g...
Definition engine.cpp:137
void initWindow()
This function initializes the GLFW window.
Definition engine.cpp:58
Chronos::Engine::ObjectManager objectManager
Definition engine.hpp:99
void cleanup()
Cleans up vulkan objects.
Definition engine.cpp:104
void createSyncObjects()
Creates sync objects for rendering.
Definition engine.cpp:404
GLFWwindow * window
This is the GLFW window reference that is used by the engine.
Definition engine.hpp:124
void createInstance()
Creates a vulkan instance.
Definition engine.cpp:319
float bgColor[3]
This is the background color of the window.
Definition engine.hpp:132
~Engine()
This is the destructor of the engine.
Definition engine.cpp:49
Engine()
Initlizes the engine.
Definition engine.cpp:37
int height
This is the initial width of the window. It can be changed later just by changing this directly.
Definition engine.hpp:119
VkSampleCountFlagBits newMSAAMode
Definition engine.hpp:255
Chronos::Engine::TextureManager textureManager
Used to create and manage textures.
Definition engine.hpp:107
void setPresentMode(std::string mode)
Changes the present mode of the swapchain.
Definition engine.cpp:452
bool framebufferResized
Does the framebuffer need to be resized?
Definition engine.hpp:268
void changeMSAA(std::string)
Definition engine.cpp:495
std::vector< std::string > getAvailableMSAAModes()
Definition engine.cpp:469
VkSurfaceKHR surface
The surface to render to.
Definition engine.hpp:304
int width
This is the initial width of the window. It can be changed later just by changing this directly.
Definition engine.hpp:113
Chronos::Engine::SwapChain swapChain
This is the object that manages the swapchain.
Definition engine.hpp:243
This is the texture manager for Chronos. It handles creation, modification, updating and desrtuction ...
Defines the ObjectManager class for managing objects in the Chronos::Engine namespace.
Contains the swapChain class along with all the swapChain related functions.
Contains the class for managing textures in the Chronos::Engine namespace.