diff options
Diffstat (limited to 'src/vk/texture.cpp')
-rw-r--r-- | src/vk/texture.cpp | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/src/vk/texture.cpp b/src/vk/texture.cpp index c699ecc..92ce5b5 100644 --- a/src/vk/texture.cpp +++ b/src/vk/texture.cpp @@ -16,12 +16,10 @@ #include "texture.hpp" -#define QOI_IMPLEMENTATION 0 -#include <qoi.h> - #include "../command.hpp" #include "../core.hpp" #include "image.hpp" +#include "qoi.hpp" #include "source_buffer.hpp" namespace @@ -77,25 +75,21 @@ load_image(void *obj) { auto self = static_cast<ImageTextureBuilder*>(obj); - qoi_desc img_desc; const int num_channels = 4; // all images are converted to RGBA - unsigned char *pixels; + VK::QOI::Image qoi_image(self->texture_path.c_str(), num_channels); + uint8_t *pixels; { // Load file image from file. - void *pixels_ptr = qoi_read(self->texture_path.c_str(), &img_desc, 4); - if(pixels_ptr == NULL) throw CommandError{"Failed to open image."}; - - pixels = static_cast<unsigned char*>(pixels_ptr); - self->texture->width = static_cast<uint32_t>(img_desc.width); - self->texture->height = static_cast<uint32_t>(img_desc.height); + self->texture->width = qoi_image.header.width; + self->texture->height = qoi_image.header.height; self->texture->mip_levels = 1; - pixels = static_cast<unsigned char*>(pixels_ptr); + pixels = qoi_image.pixels; } // Load file image into a vulkan buffer. size_t image_size{static_cast<size_t>( - img_desc.width * img_desc.height * num_channels)}; + qoi_image.header.width * qoi_image.header.height * num_channels)}; VK::SourceBuffer source_image_buffer{ cg_core.vk_device_with_swapchain, pixels, image_size}; @@ -155,9 +149,6 @@ load_image(void *obj) VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); }); } - - // Free resources. - QOI_FREE(pixels); } void |