MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / JNI_OnLoad

Function JNI_OnLoad

interface/java_binding/src/main/cpp/libktx-jni.cpp:85–179  ·  view source on GitHub ↗

* Called when the library is loaded. * * This will initialize all required classes, field IDs, and method IDs */

Source from the content-addressed store, hash-verified

83 * This will initialize all required classes, field IDs, and method IDs
84 */
85JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *)
86{
87 JNIEnv *env = NULL;
88 if (jvm->GetEnv((void **)&env, JNI_VERSION_1_4))
89 {
90 return JNI_ERR;
91 }
92
93 jclass cls = NULL;
94
95 // Obtain the KtxTexture1 class and its constructor
96 if (!initClass(env, cls, "org/khronos/ktx/KtxTexture1")) return JNI_ERR;
97 if (!initMethod(env, cls, KtxTexture1_constructor, "<init>", "(J)V")) return JNI_ERR;
98 KtxTexture1_class = (jclass)env->NewGlobalRef(cls);
99 if (KtxTexture1_class == NULL)
100 {
101 std::cerr << "Failed to create reference to KtxTexture1 class " << std::endl;
102 return JNI_ERR;
103 }
104
105 // Obtain the KtxTexture2 class and its constructor
106 if (!initClass(env, cls, "org/khronos/ktx/KtxTexture2")) return JNI_ERR;
107 if (!initMethod(env, cls, KtxTexture2_constructor, "<init>", "(J)V")) return JNI_ERR;
108 KtxTexture2_class = (jclass)env->NewGlobalRef(cls);
109 if (KtxTexture1_class == NULL)
110 {
111 std::cerr << "Failed to create reference to KtxTexture2 class " << std::endl;
112 return JNI_ERR;
113 }
114
115 // Obtain the method IDs for the Buffer class
116 if (!initClass(env, cls, "java/nio/Buffer")) return JNI_ERR;
117 if (!initMethod(env, cls, Buffer_position_method, "position", "()I")) return JNI_ERR;
118 if (!initMethod(env, cls, Buffer_limit_method, "limit", "()I")) return JNI_ERR;
119 if (!initMethod(env, cls, Buffer_isDirect_method, "isDirect", "()Z")) return JNI_ERR;
120 if (!initMethod(env, cls, Buffer_hasArray_method, "hasArray", "()Z")) return JNI_ERR;
121 if (!initMethod(env, cls, Buffer_array_method, "array", "()Ljava/lang/Object;")) return JNI_ERR;
122
123 // Obtain the fieldIDs of the KtxTexture class
124 if (!initClass(env, cls, "org/khronos/ktx/KtxTexture")) return JNI_ERR;
125 if (!initField(env, cls, KtxTexture_instance_field, "instance", "J")) return JNI_ERR;
126
127 // Obtain the fieldIDs of the KtxTextureCreateInfo class
128 if (!initClass(env, cls, "org/khronos/ktx/KtxTextureCreateInfo")) return JNI_ERR;
129 if (!initField(env, cls, KtxTextureCreateInfo_glInternalformat_field, "glInternalformat", "I")) return JNI_ERR;
130 if (!initField(env, cls, KtxTextureCreateInfo_baseWidth_field, "baseWidth", "I")) return JNI_ERR;
131 if (!initField(env, cls, KtxTextureCreateInfo_baseHeight_field, "baseHeight", "I")) return JNI_ERR;
132 if (!initField(env, cls, KtxTextureCreateInfo_baseDepth_field, "baseDepth", "I")) return JNI_ERR;
133 if (!initField(env, cls, KtxTextureCreateInfo_numDimensions_field, "numDimensions", "I")) return JNI_ERR;
134 if (!initField(env, cls, KtxTextureCreateInfo_numLevels_field, "numLevels", "I")) return JNI_ERR;
135 if (!initField(env, cls, KtxTextureCreateInfo_numLayers_field, "numLayers", "I")) return JNI_ERR;
136 if (!initField(env, cls, KtxTextureCreateInfo_numFaces_field, "numFaces", "I")) return JNI_ERR;
137 if (!initField(env, cls, KtxTextureCreateInfo_isArray_field, "isArray", "Z")) return JNI_ERR;
138 if (!initField(env, cls, KtxTextureCreateInfo_generateMipmaps_field, "generateMipmaps", "Z")) return JNI_ERR;
139 if (!initField(env, cls, KtxTextureCreateInfo_vkFormat_field, "vkFormat", "I")) return JNI_ERR;
140
141 // Obtain the fieldIDs of the KtxAstcParams class
142 if (!initClass(env, cls, "org/khronos/ktx/KtxAstcParams")) return JNI_ERR;

Callers

nothing calls this directly

Calls 3

initClassFunction · 0.85
initMethodFunction · 0.85
initFieldFunction · 0.85

Tested by

no test coverage detected