diff --git a/base/VulkanHeightmap.hpp b/base/VulkanHeightmap.hpp index b8c5033e..c96a3faa 100644 --- a/base/VulkanHeightmap.hpp +++ b/base/VulkanHeightmap.hpp @@ -1,18 +1,19 @@ /* * Heightmap terrain generator * -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +* Copyright (C) by Sascha Willems - www.saschawillems.de * * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) */ #include #include -#include #include "vulkan/vulkan.h" #include "VulkanDevice.hpp" #include "VulkanBuffer.hpp" +#include +#include namespace vks { @@ -75,27 +76,31 @@ namespace vks assert(device); assert(copyQueue != VK_NULL_HANDLE); + ktxResult result; + ktxTexture* ktxTexture; #if defined(__ANDROID__) - AAsset* asset = AAssetManager_open(assetManager, filename.c_str(), AASSET_MODE_STREAMING); + AAsset* asset = AAssetManager_open(androidApp->activity->assetManager, filename.c_str(), AASSET_MODE_STREAMING); assert(asset); size_t size = AAsset_getLength(asset); assert(size > 0); void *textureData = malloc(size); AAsset_read(asset, textureData, size); AAsset_close(asset); - gli::texture2d heightTex(gli::load((const char*)textureData, size)); + result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, target); free(textureData); #else - gli::texture2d heightTex(gli::load(filename)); + result = ktxTexture_CreateFromNamedFile(filename.c_str(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture); #endif - dim = static_cast(heightTex.extent().x); + assert(result == KTX_SUCCESS); + ktx_size_t ktxSize = ktxTexture_GetImageSize(ktxTexture, 0); + ktx_uint8_t* ktxImage = ktxTexture_GetData(ktxTexture); + dim = ktxTexture->baseWidth; heightdata = new uint16_t[dim * dim]; - memcpy(heightdata, heightTex.data(), heightTex.size()); + memcpy(heightdata, ktxImage, ktxSize); this->scale = dim / patchsize; - this->heightScale = scale.y; + ktxTexture_Destroy(ktxTexture); // Generate vertices - Vertex * vertices = new Vertex[patchsize * patchsize * 4]; const float wx = 2.0f; diff --git a/examples/terraintessellation/terraintessellation.cpp b/examples/terraintessellation/terraintessellation.cpp index 9ac3d66a..847e74dc 100644 --- a/examples/terraintessellation/terraintessellation.cpp +++ b/examples/terraintessellation/terraintessellation.cpp @@ -17,7 +17,6 @@ #define GLM_FORCE_DEPTH_ZERO_TO_ONE #include #include -#include #include #include "vulkanexamplebase.h" @@ -25,6 +24,8 @@ #include "VulkanTexture.hpp" #include "VulkanModel.hpp" #include "frustum.hpp" +#include +#include #define VERTEX_BUFFER_BIND_ID 0 #define ENABLE_VALIDATION false @@ -396,25 +397,32 @@ public: HeightMap(std::string filename, uint32_t patchsize, AAssetManager* assetManager) #else HeightMap(std::string filename, uint32_t patchsize) -#endif +#endif { + ktxResult result; + ktxTexture* ktxTexture; #if defined(__ANDROID__) - AAsset* asset = AAssetManager_open(assetManager, filename.c_str(), AASSET_MODE_STREAMING); + AAsset* asset = AAssetManager_open(androidApp->activity->assetManager, filename.c_str(), AASSET_MODE_STREAMING); assert(asset); size_t size = AAsset_getLength(asset); assert(size > 0); void *textureData = malloc(size); AAsset_read(asset, textureData, size); AAsset_close(asset); - gli::texture2d heightTex(gli::load((const char*)textureData, size)); + result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, target); free(textureData); + #else - gli::texture2d heightTex(gli::load(filename)); + result = ktxTexture_CreateFromNamedFile(filename.c_str(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture); #endif - dim = static_cast(heightTex.extent().x); + assert(result == KTX_SUCCESS); + ktx_size_t ktxSize = ktxTexture_GetImageSize(ktxTexture, 0); + ktx_uint8_t* ktxImage = ktxTexture_GetData(ktxTexture); + dim = ktxTexture->baseWidth; heightdata = new uint16_t[dim * dim]; - memcpy(heightdata, heightTex.data(), heightTex.size()); + memcpy(heightdata, ktxImage, ktxSize); this->scale = dim / patchsize; + ktxTexture_Destroy(ktxTexture); }; ~HeightMap()