Added changes to support the selection of display modes on OSX in multiple monitor configurations. Currently defaults to only getting the display modes of display[0] - the primary display since lwjgl doesn't yet support clean multi monitor configuration programatically.
This code based off the Apple provided sample code at http://developer.apple.com/samplecode/Sample_Code/Graphics_2D/Mode.htm
This commit is contained in:
parent
0f223b7e65
commit
529748c7b7
|
@ -41,6 +41,10 @@
|
||||||
|
|
||||||
#include "RenderingContext.h"
|
#include "RenderingContext.h"
|
||||||
|
|
||||||
|
#define kMaxDisplays 16
|
||||||
|
|
||||||
|
CGDirectDisplayID display[kMaxDisplays];
|
||||||
|
|
||||||
RenderingContext::RenderingContext()
|
RenderingContext::RenderingContext()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -79,6 +83,41 @@ void RenderingContext::destroyDisplay()
|
||||||
DisposeWindow( windowPtr );
|
DisposeWindow( windowPtr );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGDirectDisplayID * RenderingContext::enumerateDisplays()
|
||||||
|
{
|
||||||
|
|
||||||
|
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 )
|
bool RenderingContext::createGL( int colorBits, int alphaBits, int depthBits, int stencilBits )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
|
|
||||||
#include "extgl.h"
|
#include "extgl.h"
|
||||||
#include <Carbon/Carbon.h>
|
#include <Carbon/Carbon.h>
|
||||||
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
|
||||||
class RenderingContext
|
class RenderingContext
|
||||||
{
|
{
|
||||||
|
@ -59,6 +60,8 @@ public:
|
||||||
|
|
||||||
bool createDisplay( int width, int height, int bpp, int freq );
|
bool createDisplay( int width, int height, int bpp, int freq );
|
||||||
void destroyDisplay();
|
void destroyDisplay();
|
||||||
|
CGDirectDisplayID * enumerateDisplays();
|
||||||
|
CFArrayRef enumerateDisplayModes( CGDirectDisplayID display );
|
||||||
|
|
||||||
bool createGL( int colorBits, int alphaBits, int depthBits, int stencilBits );
|
bool createGL( int colorBits, int alphaBits, int depthBits, int stencilBits );
|
||||||
void destroyGL();
|
void destroyGL();
|
||||||
|
|
|
@ -36,6 +36,20 @@
|
||||||
|
|
||||||
RenderingContext * renderingContext;
|
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
|
* Class: org_lwjgl_Display
|
||||||
* Method: getAvailableDisplayModes
|
* Method: getAvailableDisplayModes
|
||||||
|
@ -44,7 +58,54 @@ RenderingContext * renderingContext;
|
||||||
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_getAvailableDisplayModes
|
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_getAvailableDisplayModes
|
||||||
(JNIEnv * env, jclass clazz)
|
(JNIEnv * env, jclass clazz)
|
||||||
{
|
{
|
||||||
return NULL;
|
CGDirectDisplayID * displays = renderingContext->enumerateDisplays();
|
||||||
|
CFArrayRef modeList = renderingContext->enumerateDisplayModes( displays[0] );
|
||||||
|
|
||||||
|
// count the display modes
|
||||||
|
//
|
||||||
|
int cnt = CFArrayGetCount( modeList );
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIIIIII)V");
|
||||||
|
|
||||||
|
CFDictionaryRef mode;
|
||||||
|
for ( int i=0; i< cnt; i++ )
|
||||||
|
{
|
||||||
|
mode = CFArrayGetValueAtIndex( modeList, i );
|
||||||
|
|
||||||
|
int width = numberForKey( mode, kCGDisplayWidth );
|
||||||
|
int height = numberForKey( mode, kCGDisplayHeight );
|
||||||
|
int bpp = numberForKey( mode, kCGDisplayBitsPerPixel );
|
||||||
|
int refreshRate = numberForKey( mode, kCGDisplayRefreshRate );
|
||||||
|
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -67,6 +128,10 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate
|
||||||
jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I");
|
jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I");
|
||||||
env->SetStaticIntField(clazz, fid_handle, (jint) renderingContext->windowPtr );
|
env->SetStaticIntField(clazz, fid_handle, (jint) renderingContext->windowPtr );
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("Display created\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
return JNI_TRUE;
|
return JNI_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,9 +42,6 @@
|
||||||
#include "RenderingContext.h"
|
#include "RenderingContext.h"
|
||||||
#include "org_lwjgl_opengl_BaseGL.h"
|
#include "org_lwjgl_opengl_BaseGL.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_lwjgl_opengl_BaseGL
|
* Class: org_lwjgl_opengl_BaseGL
|
||||||
* Method: nCreate
|
* Method: nCreate
|
||||||
|
|
Loading…
Reference in New Issue