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.
I am in the process of converting the codebase from using vulkan.h to vulkan.hpp, as well as utilising RAII. Here is the header and some source code from the Renderer class:
Renderer.h:
#pragma once
#include <vulkan/vulkan.hpp> #include “Window.h” #include #include #include #include #include #include “Pipeline.h” #include “Material.h” #include “Mesh.h”
struct QueueFamilyIndices { std::optional<uint32_t> graphicsFamily; std::optional<uint32_t> presentFamily;
codebool IsComplete() { return graphicsFamily.has_value() && presentFamily.has_value(); }};
struct SwapChainSupportDetails { vk::SurfaceCapabilitiesKHR capabilities; std::vectorvk::SurfaceFormatKHR formats; std::vectorvk::PresentModeKHR presentModes; };
struct MVP { glm::mat4 model; glm::mat4 view; glm::mat4 projection; };
class Renderer { public: Renderer(); ~Renderer();
codevoid Initialize(GLFWwindow* window); void Shutdown(); void BeginFrame(); void EndFrame(); vk::DescriptorSetLayout CreateDescriptorSetLayout(); vk::DescriptorPool CreateDescriptorPool(uint32_t maxSets); vk::Device* GetDevice(); vk::PhysicalDevice* GetPhysicalDevice(); vk::CommandPool* GetCommandPool(); vk::Queue* GetGraphicsQueue(); vk::CommandBuffer* GetCurrentCommandBuffer(); std::shared_ptr<Pipeline> GetPipeline(); void CreateGraphicsPipeline(Mesh* mesh, Material* material); std::pair<vk::Buffer, vk::DeviceMemory> RequestMvpBuffer();private:
code - Assistant
The error is due to an ambiguous call to the assignment operator for
renderPassInfo.renderArea.offset. Since you are using the Vulkan C++ API, you need to use the C++ constructs for Vulcan types. In this case, you should use thevk::Offset2Dconstructor to create the appropriate object for the offset:Replace:
cpprenderPassInfo.renderArea.offset = { 0, 0 };With:
cpprenderPassInfo.renderArea.offset = vk::Offset2D{ 0, 0 };