Chronos 0.0
A advanced 2D rendering and animation system
|
#include <engine.hpp>
Public Member Functions | |
Engine () | |
Initlizes the engine. | |
void | drawFrame () |
Main draw call. Its responsible for drawing frames and resizing the window. To be added to the main game loop. | |
void | resizeFrameBuffer () |
Tells the engine that the window has to be resized. This is called by GLFW. | |
void | setPresentMode (std::string mode) |
Changes the present mode of the swapchain. | |
~Engine () | |
This is the destructor of the engine. | |
void | changeMSAA (std::string) |
std::vector< std::string > | getAvailableMSAAModes () |
Public Attributes | |
Chronos::Engine::ObjectManager | objectManager |
Chronos::Engine::TextureManager | textureManager |
Used to create and manage textures. | |
int | width = 800 |
This is the initial width of the window. It can be changed later just by changing this directly. | |
int | height = 600 |
This is the initial width of the window. It can be changed later just by changing this directly. | |
GLFWwindow * | window |
This is the GLFW window reference that is used by the engine. | |
float | bgColor [3] = { 0.0f, 0.0f, 0.0f } |
This is the background color of the window. | |
Chronos::Engine::Device | device = Chronos::Engine::Device() |
This is the object that manages the device. | |
Chronos::Engine::SwapChain | swapChain = Chronos::Engine::SwapChain() |
This is the object that manages the swapchain. | |
VkCommandPool | commandPool |
The command Pool. | |
Private Member Functions | |
void | changeMSAASettings () |
void | initWindow () |
This function initializes the GLFW window. | |
void | initVulkan () |
The complicated process of initalizing the vulkan API is done here. | |
void | cleanup () |
Cleans up vulkan objects. | |
void | createInstance () |
Creates a vulkan instance. | |
void | createSurface () |
Creates the surface to render to. | |
void | createSyncObjects () |
Creates sync objects for rendering. | |
void | changePresentMode () |
Private Attributes | |
bool | changeMSAAFlag = false |
VkSampleCountFlagBits | newMSAAMode |
bool | framebufferResized = false |
Does the framebuffer need to be resized? | |
uint32_t | currentFrame = 0 |
The current frame to be rendered to. | |
VkInstance | instance |
The Vulkan instance. | |
VkSurfaceKHR | surface |
The surface to render to. | |
std::vector< VkSemaphore > | imageAvailableSemaphores |
std::vector< VkSemaphore > | renderFinishedSemaphores |
std::vector< VkFence > | inFlightFences |
\brief This is the main vulkan backend for Chronos. This is for use by the API only and should not be used for any other purpose. This is resposible for managing the object and shapes that related to vulkan. It is also in charge of drawing frames and managing the window. It automatically handles window resizing, creation and destruction of necessary objects. Any shapes or text to be created is to be done throught the shapeManager and textManager respectively. In order to draw a frame, create a loop and call the drawFrame. ##Important drawFrame will not handle inputs. It will also draw only one frame per call. Hence the inputs must be managed by the main loop. This is done to allow flexibility in inputs and management of the frame drawing. ## drawFrame() example Suppose Engine class is initialized as engine The following code snippet is an example of a basic rendering loop. It also includes functionaility to close the window either when the escape key is pressed or when the window is closed. For more on handling inputs, please see the GLFW documentation. ~~~~~~~~~~~~~~~{.cpp} while (!glfwWindowShouldClose(engine.window)) {
if esc is pressed, then ask GLFW to close the window if (glfwGetKey(engine.window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { glfwSetWindowShouldClose(engine.window, true); } draw the frame engine.drawFrame(); } ~~~~~~~~~~~~~~~
Definition at line 81 of file engine.hpp.
Chronos::Engine::Engine::Engine | ( | ) |
Initlizes the engine.
During initialization of the engine, all the processes and calls needed to intialize vulkan and GLFW are done. No other function needs to be called to initialize the engine. During initialization the following occurs:
If the editor is enabled, then the editor(EditorRenderer) settings are initialized The window is created The vulkan API is initialized along with all the necessary objects.
Definition at line 37 of file engine.cpp.
References initVulkan(), initWindow(), and LOG.
Chronos::Engine::Engine::~Engine | ( | ) |
This is the destructor of the engine.
It basically stops the device, and runs the cleanup function. This is so that it is guranteed that Vulkan objects will be cleaned up correctly.
Definition at line 49 of file engine.cpp.
References LOG.
void Chronos::Engine::Engine::changeMSAA | ( | std::string | mode | ) |
Definition at line 495 of file engine.cpp.
References LOG.
|
private |
Definition at line 521 of file engine.cpp.
References LOG.
|
private |
Definition at line 442 of file engine.cpp.
|
private |
Cleans up vulkan objects.
When the engine is exited, we need to clean up the vulkan objects. If we do not do this, vulkan validation layers will throw errors. The following occurs during this function:
Definition at line 104 of file engine.cpp.
References LOG, and MAX_FRAMES_IN_FLIGHT.
|
private |
Creates a vulkan instance.
This function sets some of the information about our app. It enables all the extensions and validation layers.
Definition at line 319 of file engine.cpp.
References getRequiredExtensions(), and LOG.
|
private |
Creates the surface to render to.
Definition at line 395 of file engine.cpp.
References LOG.
|
private |
Creates sync objects for rendering.
Since Vulkan uses explict sync, we need sync objects such as fences and semaphores to maintain synchronization.
Since there are multiple frames in flight, we need multiple copies for each sync object. In particular, we need:
Definition at line 404 of file engine.cpp.
References LOG, and MAX_FRAMES_IN_FLIGHT.
void Chronos::Engine::Engine::drawFrame | ( | ) |
Main draw call. Its responsible for drawing frames and resizing the window. To be added to the main game loop.
During this function the following occurs:
vkQueueSubmit
is called, the command buffers are executed and the frame is rendered.Definition at line 137 of file engine.cpp.
References LOG, and MAX_FRAMES_IN_FLIGHT.
std::vector< std::string > Chronos::Engine::Engine::getAvailableMSAAModes | ( | ) |
Definition at line 469 of file engine.cpp.
|
private |
The complicated process of initalizing the vulkan API is done here.
The following occurs during this function:
Also the objects needed for the editor are also created here
Definition at line 74 of file engine.cpp.
References Chronos::Engine::createCommandPool(), and LOG.
|
private |
This function initializes the GLFW window.
It creates a GLFWwindow*
and stores it in the window
variable. It also sets the window hints sets the framebuffer callback.
Definition at line 58 of file engine.cpp.
References framebuffer_size_callback(), and LOG.
void Chronos::Engine::Engine::resizeFrameBuffer | ( | ) |
Tells the engine that the window has to be resized. This is called by GLFW.
It sets the flag that window has to be resized. Later during the drawFrame function, the swapchain is recreated and resets the flag. This tells Vulkan that the swapChain has to be recreated.
Definition at line 56 of file engine.cpp.
void Chronos::Engine::Engine::setPresentMode | ( | std::string | mode | ) |
Changes the present mode of the swapchain.
The present mode is the mode in which the images are presented to the screen. There are various methods available. this can be used to cap or unlock the framerate, control tearing etc. Some of the presentation modes available are:
mode | The mode to change to. It can be one of the following:
|
Definition at line 452 of file engine.cpp.
References LOG.
float Chronos::Engine::Engine::bgColor[3] = { 0.0f, 0.0f, 0.0f } |
This is the background color of the window.
It can be changed by changing the values inside this float. The values should be in the range of 0 to 1.
Definition at line 132 of file engine.hpp.
|
private |
Definition at line 254 of file engine.hpp.
VkCommandPool Chronos::Engine::Engine::commandPool |
The command Pool.
All command buffers are allocated from a command pool. This is where the command pool is stored.
Definition at line 251 of file engine.hpp.
|
private |
The current frame to be rendered to.
Since there will be multiple frames in flight, we need to keep track of which frame is currently being rendered.
Definition at line 276 of file engine.hpp.
Chronos::Engine::Device Chronos::Engine::Engine::device = Chronos::Engine::Device() |
This is the object that manages the device.
This is due to the fact that device initialization and management is a complicated process. Also there are multiple variables that are needed for this. Hence for simplicity, a class was created for this purpose.
Definition at line 233 of file engine.hpp.
|
private |
Does the framebuffer need to be resized?
When the window is resized, or minimized, the swapchain needs to be recreated. GLFW will tell us that this needs to happen, and when it does, this flag is set to true. The next time the drawFrame function is called, the swapchain will be recreated. During that time, this flag will be set to false.
Definition at line 268 of file engine.hpp.
int Chronos::Engine::Engine::height = 600 |
This is the initial width of the window. It can be changed later just by changing this directly.
Definition at line 119 of file engine.hpp.
|
private |
Definition at line 306 of file engine.hpp.
|
private |
Definition at line 308 of file engine.hpp.
|
private |
The Vulkan instance.
When initializing Vulkan, the first thing we create is an instance. This is where is it stored. We need this during cleanup
Definition at line 284 of file engine.hpp.
|
private |
Definition at line 255 of file engine.hpp.
Chronos::Engine::ObjectManager Chronos::Engine::Engine::objectManager |
Definition at line 99 of file engine.hpp.
|
private |
Definition at line 307 of file engine.hpp.
|
private |
The surface to render to.
For rendering to the window from the Vulkan framebuffer, we need a surface.
Definition at line 304 of file engine.hpp.
Chronos::Engine::SwapChain Chronos::Engine::Engine::swapChain = Chronos::Engine::SwapChain() |
This is the object that manages the swapchain.
All the swapchain related functions are handled by this object. This is due to the fact that swapChain needs to be constantly mananged and recreated due to various conditions.
Definition at line 243 of file engine.hpp.
Chronos::Engine::TextureManager Chronos::Engine::Engine::textureManager |
Used to create and manage textures.
To add or remove textures, one may call the necessary methods in this class.
Definition at line 107 of file engine.hpp.
int Chronos::Engine::Engine::width = 800 |
This is the initial width of the window. It can be changed later just by changing this directly.
Definition at line 113 of file engine.hpp.
GLFWwindow* Chronos::Engine::Engine::window |
This is the GLFW window reference that is used by the engine.
Definition at line 124 of file engine.hpp.