2 #include <vulkan/vulkan.h>
72 RehtiGraphics(uint32_t width = 1200, uint32_t height = 900, glm::vec3 cameraLocation = glm::vec3(0.f));
92 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);
111 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);
140 void moveGameObject(
int objectID, glm::vec3 location,
float timeInSeconds);
170 void movePlayer(
int playerID, glm::vec3 location,
float timeInSeconds);
192 void moveCharacter(
int characterID, glm::vec3 location,
float timeInSeconds);
208 bool addArea(std::vector<Vertex> vertices, std::vector<uint32_t> indices, std::array<ImageData, 6> textures);
239 std::shared_ptr<RehtiGui>
getGui();
408 bool bbHit(
const glm::vec3 min,
const glm::vec3 max,
const glm::vec3 rayOrig,
const glm::vec3 dirInv,
float& t);
418 bool trace(
const glm::vec3 orig,
const glm::vec3 dirInv,
const AABB* pBoxNode,
AABB& boxHit,
float& t);
480 VkFormat
findSupportedFormat(
const std::vector<VkFormat>& candidates, VkImageTiling tiling, VkFormatFeatureFlags features);
597 "VK_LAYER_KHRONOS_validation"};
600 VK_KHR_SWAPCHAIN_EXTENSION_NAME};
604 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
605 VkDebugUtilsMessageTypeFlagsEXT messageType,
606 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
611 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
612 const VkAllocationCallbacks* pAllocator,
613 VkDebugUtilsMessengerEXT* pDebugMessenger);
615 static void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger,
const VkAllocationCallbacks* pAllocator);
ObjectType
Definition: BasicTypes.hpp:29
constexpr size_t OBJECT_TYPE_COUNT
Definition: BasicTypes.hpp:26
EngineFlags
Definition: RehtiGraphics.hpp:22
@ NO_FLAGS
Definition: RehtiGraphics.hpp:23
@ UNKNOWN
Definition: RehtiGraphics.hpp:25
@ FRAME_BUFFER_RESIZED
Definition: RehtiGraphics.hpp:24
Definition: Camera.hpp:32
Definition: RehtiGraphics.hpp:60
std::function< void(const Hit &)> mouseClickCallbackM
Definition: RehtiGraphics.hpp:570
bool isDeviceSuitable(VkPhysicalDevice device)
Checks whether the given device supports the required features.
Definition: RehtiGraphics.cpp:1346
void rotateGameObject(int objectID, float radians, float timeInSeconds)
Rotates a game object by given radian angle in the given time frame.
Definition: RehtiGraphics.cpp:165
void forceGameObjectRotate(int objectID, float radians)
Forces game object rotation to the given angle, quitting any remaining rotation callbacks.
Definition: RehtiGraphics.cpp:300
const std::vector< const char * > kDeviceExtensionsM
Definition: RehtiGraphics.hpp:599
size_t getNextFrame()
Returns the index of the next frame.
Definition: RehtiGraphics.cpp:1606
std::shared_ptr< RehtiGui > getGui()
Definition: RehtiGraphics.cpp:1729
bool addArea(std::vector< Vertex > vertices, std::vector< uint32_t > indices, std::array< ImageData, 6 > textures)
Adds an area to the game.
Definition: RehtiGraphics.cpp:306
VkDevice logDeviceM
Definition: RehtiGraphics.hpp:528
void moveBoundingBox(int objectID, ObjectType objType, glm::vec3 location)
Helper function to move a bounding box.
Definition: RehtiGraphics.cpp:1611
const bool enableValidationLayers
Definition: RehtiGraphics.hpp:622
void cleanupSwapChain()
Cleans up swapchain related resources. This function is used for easier recreation of the swap chain.
Definition: RehtiGraphics.cpp:1105
Hit traceClick()
Traces a ray against all bounding boxes, starting with objects, then characters and lastly the map.
Definition: RehtiGraphics.cpp:332
VkFormat depthFormatM
Definition: RehtiGraphics.hpp:551
void recreateSwapChain()
Recreates the swapchain.
Definition: RehtiGraphics.cpp:638
bool checkDeviceExtensionSupport(VkPhysicalDevice device)
Checks whether the given device supports the required extensions.
Definition: RehtiGraphics.cpp:1297
VkSampler textureSamplerM
Definition: RehtiGraphics.hpp:553
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device)
Looks for swapchain support.
Definition: RehtiGraphics.cpp:1491
void createCommandPool()
Creates the command pool.
Definition: RehtiGraphics.cpp:901
void createInstance()
Creates vulkan instance.
Definition: RehtiGraphics.cpp:1165
void addMapBoundingBox(const MapAABBData &mapAABBData)
Adds a bounding box for the world map.
Definition: RehtiGraphics.cpp:321
void createSwapChain()
Creates the swapchain.
Definition: RehtiGraphics.cpp:575
DirectionalLight sunM
Definition: RehtiGraphics.hpp:586
void forceGameObjectMove(int objectID, glm::vec3 location)
Forces the game object to move to the given location, quitting any remaining movement callbacks.
Definition: RehtiGraphics.cpp:180
std::vector< VkSemaphore > imagesReadyM
Definition: RehtiGraphics.hpp:565
void addMouseClickCallback(std::function< void(const Hit &)> callback)
Adds a mouse click callback.
Definition: RehtiGraphics.cpp:1701
std::array< VkPipeline, OBJECT_TYPE_COUNT > pipelinesM
Definition: RehtiGraphics.hpp:558
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device)
Looks for queue families.
Definition: RehtiGraphics.cpp:1457
TimerCallbackSystem timersM
Definition: RehtiGraphics.hpp:589
std::array< VkPipelineLayout, OBJECT_TYPE_COUNT > pipelineLayoutsM
Definition: RehtiGraphics.hpp:557
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.
Definition: RehtiGraphics.cpp:1374
std::array< std::map< int, AABB >, OBJECT_TYPE_COUNT > boundingBoxesM
Definition: RehtiGraphics.hpp:581
const std::vector< const char * > kValidationlayersM
Definition: RehtiGraphics.hpp:596
bool doesGameObjectExist(int objectID)
Checks if a game object with the given id exists.
Definition: RehtiGraphics.cpp:134
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo)
Populates the debug messenger info.
Definition: RehtiGraphics.cpp:443
void createTextureSampler()
Creates a texture sampler.
Definition: RehtiGraphics.cpp:1222
std::vector< VkFence > frameFencesM
Definition: RehtiGraphics.hpp:567
bool removeGameObject(int objectID)
Removes a game object with the given id from the graphics backend.
Definition: RehtiGraphics.cpp:116
VkQueue graphicsQueueM
Definition: RehtiGraphics.hpp:536
void createObjectManager()
Creates the graphics object manager.
Definition: RehtiGraphics.cpp:553
EngineStatistics statsM
Definition: RehtiGraphics.hpp:577
VkFormat findSupportedFormat(const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features)
Looks for a suitable format from given candidates.
Definition: RehtiGraphics.cpp:1587
static VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT *pDebugMessenger)
Definition: RehtiGraphics.cpp:1679
uint32_t widthM
Definition: RehtiGraphics.hpp:573
void setEngineFlags(EngineFlags flags)
Sets flags for engine. Flags can only be set by this interface, not unset.
Definition: RehtiGraphics.cpp:397
void createImageViews()
Creates the image views.
Definition: RehtiGraphics.cpp:658
VkPhysicalDevice gpuM
Definition: RehtiGraphics.hpp:525
std::vector< VkImage > swapChainImagesM
Definition: RehtiGraphics.hpp:541
VkRenderPass renderPassM
Definition: RehtiGraphics.hpp:556
void moveGameObject(int objectID, glm::vec3 location, float timeInSeconds)
Moves a game object to the given location in the given time.
Definition: RehtiGraphics.cpp:146
VkFormat swapChainImageFormatM
Definition: RehtiGraphics.hpp:542
void fillAABB(std::vector< Vertex > vertices, AABB &box)
Fills the min and max of the given bounding box.
Definition: RehtiGraphics.cpp:1655
void recordCommandBuffer(VkCommandBuffer cmdBuffer, uint32_t imageIndex)
Records the command buffer.
Definition: RehtiGraphics.cpp:928
void forcePlayerMove(int playerID, glm::vec3 location)
Forces player to move to the location given, cancelling any remaining movement callbacks and animatio...
Definition: RehtiGraphics.cpp:250
void transformTestObject(int id, glm::mat4 transformation)
Transforms object with the given id.
Definition: RehtiGraphics.cpp:315
VkDebugUtilsMessengerEXT debugMessengerM
Definition: RehtiGraphics.hpp:518
int rateDevice(VkPhysicalDevice device)
Rates the given gpu.
Definition: RehtiGraphics.cpp:1447
std::vector< const char * > getRequiredExtensions()
Returns the required extensions as c strings.
Definition: RehtiGraphics.cpp:1519
static void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks *pAllocator)
Definition: RehtiGraphics.cpp:1692
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities)
Chooses a swap extent based on the provided capabilities.
Definition: RehtiGraphics.cpp:1557
void createFramebuffers()
Creates the framebuffers.
Definition: RehtiGraphics.cpp:880
void createGui()
Creates RehtiGui member and initializes it.
Definition: RehtiGraphics.cpp:1262
AllocatedImage depthImageM
Definition: RehtiGraphics.hpp:549
std::map< int, GfxOrientation > gameObjectOrientationsM
Definition: RehtiGraphics.hpp:583
void setupDebugMessenger()
Setups the debug messenger.
Definition: RehtiGraphics.cpp:452
void mainLoop()
Loops, polls events and draws frames.
Definition: RehtiGraphics.cpp:1075
void playAnimation(int characterID, AnimationConfig cfg)
Plays an animation for the given character.
Definition: RehtiGraphics.cpp:221
void initWindow()
Initializes the window.
Definition: RehtiGraphics.cpp:402
static void frameBufferResizeCallback(GLFWwindow *window, int width, int height)
Definition: RehtiGraphics.cpp:416
EngineFlags engineFlagsM
Definition: RehtiGraphics.hpp:576
void createLogicalDevice()
Creates the interactable logical device.
Definition: RehtiGraphics.cpp:496
VkImageView depthImageViewM
Definition: RehtiGraphics.hpp:550
void forceCharacterMove(int characterID, glm::vec3 location)
Forces character to the given location, cancelling any remaining movement callbacks and animations.
Definition: RehtiGraphics.cpp:290
std::vector< VkSemaphore > rendersFinishedM
Definition: RehtiGraphics.hpp:566
float anisotropyM
Definition: RehtiGraphics.hpp:575
bool removeCharacterObject(int characterID)
Removes a character object with the given id from the graphics backend.
Definition: RehtiGraphics.cpp:77
void pickPhysicalDevice()
Chooses an appropriate gpu.
Definition: RehtiGraphics.cpp:465
size_t currentFrameM
Definition: RehtiGraphics.hpp:592
VkInstance instanceM
Definition: RehtiGraphics.hpp:517
VkSwapchainKHR swapChainM
Definition: RehtiGraphics.hpp:540
void createRenderPass()
Creates the render pass.
Definition: RehtiGraphics.cpp:686
const int kConcurrentFramesM
Definition: RehtiGraphics.hpp:591
std::vector< VkFramebuffer > swapChainFramebuffersM
Definition: RehtiGraphics.hpp:547
GLFWwindow * pWindowM
Definition: RehtiGraphics.hpp:516
std::vector< VkCommandBuffer > commandBuffersM
Definition: RehtiGraphics.hpp:562
VkExtent2D swapChainExtentM
Definition: RehtiGraphics.hpp:543
std::map< int, CharacterData > characterOrientationsM
Definition: RehtiGraphics.hpp:584
VkQueue presentQueueM
Definition: RehtiGraphics.hpp:537
void startMainLoop()
Starts a rendering loop until the window is closed.
Definition: RehtiGraphics.cpp:8
void createSurface()
Creates a surface to draw on.
Definition: RehtiGraphics.cpp:1214
void drawFrame()
Draws a frame and records the previous frame time.
Definition: RehtiGraphics.cpp:1010
void moveCharacter(int characterID, glm::vec3 location, float timeInSeconds)
Moves character smoothly (without animation) to the given location in the given time.
Definition: RehtiGraphics.cpp:266
void createGraphicsPipeline()
Creates the graphics pipeline.
Definition: RehtiGraphics.cpp:744
bool checkValidationLayerSupport()
Checks whether the given device supports the required layers.
Definition: RehtiGraphics.cpp:1315
~RehtiGraphics()
Cleans up all the resources used by vulkan.
Definition: RehtiGraphics.cpp:22
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector< VkSurfaceFormatKHR > availableFormats)
Chooses a surface format.
Definition: RehtiGraphics.cpp:1535
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 th...
Definition: RehtiGraphics.cpp:27
bool validationLayersEnabledM
Definition: RehtiGraphics.hpp:594
void createCommandBuffers()
Creates the command buffers.
Definition: RehtiGraphics.cpp:914
VkSurfaceKHR surfaceM
Definition: RehtiGraphics.hpp:519
void movePlayer(int playerID, glm::vec3 location, float timeInSeconds)
Moves the player smoothly (without animation) to the given location in the given time.
Definition: RehtiGraphics.cpp:191
uint32_t heightM
Definition: RehtiGraphics.hpp:574
void debugAABB(const AABB &aabb, int level)
Prints out the given aabb.
Definition: RehtiGraphics.cpp:1630
void createSynchronization()
Initializes the appropriate semaphores and fences.
Definition: RehtiGraphics.cpp:990
void cleanup()
Cleans up used resources.
Definition: RehtiGraphics.cpp:1117
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.
Definition: RehtiGraphics.cpp:1402
void debugMatrix(glm::mat4 matrix)
Prints out a matrix.
Definition: RehtiGraphics.cpp:1621
VkCommandPool commandPoolM
Definition: RehtiGraphics.hpp:561
std::vector< VkImageView > swapChainImageViewsM
Definition: RehtiGraphics.hpp:544
RehtiGraphics(uint32_t width=1200, uint32_t height=900, glm::vec3 cameraLocation=glm::vec3(0.f))
Initializes the graphics backend.
Definition: RehtiGraphics.cpp:13
std::shared_ptr< RehtiGui > pGuiM
Definition: RehtiGraphics.hpp:532
void initVulkan()
Initializes vulkan instance.
Definition: RehtiGraphics.cpp:422
void createDepthResources()
Creates resources required for a depth buffer.
Definition: RehtiGraphics.cpp:1252
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 obj...
Definition: RehtiGraphics.cpp:91
std::shared_ptr< GraphicsObjectManager > pObjectManagerM
Definition: RehtiGraphics.hpp:531
bool doesCharacterExist(int characterID)
Checks if a characterwith the given id exists.
Definition: RehtiGraphics.cpp:140
std::shared_mutex dataMutexM
Mutex that must be acquired before modifying the data structures below (timer has its own mutex)
Definition: RehtiGraphics.hpp:579
Camera cameraM
Definition: RehtiGraphics.hpp:522
VkPresentModeKHR chooseSwapPresentMode(const std::vector< VkPresentModeKHR > availableModes)
Chooses a present mode.
Definition: RehtiGraphics.cpp:1546
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData)
Definition: RehtiGraphics.cpp:1669
std::shared_mutex graphicsQueueMutexM
Definition: RehtiGraphics.hpp:535
VkPushConstantRange getCameraRange()
Returns the size of the camera matrix.
Definition: RehtiGraphics.cpp:1578
Class that manages the GUI window.
Definition: RehtiGui.hpp:27
Class for handling smooth interpolation of events. A callback can be registered with a given id and t...
Definition: TimerCallbackSystem.hpp:22
Axis Aligned Bounding Box data structure.
Definition: AABB.hpp:14
Definition: GraphicsTypes.hpp:15
Definition: BasicTypes.hpp:190
Directional light struct representing a directional light.
Definition: BasicTypes.hpp:118
Definition: RehtiGraphics.hpp:53
uint64_t frameTime
Definition: RehtiGraphics.hpp:54
double ftPerSec
Definition: RehtiGraphics.hpp:55
Definition: BasicTypes.hpp:153
Definition: BasicTypes.hpp:161
Helper struct to store all the data necessary for creating a map AABB tree.
Definition: AABB.hpp:48
Definition: RehtiGraphics.hpp:30
std::optional< uint32_t > transferFamily
Definition: RehtiGraphics.hpp:33
std::optional< uint32_t > graphicsFamily
Definition: RehtiGraphics.hpp:31
bool isComplete()
Definition: RehtiGraphics.hpp:35
std::optional< uint32_t > presentFamily
Definition: RehtiGraphics.hpp:32
bool hasTransferOnlyQueue()
Definition: RehtiGraphics.hpp:39
Definition: RehtiGraphics.hpp:46
std::vector< VkSurfaceFormatKHR > formats
Definition: RehtiGraphics.hpp:48
VkSurfaceCapabilitiesKHR capabilities
Definition: RehtiGraphics.hpp:47
std::vector< VkPresentModeKHR > presentModes
Definition: RehtiGraphics.hpp:49