89 void load(
VK_Window *window,
const std::string &modelPath,
const std::string &textureManifestPath,
const std::string &textureBasePath,
float scale = 1.0f);
99 void load(
VK_Window *window,
MXModel &&
model,
const std::string &textureManifestPath,
const std::string &textureBasePath, [[maybe_unused]]
float scale = 1.0f);
107 void setShaders(
VK_Window *window,
const std::string &vertSpv,
const std::string &fragSpv);
133 [[nodiscard]]
bool updatePrimaryTexture(
const void *pixels,
int width,
int height,
int pitch = 0);
142 [[nodiscard]]
bool updatePrimaryTextureCuda(
const cv::cuda::GpuMat &rgba, cv::cuda::Stream &stream);
151 void render(VkCommandBuffer cmd, uint32_t imageIndex,
bool wireframe =
false)
const;
187 [[nodiscard]]
bool isLoaded()
const {
return obj.indexCount() > 0 && vertexBufferReady(); }
205 struct TextureEntry {
206 VkImage image = VK_NULL_HANDLE;
207 VkDeviceMemory memory = VK_NULL_HANDLE;
208 VkImageView view = VK_NULL_HANDLE;
212 VkDeviceSize cudaExportMemorySize = 0;
213 cudaExternalMemory_t cudaExternalMemory =
nullptr;
214 cudaMipmappedArray_t cudaMipmappedArray =
nullptr;
215 cudaArray_t cudaArray =
nullptr;
216 bool cudaInteropEnabled =
false;
217 bool cudaInteropUnavailableLogged =
false;
218 bool cudaUploadLogged =
false;
219 bool cudaWriteTransitionLogged =
false;
220 bool cudaShaderTransitionLogged =
false;
221 VkImageLayout cudaImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
226 std::vector<TextureEntry> textures{};
228 VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE;
229 VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
230 uint32_t descriptorPoolSetCapacity = 0;
231 std::vector<VkDescriptorSet> descriptorSets{};
233 VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
234 VkPipeline pipelineFill = VK_NULL_HANDLE;
235 VkPipeline pipelineWireframe = VK_NULL_HANDLE;
236 VkSampler textureSampler = VK_NULL_HANDLE;
238 std::vector<VkBuffer> uniformBuffers{};
239 std::vector<VkDeviceMemory> uniformBufferMemory{};
240 std::vector<void *> uniformBuffersMapped{};
241 std::vector<VkBuffer> fragmentUniformBuffers{};
242 std::vector<VkDeviceMemory> fragmentUniformBufferMemory{};
243 std::vector<void *> fragmentUniformBuffersMapped{};
245 glm::vec3 modelCenterOffsetValue{0.0f, 0.0f, 0.0f};
246 float modelRenderScaleValue = 1.0f;
247 glm::vec3 modelAxisExtentValue{1.0f, 1.0f, 1.0f};
249 std::string vertexShaderPath{};
250 std::string fragmentShaderPath{};
251 bool backfaceCullingEnabled =
false;
252 bool alphaBlendingEnabled =
false;
253 ModelFragmentPushConstants fragmentPushConstants{};
254 bool extendedFragmentUniformsEnabled =
false;
255 VkFormat colorAttachmentFormat = VK_FORMAT_UNDEFINED;
257 VK_Window *windowPtr =
nullptr;
259 [[nodiscard]]
bool vertexBufferReady()
const {
return obj.vertexBuffer() != VK_NULL_HANDLE && obj.indexBuffer() != VK_NULL_HANDLE; }
261 void computeBoundsAndScale();
262 void loadTextures(
const std::string &textureManifestPath,
const std::string &textureBasePath);
263 void loadTexturesFromMTL(
const std::string &textureBasePath);
264 void createFallbackTexture();
266 void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory)
const;
267 [[nodiscard]] uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties)
const;
268 [[nodiscard]] VkCommandBuffer beginSingleTimeCommands()
const;
269 void endSingleTimeCommands(VkCommandBuffer commandBuffer)
const;
270 void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage &image, VkDeviceMemory &memory)
const;
271 void createTextureImage(uint32_t width, uint32_t height, TextureEntry &texture)
const;
273 void createCudaExportableImage(uint32_t width, uint32_t height, TextureEntry &texture)
const;
274 void destroyTextureCudaInterop(TextureEntry &texture)
const;
275 [[nodiscard]]
bool ensureTextureCudaInterop(TextureEntry &texture)
const;
276 [[nodiscard]]
bool transitionTextureForCudaWrite(TextureEntry &texture)
const;
277 [[nodiscard]]
bool transitionTextureForShaderRead(TextureEntry &texture)
const;
278 [[nodiscard]]
bool updatePrimaryTextureCudaHost(TextureEntry &texture,
const void *pixels, uint32_t width, uint32_t height, uint32_t pitch)
const;
279 void recreatePrimaryTextureForCuda(TextureEntry &texture, uint32_t width, uint32_t height);
281 [[nodiscard]] VkImageView createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags)
const;
282 void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout)
const;
283 void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height)
const;
285 void createTextureSampler();
286 void createDescriptorSetLayout();
287 void createUniformBuffers();
288 void destroyUniformBuffers();
289 void createDescriptorPool();
290 void createDescriptorSets();
291 void updateTextureDescriptor(VkDescriptorSet descriptorSet, VkImageView imageView)
const;
292 void createPipelines();
294 void destroyPipelines();
295 void destroyDescriptors();
296 void destroyTextures();