From af3ae38bd2af4920ced269cc67b626e6f3cafe34 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Sun, 8 Dec 2019 08:58:35 +0100 Subject: [PATCH] ktx loading fixes --- examples/terraintessellation/terraintessellation.cpp | 6 +++--- examples/texturemipmapgen/texturemipmapgen.cpp | 9 ++------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/examples/terraintessellation/terraintessellation.cpp b/examples/terraintessellation/terraintessellation.cpp index 3b67c8e2..284431d5 100644 --- a/examples/terraintessellation/terraintessellation.cpp +++ b/examples/terraintessellation/terraintessellation.cpp @@ -406,11 +406,11 @@ public: assert(asset); size_t size = AAsset_getLength(asset); assert(size > 0); - void *textureData = malloc(size); + ktx_uint8_t* textureData = new ktx_uint8_t[size]; AAsset_read(asset, textureData, size); AAsset_close(asset); - result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, target); - free(textureData); + result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture); + delete[] textureData; #else result = ktxTexture_CreateFromNamedFile(filename.c_str(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture); diff --git a/examples/texturemipmapgen/texturemipmapgen.cpp b/examples/texturemipmapgen/texturemipmapgen.cpp index 28c1e3d1..04c98e33 100644 --- a/examples/texturemipmapgen/texturemipmapgen.cpp +++ b/examples/texturemipmapgen/texturemipmapgen.cpp @@ -115,7 +115,7 @@ public: } } - void loadTexture(std::string fileName, VkFormat format, bool forceLinearTiling) + void loadTexture(std::string filename, VkFormat format, bool forceLinearTiling) { ktxResult result; ktxTexture* ktxTexture; @@ -143,11 +143,6 @@ public: #endif assert(result == KTX_SUCCESS); - VkFormatProperties formatProperties; - - - VkFormatProperties formatProperties; - texture.width = ktxTexture->baseWidth; texture.height = ktxTexture->baseHeight; ktx_uint8_t *ktxTextureData = ktxTexture_GetData(ktxTexture); @@ -159,8 +154,8 @@ public: texture.mipLevels = floor(log2(std::max(texture.width, texture.height))) + 1; // Get device properites for the requested texture format + VkFormatProperties formatProperties; vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &formatProperties); - // Mip-chain generation requires support for blit source and destination assert(formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT); assert(formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT);