Fixes to load cubemap

This commit is contained in:
Brad Davis 2018-01-05 22:12:02 -08:00
parent 3d186efbac
commit a2c2e7d9ff
7 changed files with 71 additions and 7 deletions

1
.gitignore vendored
View file

@ -77,3 +77,4 @@ TAGS
# ignore node files for the console
node_modules
npm-debug.log
*___jb_old___

View file

@ -212,6 +212,8 @@
#if defined(Q_OS_ANDROID)
#include <QtAndroidExtras/QAndroidJniObject>
#include <android/log.h>
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
#endif
// On Windows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU
// FIXME seems to be broken.
@ -238,6 +240,7 @@ extern "C" {
extern "C" {
JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnCreate(JNIEnv* env, jobject obj, jobject instance, jobject asset_mgr) {
storage::FileStorage::setAssetManager(AAssetManager_fromJava(env, asset_mgr));
qDebug() << "nativeOnCreate On thread " << QThread::currentThreadId();
}
@ -332,7 +335,11 @@ static QTimer identityPacketTimer;
static QTimer pingTimer;
static const QString DISABLE_WATCHDOG_FLAG("HIFI_DISABLE_WATCHDOG");
#if defined(Q_OS_ANDROID)
static bool DISABLE_WATCHDOG = true;
#else
static bool DISABLE_WATCHDOG = QProcessEnvironment::systemEnvironment().contains(DISABLE_WATCHDOG_FLAG);
#endif
static const int MAX_CONCURRENT_RESOURCE_DOWNLOADS = 16;
@ -1777,7 +1784,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
static int lastCountOfNearbyAvatars = -1;
QTimer* checkNearbyAvatarsTimer = new QTimer(this);
checkNearbyAvatarsTimer->setInterval(CHECK_NEARBY_AVATARS_INTERVAL_MS); // 10 seconds, Qt::CoarseTimer ok
connect(checkNearbyAvatarsTimer, &QTimer::timeout, this, [this]() {
connect(checkNearbyAvatarsTimer, &QTimer::timeout, this, []() {
auto avatarManager = DependencyManager::get<AvatarManager>();
int nearbyAvatars = avatarManager->numberOfAvatarsInRange(avatarManager->getMyAvatar()->getWorldPosition(),
NEARBY_AVATAR_RADIUS_METERS) - 1;

View file

@ -499,9 +499,13 @@ TexturePointer Texture::build(const ktx::KTXDescriptor& descriptor) {
GPUKTXPayload gpuktxKeyValue;
if (!GPUKTXPayload::findInKeyValues(descriptor.keyValues, gpuktxKeyValue)) {
qCWarning(gpulogging) << "Could not find GPUKTX key values.";
return TexturePointer();
// FIXME use sensible defaults based on the texture type and format
gpuktxKeyValue._usageType = TextureUsageType::RESOURCE;
gpuktxKeyValue._usage = Texture::Usage::Builder().withColor().withAlpha().build();
}
auto texture = create(gpuktxKeyValue._usageType,
type,
texelFormat,

View file

@ -7,5 +7,9 @@ if (WIN32)
target_link_libraries(${TARGET_NAME} Wbemuuid.lib)
endif()
if (ANDROID)
target_link_libraries(${TARGET_NAME} android)
endif()
target_zlib()
target_nsight()

View file

@ -33,7 +33,7 @@ const QString& PathUtils::resourcesPath() {
#ifdef Q_OS_MAC
static const QString staticResourcePath = QCoreApplication::applicationDirPath() + "/../Resources/";
#elif defined (ANDROID)
static const QString staticResourcePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/resources/";
static const QString staticResourcePath = "assets:/resources/";
#else
static const QString staticResourcePath = QCoreApplication::applicationDirPath() + "/resources/";
#endif

View file

@ -47,6 +47,13 @@ MemoryStorage::MemoryStorage(size_t size, const uint8_t* data) {
}
}
#if defined(Q_OS_ANDROID)
static AAssetManager* g_assetManager = nullptr;
void FileStorage::setAssetManager(AAssetManager* assetManager) {
::g_assetManager = assetManager;
}
#endif
StoragePointer FileStorage::create(const QString& filename, size_t size, const uint8_t* data) {
QFile file(filename);
if (!file.open(QFile::ReadWrite | QIODevice::Truncate)) {
@ -69,7 +76,27 @@ StoragePointer FileStorage::create(const QString& filename, size_t size, const u
return std::make_shared<FileStorage>(filename);
}
FileStorage::FileStorage(const QString& filename) : _file(filename) {
#if defined(Q_OS_ANDROID)
static const QString ASSETS_PREFIX("assets:/");
bool isAsset = filename.startsWith(ASSETS_PREFIX);
if (isAsset) {
_hasWriteAccess = false;
std::string strFilename = filename.mid(ASSETS_PREFIX.size()).toStdString();
// Load shader from compressed asset
_asset = AAssetManager_open(g_assetManager, strFilename.c_str(), AASSET_MODE_BUFFER);
if (!_asset) {
return;
}
_size = AAsset_getLength64(_asset);
_mapped = (uint8_t*)AAsset_getBuffer(_asset);
if (_mapped) {
_valid = true;
}
return;
}
#endif
bool opened = _file.open(QFile::ReadWrite);
if (opened) {
_hasWriteAccess = true;
@ -79,6 +106,7 @@ FileStorage::FileStorage(const QString& filename) : _file(filename) {
}
if (opened) {
_size = _file.size();
_mapped = _file.map(0, _file.size());
if (_mapped) {
_valid = true;
@ -91,6 +119,14 @@ FileStorage::FileStorage(const QString& filename) : _file(filename) {
}
FileStorage::~FileStorage() {
#if defined(Q_OS_ANDROID)
if (_asset) {
_mapped = nullptr;
AAsset_close(_asset);
_asset = nullptr;
return;
}
#endif
if (_mapped) {
_file.unmap(_mapped);
_mapped = nullptr;

View file

@ -13,8 +13,14 @@
#include <stdint.h>
#include <vector>
#include <memory>
#include <QFile>
#include <QString>
#include <QtCore/qtglobal>
#include <QtCore/QFile>
#include <QtCore/QString>
#if defined(Q_OS_ANDROID)
#include <android/asset_manager.h>
#endif
namespace storage {
class Storage;
@ -52,6 +58,9 @@ namespace storage {
class FileStorage : public Storage {
public:
#if defined(Q_OS_ANDROID)
static void setAssetManager(AAssetManager* assetManager);
#endif
static StoragePointer create(const QString& filename, size_t size, const uint8_t* data);
FileStorage(const QString& filename);
~FileStorage();
@ -61,10 +70,13 @@ namespace storage {
const uint8_t* data() const override { return _mapped; }
uint8_t* mutableData() override { return _hasWriteAccess ? _mapped : nullptr; }
size_t size() const override { return _file.size(); }
size_t size() const override { return _size; }
operator bool() const override { return _valid; }
private:
#if defined(Q_OS_ANDROID)
AAsset* _asset { nullptr };
#endif
size_t _size { 0 };
bool _valid { false };
bool _hasWriteAccess { false };
QFile _file;