Rehti MMORPG  1.0.0
Rehti MMORPG is a free and open source MMORPG game.
RehtiGraphics Class Reference

#include <RehtiGraphics.hpp>

Collaboration diagram for RehtiGraphics:
Collaboration graph

Public Member Functions

void startMainLoop ()
 Starts a rendering loop until the window is closed. More...
 
 RehtiGraphics (uint32_t width=1200, uint32_t height=900, glm::vec3 cameraLocation=glm::vec3(0.f))
 Initializes the graphics backend. More...
 
 ~RehtiGraphics ()
 Cleans up all the resources used by vulkan. More...
 
bool addCharacterObject (int characterID, std::vector< CharacterVertex > vertices, std::vector< uint32_t > indices, ImageData texture, std::array< Animation, ANIMATION_TYPE_COUNT > animations, std::vector< BoneNode > bones, std::vector< glm::mat4 > transformations, glm::vec3 location=glm::vec3(0.f), float rotation=0.f, bool isPlayer=false)
 Adds a character object with the given id to the graphics backend. Also creates a bounding box for the object. More...
 
bool removeCharacterObject (int characterID)
 Removes a character object with the given id from the graphics backend. More...
 
bool addGameObject (int objectID, std::vector< Vertex > vertices, std::vector< uint32_t > indices, ImageData texture, glm::vec3 location=glm::vec3(0.f), float rotation=0.f)
 Adds a game object with the given id to the graphics backend. Also creates a bounding box for the object. More...
 
bool removeGameObject (int objectID)
 Removes a game object with the given id from the graphics backend. More...
 
bool doesGameObjectExist (int objectID)
 Checks if a game object with the given id exists. More...
 
bool doesCharacterExist (int characterID)
 Checks if a characterwith the given id exists. More...
 
void moveGameObject (int objectID, glm::vec3 location, float timeInSeconds)
 Moves a game object to the given location in the given time. More...
 
void rotateGameObject (int objectID, float radians, float timeInSeconds)
 Rotates a game object by given radian angle in the given time frame. More...
 
void forceGameObjectMove (int objectID, glm::vec3 location)
 Forces the game object to move to the given location, quitting any remaining movement callbacks. More...
 
void forceGameObjectRotate (int objectID, float radians)
 Forces game object rotation to the given angle, quitting any remaining rotation callbacks. More...
 
void movePlayer (int playerID, glm::vec3 location, float timeInSeconds)
 Moves the player smoothly (without animation) to the given location in the given time. More...
 
void playAnimation (int characterID, AnimationConfig cfg)
 Plays an animation for the given character. More...
 
void forcePlayerMove (int playerID, glm::vec3 location)
 Forces player to move to the location given, cancelling any remaining movement callbacks and animations. More...
 
void moveCharacter (int characterID, glm::vec3 location, float timeInSeconds)
 Moves character smoothly (without animation) to the given location in the given time. More...
 
void forceCharacterMove (int characterID, glm::vec3 location)
 Forces character to the given location, cancelling any remaining movement callbacks and animations. More...
 
bool addArea (std::vector< Vertex > vertices, std::vector< uint32_t > indices, std::array< ImageData, 6 > textures)
 Adds an area to the game. More...
 
void transformTestObject (int id, glm::mat4 transformation)
 Transforms object with the given id. More...
 
void addMapBoundingBox (const MapAABBData &mapAABBData)
 Adds a bounding box for the world map. More...
 
Hit traceClick ()
 Traces a ray against all bounding boxes, starting with objects, then characters and lastly the map. More...
 
void setEngineFlags (EngineFlags flags)
 Sets flags for engine. Flags can only be set by this interface, not unset. More...
 
void addMouseClickCallback (std::function< void(const Hit &)> callback)
 Adds a mouse click callback. More...
 
std::shared_ptr< RehtiGuigetGui ()
 

Private Member Functions

void initWindow ()
 Initializes the window. More...
 
void initVulkan ()
 Initializes vulkan instance. More...
 
void populateDebugMessengerCreateInfo (VkDebugUtilsMessengerCreateInfoEXT &createInfo)
 Populates the debug messenger info. More...
 
void setupDebugMessenger ()
 Setups the debug messenger. More...
 
void pickPhysicalDevice ()
 Chooses an appropriate gpu. More...
 
void createLogicalDevice ()
 Creates the interactable logical device. More...
 
void createObjectManager ()
 Creates the graphics object manager. More...
 
void createSwapChain ()
 Creates the swapchain. More...
 
void recreateSwapChain ()
 Recreates the swapchain. More...
 
void cleanupSwapChain ()
 Cleans up swapchain related resources. This function is used for easier recreation of the swap chain. More...
 
void createImageViews ()
 Creates the image views. More...
 
void createRenderPass ()
 Creates the render pass. More...
 
void createGraphicsPipeline ()
 Creates the graphics pipeline. More...
 
void createFramebuffers ()
 Creates the framebuffers. More...
 
void createCommandPool ()
 Creates the command pool. More...
 
void createCommandBuffers ()
 Creates the command buffers. More...
 
void recordCommandBuffer (VkCommandBuffer cmdBuffer, uint32_t imageIndex)
 Records the command buffer. More...
 
void createSynchronization ()
 Initializes the appropriate semaphores and fences. More...
 
void drawFrame ()
 Draws a frame and records the previous frame time. More...
 
void mainLoop ()
 Loops, polls events and draws frames. More...
 
void cleanup ()
 Cleans up used resources. More...
 
void createInstance ()
 Creates vulkan instance. More...
 
void createSurface ()
 Creates a surface to draw on. More...
 
void createTextureSampler ()
 Creates a texture sampler. More...
 
void createDepthResources ()
 Creates resources required for a depth buffer. More...
 
void createGui ()
 Creates RehtiGui member and initializes it. More...
 
bool checkDeviceExtensionSupport (VkPhysicalDevice device)
 Checks whether the given device supports the required extensions. More...
 
bool checkValidationLayerSupport ()
 Checks whether the given device supports the required layers. More...
 
bool isDeviceSuitable (VkPhysicalDevice device)
 Checks whether the given device supports the required features. More...
 
bool bbHit (const glm::vec3 min, const glm::vec3 max, const glm::vec3 rayOrig, const glm::vec3 dirInv, float &t)
 Checks whether the given bounding box is hit by the given ray. More...
 
bool trace (const glm::vec3 orig, const glm::vec3 dirInv, const AABB *pBoxNode, AABB &boxHit, float &t)
 Traces a given ray against a given bounding box. More...
 
int rateDevice (VkPhysicalDevice device)
 Rates the given gpu. More...
 
QueueFamilyIndices findQueueFamilies (VkPhysicalDevice device)
 Looks for queue families. More...
 
SwapChainSupportDetails querySwapChainSupport (VkPhysicalDevice device)
 Looks for swapchain support. More...
 
std::vector< const char * > getRequiredExtensions ()
 Returns the required extensions as c strings. More...
 
VkSurfaceFormatKHR chooseSwapSurfaceFormat (const std::vector< VkSurfaceFormatKHR > availableFormats)
 Chooses a surface format. More...
 
VkPresentModeKHR chooseSwapPresentMode (const std::vector< VkPresentModeKHR > availableModes)
 Chooses a present mode. More...
 
VkExtent2D chooseSwapExtent (const VkSurfaceCapabilitiesKHR &capabilities)
 Chooses a swap extent based on the provided capabilities. More...
 
VkPushConstantRange getCameraRange ()
 Returns the size of the camera matrix. More...
 
VkFormat findSupportedFormat (const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features)
 Looks for a suitable format from given candidates. More...
 
size_t getNextFrame ()
 Returns the index of the next frame. More...
 
void moveBoundingBox (int objectID, ObjectType objType, glm::vec3 location)
 Helper function to move a bounding box. More...
 
void debugMatrix (glm::mat4 matrix)
 Prints out a matrix. More...
 
void debugAABB (const AABB &aabb, int level)
 Prints out the given aabb. More...
 
void fillAABB (std::vector< Vertex > vertices, AABB &box)
 Fills the min and max of the given bounding box. More...
 

Static Private Member Functions

static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData)
 
static VkResult CreateDebugUtilsMessengerEXT (VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT *pDebugMessenger)
 
static void DestroyDebugUtilsMessengerEXT (VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks *pAllocator)
 
static void frameBufferResizeCallback (GLFWwindow *window, int width, int height)
 

Private Attributes

GLFWwindow * pWindowM
 
VkInstance instanceM
 
VkDebugUtilsMessengerEXT debugMessengerM
 
VkSurfaceKHR surfaceM
 
Camera cameraM
 
VkPhysicalDevice gpuM
 
VkDevice logDeviceM
 
std::shared_ptr< GraphicsObjectManagerpObjectManagerM
 
std::shared_ptr< RehtiGuipGuiM
 
std::shared_mutex graphicsQueueMutexM
 
VkQueue graphicsQueueM
 
VkQueue presentQueueM
 
VkSwapchainKHR swapChainM
 
std::vector< VkImage > swapChainImagesM
 
VkFormat swapChainImageFormatM
 
VkExtent2D swapChainExtentM
 
std::vector< VkImageView > swapChainImageViewsM
 
std::vector< VkFramebuffer > swapChainFramebuffersM
 
AllocatedImage depthImageM
 
VkImageView depthImageViewM
 
VkFormat depthFormatM
 
VkSampler textureSamplerM
 
VkRenderPass renderPassM
 
std::array< VkPipelineLayout, OBJECT_TYPE_COUNTpipelineLayoutsM
 
std::array< VkPipeline, OBJECT_TYPE_COUNTpipelinesM
 
VkCommandPool commandPoolM
 
std::vector< VkCommandBuffer > commandBuffersM
 
std::vector< VkSemaphore > imagesReadyM
 
std::vector< VkSemaphore > rendersFinishedM
 
std::vector< VkFence > frameFencesM
 
std::function< void(const Hit &)> mouseClickCallbackM
 
uint32_t widthM
 
uint32_t heightM
 
float anisotropyM
 
EngineFlags engineFlagsM = EngineFlags::NO_FLAGS
 
EngineStatistics statsM
 
std::shared_mutex dataMutexM
 Mutex that must be acquired before modifying the data structures below (timer has its own mutex) More...
 
std::array< std::map< int, AABB >, OBJECT_TYPE_COUNTboundingBoxesM
 
std::map< int, GfxOrientationgameObjectOrientationsM
 
std::map< int, CharacterDatacharacterOrientationsM
 
DirectionalLight sunM
 
TimerCallbackSystem timersM
 
const int kConcurrentFramesM = 2
 
size_t currentFrameM = 0
 
bool validationLayersEnabledM = false
 
const std::vector< const char * > kValidationlayersM
 
const std::vector< const char * > kDeviceExtensionsM
 
const bool enableValidationLayers = true
 

Constructor & Destructor Documentation

◆ RehtiGraphics()

RehtiGraphics::RehtiGraphics ( uint32_t  width = 1200,
uint32_t  height = 900,
glm::vec3  cameraLocation = glm::vec3(0.f) 
)

Initializes the graphics backend.

Parameters
widthof the window
heightof the window

◆ ~RehtiGraphics()

RehtiGraphics::~RehtiGraphics ( )

Cleans up all the resources used by vulkan.

Here is the call graph for this function:

Member Function Documentation

◆ addArea()

bool RehtiGraphics::addArea ( std::vector< Vertex vertices,
std::vector< uint32_t >  indices,
std::array< ImageData, 6 >  textures 
)

Adds an area to the game.

Parameters
verticesare the vertices of the area. They are expected to be moved to their corresponding area coordinates before calling this function.
indicesof the triangles.
texturesof the area. Areas support 5 textures with a blendmap: Order is: blendmap (0), black (1), red (2), green (3), blue (4), alpha (5).
Returns
boolean indicating whether the area was added successfully.
Here is the caller graph for this function:

◆ addCharacterObject()

bool RehtiGraphics::addCharacterObject ( int  characterID,
std::vector< CharacterVertex vertices,
std::vector< uint32_t >  indices,
ImageData  texture,
std::array< Animation, ANIMATION_TYPE_COUNT >  animations,
std::vector< BoneNode bones,
std::vector< glm::mat4 >  transformations,
glm::vec3  location = glm::vec3(0.f),
float  rotation = 0.f,
bool  isPlayer = false 
)

Adds a character object with the given id to the graphics backend. Also creates a bounding box for the object.

Parameters
characterIDof the character object.
verticesof the model
indicesof the triangles of the model
textureof the model
animationslist of Animation structs for the character
boneslist of BoneNode structs for the character
transformationslist of transformation matrices for the character. IMPORTANT: THE FIRST MATRIX IS THE GLOBAL INVERSE TRANSFORMATION MATRIX. So the transformations start from the second matrix.
locationof the character to be placed
rotationof the character to be placed
Returns
boolean indicating whether the object was added successfully.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addGameObject()

bool RehtiGraphics::addGameObject ( int  objectID,
std::vector< Vertex vertices,
std::vector< uint32_t >  indices,
ImageData  texture,
glm::vec3  location = glm::vec3(0.f),
float  rotation = 0.f 
)

Adds a game object with the given id to the graphics backend. Also creates a bounding box for the object.

Parameters
objectID
verticesof the model
indicesof the triangles of the model
textureof the model
locationis the location of the model
rotationis the rotation around y axis clockwise
Returns
boolean indicating whether the object was added successfully.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addMapBoundingBox()

void RehtiGraphics::addMapBoundingBox ( const MapAABBData mapAABBData)

Adds a bounding box for the world map.

Parameters
mapAABBDatasee mapAABBData
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addMouseClickCallback()

void RehtiGraphics::addMouseClickCallback ( std::function< void(const Hit &)>  callback)

Adds a mouse click callback.

Parameters
callbackfunction after a mouse click has happened
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bbHit()

bool RehtiGraphics::bbHit ( const glm::vec3  min,
const glm::vec3  max,
const glm::vec3  rayOrig,
const glm::vec3  dirInv,
float &  t 
)
private

Checks whether the given bounding box is hit by the given ray.

Parameters
minis the smaller coordinate of the bounding box.
maxis the larger coordinate of the bounding box.
rayOrigis the origin of the ray.
dirInvis the coordinate-wise inverse of the direction of the ray.
tis the distance to the hit point.
Returns
true if hit, false otherwise.
Here is the caller graph for this function:

◆ checkDeviceExtensionSupport()

bool RehtiGraphics::checkDeviceExtensionSupport ( VkPhysicalDevice  device)
private

Checks whether the given device supports the required extensions.

Parameters
deviceto check.
Returns
boolean indicating whether the device supports the required extensions.
Here is the caller graph for this function:

◆ checkValidationLayerSupport()

bool RehtiGraphics::checkValidationLayerSupport ( )
private

Checks whether the given device supports the required layers.

Returns
boolean indicating whether the layers are found.
Here is the caller graph for this function:

◆ chooseSwapExtent()

VkExtent2D RehtiGraphics::chooseSwapExtent ( const VkSurfaceCapabilitiesKHR &  capabilities)
private

Chooses a swap extent based on the provided capabilities.

Parameters
capabilitiesof the surface in use.
Returns
VkExtent2D object.
Here is the caller graph for this function:

◆ chooseSwapPresentMode()

VkPresentModeKHR RehtiGraphics::chooseSwapPresentMode ( const std::vector< VkPresentModeKHR >  availableModes)
private

Chooses a present mode.

Parameters
availableModesto choose from.
Returns
Presentmode chosen.
Here is the caller graph for this function:

◆ chooseSwapSurfaceFormat()

VkSurfaceFormatKHR RehtiGraphics::chooseSwapSurfaceFormat ( const std::vector< VkSurfaceFormatKHR >  availableFormats)
private

Chooses a surface format.

Parameters
availableFormatsto choose from.
Returns
format from the list.
Here is the caller graph for this function:

◆ cleanup()

void RehtiGraphics::cleanup ( )
private

Cleans up used resources.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanupSwapChain()

void RehtiGraphics::cleanupSwapChain ( )
private

Cleans up swapchain related resources. This function is used for easier recreation of the swap chain.

Here is the caller graph for this function:

◆ createCommandBuffers()

void RehtiGraphics::createCommandBuffers ( )
private

Creates the command buffers.

Here is the caller graph for this function:

◆ createCommandPool()

void RehtiGraphics::createCommandPool ( )
private

Creates the command pool.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateDebugUtilsMessengerEXT()

VkResult RehtiGraphics::CreateDebugUtilsMessengerEXT ( VkInstance  instance,
const VkDebugUtilsMessengerCreateInfoEXT *  pCreateInfo,
const VkAllocationCallbacks *  pAllocator,
VkDebugUtilsMessengerEXT *  pDebugMessenger 
)
staticprivate
Here is the caller graph for this function:

◆ createDepthResources()

void RehtiGraphics::createDepthResources ( )
private

Creates resources required for a depth buffer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createFramebuffers()

void RehtiGraphics::createFramebuffers ( )
private

Creates the framebuffers.

Here is the caller graph for this function:

◆ createGraphicsPipeline()

void RehtiGraphics::createGraphicsPipeline ( )
private

Creates the graphics pipeline.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createGui()

void RehtiGraphics::createGui ( )
private

Creates RehtiGui member and initializes it.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createImageViews()

void RehtiGraphics::createImageViews ( )
private

Creates the image views.

Here is the caller graph for this function:

◆ createInstance()

void RehtiGraphics::createInstance ( )
private

Creates vulkan instance.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createLogicalDevice()

void RehtiGraphics::createLogicalDevice ( )
private

Creates the interactable logical device.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createObjectManager()

void RehtiGraphics::createObjectManager ( )
private

Creates the graphics object manager.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createRenderPass()

void RehtiGraphics::createRenderPass ( )
private

Creates the render pass.

Here is the caller graph for this function:

◆ createSurface()

void RehtiGraphics::createSurface ( )
private

Creates a surface to draw on.

Here is the caller graph for this function:

◆ createSwapChain()

void RehtiGraphics::createSwapChain ( )
private

Creates the swapchain.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createSynchronization()

void RehtiGraphics::createSynchronization ( )
private

Initializes the appropriate semaphores and fences.

Here is the caller graph for this function:

◆ createTextureSampler()

void RehtiGraphics::createTextureSampler ( )
private

Creates a texture sampler.

Here is the caller graph for this function:

◆ debugAABB()

void RehtiGraphics::debugAABB ( const AABB aabb,
int  level 
)
private

Prints out the given aabb.

Parameters
aabb
Here is the call graph for this function:

◆ debugCallback()

VKAPI_ATTR VkBool32 VKAPI_CALL RehtiGraphics::debugCallback ( VkDebugUtilsMessageSeverityFlagBitsEXT  messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT  messageType,
const VkDebugUtilsMessengerCallbackDataEXT *  pCallbackData,
void *  pUserData 
)
staticprivate
Here is the caller graph for this function:

◆ debugMatrix()

void RehtiGraphics::debugMatrix ( glm::mat4  matrix)
private

Prints out a matrix.

Parameters
matrixto print

◆ DestroyDebugUtilsMessengerEXT()

void RehtiGraphics::DestroyDebugUtilsMessengerEXT ( VkInstance  instance,
VkDebugUtilsMessengerEXT  debugMessenger,
const VkAllocationCallbacks *  pAllocator 
)
staticprivate
Here is the caller graph for this function:

◆ doesCharacterExist()

bool RehtiGraphics::doesCharacterExist ( int  characterID)

Checks if a characterwith the given id exists.

Parameters
characterID
Returns

◆ doesGameObjectExist()

bool RehtiGraphics::doesGameObjectExist ( int  objectID)

Checks if a game object with the given id exists.

Parameters
objectID
Returns

◆ drawFrame()

void RehtiGraphics::drawFrame ( )
private

Draws a frame and records the previous frame time.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fillAABB()

void RehtiGraphics::fillAABB ( std::vector< Vertex vertices,
AABB box 
)
private

Fills the min and max of the given bounding box.

Parameters
verticesto create a bounding box for.
boxto fill.

◆ findQueueFamilies()

QueueFamilyIndices RehtiGraphics::findQueueFamilies ( VkPhysicalDevice  device)
private

Looks for queue families.

Parameters
deviceto look queues for.
Returns
Struct indicating queue family support.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findSupportedFormat()

VkFormat RehtiGraphics::findSupportedFormat ( const std::vector< VkFormat > &  candidates,
VkImageTiling  tiling,
VkFormatFeatureFlags  features 
)
private

Looks for a suitable format from given candidates.

Parameters
candidates
tiling
features
Returns
Here is the caller graph for this function:

◆ forceCharacterMove()

void RehtiGraphics::forceCharacterMove ( int  characterID,
glm::vec3  location 
)

Forces character to the given location, cancelling any remaining movement callbacks and animations.

Parameters
characterID
location
Here is the call graph for this function:
Here is the caller graph for this function:

◆ forceGameObjectMove()

void RehtiGraphics::forceGameObjectMove ( int  objectID,
glm::vec3  location 
)

Forces the game object to move to the given location, quitting any remaining movement callbacks.

Parameters
objectIDof the object to move.
locationto move the object to.
Here is the call graph for this function:

◆ forceGameObjectRotate()

void RehtiGraphics::forceGameObjectRotate ( int  objectID,
float  radians 
)

Forces game object rotation to the given angle, quitting any remaining rotation callbacks.

Parameters
objectIDof the object to rotate.
radiansto rotate the object by.
Here is the call graph for this function:

◆ forcePlayerMove()

void RehtiGraphics::forcePlayerMove ( int  playerID,
glm::vec3  location 
)

Forces player to move to the location given, cancelling any remaining movement callbacks and animations.

Parameters
playerIDof the player to move.
locationto move the player to.
Here is the call graph for this function:

◆ frameBufferResizeCallback()

void RehtiGraphics::frameBufferResizeCallback ( GLFWwindow *  window,
int  width,
int  height 
)
staticprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCameraRange()

VkPushConstantRange RehtiGraphics::getCameraRange ( )
private

Returns the size of the camera matrix.

Returns
VkPushConstantRange object.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGui()

std::shared_ptr< RehtiGui > RehtiGraphics::getGui ( )
Here is the caller graph for this function:

◆ getNextFrame()

size_t RehtiGraphics::getNextFrame ( )
private

Returns the index of the next frame.

Returns
Here is the caller graph for this function:

◆ getRequiredExtensions()

std::vector< const char * > RehtiGraphics::getRequiredExtensions ( )
private

Returns the required extensions as c strings.

Returns
vector of c strings.
Here is the caller graph for this function:

◆ initVulkan()

void RehtiGraphics::initVulkan ( )
private

Initializes vulkan instance.

Here is the call graph for this function:

◆ initWindow()

void RehtiGraphics::initWindow ( )
private

Initializes the window.

Here is the call graph for this function:

◆ isDeviceSuitable()

bool RehtiGraphics::isDeviceSuitable ( VkPhysicalDevice  device)
private

Checks whether the given device supports the required features.

Parameters
deviceto check.
Returns
boolean indicating whether the device supports the required features.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mainLoop()

void RehtiGraphics::mainLoop ( )
private

Loops, polls events and draws frames.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveBoundingBox()

void RehtiGraphics::moveBoundingBox ( int  objectID,
ObjectType  objType,
glm::vec3  location 
)
private

Helper function to move a bounding box.

Parameters
objectIDof the object
objTypeof the object
locationthat the object is to be moved to
Here is the caller graph for this function:

◆ moveCharacter()

void RehtiGraphics::moveCharacter ( int  characterID,
glm::vec3  location,
float  timeInSeconds 
)

Moves character smoothly (without animation) to the given location in the given time.

Parameters
characterIDto move
locationto move the character into
timeInSecondsthat this action takes.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveGameObject()

void RehtiGraphics::moveGameObject ( int  objectID,
glm::vec3  location,
float  timeInSeconds 
)

Moves a game object to the given location in the given time.

Parameters
objectIDof the object to move.
locationto move the object to.
timeInSecondsthat it takes to move the object.
Here is the call graph for this function:

◆ movePlayer()

void RehtiGraphics::movePlayer ( int  playerID,
glm::vec3  location,
float  timeInSeconds 
)

Moves the player smoothly (without animation) to the given location in the given time.

Parameters
playerIDof the player to move.
locationto move the player to.
timeInSecondsit takes for the player to move to that location.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pickPhysicalDevice()

void RehtiGraphics::pickPhysicalDevice ( )
private

Chooses an appropriate gpu.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playAnimation()

void RehtiGraphics::playAnimation ( int  characterID,
AnimationConfig  cfg 
)

Plays an animation for the given character.

Parameters
characterID
cfg
Here is the call graph for this function:
Here is the caller graph for this function:

◆ populateDebugMessengerCreateInfo()

void RehtiGraphics::populateDebugMessengerCreateInfo ( VkDebugUtilsMessengerCreateInfoEXT &  createInfo)
private

Populates the debug messenger info.

Parameters
createInfo
Here is the call graph for this function:
Here is the caller graph for this function:

◆ querySwapChainSupport()

SwapChainSupportDetails RehtiGraphics::querySwapChainSupport ( VkPhysicalDevice  device)
private

Looks for swapchain support.

Parameters
deviceto look support for.
Returns
Swapchain support details.
Here is the caller graph for this function:

◆ rateDevice()

int RehtiGraphics::rateDevice ( VkPhysicalDevice  device)
private

Rates the given gpu.

Parameters
deviceto rate.

◆ recordCommandBuffer()

void RehtiGraphics::recordCommandBuffer ( VkCommandBuffer  cmdBuffer,
uint32_t  imageIndex 
)
private

Records the command buffer.

Parameters
cmdBufferto record to.
imageIndexof the swapchain image.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ recreateSwapChain()

void RehtiGraphics::recreateSwapChain ( )
private

Recreates the swapchain.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeCharacterObject()

bool RehtiGraphics::removeCharacterObject ( int  characterID)

Removes a character object with the given id from the graphics backend.

Parameters
characterIDof the character object.
Returns
boolean indicating whether the object was removed successfully.
Here is the caller graph for this function:

◆ removeGameObject()

bool RehtiGraphics::removeGameObject ( int  objectID)

Removes a game object with the given id from the graphics backend.

Parameters
objectIDof the game object.
Returns
boolean indicating whether the object was removed successfully.
Here is the caller graph for this function:

◆ rotateGameObject()

void RehtiGraphics::rotateGameObject ( int  objectID,
float  radians,
float  timeInSeconds 
)

Rotates a game object by given radian angle in the given time frame.

Parameters
objectIDof the object to rotate.
radiansto rotate the object by.
timeInSecondsthat it takes to rotate the object.
Here is the call graph for this function:

◆ setEngineFlags()

void RehtiGraphics::setEngineFlags ( EngineFlags  flags)

Sets flags for engine. Flags can only be set by this interface, not unset.

Parameters
flagsto be set
Here is the caller graph for this function:

◆ setupDebugMessenger()

void RehtiGraphics::setupDebugMessenger ( )
private

Setups the debug messenger.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startMainLoop()

void RehtiGraphics::startMainLoop ( )

Starts a rendering loop until the window is closed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trace()

bool RehtiGraphics::trace ( const glm::vec3  orig,
const glm::vec3  dirInv,
const AABB pBoxNode,
AABB boxHit,
float &  t 
)
private

Traces a given ray against a given bounding box.

Parameters
origis the origin of the ray.
dirInvis the inverse of the direction of the ray.
boxNodeis the bounding box to trace against.
boxHitis the bounding box that was hit.
Returns
the distance to the hit point.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ traceClick()

Hit RehtiGraphics::traceClick ( )

Traces a ray against all bounding boxes, starting with objects, then characters and lastly the map.

Returns
Hit object containing information about the hit.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transformTestObject()

void RehtiGraphics::transformTestObject ( int  id,
glm::mat4  transformation 
)

Transforms object with the given id.

Member Data Documentation

◆ anisotropyM

float RehtiGraphics::anisotropyM
private

◆ boundingBoxesM

std::array<std::map<int, AABB>, OBJECT_TYPE_COUNT> RehtiGraphics::boundingBoxesM
private

◆ cameraM

Camera RehtiGraphics::cameraM
private

◆ characterOrientationsM

std::map<int, CharacterData> RehtiGraphics::characterOrientationsM
private

◆ commandBuffersM

std::vector<VkCommandBuffer> RehtiGraphics::commandBuffersM
private

◆ commandPoolM

VkCommandPool RehtiGraphics::commandPoolM
private

◆ currentFrameM

size_t RehtiGraphics::currentFrameM = 0
private

◆ dataMutexM

std::shared_mutex RehtiGraphics::dataMutexM
private

Mutex that must be acquired before modifying the data structures below (timer has its own mutex)

◆ debugMessengerM

VkDebugUtilsMessengerEXT RehtiGraphics::debugMessengerM
private

◆ depthFormatM

VkFormat RehtiGraphics::depthFormatM
private

◆ depthImageM

AllocatedImage RehtiGraphics::depthImageM
private

◆ depthImageViewM

VkImageView RehtiGraphics::depthImageViewM
private

◆ enableValidationLayers

const bool RehtiGraphics::enableValidationLayers = true
private

◆ engineFlagsM

EngineFlags RehtiGraphics::engineFlagsM = EngineFlags::NO_FLAGS
private

◆ frameFencesM

std::vector<VkFence> RehtiGraphics::frameFencesM
private

◆ gameObjectOrientationsM

std::map<int, GfxOrientation> RehtiGraphics::gameObjectOrientationsM
private

◆ gpuM

VkPhysicalDevice RehtiGraphics::gpuM
private

◆ graphicsQueueM

VkQueue RehtiGraphics::graphicsQueueM
private

◆ graphicsQueueMutexM

std::shared_mutex RehtiGraphics::graphicsQueueMutexM
private

◆ heightM

uint32_t RehtiGraphics::heightM
private

◆ imagesReadyM

std::vector<VkSemaphore> RehtiGraphics::imagesReadyM
private

◆ instanceM

VkInstance RehtiGraphics::instanceM
private

◆ kConcurrentFramesM

const int RehtiGraphics::kConcurrentFramesM = 2
private

◆ kDeviceExtensionsM

const std::vector<const char*> RehtiGraphics::kDeviceExtensionsM
private
Initial value:
= {
VK_KHR_SWAPCHAIN_EXTENSION_NAME}

◆ kValidationlayersM

const std::vector<const char*> RehtiGraphics::kValidationlayersM
private
Initial value:
= {
"VK_LAYER_KHRONOS_validation"}

◆ logDeviceM

VkDevice RehtiGraphics::logDeviceM
private

◆ mouseClickCallbackM

std::function<void(const Hit&)> RehtiGraphics::mouseClickCallbackM
private

◆ pGuiM

std::shared_ptr<RehtiGui> RehtiGraphics::pGuiM
private

◆ pipelineLayoutsM

std::array<VkPipelineLayout, OBJECT_TYPE_COUNT> RehtiGraphics::pipelineLayoutsM
private

◆ pipelinesM

std::array<VkPipeline, OBJECT_TYPE_COUNT> RehtiGraphics::pipelinesM
private

◆ pObjectManagerM

std::shared_ptr<GraphicsObjectManager> RehtiGraphics::pObjectManagerM
private

◆ presentQueueM

VkQueue RehtiGraphics::presentQueueM
private

◆ pWindowM

GLFWwindow* RehtiGraphics::pWindowM
private

◆ renderPassM

VkRenderPass RehtiGraphics::renderPassM
private

◆ rendersFinishedM

std::vector<VkSemaphore> RehtiGraphics::rendersFinishedM
private

◆ statsM

EngineStatistics RehtiGraphics::statsM
private

◆ sunM

DirectionalLight RehtiGraphics::sunM
private

◆ surfaceM

VkSurfaceKHR RehtiGraphics::surfaceM
private

◆ swapChainExtentM

VkExtent2D RehtiGraphics::swapChainExtentM
private

◆ swapChainFramebuffersM

std::vector<VkFramebuffer> RehtiGraphics::swapChainFramebuffersM
private

◆ swapChainImageFormatM

VkFormat RehtiGraphics::swapChainImageFormatM
private

◆ swapChainImagesM

std::vector<VkImage> RehtiGraphics::swapChainImagesM
private

◆ swapChainImageViewsM

std::vector<VkImageView> RehtiGraphics::swapChainImageViewsM
private

◆ swapChainM

VkSwapchainKHR RehtiGraphics::swapChainM
private

◆ textureSamplerM

VkSampler RehtiGraphics::textureSamplerM
private

◆ timersM

TimerCallbackSystem RehtiGraphics::timersM
private

◆ validationLayersEnabledM

bool RehtiGraphics::validationLayersEnabledM = false
private

◆ widthM

uint32_t RehtiGraphics::widthM
private

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