From b7e4214a1aa2b9f8f7925270957839022c5eb765 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 4 Jul 2004 09:13:19 +0000 Subject: [PATCH] Moved openal native stub loading to java --- src/java/org/lwjgl/openal/AL.java | 1 + src/java/org/lwjgl/openal/AL10.java | 2 ++ src/java/org/lwjgl/openal/ALC.java | 4 ++- src/native/common/common_tools.cpp | 40 +++------------------ src/native/common/common_tools.h | 4 +-- src/native/common/extal.cpp | 23 ++---------- src/native/common/extal.h | 2 +- src/native/common/extgl.cpp | 19 ++-------- src/native/common/extgl.h | 4 +-- src/native/common/org_lwjgl_openal_AL10.cpp | 7 ++-- src/native/common/org_lwjgl_openal_ALC.cpp | 7 ++-- src/native/linux/extgl_glx.cpp | 2 +- src/native/win32/extgl_wgl.cpp | 4 +-- 13 files changed, 30 insertions(+), 89 deletions(-) diff --git a/src/java/org/lwjgl/openal/AL.java b/src/java/org/lwjgl/openal/AL.java index 07ed7bb9..b87e6341 100644 --- a/src/java/org/lwjgl/openal/AL.java +++ b/src/java/org/lwjgl/openal/AL.java @@ -170,6 +170,7 @@ public abstract class AL { oalPaths[oalPaths.length - 1] = ""; nCreate(oalPaths); + AL10.initNativeStubs(); ALC.create(); device = ALC.alcOpenDevice(deviceArguments); diff --git a/src/java/org/lwjgl/openal/AL10.java b/src/java/org/lwjgl/openal/AL10.java index e8e296ec..15298532 100644 --- a/src/java/org/lwjgl/openal/AL10.java +++ b/src/java/org/lwjgl/openal/AL10.java @@ -357,6 +357,8 @@ public final class AL10 { /** Distance model */ public static final int AL_INVERSE_DISTANCE_CLAMPED = 0xD002; + static native void initNativeStubs(); + /** * The application can temporarily disable certain AL capabilities on a per Context * basis. This allows the driver implementation to optimize for certain subsets of diff --git a/src/java/org/lwjgl/openal/ALC.java b/src/java/org/lwjgl/openal/ALC.java index b4a88eb0..67550964 100644 --- a/src/java/org/lwjgl/openal/ALC.java +++ b/src/java/org/lwjgl/openal/ALC.java @@ -165,11 +165,13 @@ public class ALC { if (created) { return; } - + initNativeStubs(); init(); created = true; } + private static native void initNativeStubs(); + /** * Calls whatever destruction rutines that are needed */ diff --git a/src/native/common/common_tools.cpp b/src/native/common/common_tools.cpp index 8fd0b625..cd4a1202 100644 --- a/src/native/common/common_tools.cpp +++ b/src/native/common/common_tools.cpp @@ -139,33 +139,6 @@ void throwException(JNIEnv * env, const char * err) { throwGeneralException(env, "org/lwjgl/LWJGLException", err); } -void doExtension(JNIEnv *env, jobject ext_set, const char *method_name, const char *ext) { - jclass clazz = env->GetObjectClass(ext_set); - jmethodID id = env->GetMethodID(clazz, method_name, "(Ljava/lang/Object;)Z"); - if (id == NULL) - return; - jstring ext_string = env->NewStringUTF(ext); - if (ext_string == NULL) { - printfDebug("Could not allocate java string from %s\n", ext); - return; - } - env->CallBooleanMethod(ext_set, id, ext_string); -} - -static void ext_removeExtension(JNIEnv *env, jobject ext_set, const char *ext) { - doExtension(env, ext_set, "remove", ext); -} - -jclass ext_ResetClass(JNIEnv *env, const char *class_name) { - jclass clazz = env->FindClass(class_name); - if (clazz == NULL) - return NULL; - jint result = env->UnregisterNatives(clazz); - if (result != 0) - printfDebug("Could not unregister natives for class %s\n", class_name); - return clazz; -} - bool ext_InitializeFunctions(ExtGetProcAddressPROC gpa, int num_functions, ExtFunction *functions) { for (int i = 0; i < num_functions; i++) { ExtFunction *function = functions + i; @@ -180,20 +153,17 @@ bool ext_InitializeFunctions(ExtGetProcAddressPROC gpa, int num_functions, ExtFu return true; } -bool ext_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char *ext_name, ExtGetProcAddressPROC gpa, int num_functions, JavaMethodAndExtFunction *functions) { - if (clazz == NULL) +bool ext_InitializeClass(JNIEnv *env, jclass clazz, ExtGetProcAddressPROC gpa, int num_functions, JavaMethodAndExtFunction *functions) { + if (clazz == NULL) { + throwException(env, "Null class"); return false; + } JNINativeMethod *methods = (JNINativeMethod *)malloc(num_functions*sizeof(JNINativeMethod)); for (int i = 0; i < num_functions; i++) { JavaMethodAndExtFunction *function = functions + i; if (function->ext_function_name != NULL) { void *ext_func_pointer = gpa(function->ext_function_name); if (ext_func_pointer == NULL) { - if (ext_name != NULL) { - printfDebug("NOTICE: %s disabled because of missing driver symbols\n", ext_name); - if (ext_set != NULL) - ext_removeExtension(env, ext_set, ext_name); - } free(methods); throwException(env, "Missing driver symbols"); return false; @@ -209,8 +179,6 @@ bool ext_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char jint result = env->RegisterNatives(clazz, methods, num_functions); free(methods); if (result != 0) { - if (ext_name != NULL) - printfDebug("Could not register natives for extension %s\n", ext_name); return false; } else return true; diff --git a/src/native/common/common_tools.h b/src/native/common/common_tools.h index 83da3a8c..1b46833d 100644 --- a/src/native/common/common_tools.h +++ b/src/native/common/common_tools.h @@ -114,9 +114,7 @@ typedef struct { #define NUMFUNCTIONS(x) (sizeof(x)/sizeof(JavaMethodAndExtFunction)); -extern void doExtension(JNIEnv *env, jobject ext_set, const char *method_name, const char *ext); -extern jclass ext_ResetClass(JNIEnv *env, const char *class_name); -extern bool ext_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char *ext_name, ExtGetProcAddressPROC gpa, int num_functions, JavaMethodAndExtFunction *functions); +extern bool ext_InitializeClass(JNIEnv *env, jclass clazz, ExtGetProcAddressPROC gpa, int num_functions, JavaMethodAndExtFunction *functions); extern bool ext_InitializeFunctions(ExtGetProcAddressPROC gpa, int num_functions, ExtFunction *functions); #endif diff --git a/src/native/common/extal.cpp b/src/native/common/extal.cpp index 3f4c0432..9e787906 100644 --- a/src/native/common/extal.cpp +++ b/src/native/common/extal.cpp @@ -76,12 +76,6 @@ static bool LoadOpenAL(JNIEnv *env, jobjectArray oalPaths); /* Unloads OpenAL */ static void UnLoadOpenAL(void); -/* Loads OpenAL basic functions */ -extern bool LoadAL(JNIEnv *env); - -/* Loads OpenAL ALC functions */ -extern bool LoadALC(JNIEnv *env); - static void *NativeGetFunctionPointer(const char *function) { #ifdef _WIN32 return GetProcAddress(handleOAL, function); @@ -235,19 +229,6 @@ void InitializeOpenAL(JNIEnv *env, jobjectArray oalPaths) { throwException(env, "Could not load alGetProcAddress function pointer."); return; } - //load basic OpenAL functions - if(!LoadAL(env)) { - DeInitializeOpenAL(); - throwException(env, "Could not load OpenAL function pointers."); - return; - } - - //load OpenAL context functions - if(!LoadALC(env)) { - DeInitializeOpenAL(); - throwException(env, "Could not load ALC function pointers."); - return; - } } /** @@ -258,7 +239,7 @@ void DeInitializeOpenAL() { handleOAL = 0; } -bool extal_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char *ext_name, int num_functions, JavaMethodAndExtFunction *functions) { - return ext_InitializeClass(env, clazz, ext_set, ext_name, &extal_GetProcAddress, num_functions, functions); +void extal_InitializeClass(JNIEnv *env, jclass clazz, int num_functions, JavaMethodAndExtFunction *functions) { + ext_InitializeClass(env, clazz, &extal_GetProcAddress, num_functions, functions); } diff --git a/src/native/common/extal.h b/src/native/common/extal.h index f9acdc52..0b14093c 100644 --- a/src/native/common/extal.h +++ b/src/native/common/extal.h @@ -53,7 +53,7 @@ #include #include "common_tools.h" -bool extal_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char *ext_name, int num_functions, JavaMethodAndExtFunction *functions); +void extal_InitializeClass(JNIEnv *env, jclass clazz, int num_functions, JavaMethodAndExtFunction *functions); #ifdef __cplusplus extern "C" { diff --git a/src/native/common/extgl.cpp b/src/native/common/extgl.cpp index ab2e40b5..709a1392 100755 --- a/src/native/common/extgl.cpp +++ b/src/native/common/extgl.cpp @@ -149,18 +149,14 @@ void *extgl_GetProcAddress(const char *name) #endif } -bool extgl_InitializeClass(JNIEnv *env, jclass clazz, int num_functions, JavaMethodAndExtFunction *functions) { - return ext_InitializeClass(env, clazz, NULL, NULL, &extgl_GetProcAddress, num_functions, functions); +void extgl_InitializeClass(JNIEnv *env, jclass clazz, int num_functions, JavaMethodAndExtFunction *functions) { + ext_InitializeClass(env, clazz, &extgl_GetProcAddress, num_functions, functions); } bool extgl_InitializeFunctions(int num_functions, ExtFunction *functions) { return ext_InitializeFunctions(&extgl_GetProcAddress, num_functions, functions); } -static void insertExtension(JNIEnv *env, jobject ext_set, const char *ext) { - doExtension(env, ext_set, "add", ext); -} - #ifdef _AGL // ------------------------- static CFBundleRef loadBundle(const Str255 frameworkName) @@ -232,7 +228,7 @@ static void aglUnloadFramework(CFBundleRef f) #endif -bool extgl_QueryExtension(JNIEnv *env, jobject ext_set, const GLubyte*extensions, const char *name) +bool extgl_QueryExtension(JNIEnv *env, const GLubyte*extensions, const char *name) { const GLubyte *start; GLubyte *where, *terminator; @@ -259,9 +255,6 @@ bool extgl_QueryExtension(JNIEnv *env, jobject ext_set, const GLubyte*extensions terminator = where + strlen(name); if (where == start || *(where - 1) == ' ') if (*terminator == ' ' || *terminator == '\0') { - if (ext_set != NULL) { - insertExtension(env, ext_set, name); - } return true; } start = terminator; @@ -319,12 +312,6 @@ bool extgl_InitAGL(JNIEnv *env) /* AGL stuff END*/ /*-----------------------------------------------------*/ -/** returns true if the extention is available */ -static bool GLQueryExtension(JNIEnv *env, jobject ext_set, const char *name) -{ - return extgl_QueryExtension(env, ext_set, glGetString(GL_EXTENSIONS), name); -} - #ifdef _AGL bool extgl_Open(void) { if (opengl_bundle_ref != NULL) diff --git a/src/native/common/extgl.h b/src/native/common/extgl.h index 6239e247..e5978560 100644 --- a/src/native/common/extgl.h +++ b/src/native/common/extgl.h @@ -438,9 +438,9 @@ extern bool extgl_Open(void); extern bool extgl_InitAGL(JNIEnv *env); #endif extern void extgl_Close(void); -extern bool extgl_InitializeClass(JNIEnv *env, jclass clazz, int num_functions, JavaMethodAndExtFunction *functions); +extern void extgl_InitializeClass(JNIEnv *env, jclass clazz, int num_functions, JavaMethodAndExtFunction *functions); extern bool extgl_InitializeFunctions(int num_functions, ExtFunction *functions); -extern bool extgl_QueryExtension(JNIEnv *env, jobject ext_set, const GLubyte*extensions, const char *name); +extern bool extgl_QueryExtension(JNIEnv *env, const GLubyte*extensions, const char *name); #ifdef __cplusplus } diff --git a/src/native/common/org_lwjgl_openal_AL10.cpp b/src/native/common/org_lwjgl_openal_AL10.cpp index a1b1f58c..51a7b460 100644 --- a/src/native/common/org_lwjgl_openal_AL10.cpp +++ b/src/native/common/org_lwjgl_openal_AL10.cpp @@ -733,7 +733,8 @@ static void JNICALL Java_org_lwjgl_openal_AL10_alDopplerVelocity (JNIEnv *env, j * * @return true if all methods were loaded, false if one of the methods could not be loaded */ -bool LoadAL(JNIEnv *env) { +extern "C" { +JNIEXPORT void JNICALL Java_org_lwjgl_openal_AL10_initNativeStubs(JNIEnv *env, jclass clazz) { JavaMethodAndExtFunction functions[] = { {"alEnable", "(I)V", (void*)&Java_org_lwjgl_openal_AL10_alEnable, "alEnable", (void**)&alEnable}, {"alDisable", "(I)V", (void*)&Java_org_lwjgl_openal_AL10_alDisable, "alDisable", (void**)&alDisable}, @@ -786,6 +787,6 @@ bool LoadAL(JNIEnv *env) { {"alDopplerVelocity", "(F)V", (void*)&Java_org_lwjgl_openal_AL10_alDopplerVelocity, "alDopplerVelocity", (void**)&alDopplerVelocity} }; int num_functions = NUMFUNCTIONS(functions); - jclass clazz = ext_ResetClass(env, "org/lwjgl/openal/AL10"); - return extal_InitializeClass(env, clazz, NULL, NULL, num_functions, functions); + extal_InitializeClass(env, clazz, num_functions, functions); +} } diff --git a/src/native/common/org_lwjgl_openal_ALC.cpp b/src/native/common/org_lwjgl_openal_ALC.cpp index 2f763254..db8f1f7c 100644 --- a/src/native/common/org_lwjgl_openal_ALC.cpp +++ b/src/native/common/org_lwjgl_openal_ALC.cpp @@ -352,7 +352,8 @@ static jint JNICALL Java_org_lwjgl_openal_ALC_nalcGetEnumValue (JNIEnv *env, jcl * * @return true if all methods were loaded, false if one of the methods could not be loaded */ -bool LoadALC(JNIEnv *env) { +extern "C" { +JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC_initNativeStubs(JNIEnv *env, jclass clazz) { JavaMethodAndExtFunction functions[] = { {"nalcGetString", "(II)Ljava/lang/String;", (void*)&Java_org_lwjgl_openal_ALC_nalcGetString, "alcGetString", (void**)&alcGetString}, {"nalcGetIntegerv", "(IIILjava/nio/Buffer;I)V", (void*)&Java_org_lwjgl_openal_ALC_nalcGetIntegerv, "alcGetIntegerv", (void**)&alcGetIntegerv}, @@ -370,6 +371,6 @@ bool LoadALC(JNIEnv *env) { {"nalcGetEnumValue", "(ILjava/lang/String;)I", (void*)&Java_org_lwjgl_openal_ALC_nalcGetEnumValue, "alcGetEnumValue", (void**)&alcGetEnumValue} }; int num_functions = NUMFUNCTIONS(functions); - jclass clazz = ext_ResetClass(env, "org/lwjgl/openal/ALC"); - return extal_InitializeClass(env, clazz, NULL, NULL, num_functions, functions); + extal_InitializeClass(env, clazz, num_functions, functions); +} } diff --git a/src/native/linux/extgl_glx.cpp b/src/native/linux/extgl_glx.cpp index d5fec956..037ede86 100644 --- a/src/native/linux/extgl_glx.cpp +++ b/src/native/linux/extgl_glx.cpp @@ -77,7 +77,7 @@ glXSwapIntervalSGIPROC glXSwapIntervalSGI = NULL; static bool GLXQueryExtension(JNIEnv* env, Display *disp, int screen, const char *name) { const GLubyte *exts = (const GLubyte *)glXQueryExtensionsString(disp, screen); - return extgl_QueryExtension(env, NULL, exts, name); + return extgl_QueryExtension(env, exts, name); } static void extgl_InitGLX13(JNIEnv *env) diff --git a/src/native/win32/extgl_wgl.cpp b/src/native/win32/extgl_wgl.cpp index 27e50d9a..3441ee1d 100644 --- a/src/native/win32/extgl_wgl.cpp +++ b/src/native/win32/extgl_wgl.cpp @@ -89,7 +89,7 @@ static bool WGLQueryExtension(JNIEnv *env, const char *name) extensions = (GLubyte*)wglGetExtensionsStringEXT(); else extensions = (GLubyte*)wglGetExtensionsStringARB(wglGetCurrentDC()); - return extgl_QueryExtension(env, NULL, extensions, name); + return extgl_QueryExtension(env, extensions, name); } static void extgl_InitWGLARBPbuffer(JNIEnv *env) @@ -172,4 +172,4 @@ void extgl_InitWGL(JNIEnv *env) extgl_InitWGLARBPixelFormat(env); extgl_InitWGLARBPbuffer(env); //extgl_InitWGLARBBufferRegion(env); -} \ No newline at end of file +}