2002-11-18 15:02:17 -05:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
Copyright (c) 2001-2002, Lev Povalahev
|
|
|
|
All rights reserved.
|
|
|
|
|
2004-02-15 10:21:24 -05:00
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
2002-11-18 15:02:17 -05:00
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
2004-02-15 10:21:24 -05:00
|
|
|
* Redistributions of source code must retain the above copyright notice,
|
2003-09-21 03:43:02 -04:00
|
|
|
this list of conditions and the following disclaimer.
|
2004-02-15 10:21:24 -05:00
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2003-09-21 03:43:02 -04:00
|
|
|
and/or other materials provided with the distribution.
|
2004-02-15 10:21:24 -05:00
|
|
|
* The name of the author may be used to endorse or promote products
|
2003-09-21 03:43:02 -04:00
|
|
|
derived from this software without specific prior written permission.
|
2002-11-18 15:02:17 -05:00
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
2004-02-15 10:21:24 -05:00
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
|
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
|
|
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
2002-11-18 15:02:17 -05:00
|
|
|
THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
------------------------------------------------------------------------------*/
|
2004-02-15 10:21:24 -05:00
|
|
|
/*
|
2003-09-21 03:43:02 -04:00
|
|
|
Lev Povalahev
|
2002-11-18 15:02:17 -05:00
|
|
|
|
2003-09-21 03:43:02 -04:00
|
|
|
levp@gmx.net
|
2002-11-18 15:02:17 -05:00
|
|
|
|
2003-09-21 03:43:02 -04:00
|
|
|
http://www.uni-karlsruhe.de/~uli2/
|
2002-11-18 15:02:17 -05:00
|
|
|
|
2004-02-15 10:21:24 -05:00
|
|
|
*/
|
2002-12-31 23:05:44 -05:00
|
|
|
|
2002-11-18 15:02:17 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2003-12-15 06:49:17 -05:00
|
|
|
#include "extgl.h"
|
|
|
|
#include "common_tools.h"
|
2002-11-18 15:02:17 -05:00
|
|
|
|
|
|
|
/* turn off the warning for the borland compiler*/
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma warn -8064
|
|
|
|
#pragma warn -8065
|
|
|
|
#endif /* __BORLANDC__ */
|
|
|
|
|
2002-12-30 02:07:40 -05:00
|
|
|
#ifdef _X11
|
2002-12-11 02:16:31 -05:00
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
2003-09-29 05:26:20 -04:00
|
|
|
#ifdef _AGL
|
|
|
|
aglChoosePixelFormatPROC aglChoosePixelFormat = NULL;
|
|
|
|
aglDestroyPixelFormatPROC aglDestroyPixelFormat = NULL;
|
|
|
|
aglNextPixelFormatPROC aglNextPixelFormat = NULL;
|
|
|
|
aglDescribePixelFormatPROC aglDescribePixelFormat = NULL;
|
|
|
|
aglDevicesOfPixelFormatPROC aglDevicesOfPixelFormat = NULL;
|
|
|
|
aglQueryRendererInfoPROC aglQueryRendererInfo = NULL;
|
|
|
|
aglDestroyRendererInfoPROC aglDestroyRendererInfo = NULL;
|
|
|
|
aglNextRendererInfoPROC aglNextRendererInfo = NULL;
|
|
|
|
aglDescribeRendererPROC aglDescribeRenderer = NULL;
|
|
|
|
aglCreateContextPROC aglCreateContext = NULL;
|
|
|
|
aglDestroyContextPROC aglDestroyContext = NULL;
|
|
|
|
aglCopyContextPROC aglCopyContext = NULL;
|
|
|
|
aglUpdateContextPROC aglUpdateContext = NULL;
|
|
|
|
aglSetCurrentContextPROC aglSetCurrentContext = NULL;
|
|
|
|
aglGetCurrentContextPROC aglGetCurrentContext = NULL;
|
|
|
|
aglSetDrawablePROC aglSetDrawable = NULL;
|
|
|
|
aglSetOffScreenPROC aglSetOffScreen = NULL;
|
|
|
|
aglSetFullScreenPROC aglSetFullScreen = NULL;
|
|
|
|
aglGetDrawablePROC aglGetDrawable = NULL;
|
|
|
|
aglSetVirtualScreenPROC aglSetVirtualScreen = NULL;
|
|
|
|
aglGetVirtualScreenPROC aglGetVirtualScreen = NULL;
|
|
|
|
aglGetVersionPROC aglGetVersion = NULL;
|
|
|
|
aglSwapBuffersPROC aglSwapBuffers = NULL;
|
|
|
|
aglEnablePROC aglEnable = NULL;
|
|
|
|
aglDisablePROC aglDisable = NULL;
|
|
|
|
aglIsEnabledPROC aglIsEnabled = NULL;
|
|
|
|
aglSetIntegerPROC aglSetInteger = NULL;
|
|
|
|
aglGetIntegerPROC aglGetInteger = NULL;
|
|
|
|
aglUseFontPROC aglUseFont = NULL;
|
|
|
|
aglGetErrorPROC aglGetError = NULL;
|
|
|
|
aglErrorStringPROC aglErrorString = NULL;
|
|
|
|
aglResetLibraryPROC aglResetLibrary = NULL;
|
2004-02-15 10:21:24 -05:00
|
|
|
aglSurfaceTexturePROC aglSurfaceTexture = NULL;
|
2003-09-29 05:26:20 -04:00
|
|
|
#endif
|
|
|
|
|
2002-11-18 15:02:17 -05:00
|
|
|
|
|
|
|
struct ExtensionTypes extgl_Extensions;
|
|
|
|
|
2002-12-11 02:16:31 -05:00
|
|
|
#ifdef _WIN32
|
|
|
|
HMODULE lib_gl_handle = NULL;
|
2002-12-30 02:07:40 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _X11
|
2002-12-11 02:16:31 -05:00
|
|
|
void * lib_gl_handle = NULL;
|
2004-03-11 07:38:13 -05:00
|
|
|
|
|
|
|
typedef void * (APIENTRY * glXGetProcAddressARBPROC) (const GLubyte *procName);
|
|
|
|
|
|
|
|
static glXGetProcAddressARBPROC glXGetProcAddressARB;
|
2002-12-11 02:16:31 -05:00
|
|
|
#endif
|
2002-11-18 15:02:17 -05:00
|
|
|
|
2003-09-07 12:11:15 -04:00
|
|
|
#ifdef _AGL
|
2003-09-29 07:58:35 -04:00
|
|
|
CFBundleRef opengl_bundle_ref = NULL;
|
|
|
|
CFBundleRef agl_bundle_ref = NULL;
|
2003-09-07 12:11:15 -04:00
|
|
|
#endif
|
|
|
|
|
2004-03-09 04:25:10 -05:00
|
|
|
/* getProcAddress */
|
2004-03-07 10:18:47 -05:00
|
|
|
|
2004-03-11 07:38:13 -05:00
|
|
|
void *extgl_GetProcAddress(const char *name)
|
2004-03-09 04:25:10 -05:00
|
|
|
{
|
|
|
|
#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);
|
2004-03-07 10:18:47 -05:00
|
|
|
}
|
|
|
|
}
|
2004-03-09 04:25:10 -05:00
|
|
|
return t;
|
|
|
|
#endif
|
2004-03-07 10:18:47 -05:00
|
|
|
|
2004-03-09 04:25:10 -05:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2003-09-26 09:59:50 -04:00
|
|
|
}
|
2004-03-09 04:25:10 -05:00
|
|
|
CFRelease(str);
|
|
|
|
return func_pointer;
|
|
|
|
#endif
|
2003-09-26 09:59:50 -04:00
|
|
|
}
|
|
|
|
|
2004-07-03 17:12:33 -04:00
|
|
|
bool extgl_InitializeClass(JNIEnv *env, jclass clazz, int num_functions, JavaMethodAndExtFunction *functions) {
|
|
|
|
return ext_InitializeClass(env, clazz, NULL, NULL, &extgl_GetProcAddress, num_functions, functions);
|
2003-09-26 09:59:50 -04:00
|
|
|
}
|
|
|
|
|
2004-03-11 07:38:13 -05:00
|
|
|
bool extgl_InitializeFunctions(int num_functions, ExtFunction *functions) {
|
|
|
|
return ext_InitializeFunctions(&extgl_GetProcAddress, num_functions, functions);
|
|
|
|
}
|
2004-03-09 04:25:10 -05:00
|
|
|
|
2003-09-26 09:59:50 -04:00
|
|
|
static void insertExtension(JNIEnv *env, jobject ext_set, const char *ext) {
|
|
|
|
doExtension(env, ext_set, "add", ext);
|
|
|
|
}
|
2003-09-22 04:31:51 -04:00
|
|
|
|
2003-09-07 12:11:15 -04:00
|
|
|
#ifdef _AGL
|
|
|
|
// -------------------------
|
2003-09-29 07:58:35 -04:00
|
|
|
static CFBundleRef loadBundle(const Str255 frameworkName)
|
2003-09-07 12:11:15 -04:00
|
|
|
{
|
2003-09-21 03:43:02 -04:00
|
|
|
OSStatus err = noErr;
|
|
|
|
FSRefParam fileRefParam;
|
|
|
|
FSRef fileRef;
|
|
|
|
CFURLRef bundleURLOpenGL;
|
2003-09-29 07:58:35 -04:00
|
|
|
CFBundleRef bundle_ref;
|
|
|
|
|
2003-09-21 03:43:02 -04:00
|
|
|
memset(&fileRefParam, 0, sizeof(fileRefParam));
|
|
|
|
memset(&fileRef, 0, sizeof(fileRef));
|
|
|
|
fileRefParam.ioNamePtr = frameworkName;
|
|
|
|
fileRefParam.newRef = &fileRef;
|
|
|
|
|
|
|
|
// Frameworks directory/folder
|
|
|
|
//
|
|
|
|
err = FindFolder (kSystemDomain, kFrameworksFolderType, false, &fileRefParam.ioVRefNum, &fileRefParam.ioDirID);
|
|
|
|
if (noErr != err)
|
|
|
|
{
|
2003-12-20 17:03:25 -05:00
|
|
|
printfDebug("Could not find frameworks folder\n");
|
2003-09-29 07:58:35 -04:00
|
|
|
return NULL;
|
2003-09-21 03:43:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// make FSRef for folder
|
|
|
|
//
|
|
|
|
err = PBMakeFSRefSync (&fileRefParam);
|
|
|
|
|
|
|
|
|
|
|
|
if (noErr != err)
|
|
|
|
{
|
2003-12-20 17:03:25 -05:00
|
|
|
printfDebug("Could make FSref to frameworks folder\n");
|
2003-09-29 07:58:35 -04:00
|
|
|
return NULL;
|
2003-09-21 03:43:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// create URL to folder
|
|
|
|
//
|
|
|
|
bundleURLOpenGL = CFURLCreateFromFSRef (kCFAllocatorDefault, &fileRef);
|
|
|
|
if (!bundleURLOpenGL)
|
|
|
|
{
|
2003-12-20 17:03:25 -05:00
|
|
|
printfDebug("Could create framework URL\n");
|
2003-09-29 07:58:35 -04:00
|
|
|
return NULL;
|
2003-09-21 03:43:02 -04:00
|
|
|
}
|
|
|
|
|
2003-09-29 07:58:35 -04:00
|
|
|
bundle_ref = CFBundleCreate(kCFAllocatorDefault,bundleURLOpenGL);
|
|
|
|
CFRelease (bundleURLOpenGL);
|
|
|
|
if (bundle_ref == NULL)
|
2003-09-21 03:43:02 -04:00
|
|
|
{
|
2003-12-20 17:03:25 -05:00
|
|
|
printfDebug("Could not load framework\n");
|
2003-09-29 07:58:35 -04:00
|
|
|
return NULL;
|
2003-09-21 03:43:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// if the code was successfully loaded, look for our function.
|
2003-09-29 07:58:35 -04:00
|
|
|
if (!CFBundleLoadExecutable(bundle_ref))
|
2003-09-21 03:43:02 -04:00
|
|
|
{
|
2003-12-20 17:03:25 -05:00
|
|
|
printfDebug("Could not load MachO executable\n");
|
2003-09-29 07:58:35 -04:00
|
|
|
CFRelease(bundle_ref);
|
|
|
|
return NULL;
|
2003-09-21 03:43:02 -04:00
|
|
|
}
|
|
|
|
|
2003-09-29 07:58:35 -04:00
|
|
|
return bundle_ref;
|
2003-09-07 12:11:15 -04:00
|
|
|
}
|
|
|
|
|
2003-09-29 07:58:35 -04:00
|
|
|
static void aglUnloadFramework(CFBundleRef f)
|
2003-09-07 12:11:15 -04:00
|
|
|
{
|
2003-09-29 07:58:35 -04:00
|
|
|
CFBundleUnloadExecutable(f);
|
|
|
|
CFRelease(f);
|
2003-09-07 12:11:15 -04:00
|
|
|
}
|
|
|
|
|
2002-12-30 17:06:28 -05:00
|
|
|
#endif
|
|
|
|
|
2004-03-11 07:38:13 -05:00
|
|
|
bool extgl_QueryExtension(JNIEnv *env, jobject ext_set, const GLubyte*extensions, const char *name)
|
2002-11-18 15:02:17 -05:00
|
|
|
{
|
2003-09-21 03:43:02 -04:00
|
|
|
const GLubyte *start;
|
|
|
|
GLubyte *where, *terminator;
|
|
|
|
|
2003-09-26 09:59:50 -04:00
|
|
|
if (extensions == NULL) {
|
2003-12-20 17:03:25 -05:00
|
|
|
printfDebug("NULL extension string\n");
|
2003-09-26 09:59:50 -04:00
|
|
|
return false;
|
|
|
|
}
|
2004-01-20 04:06:00 -05:00
|
|
|
|
2003-09-21 03:43:02 -04:00
|
|
|
/* Extension names should not have spaces. */
|
|
|
|
where = (GLubyte *) strchr(name, ' ');
|
|
|
|
if (where || *name == '\0')
|
2003-09-26 09:59:50 -04:00
|
|
|
return false;
|
2004-01-20 04:06:00 -05:00
|
|
|
|
2003-09-21 03:43:02 -04:00
|
|
|
/* It takes a bit of care to be fool-proof about parsing the
|
|
|
|
OpenGL extensions string. Don't be fooled by sub-strings,
|
|
|
|
etc. */
|
|
|
|
start = extensions;
|
2004-02-15 10:21:24 -05:00
|
|
|
for (;;)
|
2003-09-21 03:43:02 -04:00
|
|
|
{
|
|
|
|
where = (GLubyte *) strstr((const char *) start, name);
|
|
|
|
if (!where)
|
|
|
|
break;
|
|
|
|
terminator = where + strlen(name);
|
|
|
|
if (where == start || *(where - 1) == ' ')
|
2003-09-26 09:59:50 -04:00
|
|
|
if (*terminator == ' ' || *terminator == '\0') {
|
2004-02-23 18:42:58 -05:00
|
|
|
if (ext_set != NULL) {
|
|
|
|
insertExtension(env, ext_set, name);
|
|
|
|
}
|
2003-09-26 09:59:50 -04:00
|
|
|
return true;
|
|
|
|
}
|
2003-09-21 03:43:02 -04:00
|
|
|
start = terminator;
|
|
|
|
}
|
2003-09-26 09:59:50 -04:00
|
|
|
return false;
|
2004-01-20 04:06:00 -05:00
|
|
|
|
2003-09-26 09:59:50 -04:00
|
|
|
}
|
2004-01-20 04:06:00 -05:00
|
|
|
|
2002-11-18 15:02:17 -05:00
|
|
|
|
2002-12-30 17:06:28 -05:00
|
|
|
/*-----------------------------------------------------*/
|
|
|
|
/* AGL stuff BEGIN*/
|
|
|
|
/*-----------------------------------------------------*/
|
2003-09-07 12:11:15 -04:00
|
|
|
#ifdef _AGL
|
2002-12-30 17:06:28 -05:00
|
|
|
|
2004-03-05 17:57:51 -05:00
|
|
|
bool extgl_InitAGL(JNIEnv *env)
|
2003-09-29 05:26:20 -04:00
|
|
|
{
|
|
|
|
aglChoosePixelFormat = (aglChoosePixelFormatPROC)extgl_GetProcAddress("aglChoosePixelFormat");
|
|
|
|
aglDestroyPixelFormat = (aglDestroyPixelFormatPROC)extgl_GetProcAddress("aglDestroyPixelFormat");
|
|
|
|
aglNextPixelFormat = (aglNextPixelFormatPROC)extgl_GetProcAddress("aglNextPixelFormat");
|
|
|
|
aglDescribePixelFormat = (aglDescribePixelFormatPROC)extgl_GetProcAddress("aglDescribePixelFormat");
|
|
|
|
aglDevicesOfPixelFormat = (aglDevicesOfPixelFormatPROC)extgl_GetProcAddress("aglDevicesOfPixelFormat");
|
|
|
|
aglQueryRendererInfo = (aglQueryRendererInfoPROC)extgl_GetProcAddress("aglQueryRendererInfo");
|
|
|
|
aglDestroyRendererInfo = (aglDestroyRendererInfoPROC)extgl_GetProcAddress("aglDestroyRendererInfo");
|
|
|
|
aglNextRendererInfo = (aglNextRendererInfoPROC)extgl_GetProcAddress("aglNextRendererInfo");
|
|
|
|
aglDescribeRenderer = (aglDescribeRendererPROC)extgl_GetProcAddress("aglDescribeRenderer");
|
|
|
|
aglCreateContext = (aglCreateContextPROC)extgl_GetProcAddress("aglCreateContext");
|
|
|
|
aglDestroyContext = (aglDestroyContextPROC)extgl_GetProcAddress("aglDestroyContext");
|
|
|
|
aglCopyContext = (aglCopyContextPROC)extgl_GetProcAddress("aglCopyContext");
|
|
|
|
aglUpdateContext = (aglUpdateContextPROC)extgl_GetProcAddress("aglUpdateContext");
|
|
|
|
aglSetCurrentContext = (aglSetCurrentContextPROC)extgl_GetProcAddress("aglSetCurrentContext");
|
|
|
|
aglGetCurrentContext = (aglGetCurrentContextPROC)extgl_GetProcAddress("aglGetCurrentContext");
|
|
|
|
aglSetDrawable = (aglSetDrawablePROC)extgl_GetProcAddress("aglSetDrawable");
|
|
|
|
aglSetOffScreen = (aglSetOffScreenPROC)extgl_GetProcAddress("aglSetOffScreen");
|
|
|
|
aglSetFullScreen = (aglSetFullScreenPROC)extgl_GetProcAddress("aglSetFullScreen");
|
|
|
|
aglGetDrawable = (aglGetDrawablePROC)extgl_GetProcAddress("aglGetDrawable");
|
|
|
|
aglSetVirtualScreen = (aglSetVirtualScreenPROC)extgl_GetProcAddress("aglSetVirtualScreen");
|
|
|
|
aglGetVirtualScreen = (aglGetVirtualScreenPROC)extgl_GetProcAddress("aglGetVirtualScreen");
|
|
|
|
aglGetVersion = (aglGetVersionPROC)extgl_GetProcAddress("aglGetVersion");
|
|
|
|
aglSwapBuffers = (aglSwapBuffersPROC)extgl_GetProcAddress("aglSwapBuffers");
|
|
|
|
aglEnable = (aglEnablePROC)extgl_GetProcAddress("aglEnable");
|
|
|
|
aglDisable = (aglDisablePROC)extgl_GetProcAddress("aglDisable");
|
|
|
|
aglIsEnabled = (aglIsEnabledPROC)extgl_GetProcAddress("aglIsEnabled");
|
|
|
|
aglSetInteger = (aglSetIntegerPROC)extgl_GetProcAddress("aglSetInteger");
|
|
|
|
aglGetInteger = (aglGetIntegerPROC)extgl_GetProcAddress("aglGetInteger");
|
|
|
|
aglUseFont = (aglUseFontPROC)extgl_GetProcAddress("aglUseFont");
|
|
|
|
aglGetError = (aglGetErrorPROC)extgl_GetProcAddress("aglGetError");
|
|
|
|
aglErrorString = (aglErrorStringPROC)extgl_GetProcAddress("aglErrorString");
|
|
|
|
aglResetLibrary = (aglResetLibraryPROC)extgl_GetProcAddress("aglResetLibrary");
|
|
|
|
aglSurfaceTexture = (aglSurfaceTexturePROC)extgl_GetProcAddress("aglSurfaceTexture");
|
2004-07-03 10:59:15 -04:00
|
|
|
return !extgl_error; // Split out AGL into extgl_agl.cpp like wgl and glx and replace with InitializeFunctions
|
2002-12-30 17:06:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/*-----------------------------------------------------*/
|
|
|
|
/* AGL stuff END*/
|
|
|
|
/*-----------------------------------------------------*/
|
|
|
|
|
2002-12-11 02:16:31 -05:00
|
|
|
/** returns true if the extention is available */
|
2003-09-26 09:59:50 -04:00
|
|
|
static bool GLQueryExtension(JNIEnv *env, jobject ext_set, const char *name)
|
2002-12-11 02:16:31 -05:00
|
|
|
{
|
2004-03-11 07:38:13 -05:00
|
|
|
return extgl_QueryExtension(env, ext_set, glGetString(GL_EXTENSIONS), name);
|
2002-12-11 02:16:31 -05:00
|
|
|
}
|
|
|
|
|
2003-09-29 07:58:35 -04:00
|
|
|
#ifdef _AGL
|
|
|
|
bool extgl_Open(void) {
|
2004-02-28 11:59:30 -05:00
|
|
|
if (opengl_bundle_ref != NULL)
|
|
|
|
return true;
|
2003-09-29 07:58:35 -04:00
|
|
|
opengl_bundle_ref = loadBundle("\pOpenGL.framework");
|
|
|
|
if (opengl_bundle_ref == NULL)
|
|
|
|
return false;
|
|
|
|
agl_bundle_ref = loadBundle("\pAGL.framework");
|
|
|
|
if (agl_bundle_ref == NULL) {
|
|
|
|
aglUnloadFramework(opengl_bundle_ref);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-12-30 02:07:40 -05:00
|
|
|
#ifdef _X11
|
2003-09-26 09:59:50 -04:00
|
|
|
bool extgl_Open()
|
2002-12-23 06:31:32 -05:00
|
|
|
{
|
2004-02-28 11:59:30 -05:00
|
|
|
if (lib_gl_handle != NULL)
|
|
|
|
return true;
|
2003-09-21 03:43:02 -04:00
|
|
|
lib_gl_handle = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL);
|
|
|
|
if (lib_gl_handle == NULL) {
|
2003-12-20 17:03:25 -05:00
|
|
|
printfDebug("Error loading libGL.so.1: %s\n", dlerror());
|
2003-09-26 09:59:50 -04:00
|
|
|
return false;
|
2003-09-21 03:43:02 -04:00
|
|
|
}
|
2004-02-29 03:24:56 -05:00
|
|
|
glXGetProcAddressARB = (glXGetProcAddressARBPROC) dlsym(lib_gl_handle, "glXGetProcAddressARB");
|
|
|
|
if (glXGetProcAddressARB == NULL) {
|
|
|
|
extgl_Close();
|
|
|
|
return false;
|
|
|
|
}
|
2003-09-26 09:59:50 -04:00
|
|
|
return true;
|
2002-12-23 06:31:32 -05:00
|
|
|
}
|
2003-03-30 14:26:39 -05:00
|
|
|
|
2002-12-30 17:06:28 -05:00
|
|
|
#endif /* X11 */
|
2002-12-30 02:07:40 -05:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2003-09-26 09:59:50 -04:00
|
|
|
bool extgl_Open(void)
|
2002-12-23 06:31:32 -05:00
|
|
|
{
|
2004-02-28 11:59:30 -05:00
|
|
|
if (lib_gl_handle != NULL)
|
|
|
|
return true;
|
2003-09-21 03:43:02 -04:00
|
|
|
// load the dynamic libraries for OpenGL
|
|
|
|
lib_gl_handle = LoadLibrary("opengl32.dll");
|
2002-12-11 02:16:31 -05:00
|
|
|
if (lib_gl_handle == NULL)
|
2003-09-26 09:59:50 -04:00
|
|
|
return false;
|
|
|
|
return true;
|
2002-12-30 17:06:28 -05:00
|
|
|
}
|
2003-09-29 07:58:35 -04:00
|
|
|
#endif /* WIN32 */
|
2002-12-11 02:16:31 -05:00
|
|
|
|
|
|
|
void extgl_Close(void)
|
|
|
|
{
|
2002-12-30 02:07:40 -05:00
|
|
|
#ifdef _X11
|
2002-12-11 02:16:31 -05:00
|
|
|
dlclose(lib_gl_handle);
|
2004-02-28 11:59:30 -05:00
|
|
|
lib_gl_handle = NULL;
|
2002-12-30 02:07:40 -05:00
|
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
2002-12-11 02:16:31 -05:00
|
|
|
FreeLibrary(lib_gl_handle);
|
2004-02-28 11:59:30 -05:00
|
|
|
lib_gl_handle = NULL;
|
2002-12-11 02:16:31 -05:00
|
|
|
#endif
|
2003-09-07 12:11:15 -04:00
|
|
|
#ifdef _AGL
|
2003-09-29 07:58:35 -04:00
|
|
|
aglUnloadFramework(opengl_bundle_ref);
|
|
|
|
aglUnloadFramework(agl_bundle_ref);
|
2004-02-28 11:59:30 -05:00
|
|
|
opengl_bundle_ref = NULL;
|
2004-02-15 10:21:24 -05:00
|
|
|
#endif
|
2002-11-18 15:02:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* turn on the warning for the borland compiler*/
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma warn .8064
|
|
|
|
#pragma warn .8065
|
|
|
|
#endif /* __BORLANDC__ */
|
|
|
|
|