evan 2026.1.4
Evan
Loading...
Searching...
No Matches
evan::Engine Class Reference

The Engine class is the main entry point for the Evan Engine. It manages the core components of the engine, including the device context, renderer, swapchain context, and platform abstraction. The Engine class is responsible for initializing these components, running the main loop of the engine, and providing methods for updating and rendering its render objects. It serves as the central hub for managing the engine's functionality and orchestrating the various subsystems to create a cohesive experience. More...

#include <headers/evan/Engine.hpp>

Inheritance diagram for evan::Engine:
Collaboration diagram for evan::Engine:

Public Member Functions

 Engine (std::shared_ptr< utility::RessourceProvider > ressourceProvider, std::shared_ptr< IPlatform > platform, RenderSettings settings={})
 Constructs a new Engine object with default settings. This constructor initializes the engine with default parameters, such as a default window name, width, and height. It sets up the necessary components of the engine, including the device context, renderer, swapchain context, and platform abstraction, using default configurations. This constructor is useful for quickly getting started with the engine without needing to specify custom parameters.
 
bool setObjectTransform (size_t objectID, const glm::mat4 &transform)
 Sets the model transform of an object in the current scene.
 
void setInstancingEnabled (bool enabled)
 Enables or disables merging of identical meshes.
 
bool isInstancingEnabled () const
 Checks whether identical meshes are merged into one draw.
 
void setIndirectDrawingEnabled (bool enabled)
 Enables or disables indirect drawing.
 
bool isIndirectDrawingEnabled () const
 Checks whether indirect drawing is enabled.
 
utility::graphic::ViewF getView (void) const override
 Get the mirrored view state.
 
utility::graphic::SizeF measureText (const utility::graphic::Text &text) const override
 Measures the pixel dimensions of a given text string when rendered with a specific font.
 
size_t addMesh (const utility::graphic::Mesh &mesh, const std::string &materialName="default_material", const std::string &shader="default")
 Adds a mesh to the renderer. This method takes a Mesh object, which contains the necessary information for rendering the mesh, such as the vertex data, index data, and material properties.
 
size_t createObject (std::shared_ptr< utility::graphic::Renderable > object) override
 Creates a new renderable object.
 
bool updateObject (std::shared_ptr< utility::graphic::Renderable > object, size_t objectID) override
 Updates an existing renderable object.
 
bool removeObject (std::shared_ptr< utility::graphic::Renderable > object, size_t objectID) override
 Removes a renderable object from the engine.
 
void update () override
 Updates the state of the engine. This method is responsible for handling logic updates, input processing, and other non-rendering related tasks. It is typically called once per frame, allowing the engine to respond to user input, update the state of objects in the scene, and perform any necessary calculations or updates before rendering. The update method may also handle events such as collisions, physics simulations, or AI behavior, depending on the specific requirements of the application being developed with the engine.
 
void clear (void) override
 Clears the current rendering target.
 
void present (void) override
 Presents the composed back buffer to the screen.
 
Error render ()
 Renders the engine's render objects. This method is responsible for drawing the render objects registered in the engine to the screen using the renderer. It typically involves setting up the necessary graphics pipelines, binding resources, and issuing draw calls to render the objects. The render method may also handle post-processing effects, such as bloom or anti-aliasing, depending on the specific requirements of the application being developed with the engine.
 
float getDeltaTime (void) const override
 Get the delta time from the last frame in seconds.
 
const FrameStats & getFrameStats () const
 Gets the renderer's frame statistics window.
 
void setScissor (const utility::graphic::ScissorRect &rect) override
 Set the scissor (clip) rectangle, in framebuffer pixels.
 
void clearScissor (void) override
 Clear the active scissor rectangle (restore full extent).
 
Error getLastError () const
 Returns the last error recorded by the platform.
 
void pollEvents () override
 Polls for events from the platform. This method is responsible for handling input events, window events, and other platform-specific events. It is typically called once per frame, allowing the engine to respond to user input, window resizing, and other events that may occur during the application's runtime. The pollEvents method interacts with the platform abstraction layer to retrieve and process events, ensuring that the engine can respond to user interactions and system events in a timely manner.
 
bool shouldCaptureViewportInput (void) const
 Checks if the engine should capture viewport input. This method returns a boolean value indicating whether the engine is currently set to capture input events for the viewport, such as mouse movements or keyboard inputs.
 
void setShouldCaptureViewportInput (bool shouldCapture)
 Sets whether the engine should capture viewport input. This method allows users to enable or disable the capturing of input events for the viewport, such as mouse movements or keyboard inputs.
 
float getTargetFps (void) const
 Gets the configured target frame rate for the loop limiter.
 
void setTargetFps (float fps)
 Sets an optional frame-rate limiter for the main loop.
 

Protected Attributes

const std::string _engineName = "Evan Engine"
 
const std::string _engineVersion = "0.1.0"
 
const std::shared_ptr< Version > _version
 
std::shared_ptr< DeviceContext > _deviceContext
 
std::shared_ptr< Renderer > _renderer
 
std::shared_ptr< ASwapchainContext > _swapchainContext
 
std::shared_ptr< IPlatform > _platform
 
std::shared_ptr< utility::RessourceProvider > _ressourceProvider
 
std::shared_ptr< RessourceManager > _ressourceManager
 

Detailed Description

The Engine class is the main entry point for the Evan Engine. It manages the core components of the engine, including the device context, renderer, swapchain context, and platform abstraction. The Engine class is responsible for initializing these components, running the main loop of the engine, and providing methods for updating and rendering its render objects. It serves as the central hub for managing the engine's functionality and orchestrating the various subsystems to create a cohesive experience.

The Engine class provides a high-level interface for interacting with the engine, allowing users to add render objects, handle updates, and manage rendering without needing to directly interact with the lower-level components. It abstracts away the complexities of Vulkan and platform-specific details, providing a more user-friendly API for developers using the Evan Engine.

The Engine class is designed to be extensible and modular, allowing for future enhancements and additions to the engine's capabilities. It can be extended to support additional features such as physics, audio, or networking, while still maintaining a clear separation of concerns between different subsystems of the engine.

Overall, the Engine class serves as the backbone of the Evan Engine, providing a structured and organized way to manage the various components and functionalities of the engine while offering a user-friendly interface for developers to create their applications.

Note
The Engine class is currently in its early stages of development, and additional features and improvements are expected to be added in future iterations of the engine. The current implementation focuses on establishing the core structure and functionality of the engine, with plans for further enhancements and optimizations in the future.

Definition at line 85 of file Engine.hpp.

Constructor & Destructor Documentation

◆ Engine()

evan::Engine::Engine ( std::shared_ptr< utility::RessourceProvider >  ressourceProvider,
std::shared_ptr< IPlatform >  platform,
RenderSettings  settings = {} 
)

Constructs a new Engine object with default settings. This constructor initializes the engine with default parameters, such as a default window name, width, and height. It sets up the necessary components of the engine, including the device context, renderer, swapchain context, and platform abstraction, using default configurations. This constructor is useful for quickly getting started with the engine without needing to specify custom parameters.

Parameters
ressourceProviderA shared pointer to a RessourceProvider object, which is responsible for managing the loading and synchronization of GPU resources such as materials and textures. The RessourceProvider interacts with the utility::RessourceProvider to load resources from disk or other sources, and creates corresponding GPU resources using the DeviceContext. It provides methods for synchronizing resources, retrieving specific materials or textures by ID, and managing the lifecycle of GPU resources to ensure efficient memory usage and performance in the rendering process.
platformA shared pointer to an IPlatform object, which provides an abstraction layer for platform-specific operations. The IPlatform interface defines methods for window management, input handling, and other platform-dependent functionality, allowing the engine to be portable across different operating systems and platforms.
settingsConstruction-time rendering configuration.
Note
The sample count in settings is applied before the swapchain and its render pass are created, because both bake the attachment sample count. Changing it later requires recreating the engine.
The Engine class is designed to be flexible and extensible, allowing for future enhancements and additions to the engine's capabilities. The current implementation focuses on establishing the core structure and functionality of the engine, with plans for further improvements and optimizations in the future.

Member Function Documentation

◆ addMesh()

size_t evan::Engine::addMesh ( const utility::graphic::Mesh &  mesh,
const std::string &  materialName = "default_material",
const std::string &  shader = "default" 
)

Adds a mesh to the renderer. This method takes a Mesh object, which contains the necessary information for rendering the mesh, such as the vertex data, index data, and material properties.

The addMesh method is responsible for setting up the appropriate graphics pipeline, binding the necessary resources, and issuing the draw calls to render the mesh on the screen. It interacts with the Renderer and DeviceContext to ensure that the mesh is rendered correctly, taking into account factors such as the current scene, camera position, and any transformations applied to the mesh.

Parameters
meshThe Mesh object to be added to the renderer.
materialNameThe name of the material to be used for rendering the mesh. This parameter allows for flexibility in specifying the material properties to be applied to the mesh during rendering.
shaderThe name of the shader to be used for rendering the mesh. This parameter allows for flexibility in specifying the shader program to be used for rendering the mesh, enabling different visual effects and rendering techniques to be applied to the mesh.
Returns
The unique identifier (size_t) of the added mesh within the renderer, which can be used for future reference or manipulation of the mesh in the renderer.

◆ clear()

void evan::Engine::clear ( void  )
override

Clears the current rendering target.

Vulkan clears the render target through the render pass clear values, so this is a no-op for the Evan engine.

◆ createObject()

size_t evan::Engine::createObject ( std::shared_ptr< utility::graphic::Renderable >  object)
override

Creates a new renderable object.

Parameters
objectThe renderable object to create.
Returns
The ID of the created object, or 0 if creation failed.

◆ getDeltaTime()

float evan::Engine::getDeltaTime ( void  ) const
override

Get the delta time from the last frame in seconds.

Returns
Delta time in seconds.

◆ getFrameStats()

const FrameStats & evan::Engine::getFrameStats ( ) const

Gets the renderer's frame statistics window.

CPU phase timings and per-frame counters, filled while frames are drawn when EVAN_STATS is enabled; GPU pass times are included when timestamp queries are available. An application may render these values in its own debug overlay; the engine itself only emits one aggregated log record every EVAN_STATS_INTERVAL frames.

Returns
The current frame statistics of the renderer.

◆ getLastError()

Error evan::Engine::getLastError ( ) const

Returns the last error recorded by the platform.

Platforms record a sticky error while polling events (e.g. evan::Error::RuntimeLost when the OpenXR session is lost). Call this after pollEvents() to decide whether to tear down cleanly.

Returns
The last normalized error recorded by the platform.

◆ getTargetFps()

float evan::Engine::getTargetFps ( void  ) const
inline

Gets the configured target frame rate for the loop limiter.

A value of 0 means the loop is uncapped and paced by the presentation mechanism (vsync on desktop, xrWaitFrame on OpenXR).

Returns
The target FPS, or 0 when the limiter is disabled.

Definition at line 417 of file Engine.hpp.

◆ getView()

utility::graphic::ViewF evan::Engine::getView ( void  ) const
override

Get the mirrored view state.

Returns
The current view.

◆ isIndirectDrawingEnabled()

bool evan::Engine::isIndirectDrawingEnabled ( ) const

Checks whether indirect drawing is enabled.

Returns
True when indirect drawing is enabled.

◆ isInstancingEnabled()

bool evan::Engine::isInstancingEnabled ( ) const

Checks whether identical meshes are merged into one draw.

Returns
True when consecutive identical meshes are merged.

◆ measureText()

utility::graphic::SizeF evan::Engine::measureText ( const utility::graphic::Text &  text) const
override

Measures the pixel dimensions of a given text string when rendered with a specific font.

Parameters
textThe text to measure.
Returns
A 2D vector containing the width and height of the rendered text in pixels.

◆ pollEvents()

void evan::Engine::pollEvents ( )
override

Polls for events from the platform. This method is responsible for handling input events, window events, and other platform-specific events. It is typically called once per frame, allowing the engine to respond to user input, window resizing, and other events that may occur during the application's runtime. The pollEvents method interacts with the platform abstraction layer to retrieve and process events, ensuring that the engine can respond to user interactions and system events in a timely manner.

Note
The Engine class is designed to be flexible and extensible, allowing for future enhancements and additions to the engine's capabilities. The current implementation focuses on establishing the core structure and functionality of the engine, with plans for further improvements and optimizations in the future.
Returns
A vector of shared pointers to Event objects representing the events that were polled from the platform. Each Event object contains information about the type of event, such as input events. The vector may contain events such as keyboard input, mouse input, or xr controller input, depending on the specific events that were polled from the platform during the current frame.

see utility::event::Event for more details on the Event class and its derived classes representing specific types of events.

◆ present()

void evan::Engine::present ( void  )
override

Presents the composed back buffer to the screen.

Delegates to the renderer's frame drawing pipeline.

◆ removeObject()

bool evan::Engine::removeObject ( std::shared_ptr< utility::graphic::Renderable >  object,
size_t  objectID 
)
override

Removes a renderable object from the engine.

Parameters
objectThe renderable object to remove.
objectIDThe ID of the object to remove.
Returns
True if the removal was successful, false otherwise.

◆ render()

Error evan::Engine::render ( )

Renders the engine's render objects. This method is responsible for drawing the render objects registered in the engine to the screen using the renderer. It typically involves setting up the necessary graphics pipelines, binding resources, and issuing draw calls to render the objects. The render method may also handle post-processing effects, such as bloom or anti-aliasing, depending on the specific requirements of the application being developed with the engine.

Note
The Engine class is designed to be flexible and extensible, allowing for future enhancements and additions to the engine's capabilities. The current implementation focuses on establishing the core structure and functionality of the engine, with plans for further improvements and optimizations in the future.

◆ setIndirectDrawingEnabled()

void evan::Engine::setIndirectDrawingEnabled ( bool  enabled)

Enables or disables indirect drawing.

Forwards to the underlying Renderer. See Renderer::setIndirectDrawingEnabled for details.

Parameters
enabledTrue to batch draws through the indirect buffer.

◆ setInstancingEnabled()

void evan::Engine::setInstancingEnabled ( bool  enabled)

Enables or disables merging of identical meshes.

Forwards to the underlying Renderer. See Renderer::setInstancingEnabled: this only controls batching of consecutive identical meshes, it is never what routes an object transform to the GPU, which happens unconditionally. The application must provide local-space geometry, and the vertex shader must consume the per-instance matrix, for merging to render correctly.

Parameters
enabledTrue to merge identical meshes into instanced draws.

◆ setObjectTransform()

bool evan::Engine::setObjectTransform ( size_t  objectID,
const glm::mat4 &  transform 
)

Sets the model transform of an object in the current scene.

The transform is stored per mesh and is always applied on the GPU: the engine writes it into the frame's instance buffer and every draw addresses it through firstInstance, so the vertex shader applies it for every object, whether or not batching is enabled.

Geometry is therefore expected in local space. World-baked geometry still renders, but its pose can only change by rebuilding the vertex buffer, which is exactly what per-object transforms remove.

Parameters
objectIDThe identifier returned by addText/addMesh/addObject.
transformThe 4x4 model matrix to apply to the object.
Returns
True when the object was found and updated.

◆ setScissor()

void evan::Engine::setScissor ( const utility::graphic::ScissorRect &  rect)
override

Set the scissor (clip) rectangle, in framebuffer pixels.

The rectangle is applied when recording each view's command buffer and clamped to the swapchain extent.

Parameters
rectThe scissor rectangle to apply.

◆ setShouldCaptureViewportInput()

void evan::Engine::setShouldCaptureViewportInput ( bool  shouldCapture)
inline

Sets whether the engine should capture viewport input. This method allows users to enable or disable the capturing of input events for the viewport, such as mouse movements or keyboard inputs.

Parameters
shouldCaptureA boolean value indicating whether the engine should capture viewport input (true) or not (false).

Definition at line 404 of file Engine.hpp.

◆ setTargetFps()

void evan::Engine::setTargetFps ( float  fps)
inline

Sets an optional frame-rate limiter for the main loop.

When set to a value greater than 0, updateDeltaTime() sleeps to prevent the loop from running faster than this rate. When set to 0 (the default), no artificial limit is applied and the loop is paced by the presentation mechanism (vsync on desktop, xrWaitFrame on OpenXR).

Parameters
fpsThe target frame rate, or 0 to disable the limiter.

Definition at line 433 of file Engine.hpp.

◆ shouldCaptureViewportInput()

bool evan::Engine::shouldCaptureViewportInput ( void  ) const
inline

Checks if the engine should capture viewport input. This method returns a boolean value indicating whether the engine is currently set to capture input events for the viewport, such as mouse movements or keyboard inputs.

Returns
True if the engine should capture viewport input, false otherwise.

Definition at line 391 of file Engine.hpp.

◆ update()

void evan::Engine::update ( )
override

Updates the state of the engine. This method is responsible for handling logic updates, input processing, and other non-rendering related tasks. It is typically called once per frame, allowing the engine to respond to user input, update the state of objects in the scene, and perform any necessary calculations or updates before rendering. The update method may also handle events such as collisions, physics simulations, or AI behavior, depending on the specific requirements of the application being developed with the engine.

Note
The Engine class is designed to be flexible and extensible, allowing for future enhancements and additions to the engine's capabilities. The current implementation focuses on establishing the core structure and functionality of the engine, with plans for further improvements and optimizations in the future.

◆ updateObject()

bool evan::Engine::updateObject ( std::shared_ptr< utility::graphic::Renderable >  object,
size_t  objectID 
)
override

Updates an existing renderable object.

Parameters
objectThe updated renderable object.
objectIDThe ID of the object to update.
Returns
True if the update was successful, false otherwise.

Member Data Documentation

◆ _deviceContext

std::shared_ptr<DeviceContext> evan::Engine::_deviceContext
protected

A shared pointer to a DeviceContext object, which manages the Vulkan device and related resources. The DeviceContext is responsible for initializing Vulkan, selecting physical devices, creating logical devices, and managing command pools and queues.

Definition at line 471 of file Engine.hpp.

◆ _engineName

const std::string evan::Engine::_engineName = "Evan Engine"
protected

The name of the engine.

Definition at line 442 of file Engine.hpp.

◆ _engineVersion

const std::string evan::Engine::_engineVersion = "0.1.0"
protected

The version of the engine as a string. This is a human-readable representation of the engine's version, typically following semantic versioning (e.g., "0.1.0"). It can be used for display purposes or for logging the engine's version information.

Definition at line 451 of file Engine.hpp.

◆ _platform

std::shared_ptr<IPlatform> evan::Engine::_platform
protected

A shared pointer to an IPlatform object, which provides an abstraction layer for platform-specific operations. The IPlatform interface defines methods for window management, input handling, and other platform-dependent functionality, allowing the engine to be portable across different operating systems and platforms.

Definition at line 500 of file Engine.hpp.

◆ _renderer

std::shared_ptr<Renderer> evan::Engine::_renderer
protected

A shared pointer to a Renderer object, which is responsible for rendering scenes. The Renderer manages graphics pipelines, descriptor sets, and other rendering resources needed to draw objects on the screen.

Definition at line 479 of file Engine.hpp.

◆ _ressourceManager

std::shared_ptr<RessourceManager> evan::Engine::_ressourceManager
protected

A shared pointer to a RessourceManager object, which manages the loading and synchronization of GPU resources such as materials and textures. The RessourceManager interacts with the utility::RessourceProvider to load resources from disk or other sources, and creates corresponding GPU resources using the DeviceContext. It provides methods for synchronizing resources, retrieving specific materials or textures by ID, and managing the lifecycle of GPU resources to ensure efficient memory usage and performance in the rendering process.

Definition at line 524 of file Engine.hpp.

◆ _ressourceProvider

std::shared_ptr<utility::RessourceProvider> evan::Engine::_ressourceProvider
protected

A shared pointer to a RessourceProvider object, which is responsible for managing and loading various resources such as fonts, materials, and textures in a graphics application. The RessourceProvider provides methods to load resources from file paths or from asset objects, and it maintains internal maps to store loaded resources for efficient retrieval. It supports loading fonts, materials, and textures, and it can handle different shader types for materials.

Definition at line 511 of file Engine.hpp.

◆ _swapchainContext

std::shared_ptr<ASwapchainContext> evan::Engine::_swapchainContext
protected

A shared pointer to an ASwapchainContext object, which manages the Vulkan swapchain and related resources. The ASwapchainContext is responsible for creating and managing the swapchain, handling presentation, and managing synchronization primitives related to rendering and presentation. It provides an abstraction layer for managing the swapchain, allowing the engine to handle different platforms and rendering contexts without needing to directly interact with platform-specific details of swapchain management.

Definition at line 491 of file Engine.hpp.

◆ _version

const std::shared_ptr<Version> evan::Engine::_version
protected
Initial value:
=
std::make_shared<Version>(0, 1, 0)

The version of the engine as a Version object. This is a structured representation of the engine's version, containing separate fields for the major, minor, and patch version numbers. The Version object allows for easier comparison and manipulation of version information, enabling features such as checking for compatibility or determining if an update is available based on version numbers.

Definition at line 462 of file Engine.hpp.


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