Android asset loading
This commit is contained in:
parent
4e610c56ce
commit
2d636eda2c
1 changed files with 9 additions and 12 deletions
|
|
@ -32,6 +32,9 @@
|
||||||
#define TINYGLTF_IMPLEMENTATION
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#define TINYGLTF_NO_STB_IMAGE_WRITE
|
#define TINYGLTF_NO_STB_IMAGE_WRITE
|
||||||
|
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||||
|
#define TINYGLTF_ANDROID_LOAD_FROM_ASSETS
|
||||||
|
#endif
|
||||||
#include "tiny_gltf.h"
|
#include "tiny_gltf.h"
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
@ -494,19 +497,10 @@ public:
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
// On Android all assets are packed with the apk in a compressed form, so we need to open them using the asset manager
|
// On Android all assets are packed with the apk in a compressed form, so we need to open them using the asset manager
|
||||||
AAsset* asset = AAssetManager_open(androidApp->activity->assetManager, filename.c_str(), AASSET_MODE_STREAMING);
|
// We let tinygltf handle this, by passing the asset manager of our app
|
||||||
assert(asset);
|
tinygltf::asset_manager = androidApp->activity->assetManager;
|
||||||
size_t size = AAsset_getLength(asset);
|
|
||||||
assert(size > 0);
|
|
||||||
char* fileData = new char[size];
|
|
||||||
AAsset_read(asset, fileData, size);
|
|
||||||
AAsset_close(asset);
|
|
||||||
std::string baseDir;
|
|
||||||
bool fileLoaded = gltfContext.LoadASCIIFromString(&glTFInput, &error, &warning, fileData, size, baseDir);
|
|
||||||
free(fileData);
|
|
||||||
#else
|
|
||||||
bool fileLoaded = gltfContext.LoadASCIIFromFile(&glTFInput, &error, &warning, filename);
|
|
||||||
#endif
|
#endif
|
||||||
|
bool fileLoaded = gltfContext.LoadASCIIFromFile(&glTFInput, &error, &warning, filename);
|
||||||
|
|
||||||
// Pass some Vulkan resources required for setup and rendering to the glTF model loading class
|
// Pass some Vulkan resources required for setup and rendering to the glTF model loading class
|
||||||
glTFModel.vulkanDevice = vulkanDevice;
|
glTFModel.vulkanDevice = vulkanDevice;
|
||||||
|
|
@ -527,6 +521,9 @@ public:
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cerr << "Could not load gltf file: " << error << std::endl;
|
std::cerr << "Could not load gltf file: " << error << std::endl;
|
||||||
|
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||||
|
LOGE("Could not load glTF file from %s: %s", filename.c_str(), error.c_str());
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue