From 15069341c7c8c36c7371ea1de4b63ed52034b3a8 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Mon, 12 Sep 2022 22:04:54 +0200 Subject: Fix texture uploading bug --- include/gltf.hpp | 4 ++-- include/vk-renderer.hpp | 6 ++++-- src/gltf.cpp | 4 ++-- src/vk-renderer.cpp | 1 - 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/gltf.hpp b/include/gltf.hpp index 2f7377a..6e89509 100644 --- a/include/gltf.hpp +++ b/include/gltf.hpp @@ -16,8 +16,8 @@ struct node { }; struct raw_image { - int32_t x; - int32_t y; + int32_t width; + int32_t height; int32_t channels; uint8_t *data; }; diff --git a/include/vk-renderer.hpp b/include/vk-renderer.hpp index 6c6d2f0..ab15cd1 100644 --- a/include/vk-renderer.hpp +++ b/include/vk-renderer.hpp @@ -131,9 +131,11 @@ class RingBuffer { [[nodiscard]]size_t alloc(size_t alloc_size) { assert(alloc_size > 0 && alloc_size <= buffer_size); - if (ptr <= buffer_size - alloc_size) { + auto alloc_offset = ptr; + + if (alloc_offset <= buffer_size - alloc_size) { ptr += alloc_size; - return ptr; + return alloc_offset; } return invalid_alloc; diff --git a/src/gltf.cpp b/src/gltf.cpp index 537e4e1..9b55cbb 100644 --- a/src/gltf.cpp +++ b/src/gltf.cpp @@ -118,7 +118,7 @@ void gltf::load_textures(const std::filesystem::path &path) { const auto &gltf_image = gltf_images[image_index]; auto filepath = (path / gltf_image["uri"].get()).string(); auto& image = images[image_index]; - image.data = stbi_load(filepath.c_str(), &image.x, &image.y, &image.channels, 4); + image.data = stbi_load(filepath.c_str(), &image.width, &image.height, &image.channels, 4); } // const auto &gltf_samplers = gltf_json["samplers"]; @@ -143,7 +143,7 @@ void gltf::load_textures(const std::filesystem::path &path) { // sampler = samplers[sampler_index]; // } - auto *texture = vkrenderer::create_2d_texture(static_cast(image.x), static_cast(image.y), VK_FORMAT_R8G8B8A8_UNORM, sampler); + auto *texture = vkrenderer::create_2d_texture(static_cast(image.width), static_cast(image.height), VK_FORMAT_R8G8B8A8_UNORM, sampler); texture->update(image.data); diff --git a/src/vk-renderer.cpp b/src/vk-renderer.cpp index 54c667f..77e461d 100644 --- a/src/vk-renderer.cpp +++ b/src/vk-renderer.cpp @@ -130,7 +130,6 @@ void vkrenderer::update_images() { vkrenderer::api.image_barrier(command_buffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, texture->device_image); vkrenderer::api.copy_buffer(command_buffer, staging_buffer->device_buffer, texture->device_image, 0, offset); vkrenderer::api.image_barrier(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, texture->device_image); - break; } vkrenderer::api.end_record(command_buffer); -- cgit v1.3