From 647e1b2b2983eec00e24b6f6439d7aebbf9ab9d6 Mon Sep 17 00:00:00 2001 From: Gregory Pierce Date: Thu, 8 May 2003 00:53:10 +0000 Subject: [PATCH] Revamped architecture replacing AGL nastiness with cleaner CGL API --- src/native/macosx/RenderingContext.cpp | 183 +++++------------------- src/native/macosx/RenderingContext.h | 5 +- src/native/macosx/org_lwjgl_Display.cpp | 65 +-------- src/native/macosx/org_lwjgl_Sys.cpp | 1 + 4 files changed, 44 insertions(+), 210 deletions(-) diff --git a/src/native/macosx/RenderingContext.cpp b/src/native/macosx/RenderingContext.cpp index 0c7cb5cd..5fee274f 100644 --- a/src/native/macosx/RenderingContext.cpp +++ b/src/native/macosx/RenderingContext.cpp @@ -41,189 +41,76 @@ #include "RenderingContext.h" -#define kMaxDisplays 16 - -CGDirectDisplayID display[kMaxDisplays]; - RenderingContext::RenderingContext() { } bool RenderingContext::createDisplay( int width, int height, int bpp, int freq ) { - InitCursor(); + printf("Creating display"); - SetRect( &rect, 0, 0, width, height ); - windowPtr = NewCWindow( NULL, &rect, "LWJGL", true, kWindowShadowDialogProc, (WindowPtr) -1L, true, 0L ); - - SetPortWindowPort( windowPtr ); - - if ( windowPtr == NULL ) + CGDisplayCapture( kCGDirectMainDisplay ) ; + CGDisplaySwitchToMode( kCGDirectMainDisplay, + CGDisplayBestModeForParameters( kCGDirectMainDisplay, + bpp, width, height, freq ) ) ; + + CGOpenGLDisplayMask displayMask = CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ) ; + CGLPixelFormatAttribute attribs[] = { - printf("Failed to create a window\n"); - return false; - } + kCGLPFAFullScreen, + kCGLPFADisplayMask, + displayMask, + NULL + } ; - ShowWindow( windowPtr ); + CGLPixelFormatObj pixelFormatObj ; + long numPixelFormats ; + + CGLChoosePixelFormat( attribs, &pixelFormatObj, &numPixelFormats ); + + long swapInterval ; + + CGLCreateContext( pixelFormatObj, NULL, &contextObj ) ; + CGLDestroyPixelFormat( pixelFormatObj ) ; + + swapInterval = 1 ; + CGLSetParameter( contextObj, kCGLCPSwapInterval, &swapInterval ) ; + + CGLSetCurrentContext( contextObj ) ; + CGLSetFullScreen( contextObj ) ; + return true; } void RenderingContext::destroyDisplay() { - // cleanup the AGL context - // - - aglSetCurrentContext(NULL); - aglSetDrawable(aglContext, NULL); - aglDestroyContext(aglContext); - - // cleanup the window - // - DisposeWindow( windowPtr ); -} + CGLClearDrawable( contextObj ) ; + CGLDestroyContext( contextObj ) ; -CGDirectDisplayID * RenderingContext::enumerateDisplays() -{ + CGReleaseAllDisplays(); - CGDisplayCount numDisplays; - CGDisplayErr err; - - err = CGGetActiveDisplayList( kMaxDisplays, - display, - &numDisplays ); - - if ( err != CGDisplayNoErr ) - { - printf("Cannot get displays (%d). \n", err ); - } - - return display; -} - -CFArrayRef RenderingContext::enumerateDisplayModes( CGDirectDisplayID display ) -{ - CFArrayRef modeList; - - modeList = CGDisplayAvailableModes( display ); - if ( modeList = NULL ) - { - printf("Error. Display requested is invalid.\n"); - return NULL; - } - - return modeList; -} - - - - -bool RenderingContext::createGL( int colorBits, int alphaBits, int depthBits, int stencilBits ) -{ - - AGLPixelFormat fmt; - GLboolean ok; - GLint attrib[] = { AGL_RGBA, AGL_NONE }; - - - if ( extgl_Open() != 0 ) - { - printf("extgl_Open failed"); - return false; - } - - // Choose an rgb pixel format - // - fmt = aglChoosePixelFormat(NULL, 0, attrib); - if(fmt == NULL) - { - return false; - } - - // Create an AGL context - // - aglContext = aglCreateContext(fmt, NULL); - if( aglContext == NULL) - { - return false; - } - - // Attach the window to the context - // - ok = aglSetDrawable(aglContext, GetWindowPort(windowPtr) ); - if(!ok) - { - return false; - } - - // Make the context the current context - // - ok = aglSetCurrentContext(aglContext); - if(!ok) - { - return false; - } - - if ( extgl_Initialize() != 0 ) - { - printf("Failed to initialize GL [extgl_Initialize()]\n"); - return 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 - - return true; - -} - -void RenderingContext::destroyGL() -{ - // clear out the current rendering context - // - aglSetCurrentContext( NULL ); - - // destroy the context - // - aglDestroyContext( aglContext ); - - // close the gl extension context - // - extgl_Close(); } void RenderingContext::swap() { // swap the rendering buffer // - aglSwapBuffers( aglContext ); + CGLFlushDrawable( contextObj ) } void RenderingContext::makeContextCurrent() { // make the current context the one we have stored // - aglSetCurrentContext( aglContext ); + CGLSetCurrentContext( contextObj ) ; } void RenderingContext::releaseContext() { // release the context // - aglSetCurrentContext( NULL ); + CGLSetCurrentContext( NULL ) ; } RenderingContext::~RenderingContext() diff --git a/src/native/macosx/RenderingContext.h b/src/native/macosx/RenderingContext.h index 78715567..1b8c00e3 100644 --- a/src/native/macosx/RenderingContext.h +++ b/src/native/macosx/RenderingContext.h @@ -44,13 +44,12 @@ #include "extgl.h" -#include #include class RenderingContext { public: - AGLContext aglContext; + CGLContextObj contextObj; WindowPtr windowPtr; Rect rect; @@ -60,8 +59,6 @@ public: bool createDisplay( int width, int height, int bpp, int freq ); void destroyDisplay(); - CGDirectDisplayID * enumerateDisplays(); - CFArrayRef enumerateDisplayModes( CGDirectDisplayID display ); bool createGL( int colorBits, int alphaBits, int depthBits, int stencilBits ); void destroyGL(); diff --git a/src/native/macosx/org_lwjgl_Display.cpp b/src/native/macosx/org_lwjgl_Display.cpp index a475bcf8..94debaae 100644 --- a/src/native/macosx/org_lwjgl_Display.cpp +++ b/src/native/macosx/org_lwjgl_Display.cpp @@ -36,20 +36,6 @@ RenderingContext * renderingContext; -static int numberForKey( CFDictionaryRef desc, CFStringRef key ) -{ - CFNumberRef value; - int num = 0; - - if ( (value = CFDictionaryGetValue(desc, key)) == NULL ) - { - return 0; - } - - CFNumberGetValue( value, kCFNumberIntType, &num ); - return num; -} - /* * Class: org_lwjgl_Display * Method: getAvailableDisplayModes @@ -58,54 +44,23 @@ static int numberForKey( CFDictionaryRef desc, CFStringRef key ) JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_getAvailableDisplayModes (JNIEnv * env, jclass clazz) { - CGDirectDisplayID * displays = renderingContext->enumerateDisplays(); - CFArrayRef modeList = renderingContext->enumerateDisplayModes( displays[0] ); - // count the display modes - // - int cnt = CFArrayGetCount( modeList ); + printf("Getting default display mode - 1024x768x32"); // Allocate an array of DisplayModes big enough jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode"); - // Note the * 16 - this is because we are manufacturing available alpha/depth/stencil combos. - jobjectArray ret = env->NewObjectArray(cnt * 16, displayModeClass, NULL); + jobjectArray ret = env->NewObjectArray(1, displayModeClass, NULL); jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "", "(IIIIIII)V"); - CFDictionaryRef mode; - for ( int i=0; i< cnt; i++ ) - { - mode = CFArrayGetValueAtIndex( modeList, i ); + jobject displayMode = env->NewObject(displayModeClass, displayModeConstructor, + 1024, 768, 32, 0, + 0,0,0 ); - int width = numberForKey( mode, kCGDisplayWidth ); - int height = numberForKey( mode, kCGDisplayHeight ); - int bpp = numberForKey( mode, kCGDisplayBitsPerPixel ); - int refreshRate = numberForKey( mode, kCGDisplayRefreshRate ); + env->SetObjectArrayElement( ret, 0, displayMode ); - if ( bpp <= 8 ) - { - continue; - } - else - { - jobject displayMode; - for ( int depthBits = 0; depthBits <= 24; depthBits += 8 ) - { - for ( int stencilBits = 0; stencilBits <= 8; stencilBits += 8 ) - { - for ( int alphaBits = 0; alphaBits <= 8; alphaBits += 8 ) - { - displayMode = env->NewObject(displayModeClass, displayModeConstructor, - width, height, bpp, refreshRate, - alphaBits, depthBits, stencilBits ); - - env->SetObjectArrayElement( ret, i, displayMode ); - } - } - } - } - } + return ret; } /* @@ -116,10 +71,6 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_getAvailableDisplayModes JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate (JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, jboolean debug) { -#ifdef _DEBUG - printf("Creating display: size %dx%d %dhz %dbpp...\n", width, height, freq, bpp); -#endif - renderingContext = new RenderingContext(); renderingContext->createDisplay( width, height, bpp, freq ); @@ -128,9 +79,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I"); env->SetStaticIntField(clazz, fid_handle, (jint) renderingContext->windowPtr ); -#ifdef _DEBUG printf("Display created\n"); -#endif return JNI_TRUE; } diff --git a/src/native/macosx/org_lwjgl_Sys.cpp b/src/native/macosx/org_lwjgl_Sys.cpp index 65fe198f..d2a1a215 100644 --- a/src/native/macosx/org_lwjgl_Sys.cpp +++ b/src/native/macosx/org_lwjgl_Sys.cpp @@ -130,6 +130,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setTime JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority (JNIEnv * env, jclass clazz, jint priority) { + printf("Not supported on OSX \n"); } /*