|
From: <eli...@us...> - 2004-03-09 09:50:09
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/common In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28178/src/native/common Modified Files: common_tools.cpp common_tools.h extgl.cpp extgl.h org_lwjgl_opengl_GL11.cpp org_lwjgl_opengl_GL12.cpp org_lwjgl_opengl_GL13.cpp org_lwjgl_opengl_GL14.cpp org_lwjgl_opengl_GL15.cpp Log Message: Generalized function pointer initialization Index: common_tools.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/common_tools.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- common_tools.cpp 24 Dec 2003 07:32:03 -0000 1.8 +++ common_tools.cpp 9 Mar 2004 09:25:08 -0000 1.9 @@ -37,6 +37,7 @@ * @version $Revision$ */ +#include <stdlib.h> #include "common_tools.h" bool debug = false; @@ -115,3 +116,56 @@ void throwException(JNIEnv * env, const char * err) { throwGeneralException(env, "java/lang/Exception", 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) { + printf("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); + jint result = env->UnregisterNatives(clazz); + if (result != 0) + printfDebug("Could not unregister natives for class %s\n", class_name); + return clazz; +} + +void ext_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char *ext_name, ExtGetProcAddressPROC gpa, int num_functions, JavaMethodAndExtFunction *functions) { + 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) { + printf("NOTICE: %s disabled because of missing driver symbols\n", ext_name); + if (ext_set != NULL) + ext_removeExtension(env, ext_set, ext_name); + free(methods); + return; + } + void **ext_function_pointer_pointer = function->ext_function_pointer; + *ext_function_pointer_pointer = ext_func_pointer; + } + JNINativeMethod *method = methods + i; + method->name = function->method_name; + method->signature = function->signature; + method->fnPtr = function->method_pointer; + } + jint result = env->RegisterNatives(clazz, methods, num_functions); + free(methods); + if (result != 0) + printfDebug("Could not register natives for extension %s\n", ext_name); +} + Index: common_tools.h =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/common_tools.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- common_tools.h 20 Jan 2004 10:11:02 -0000 1.8 +++ common_tools.h 9 Mar 2004 09:25:08 -0000 1.9 @@ -85,4 +85,20 @@ return (const char *)NULL + offset; } +typedef void *(* ExtGetProcAddressPROC) (const char *func_name); +typedef struct { + char *method_name; + char *signature; + void *method_pointer; + + char *ext_function_name; + void **ext_function_pointer; +} JavaMethodAndExtFunction; + +#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 void ext_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char *ext_name, ExtGetProcAddressPROC gpa, int num_functions, JavaMethodAndExtFunction *functions); + #endif Index: extgl.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/extgl.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- extgl.cpp 7 Mar 2004 15:49:00 -0000 1.27 +++ extgl.cpp 9 Mar 2004 09:25:08 -0000 1.28 @@ -34,7 +34,6 @@ */ #include <stdio.h> -#include <stdlib.h> #include <string.h> #include "extgl.h" #include "common_tools.h" @@ -595,58 +594,58 @@ CFBundleRef agl_bundle_ref = NULL; #endif -jclass extgl_ResetClass(JNIEnv *env, const char *class_name) { - jclass clazz = env->FindClass(class_name); - jint result = env->UnregisterNatives(clazz); - if (result != 0) - printfDebug("Could not unregister natives for class %s\n", class_name); - return clazz; -} +/* getProcAddress */ -void extgl_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char *ext_name, int num_functions, JavaMethodAndGLFunction *functions) { - JNINativeMethod *methods = (JNINativeMethod *)malloc(num_functions*sizeof(JNINativeMethod)); - for (int i = 0; i < num_functions; i++) { - JavaMethodAndGLFunction *function = functions + i; - if (function->gl_function_name != NULL) { - void *gl_func_pointer = extgl_GetProcAddress(function->gl_function_name); - if (gl_func_pointer == NULL) { - printf("NOTICE: %s disabled because of missing driver symbols\n", ext_name); - if (ext_set != NULL) - extgl_removeExtension(env, ext_set, ext_name); - free(methods); - return; - } - void **gl_function_pointer_pointer = function->gl_function_pointer; - *gl_function_pointer_pointer = gl_func_pointer; +static void *extgl_GetProcAddress(const char *name) +{ +#ifdef _WIN32 + void *t = wglGetProcAddress(name); + if (t == NULL) + { + t = GetProcAddress(lib_gl_handle, name); + if (t == NULL) + { + printfDebug("Could not locate symbol %s\n", name); + extgl_error = true; } - JNINativeMethod *method = methods + i; - method->name = function->method_name; - method->signature = function->signature; - method->fnPtr = function->method_pointer; } - jint result = env->RegisterNatives(clazz, methods, num_functions); - free(methods); - if (result != 0) - printfDebug("Could not register natives for extension %s\n", ext_name); -} + return t; +#endif -static 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) { - printf("Could not allocate java string from %s\n", ext); - return; +#ifdef _X11 + void *t = (void*)glXGetProcAddressARB((const GLubyte*)name); + if (t == NULL) + { + t = dlsym(lib_gl_handle, name); + if (t == NULL) + { + printfDebug("Could not locate symbol %s\n", name); + extgl_error = true; + } } - env->CallBooleanMethod(ext_set, id, ext_string); + return t; +#endif + +#ifdef _AGL + CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, name, kCFStringEncodingUTF8, kCFAllocatorNull); + void *func_pointer = CFBundleGetFunctionPointerForName(opengl_bundle_ref, str); + if (func_pointer == NULL) { + func_pointer = CFBundleGetFunctionPointerForName(agl_bundle_ref, str); + if (func_pointer == NULL) { + printfDebug("Could not locate symbol %s\n", name); + extgl_error = true; + } + } + CFRelease(str); + return func_pointer; +#endif } -void extgl_removeExtension(JNIEnv *env, jobject ext_set, const char *ext) { - doExtension(env, ext_set, "remove", ext); +void extgl_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char *ext_name, int num_functions, JavaMethodAndExtFunction *functions) { + ext_InitializeClass(env, clazz, ext_set, ext_name, &extgl_GetProcAddress, num_functions, functions); } + static void insertExtension(JNIEnv *env, jobject ext_set, const char *ext) { doExtension(env, ext_set, "add", ext); } @@ -722,53 +721,6 @@ #endif -/* getProcAddress */ - -void *extgl_GetProcAddress(const char *name) -{ -#ifdef _WIN32 - void *t = wglGetProcAddress(name); - if (t == NULL) - { - t = GetProcAddress(lib_gl_handle, name); - if (t == NULL) - { - printfDebug("Could not locate symbol %s\n", name); - extgl_error = true; - } - } - return t; -#endif - -#ifdef _X11 - void *t = (void*)glXGetProcAddressARB((const GLubyte*)name); - if (t == NULL) - { - t = dlsym(lib_gl_handle, name); - if (t == NULL) - { - printfDebug("Could not locate symbol %s\n", name); - extgl_error = true; - } - } - return t; -#endif - -#ifdef _AGL - CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, name, kCFStringEncodingUTF8, kCFAllocatorNull); - void *func_pointer = CFBundleGetFunctionPointerForName(opengl_bundle_ref, str); - if (func_pointer == NULL) { - func_pointer = CFBundleGetFunctionPointerForName(agl_bundle_ref, str); - if (func_pointer == NULL) { - printfDebug("Could not locate symbol %s\n", name); - extgl_error = true; - } - } - CFRelease(str); - return func_pointer; -#endif -} - static bool QueryExtension(JNIEnv *env, jobject ext_set, const GLubyte*extensions, const char *name) { const GLubyte *start; Index: extgl.h =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/extgl.h,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- extgl.h 7 Mar 2004 15:18:45 -0000 1.29 +++ extgl.h 9 Mar 2004 09:25:08 -0000 1.30 @@ -194,6 +194,8 @@ #define GLAPI extern #define GLAPIENTRY +#include "common_tools.h" + #ifdef __cplusplus extern "C" { #endif @@ -3286,23 +3288,9 @@ #ifdef _AGL bool extgl_InitAGL(JNIEnv *env); #endif -void *extgl_GetProcAddress(const char *name); void extgl_Close(void); -void extgl_removeExtension(JNIEnv *env, jobject ext_set, const char *ext); - -typedef struct { - char *method_name; - char *signature; - void *method_pointer; - - char *gl_function_name; - void **gl_function_pointer; -} JavaMethodAndGLFunction; - -#define NUMFUNCTIONS(x) (sizeof(x)/sizeof(JavaMethodAndGLFunction)); +void extgl_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char *ext_name, int num_functions, JavaMethodAndExtFunction *functions); -jclass extgl_ResetClass(JNIEnv *env, const char *class_name); -void extgl_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char *ext_name, int num_functions, JavaMethodAndGLFunction *functions); #define EXTGL_SANITY_CHECK(e,x) if (extgl_error) { \ extgl_Extensions.x = false; \ printf("NOTICE: %s disabled because of missing driver symbols\n", #x); \ Index: org_lwjgl_opengl_GL11.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/org_lwjgl_opengl_GL11.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- org_lwjgl_opengl_GL11.cpp 7 Mar 2004 16:01:44 -0000 1.6 +++ org_lwjgl_opengl_GL11.cpp 9 Mar 2004 09:25:08 -0000 1.7 @@ -2574,7 +2574,7 @@ void extgl_InitOpenGL1_1(JNIEnv *env) { - JavaMethodAndGLFunction functions[] = { + JavaMethodAndExtFunction functions[] = { {"glAccum", "(IF)V", (void*)&Java_org_lwjgl_opengl_GL11_glAccum, "glAccum", (void**)&glAccum}, {"glAlphaFunc", "(IF)V", (void*)&Java_org_lwjgl_opengl_GL11_glAlphaFunc, "glAlphaFunc", (void**)&glAlphaFunc}, {"glClearColor", "(FFFF)V", (void*)&Java_org_lwjgl_opengl_GL11_glClearColor, "glClearColor", (void**)&glClearColor}, @@ -2783,7 +2783,7 @@ {"glViewport", "(IIII)V", (void*)&Java_org_lwjgl_opengl_GL11_glViewport, "glViewport", (void**)&glViewport} }; int num_functions = NUMFUNCTIONS(functions); - jclass clazz = extgl_ResetClass(env, "org/lwjgl/opengl/GL11"); + jclass clazz = ext_ResetClass(env, "org/lwjgl/opengl/GL11"); if (true) extgl_InitializeClass(env, clazz, NULL, "GL11", num_functions, functions); } Index: org_lwjgl_opengl_GL12.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/org_lwjgl_opengl_GL12.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- org_lwjgl_opengl_GL12.cpp 7 Mar 2004 16:01:44 -0000 1.6 +++ org_lwjgl_opengl_GL12.cpp 9 Mar 2004 09:25:08 -0000 1.7 @@ -117,7 +117,7 @@ void extgl_InitOpenGL1_2(JNIEnv *env, jobject ext_set) { - JavaMethodAndGLFunction functions[] = { + JavaMethodAndExtFunction functions[] = { {"nglDrawRangeElements", "(IIIIILjava/nio/Buffer;I)V", (void*)&Java_org_lwjgl_opengl_GL12_nglDrawRangeElements, "glDrawRangeElements", (void**)&glDrawRangeElements}, {"nglDrawRangeElementsVBO", "(IIIIII)V", (void*)&Java_org_lwjgl_opengl_GL12_nglDrawRangeElementsVBO, NULL, NULL}, {"nglTexImage3D", "(IIIIIIIIILjava/nio/Buffer;I)V", (void*)&Java_org_lwjgl_opengl_GL12_nglTexImage3D, "glTexImage3D", (void**)&glTexImage3D}, @@ -125,7 +125,7 @@ {"glCopyTexSubImage3D", "(IIIIIIIII)V", (void*)&Java_org_lwjgl_opengl_GL12_glCopyTexSubImage3D, "glCopyTexSubImage3D", (void**)&glCopyTexSubImage3D} }; int num_functions = NUMFUNCTIONS(functions); - jclass clazz = extgl_ResetClass(env, "org/lwjgl/opengl/GL12"); + jclass clazz = ext_ResetClass(env, "org/lwjgl/opengl/GL12"); if (extgl_Extensions.OpenGL12) extgl_InitializeClass(env, clazz, ext_set, "OpenGL12", num_functions, functions); } Index: org_lwjgl_opengl_GL13.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/org_lwjgl_opengl_GL13.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- org_lwjgl_opengl_GL13.cpp 7 Mar 2004 16:01:44 -0000 1.5 +++ org_lwjgl_opengl_GL13.cpp 9 Mar 2004 09:25:08 -0000 1.6 @@ -287,7 +287,7 @@ void extgl_InitOpenGL1_3(JNIEnv *env, jobject ext_set) { - JavaMethodAndGLFunction functions[] = { + JavaMethodAndExtFunction functions[] = { {"glActiveTexture", "(I)V", (void*)&Java_org_lwjgl_opengl_GL13_glActiveTexture, "glActiveTexture", (void**)&glActiveTexture}, {"glClientActiveTexture", "(I)V", (void*)&Java_org_lwjgl_opengl_GL13_glClientActiveTexture, "glClientActiveTexture", (void**)&glClientActiveTexture}, {"nglCompressedTexImage1D", "(IIIIIILjava/nio/Buffer;I)V", (void*)&Java_org_lwjgl_opengl_GL13_nglCompressedTexImage1D, "glCompressedTexImage1D", (void**)&glCompressedTexImage1D}, @@ -306,7 +306,7 @@ {"glSampleCoverage", "(FZ)V", (void*)&Java_org_lwjgl_opengl_GL13_glSampleCoverage, "glSampleCoverage", (void**)&glSampleCoverage} }; int num_functions = NUMFUNCTIONS(functions); - jclass clazz = extgl_ResetClass(env, "org/lwjgl/opengl/GL13"); + jclass clazz = ext_ResetClass(env, "org/lwjgl/opengl/GL13"); if (extgl_Extensions.OpenGL13) extgl_InitializeClass(env, clazz, ext_set, "OpenGL13", num_functions, functions); } Index: org_lwjgl_opengl_GL14.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/org_lwjgl_opengl_GL14.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- org_lwjgl_opengl_GL14.cpp 7 Mar 2004 16:01:44 -0000 1.6 +++ org_lwjgl_opengl_GL14.cpp 9 Mar 2004 09:25:08 -0000 1.7 @@ -271,7 +271,7 @@ void extgl_InitOpenGL1_4(JNIEnv *env, jobject ext_set) { - JavaMethodAndGLFunction functions[] = { + JavaMethodAndExtFunction functions[] = { {"glBlendEquation", "(I)V", (void*)&Java_org_lwjgl_opengl_GL14_glBlendEquation, "glBlendEquation", (void**)&glBlendEquation}, {"glBlendColor", "(FFFF)V", (void*)&Java_org_lwjgl_opengl_GL14_glBlendColor, "glBlendColor", (void**)&glBlendColor}, {"glFogCoordf", "(F)V", (void*)&Java_org_lwjgl_opengl_GL14_glFogCoordf, "glFogCoordf", (void**)&glFogCoordf}, @@ -292,7 +292,7 @@ {"glWindowPos3i", "(III)V", (void*)&Java_org_lwjgl_opengl_GL14_glWindowPos3i, "glWindowPos3i", (void**)&glWindowPos3i} }; int num_functions = NUMFUNCTIONS(functions); - jclass clazz = extgl_ResetClass(env, "org/lwjgl/opengl/GL14"); + jclass clazz = ext_ResetClass(env, "org/lwjgl/opengl/GL14"); if (extgl_Extensions.OpenGL14) extgl_InitializeClass(env, clazz, ext_set, "OpenGL14", num_functions, functions); } Index: org_lwjgl_opengl_GL15.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/org_lwjgl_opengl_GL15.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- org_lwjgl_opengl_GL15.cpp 7 Mar 2004 16:01:44 -0000 1.5 +++ org_lwjgl_opengl_GL15.cpp 9 Mar 2004 09:25:08 -0000 1.6 @@ -315,7 +315,7 @@ void extgl_InitOpenGL1_5(JNIEnv *env, jobject ext_set) { - JavaMethodAndGLFunction functions[] = { + JavaMethodAndExtFunction functions[] = { {"nglBindBuffer", "(II)V", (void*)&Java_org_lwjgl_opengl_GL15_nglBindBuffer, "glBindBuffer", (void**)&glBindBuffer}, {"nglDeleteBuffers", "(ILjava/nio/IntBuffer;I)V", (void*)&Java_org_lwjgl_opengl_GL15_nglDeleteBuffers, "glDeleteBuffers", (void**)&glDeleteBuffers}, {"nglGenBuffers", "(ILjava/nio/IntBuffer;I)V", (void*)&Java_org_lwjgl_opengl_GL15_nglGenBuffers, "glGenBuffers", (void**)&glGenBuffers}, @@ -337,7 +337,7 @@ {"nglGetQueryObjectuiv", "(IILjava/nio/IntBuffer;I)V", (void*)&Java_org_lwjgl_opengl_GL15_nglGetQueryObjectuiv, "glGetQueryObjectuiv", (void**)&glGetQueryObjectuiv} }; int num_functions = NUMFUNCTIONS(functions); - jclass clazz = extgl_ResetClass(env, "org/lwjgl/opengl/GL15"); + jclass clazz = ext_ResetClass(env, "org/lwjgl/opengl/GL15"); if (extgl_Extensions.OpenGL15) extgl_InitializeClass(env, clazz, ext_set, "OpenGL15", num_functions, functions); } |