Asset loading for Android (#97)

This commit is contained in:
saschawillems 2016-03-23 19:18:54 +01:00
parent 0966d21dc2
commit 6ee70824e5
3 changed files with 81 additions and 10 deletions

View file

@ -431,17 +431,35 @@ namespace vkTools
}
// Load a cubemap texture (single file)
void loadCubemap(const char* filename, VkFormat format, VulkanTexture *texture)
void loadCubemap(std::string filename, VkFormat format, VulkanTexture *texture)
{
VkFormatProperties formatProperties;
#if defined(__ANDROID__)
assert(assetManager != nullptr);
// Textures are stored inside the apk on Android (compressed)
// So they need to be loaded via the asset manager
AAsset* asset = AAssetManager_open(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::textureCube texCube(gli::load((const char*)textureData, size));
free(textureData);
#else
gli::textureCube texCube(gli::load(filename));
#endif
assert(!texCube.empty());
texture->width = (uint32_t)texCube[0].dimensions().x;
texture->height = (uint32_t)texCube[0].dimensions().y;
// Get device properites for the requested texture format
VkFormatProperties formatProperties;
vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &formatProperties);
VkImageCreateInfo imageCreateInfo = vkTools::initializers::imageCreateInfo();
@ -630,11 +648,29 @@ namespace vkTools
}
// Load an array texture (single file)
void loadTextureArray(const char* filename, VkFormat format, VulkanTexture *texture)
void loadTextureArray(std::string filename, VkFormat format, VulkanTexture *texture)
{
VkFormatProperties formatProperties;
#if defined(__ANDROID__)
assert(assetManager != nullptr);
// Textures are stored inside the apk on Android (compressed)
// So they need to be loaded via the asset manager
AAsset* asset = AAssetManager_open(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::texture2DArray tex2DArray(gli::load((const char*)textureData, size));
free(textureData);
#else
gli::texture2DArray tex2DArray(gli::load(filename));
#endif
assert(!tex2DArray.empty());
texture->width = tex2DArray.dimensions().x;
@ -642,6 +678,7 @@ namespace vkTools
texture->layerCount = tex2DArray.layers();
// Get device properites for the requested texture format
VkFormatProperties formatProperties;
vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &formatProperties);
VkImageCreateInfo imageCreateInfo = vkTools::initializers::imageCreateInfo();