Updated to include the dynamic loading of the OpenGL.framework and use function pointers so OpenGL functions can be called.

This commit is contained in:
Gregory Pierce 2002-12-30 22:06:28 +00:00
parent 951ed1bc07
commit ed5dc9487c
4 changed files with 196 additions and 19 deletions

View File

@ -268,7 +268,6 @@ glGetPixelMapusvPROC glGetPixelMapusv = NULL;
glGetPointervPROC glGetPointerv = NULL;
glGetPolygonStipplePROC glGetPolygonStipple = NULL;
glGetStringPROC glGetString = NULL;
//const GLubyte * glGetString(const GLenum name);
glGetTexEnvfvPROC glGetTexEnvfv = NULL;
glGetTexEnvivPROC glGetTexEnviv = NULL;
glGetTexGendvPROC glGetTexGendv = NULL;
@ -376,7 +375,6 @@ glRasterPos3dvPROC glRasterPos3dv = NULL;
glRasterPos3fPROC glRasterPos3f = NULL;
glRasterPos3fvPROC glRasterPos3fv = NULL;
glRasterPos3iPROC glRasterPos3i = NULL;
glRasterPos3ivPROC glRasterPos3iv = NULL;
glRasterPos3sPROC glRasterPos3s = NULL;
glRasterPos3svPROC glRasterPos3sv = NULL;
@ -776,6 +774,10 @@ glXAllocateMemoryNVPROC glXAllocateMemoryNV = NULL;
glXFreeMemoryNVPROC glXFreeMemoryNV = NULL;
#endif /* X11 */
#ifdef _OSX
// TODO: find the OSX equivalent of these functions
#endif /* OSX */
#endif /* GL_NV_vertex_array_range */
/* EXT_point_parameters */
@ -1325,8 +1327,6 @@ static int extgl_error = 0;
struct ExtensionTypes extgl_Extensions;
struct ExtensionTypes SupportedExtensions; /* deprecated, please do not use */
#ifdef _WIN32
HMODULE lib_gl_handle = NULL;
HMODULE lib_glu_handle = NULL;
@ -1337,6 +1337,12 @@ void * lib_gl_handle = NULL;
void * lib_glu_handle = NULL;
#endif
#ifdef _OSX
// Note: Not used, there is a CFBundleRef in the header file that handles the
// dynamic load from the GL Framework bundle and this framework include gl
// and glu in the same library
#endif
/* getProcAddress */
void *extgl_GetProcAddress(char *name)
@ -1371,6 +1377,12 @@ void *extgl_GetProcAddress(char *name)
}
return t;
#endif
#ifdef _OSX
void *t =(void *)aglGetProcAddress(name);
return t;
#endif
}
/*-----------------------------------------------------*/
@ -1523,6 +1535,23 @@ int extgl_InitializeWGL()
/* WGL stuff END*/
/*-----------------------------------------------------*/
/*-----------------------------------------------------*/
/* AGL stuff BEGIN*/
/*-----------------------------------------------------*/
#ifdef _OSX
int extgl_InitializeWGL()
{
// add in AGL extensions here
return 0;
}
#endif
/*-----------------------------------------------------*/
/* AGL stuff END*/
/*-----------------------------------------------------*/
int QueryExtension(const GLubyte*extensions, const char *name)
{
const GLubyte *start;
@ -3199,7 +3228,11 @@ int extgl_Initialize()
extgl_InitializeWGL();
#endif
SupportedExtensions = extgl_Extensions;
#ifdef _OSX
/* load AGL extensions */
extgl_InitializeAGL();
#endif
return extgl_error;
}
@ -3217,12 +3250,13 @@ int extgl_Open(Display *disp, int screen)
return 1;
return 0;
}
#endif
#endif /* X11 */
#ifdef _WIN32
int extgl_Open(void)
{
// load the dynamic libraries for OpenGL
//
lib_gl_handle = LoadLibrary("opengl32.dll");
if (lib_gl_handle == NULL)
return 1;
@ -3231,7 +3265,25 @@ int extgl_Open(void)
return 1;
return 0;
}
#endif
#endif /* WIN32 */
#ifdef _OSX
int extgl_Open(void)
{
OSStatus err = aglInitEntryPoints();
if ( noErr != err )
{
// if we encountered an error while initializing OpenGL
// we're hosed - return
//
return 1;
}
// open gl framework initialized just fine
//
return 0;
}
#endif /* OSX */
void extgl_Close(void)
{
@ -3243,12 +3295,9 @@ void extgl_Close(void)
FreeLibrary(lib_gl_handle);
FreeLibrary(lib_glu_handle);
#endif
}
/* deprecated function please do not use it, use extgl_Initialize() instead */
int glInitialize()
{
return extgl_Initialize();
#ifdef _OSX
aglDellocEntryPoints();
#endif
}
/* turn on the warning for the borland compiler*/

View File

@ -319,7 +319,95 @@ extern glXGetClientStringPROC glXGetClientString;
extern glXQueryServerStringPROC glXQueryServerString;
extern glXQueryExtensionsStringPROC glXQueryExtensionsString;
#endif
#endif /* X11 */
#ifdef _OSX
#include <Carbon/Carbon.h>
CFBundleRef gBundleRefOpenGL = NULL;
// -------------------------
OSStatus aglInitEntryPoints (void)
{
OSStatus err = noErr;
const Str255 frameworkName = "\pOpenGL.framework";
FSRefParam fileRefParam;
FSRef fileRef;
CFURLRef bundleURLOpenGL;
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)
{
DebugStr ("\pCould not find frameworks folder");
return err;
}
// make FSRef for folder
//
err = PBMakeFSRefSync (&fileRefParam);
if (noErr != err)
{
DebugStr ("\pCould make FSref to frameworks folder");
return err;
}
// create URL to folder
//
bundleURLOpenGL = CFURLCreateFromFSRef (kCFAllocatorDefault, &fileRef);
if (!bundleURLOpenGL)
{
DebugStr ("\pCould create OpenGL Framework bundle URL");
return paramErr;
}
// create ref to GL's bundle
//
gBundleRefOpenGL = CFBundleCreate (kCFAllocatorDefault,bundleURLOpenGL);
if (!gBundleRefOpenGL)
{
DebugStr ("\pCould not create OpenGL Framework bundle");
return paramErr;
}
// release created bundle
//
CFRelease (bundleURLOpenGL);
// if the code was successfully loaded, look for our function.
if (!CFBundleLoadExecutable (gBundleRefOpenGL))
{
DebugStr ("\pCould not load MachO executable");
return paramErr;
}
return err;
}
void aglDellocEntryPoints (void)
{
if (gBundleRefOpenGL != NULL)
{
// unload the bundle's code.
CFBundleUnloadExecutable (gBundleRefOpenGL);
CFRelease (gBundleRefOpenGL);
gBundleRefOpenGL = NULL;
}
}
void * aglGetProcAddress (char * pszProc)
{
return CFBundleGetFunctionPointerForName (gBundleRefOpenGL,CFStringCreateWithCStringNoCopy (NULL, pszProc, CFStringGetSystemEncoding (), NULL));
}
#endif /* OSX */
/*************************************************************/
/* GLU functions */
@ -5441,7 +5529,6 @@ extern wglGetCurrentReadDCARBPROC wglGetCurrentReadDCARB;
/* I use int here because C does not know bool */
#ifdef _WIN32
struct WGLExtensionTypes
{
int ARB_buffer_region;
@ -5456,11 +5543,9 @@ struct WGLExtensionTypes
int NV_render_depth_texture;
int NV_render_texture_rectangle;
};
#endif /* WIN32 */
#ifdef _X11
struct GLXExtensionTypes
{
int GLX12;
@ -5468,9 +5553,14 @@ struct GLXExtensionTypes
int EXT_visual_info;
int EXT_visual_rating;
};
#endif /* X11 */
#ifdef _OSX
struct AGLExtensionTypes
{
};
#endif;
struct GLUExtensionTypes
{
int GLU12;
@ -5487,6 +5577,10 @@ struct ExtensionTypes
#ifdef _X11
struct GLXExtensionTypes glx;
#endif /* X11 */
#ifdef _OSX
struct AGLExtensionTypes agl;
#endif /* OSX */
struct GLUExtensionTypes glu;
int ARB_imaging;
int ARB_depth_texture;
@ -5590,6 +5684,10 @@ int extgl_Open(Display *disp, int screen);
int extgl_Open(void);
#endif
#ifdef _OSX
int extgl_Open(void);
#endif
void extgl_Close(void);
int glInitialize(); /* deprecated, please do not use */

View File

@ -63,6 +63,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate
printf("Creating display: size %dx%d %dhz %dbpp...\n", width, height, freq, bpp);
#endif
renderingContext = new RenderingContext();
InitCursor();

View File

@ -39,6 +39,7 @@
* @version $Revision$
*/
#define _OSX
#include "extgl.h"
#include "org_lwjgl_opengl_BaseGL.h"
#include "RenderingContext.h"
@ -56,6 +57,12 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
AGLPixelFormat fmt;
GLboolean ok;
GLint attrib[] = { AGL_RGBA, AGL_NONE };
if ( extgl_Open() != 0 )
{
printf("extgl_Open failed");
return JNI_FALSE;
}
/* Choose an rgb pixel format */
fmt = aglChoosePixelFormat(NULL, 0, attrib);
@ -85,8 +92,26 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
return JNI_FALSE;
}
if ( extgl_Initialize() != 0 )
{
printf("Failed to initialize GL [extgl_Initialize()]\n");
return JNI_FALSE;
}
/* Pixel format is no longer needed */
aglDestroyPixelFormat(fmt);
#ifdef _DEBUG
char * p = (char * ) glGetString( GL_EXTENSIONS );
if ( NULL == p )
{
printf("NO extensions available");
}
else
{
printf("Available extensions:\n%s\n", p);
}
#endif /* DEBUG */
return JNI_TRUE;
}
@ -106,6 +131,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy
// destroy the context
//
aglDestroyContext( renderingContext->aglContext );
// close the gl extension context
//
extgl_Close();
}
/*