Moved openal native stub loading to java
This commit is contained in:
parent
8585d8b2a5
commit
b7e4214a1a
|
@ -170,6 +170,7 @@ public abstract class AL {
|
|||
oalPaths[oalPaths.length - 1] = "";
|
||||
nCreate(oalPaths);
|
||||
|
||||
AL10.initNativeStubs();
|
||||
ALC.create();
|
||||
|
||||
device = ALC.alcOpenDevice(deviceArguments);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
#include <jni.h>
|
||||
#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" {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue