aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2022-09-12 22:04:54 +0200
committerladevieq <ladevie.quentin@gmail.com>2022-09-12 22:04:54 +0200
commit15069341c7c8c36c7371ea1de4b63ed52034b3a8 (patch)
tree41d3640acdf4de9baf8f3bfd86afb91be2a9ab1f
parent1bb6caa5c8cb97f23f84ac9f3d4aa6c38b6d901c (diff)
Fix texture uploading bug
-rw-r--r--include/gltf.hpp4
-rw-r--r--include/vk-renderer.hpp6
-rw-r--r--src/gltf.cpp4
-rw-r--r--src/vk-renderer.cpp1
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<std::string>()).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<uint32_t>(image.x), static_cast<uint32_t>(image.y), VK_FORMAT_R8G8B8A8_UNORM, sampler);
+ auto *texture = vkrenderer::create_2d_texture(static_cast<uint32_t>(image.width), static_cast<uint32_t>(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);