in PlayAssetDelivery/NativeSample/common/ndk_helper/JNIHelper.cpp [283:336]
uint32_t JNIHelper::LoadCubemapTexture(const char* file_name,
const int32_t face,
const int32_t miplevel, const bool sRGB,
int32_t* outWidth, int32_t* outHeight,
bool* hasAlpha) {
if (activity_ == NULL) {
LOGI(
"JNIHelper has not been initialized. Call init() to initialize the "
"helper");
return 0;
}
// Lock mutex
std::lock_guard<std::mutex> lock(mutex_);
JNIEnv* env = AttachCurrentThread();
jstring name = env->NewStringUTF(file_name);
jmethodID mid = env->GetMethodID(jni_helper_java_class_, "loadCubemapTexture",
"(Ljava/lang/String;IIZ)Ljava/lang/Object;");
jobject out =
env->CallObjectMethod(jni_helper_java_ref_, mid, name, face, miplevel);
jclass javaCls =
RetrieveClass(env, "com/sample/helper/NDKHelper$TextureInformation");
jfieldID fidRet = env->GetFieldID(javaCls, "ret", "Z");
jfieldID fidHasAlpha = env->GetFieldID(javaCls, "alphaChannel", "Z");
jfieldID fidWidth = env->GetFieldID(javaCls, "originalWidth", "I");
jfieldID fidHeight = env->GetFieldID(javaCls, "originalHeight", "I");
bool ret = env->GetBooleanField(out, fidRet);
bool alpha = env->GetBooleanField(out, fidHasAlpha);
int32_t width = env->GetIntField(out, fidWidth);
int32_t height = env->GetIntField(out, fidHeight);
if (!ret) {
LOGI("Texture load failed %s", file_name);
}
LOGI("Loaded texture original size:%dx%d alpha:%d", width, height,
(int32_t)alpha);
if (outWidth != NULL) {
*outWidth = width;
}
if (outHeight != NULL) {
*outHeight = height;
}
if (hasAlpha != NULL) {
*hasAlpha = alpha;
}
env->DeleteLocalRef(name);
env->DeleteLocalRef(javaCls);
return 0;
}