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.
As a start, this engine will render a basic spinning box with uniform color. However, it will then expand to cover the full functionality of the game engine.
The code uses a Texture class in order to load textures for use in the game. The header and source file for this class look like this:
Header:
#pragma once
#include <vulkan/vulkan.h> #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" // Include the stb_image header #include
class Texture { public: Texture(); ~Texture();
codevoid LoadFromFile(const std::string& filename, VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, VkQueue graphicsQueue); void Cleanup(); VkImageView GetImageView() const; VkSampler GetSampler() const;private: VkDevice device; VkImage image; VkDeviceMemory imageMemory; VkImageView imageView; VkSampler sampler;
codevoid CreateImage(uint32_t width, uint32_t height, uint32_t mipLevels, VkSampleCountFlagBits numSamples, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties); void TransitionImageLayout(VkImageLayout oldLayout, VkImageLayout newLayout); void CreateImageView(VkFormat format, VkImageAspectFlags aspectFlags, uint32_t mipLevels); void CreateSampler(uint32_t mipLevels); void CopyBufferToImage(VkBuffer buffer, uint32_t width, uint32_t height); // Additional helper functions for texture loading…};
Source:
#include "Texture.h" #include
Texture::Texture() : device(VK_NULL_HANDLE), image(VK_NULL_HANDLE), imageMemory(VK_NULL_HANDLE), imageView(VK_NULL_HANDLE), sampler(VK_NULL_HANDLE) { }
Texture::~Texture() { Cleanup(); }
void Texture::LoadFromFile(const std::string& filename, VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, VkQueue graphicsQueue) { this->device = device;
- Assistant
- User
The CreateImage method references a physicalDevice variable and CopyBufferToImage method references a commandBuffer variable. These variables were not included in the header file. Where should they be declared and do they need to be initialized?
- Assistant
- User
Based on the BufferUtils.h, what would the code in the cpp source file for BufferUtils look like?
- Assistant