I’m building a video game engine using C++ as the coding language and Vulkan for…
- User
I’m building a video game engine using C++ as the coding language and Vulkan for graphics. I am trying to set up a generic renderer using Vulkan that is flexible and will render objects based on a vector that is supplied to it. The renderer will also handle the creation of the window using GLFW and use GLM for all relevant math calls. I am using the ASSIMP library to load 3d models and animations.
The basic class structure is as follows:
- Core:
- class Engine
- This is the main class that will initialize, run, and shut down other subsystems of the engine (e.g., Window, Renderer, Input, etc.)
- Window:
- class Window
- This class will handle window creation, resizing, and destruction using GLFW. It should also handle keyboard and mouse input events.
- Renderer:
- class Renderer
- This class will manage Vulkan objects (e.g., instance, device, swapchain, command buffers) and rendering pipelines.
- class Shader
- To handle shader modules creation and destruction.
- class Texture
- To handle texture loading and destruction.
- class Pipeline
- To encapsulate the description and creation of a Vulkan graphics or compute pipeline.
- Scene:
- class Scene
- This class will manage the list of objects in the vector, update their transforms, and send them to the Renderer for rendering.
- class GameObject
- To represent individual objects in the scene, store their transformation matrices, and bind the relevant data like vertices and indices.
- class Camera
- To store and manage camera properties such as position, rotation, view, and projection matrices.
- class Mesh
- To handle mesh data (e.g., vertices, indices, etc.) for individual objects.
- class Material
- To store and manage material properties such as colors, shaders, and textures.
- Math:
- Utilize GLM library to handle vector and matrix math operations.
Here are the header files for context:
BufferUtils.h:
#pragma once
#include <vulkan/vulkan.h> #include <stdint.h>
namespace BufferUtils { void CreateBuffer( VkDevice device, VkPhysicalDevice physicalDevice, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& bufferMemory);
uint32_t FindMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter, VkMemoryPropertyFlags properties); void CopyBuffer( VkDevice device, VkCommandPool commandPool, VkQueue graphicsQueue, VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size); - Assistant
- User
I am getting an error when the method tries to declare the void data variable. It is saying "incomplete type is not allowed". How would I fix this?
- Assistant
I apologize for the confusion. It seems like the error is due to the incomplete type declaration for the
datavariable. You should change the declaration ofdatafromvoid* data;tovoid* data = nullptr;.Here's the corrected version:
// Map the MVP data into the buffer and unmap void* data = nullptr; vkMapMemory(device, mvpBufferMemory, 0, sizeof(MVP), 0, &data); memcpy(data, &mvp, sizeof(MVP)); vkUnmapMemory(device, mvpBufferMemory);By initializing the
datavariable tonullptr, you should no longer encounter the "incomplete type is not allowed" error. - User
When trying to run the application, I am getting an unhandled exception in the GameObject destructor. Do you know what could be causing this issue and how to fix it?
- Assistant
The issue might be related to trying to call
Shutdown()in the destructor without checking if the GameObject's resources have been initialized. Alternatively, the GameObject might be being destroyed twice, possibly due to a copy being created unintentionally.To diagnose the issue, I suggest the following steps:
- Add a flag
initializedin your GameObject class to check if the object was initialized before calling Shutdown. Set it totruein theInitialize()method andfalsein theShutdown()method.
class GameObject { public: // ... void Initialize(const Mesh& mesh, const Material& material); // ... void Shutdown(); private: // ... bool initialized = false; // ... }; - Add a flag
- User
It seems I am getting an error due to the Terrain material not being initialized. Based on the current codebase, if I had a simple texture called "texture.png" saved in "C:\textures", how would I generate the material for the Terrain so it could be rendered?
- Assistant
- User
This approach seems to not be properly taking advantage of the current Material class and the GameObject class. It is also worth noting that I intend to use .spv files for shaders. Please rewrite the Material implementation to align with the current codebase. If you require me to provide class header files or other source code to assist with this, let me know.
- Assistant
My apologies for the confusion. To better align with the existing codebase, you can create your terrain material like this:
- In
Terrain.h, declare methodsLoadShaders()andInitializeDescriptorSetLayout():
class Terrain { public: // ... current declarations ... // Additional method declarations void LoadShaders(Renderer& renderer); void InitializeDescriptorSetLayout(VkDevice device); private: // ... current declarations ... };- In
Terrain.cpp, implement theLoadShaders()method to load
- In