Android asset loading
This commit is contained in:
parent
535c693ab2
commit
b67c35299b
4 changed files with 11 additions and 22 deletions
|
|
@ -64,22 +64,17 @@ namespace vks
|
||||||
{
|
{
|
||||||
ktxResult result = KTX_SUCCESS;
|
ktxResult result = KTX_SUCCESS;
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
// Textures are stored inside the apk on Android (compressed)
|
|
||||||
// So they need to be loaded via the asset manager
|
|
||||||
AAsset* asset = AAssetManager_open(androidApp->activity->assetManager, filename.c_str(), AASSET_MODE_STREAMING);
|
AAsset* asset = AAssetManager_open(androidApp->activity->assetManager, filename.c_str(), AASSET_MODE_STREAMING);
|
||||||
if (!asset) {
|
if (!asset) {
|
||||||
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
||||||
}
|
}
|
||||||
size_t size = AAsset_getLength(asset);
|
size_t size = AAsset_getLength(asset);
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
|
ktx_uint8_t *textureData = new ktx_uint8_t[size];
|
||||||
void *textureData = malloc(size);
|
|
||||||
AAsset_read(asset, textureData, size);
|
AAsset_read(asset, textureData, size);
|
||||||
AAsset_close(asset);
|
AAsset_close(asset);
|
||||||
|
|
||||||
result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, target);
|
result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, target);
|
||||||
|
delete[] textureData;
|
||||||
free(textureData);
|
|
||||||
#else
|
#else
|
||||||
if (!vks::tools::fileExists(filename)) {
|
if (!vks::tools::fileExists(filename)) {
|
||||||
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
||||||
|
|
|
||||||
|
|
@ -119,13 +119,11 @@ public:
|
||||||
size_t size = AAsset_getLength(asset);
|
size_t size = AAsset_getLength(asset);
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
|
|
||||||
void *textureData = malloc(size);
|
ktx_uint8_t *textureData = new ktx_uint8_t[size];
|
||||||
AAsset_read(asset, textureData, size);
|
AAsset_read(asset, textureData, size);
|
||||||
AAsset_close(asset);
|
AAsset_close(asset);
|
||||||
|
result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture);
|
||||||
result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, target);
|
delete[] textureData;
|
||||||
|
|
||||||
free(textureData);
|
|
||||||
#else
|
#else
|
||||||
if (!vks::tools::fileExists(filename)) {
|
if (!vks::tools::fileExists(filename)) {
|
||||||
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
||||||
|
|
|
||||||
|
|
@ -140,13 +140,11 @@ public:
|
||||||
size_t size = AAsset_getLength(asset);
|
size_t size = AAsset_getLength(asset);
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
|
|
||||||
void *textureData = malloc(size);
|
ktx_uint8_t *textureData = new ktx_uint8_t[size];
|
||||||
AAsset_read(asset, textureData, size);
|
AAsset_read(asset, textureData, size);
|
||||||
AAsset_close(asset);
|
AAsset_close(asset);
|
||||||
|
result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture);
|
||||||
result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, target);
|
delete[] textureData;
|
||||||
|
|
||||||
free(textureData);
|
|
||||||
#else
|
#else
|
||||||
if (!vks::tools::fileExists(filename)) {
|
if (!vks::tools::fileExists(filename)) {
|
||||||
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
||||||
|
|
|
||||||
|
|
@ -124,13 +124,11 @@ public:
|
||||||
size_t size = AAsset_getLength(asset);
|
size_t size = AAsset_getLength(asset);
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
|
|
||||||
void *textureData = malloc(size);
|
ktx_uint8_t *textureData = new ktx_uint8_t[size];
|
||||||
AAsset_read(asset, textureData, size);
|
AAsset_read(asset, textureData, size);
|
||||||
AAsset_close(asset);
|
AAsset_close(asset);
|
||||||
|
result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture);
|
||||||
result = ktxTexture_CreateFromMemory(textureData, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, target);
|
delete[] textureData;
|
||||||
|
|
||||||
free(textureData);
|
|
||||||
#else
|
#else
|
||||||
if (!vks::tools::fileExists(filename)) {
|
if (!vks::tools::fileExists(filename)) {
|
||||||
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue