Java MaterialInstance::getName now creates string lazily.
This commit is contained in:
@@ -348,3 +348,11 @@ Java_com_google_android_filament_MaterialInstance_nSetDepthCulling(JNIEnv*,
|
||||
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
|
||||
instance->setDepthCulling(enable);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nGetName(JNIEnv* env, jclass,
|
||||
jlong nativeMaterialInstance) {
|
||||
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
|
||||
return env->NewStringUTF(instance->getName());
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ public class Material {
|
||||
public MaterialInstance createInstance(@NonNull String name) {
|
||||
long nativeInstance = nCreateInstanceWithName(getNativeObject(), name);
|
||||
if (nativeInstance == 0) throw new IllegalStateException("Couldn't create MaterialInstance");
|
||||
return new MaterialInstance(this, nativeInstance, name);
|
||||
return new MaterialInstance(this, nativeInstance);
|
||||
}
|
||||
|
||||
/** Returns the material's default instance. */
|
||||
|
||||
+8
-8
@@ -22,9 +22,9 @@ import androidx.annotation.Size;
|
||||
|
||||
public class MaterialInstance {
|
||||
private Material mMaterial;
|
||||
private String mName;
|
||||
private long mNativeObject;
|
||||
private long mNativeMaterial;
|
||||
private String mName;
|
||||
|
||||
public enum BooleanElement {
|
||||
BOOL,
|
||||
@@ -54,12 +54,6 @@ public class MaterialInstance {
|
||||
mNativeObject = nativeMaterialInstance;
|
||||
}
|
||||
|
||||
MaterialInstance(@NonNull Material material, long nativeMaterialInstance, String name) {
|
||||
mMaterial = material;
|
||||
mNativeObject = nativeMaterialInstance;
|
||||
mName = name;
|
||||
}
|
||||
|
||||
MaterialInstance(long nativeMaterial, long nativeMaterialInstance) {
|
||||
mNativeMaterial = nativeMaterial;
|
||||
mNativeObject = nativeMaterialInstance;
|
||||
@@ -75,8 +69,12 @@ public class MaterialInstance {
|
||||
}
|
||||
|
||||
/** @return the name associated with this instance */
|
||||
@NonNull
|
||||
public String getName() {
|
||||
return mName == null ? mMaterial.getName() : mName;
|
||||
if (mName == null) {
|
||||
mName = nGetName(getNativeObject());
|
||||
}
|
||||
return mName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -548,4 +546,6 @@ public class MaterialInstance {
|
||||
private static native void nSetColorWrite(long nativeMaterialInstance, boolean enable);
|
||||
private static native void nSetDepthWrite(long nativeMaterialInstance, boolean enable);
|
||||
private static native void nSetDepthCulling(long nativeMaterialInstance, boolean enable);
|
||||
|
||||
private static native String nGetName(long nativeMaterialInstance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user