Finishing up changes to the Display and BaseGL classes.
This commit is contained in:
parent
4d10d662ec
commit
4766bd1c85
|
@ -1,121 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are
|
|
||||||
* met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
|
||||||
* its contributors may be used to endorse or promote products derived
|
|
||||||
* from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND 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 THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $Id$
|
|
||||||
*
|
|
||||||
* OSX rendering context management.
|
|
||||||
*
|
|
||||||
* @author Gregory Pierce <me@gregorypierce.com>
|
|
||||||
* @version $Revision$
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "RenderingContext.h"
|
|
||||||
#include <ApplicationServices/ApplicationServices.h>
|
|
||||||
#include <OpenGL/OpenGL.h>
|
|
||||||
|
|
||||||
RenderingContext::RenderingContext()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderingContext::createDisplay( int width, int height, int bpp, int freq )
|
|
||||||
{
|
|
||||||
printf("Creating display");
|
|
||||||
|
|
||||||
|
|
||||||
CGDisplayCapture( kCGDirectMainDisplay ) ;
|
|
||||||
CGDisplaySwitchToMode( kCGDirectMainDisplay,
|
|
||||||
CGDisplayBestModeForParameters( kCGDirectMainDisplay,
|
|
||||||
bpp, width, height, freq ) ) ;
|
|
||||||
|
|
||||||
CGOpenGLDisplayMask displayMask = CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ) ;
|
|
||||||
CGLPixelFormatAttribute attribs[] =
|
|
||||||
{
|
|
||||||
kCGLPFAFullScreen,
|
|
||||||
kCGLPFADisplayMask,
|
|
||||||
displayMask,
|
|
||||||
NULL
|
|
||||||
} ;
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
CGLClearDrawable( contextObj ) ;
|
|
||||||
CGLDestroyContext( contextObj ) ;
|
|
||||||
|
|
||||||
CGReleaseAllDisplays();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderingContext::swap()
|
|
||||||
{
|
|
||||||
// swap the rendering buffer
|
|
||||||
//
|
|
||||||
CGLFlushDrawable( contextObj );
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderingContext::makeContextCurrent()
|
|
||||||
{
|
|
||||||
// make the current context the one we have stored
|
|
||||||
//
|
|
||||||
CGLSetCurrentContext( contextObj ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderingContext::releaseContext()
|
|
||||||
{
|
|
||||||
// release the context
|
|
||||||
//
|
|
||||||
CGLSetCurrentContext( NULL ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderingContext::~RenderingContext()
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are
|
|
||||||
* met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
|
||||||
* its contributors may be used to endorse or promote products derived
|
|
||||||
* from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND 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 THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $Id$
|
|
||||||
*
|
|
||||||
* OSX rendering context management.
|
|
||||||
*
|
|
||||||
* @author Gregory Pierce <me@gregorypierce.com>
|
|
||||||
* @version $Revision$
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _RENDERING_CONTEXT_H
|
|
||||||
#define _RENDERING_CONTEXT_H
|
|
||||||
|
|
||||||
|
|
||||||
#include "extgl.h"
|
|
||||||
#include <ApplicationServices/ApplicationServices.h>
|
|
||||||
#include <OpenGL/OpenGL.h>
|
|
||||||
|
|
||||||
class RenderingContext
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CGLContextObj contextObj;
|
|
||||||
WindowPtr windowPtr;
|
|
||||||
Rect rect;
|
|
||||||
|
|
||||||
|
|
||||||
RenderingContext();
|
|
||||||
~RenderingContext();
|
|
||||||
|
|
||||||
bool createDisplay( int width, int height, int bpp, int freq );
|
|
||||||
void destroyDisplay();
|
|
||||||
|
|
||||||
bool createGL( int colorBits, int alphaBits, int depthBits, int stencilBits );
|
|
||||||
void destroyGL();
|
|
||||||
|
|
||||||
void swap();
|
|
||||||
void makeContextCurrent();
|
|
||||||
void releaseContext();
|
|
||||||
};
|
|
||||||
|
|
||||||
extern RenderingContext * renderingContext;
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -32,77 +32,232 @@
|
||||||
|
|
||||||
#include "org_lwjgl_Display.h"
|
#include "org_lwjgl_Display.h"
|
||||||
#include <JavaVM/jni.h>
|
#include <JavaVM/jni.h>
|
||||||
#include "RenderingContext.h"
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
#include <OpenGL/OpenGL.h>
|
||||||
|
|
||||||
RenderingContext * renderingContext;
|
bool modeSet = false;
|
||||||
|
|
||||||
/*
|
static long _getDictLong (CFDictionaryRef refDict, CFStringRef key)
|
||||||
* Class: org_lwjgl_Display
|
|
||||||
* Method: getAvailableDisplayModes
|
|
||||||
* Signature: ()[Lorg/lwjgl/DisplayMode;
|
|
||||||
*/
|
|
||||||
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_getAvailableDisplayModes
|
|
||||||
(JNIEnv * env, jclass clazz)
|
|
||||||
{
|
{
|
||||||
|
long int_value;
|
||||||
|
|
||||||
printf("Getting default display mode - 1024x768x32");
|
CFNumberRef number_value = (CFNumberRef) CFDictionaryGetValue(refDict, key);
|
||||||
|
|
||||||
|
if (!number_value)
|
||||||
|
{
|
||||||
|
// if can't get a number for the dictionary
|
||||||
|
return -1; // fail
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CFNumberGetValue(number_value, kCFNumberLongType, &int_value))
|
||||||
|
{
|
||||||
|
// or if cant convert it
|
||||||
|
return -1; // fail
|
||||||
|
}
|
||||||
|
|
||||||
|
return int_value; // otherwise return the long value
|
||||||
|
}
|
||||||
|
|
||||||
|
static double _getDictDouble (CFDictionaryRef refDict, CFStringRef key)
|
||||||
|
{
|
||||||
|
double double_value;
|
||||||
|
|
||||||
|
CFNumberRef number_value = (CFNumberRef) CFDictionaryGetValue(refDict, key);
|
||||||
|
|
||||||
|
if (!number_value)
|
||||||
|
{
|
||||||
|
// if can't get a number for the dictionary
|
||||||
|
return -1; // fail
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CFNumberGetValue(number_value, kCFNumberDoubleType, &double_value)) // or if cant convert it
|
||||||
|
{
|
||||||
|
return -1; // fail
|
||||||
|
}
|
||||||
|
|
||||||
|
return double_value; // otherwise return the long value
|
||||||
|
}
|
||||||
|
|
||||||
|
jobjectArray GetAvailableDisplayModesOSX(JNIEnv * env)
|
||||||
|
{
|
||||||
|
CFIndex i, count, availableModes;
|
||||||
|
CFArrayRef displayModes = NULL;
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
|
||||||
|
displayModes = CGDisplayAvailableModes( kCGDirectMainDisplay );
|
||||||
|
count = CFArrayGetCount( displayModes );
|
||||||
|
|
||||||
|
printf("Found %d displaymodes\n", count );
|
||||||
|
|
||||||
|
// get a count of the number of display modes on this machine with a bpp greater than 8
|
||||||
|
//
|
||||||
|
for ( i = 0; i < count; i++ )
|
||||||
|
{
|
||||||
|
CFDictionaryRef modeDict = CFArrayGetValueAtIndex( displayModes, i );
|
||||||
|
long bpp = _getDictLong( modeDict, kCGDisplayBitsPerPixel );
|
||||||
|
|
||||||
|
if ( bpp > 8 )
|
||||||
|
{
|
||||||
|
availableModes ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now that we have the count create the classes, and add 'em all - we'll remove dups in Java
|
||||||
// Allocate an array of DisplayModes big enough
|
// Allocate an array of DisplayModes big enough
|
||||||
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
|
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
|
||||||
|
|
||||||
jobjectArray ret = env->NewObjectArray(1, displayModeClass, NULL);
|
jobjectArray ret = env->NewObjectArray( availableModes, displayModeClass, NULL);
|
||||||
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIIIIII)V");
|
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
|
||||||
|
|
||||||
jobject displayMode = env->NewObject(displayModeClass, displayModeConstructor,
|
for ( i = 0; i < count; i++ )
|
||||||
1024, 768, 32, 0,
|
{
|
||||||
0,0,0 );
|
CFDictionaryRef modeDict = CFArrayGetValueAtIndex( displayModes, i );
|
||||||
|
long width = _getDictLong( modeDict, kCGDisplayWidth );
|
||||||
|
long height = _getDictLong( modeDict, kCGDisplayHeight );
|
||||||
|
long freq = (long)(_getDictDouble( modeDict, kCGDisplayRefreshRate ) + 0.5 );
|
||||||
|
long bpp = _getDictLong( modeDict, kCGDisplayBitsPerPixel );
|
||||||
|
|
||||||
env->SetObjectArrayElement( ret, 0, displayMode );
|
if ( bpp > 8 )
|
||||||
|
{
|
||||||
|
jobject displayMode;
|
||||||
|
displayMode = env->NewObject(displayModeClass, displayModeConstructor,
|
||||||
|
width, height,
|
||||||
|
bpp, freq);
|
||||||
|
|
||||||
|
env->SetObjectArrayElement(ret, n++, displayMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_lwjgl_Display
|
|
||||||
* Method: nCreate
|
|
||||||
* Signature: (IIIIZ)Z
|
|
||||||
*/
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate
|
|
||||||
(JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, jboolean debug)
|
|
||||||
{
|
|
||||||
renderingContext = new RenderingContext();
|
|
||||||
|
|
||||||
renderingContext->createDisplay( width, height, bpp, freq );
|
|
||||||
|
|
||||||
|
|
||||||
jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I");
|
|
||||||
env->SetStaticIntField(clazz, fid_handle, (jint) renderingContext->windowPtr );
|
|
||||||
|
|
||||||
printf("Display created\n");
|
|
||||||
|
|
||||||
return JNI_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_lwjgl_Display
|
* Class: org_lwjgl_Display
|
||||||
* Method: nDestroy
|
* Method: init
|
||||||
* Signature: ()V
|
* Signature: ()V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_init
|
||||||
(JNIEnv * env, jclass clazz)
|
(JNIEnv * env, jclass clazz)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
//TODO Get the current display mode from the system
|
||||||
printf("Destroying display\n");
|
//
|
||||||
#endif
|
int width = 640;
|
||||||
|
int height = 480;
|
||||||
|
int bpp = 32;
|
||||||
|
int freq = 60;
|
||||||
|
|
||||||
renderingContext->destroyDisplay();
|
jclass jclass_DisplayMode = env->FindClass("org/lwjgl/DisplayMode");
|
||||||
|
jmethodID ctor = env->GetMethodID(jclass_DisplayMode, "<init>", "(IIII)V");
|
||||||
|
jobject newMode = env->NewObject(jclass_DisplayMode, ctor, width, height, bpp, freq);
|
||||||
|
jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;");
|
||||||
|
env->SetStaticObjectField(clazz, fid_initialMode, newMode);
|
||||||
|
env->DeleteLocalRef(newMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
/*
|
||||||
printf("Destroyed display\n");
|
* Class: org_lwjgl_Display
|
||||||
#endif
|
* Method: setDisplayMode
|
||||||
|
* Signature: (Lorg/lwjgl/DisplayMode;)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode
|
||||||
|
(JNIEnv * env, jclass clazz, jobject mode)
|
||||||
|
{
|
||||||
|
jclass cls_displayMode = env->FindClass("org/lwjgl/DisplayMode");
|
||||||
|
jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I");
|
||||||
|
jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I");
|
||||||
|
jfieldID fid_bpp = env->GetFieldID(cls_displayMode, "bpp", "I");
|
||||||
|
jfieldID fid_freq = env->GetFieldID(cls_displayMode, "freq", "I");
|
||||||
|
|
||||||
|
int width = env->GetIntField(mode, fid_width);
|
||||||
|
int height = env->GetIntField(mode, fid_height);
|
||||||
|
int bpp = env->GetIntField(mode, fid_bpp);
|
||||||
|
int freq = env->GetIntField(mode, fid_freq);
|
||||||
|
|
||||||
|
CFDictionaryRef displayMode;
|
||||||
|
displayMode = CGDisplayBestModeForParametersAndRefreshRate( kCGDirectMainDisplay,
|
||||||
|
bpp,
|
||||||
|
width, height,
|
||||||
|
freq,
|
||||||
|
NULL );
|
||||||
|
CGDisplaySwitchToMode( kCGDirectMainDisplay, displayMode ) ;
|
||||||
|
|
||||||
|
// The change was successful but might not be the exact change we were expecting.
|
||||||
|
// Now we'll construct a new DisplayMode instance and stash it back in the Display
|
||||||
|
// class's mode instance variable.
|
||||||
|
|
||||||
|
jmethodID ctor = env->GetMethodID(cls_displayMode, "<init>", "(IIII)V");
|
||||||
|
jobject newMode = env->NewObject(cls_displayMode, ctor, width, height, bpp, freq);
|
||||||
|
jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;");
|
||||||
|
env->SetStaticObjectField(clazz, fid_initialMode, newMode);
|
||||||
|
env->DeleteLocalRef(newMode);
|
||||||
|
|
||||||
|
modeSet = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_lwjgl_Display
|
||||||
|
* Method: resetDisplayMode
|
||||||
|
* Signature: ()V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode
|
||||||
|
(JNIEnv *, jclass)
|
||||||
|
{
|
||||||
|
// the purpose of this method is to return the display mode to whatever it was before
|
||||||
|
// the application takes over. OSX is smart enough to not require any of this
|
||||||
|
// foolishness :)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_lwjgl_Display
|
||||||
|
* Method: nGetAvailableDisplayModes
|
||||||
|
* Signature: ()[Lorg/lwjgl/DisplayMode;
|
||||||
|
*/
|
||||||
|
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
|
||||||
|
(JNIEnv * env, jclass clazz)
|
||||||
|
{
|
||||||
|
return GetAvailableDisplayModesOSX( env );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_lwjgl_Display
|
||||||
|
* Method: getPlatform
|
||||||
|
* Signature: ()I
|
||||||
|
*/
|
||||||
|
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getPlatform
|
||||||
|
(JNIEnv * env, jclass clazz)
|
||||||
|
{
|
||||||
|
return org_lwjgl_Display_PLATFORM_AGL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_lwjgl_Display
|
||||||
|
* Method: getGammaRamp
|
||||||
|
* Signature: ([I[I[I)Z
|
||||||
|
*/
|
||||||
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_getGammaRamp
|
||||||
|
(JNIEnv *, jclass, jintArray, jintArray, jintArray)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_lwjgl_Display
|
||||||
|
* Method: setGammaRamp
|
||||||
|
* Signature: ([I[I[I)Z
|
||||||
|
*/
|
||||||
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_setGammaRamp
|
||||||
|
(JNIEnv *, jclass, jintArray, jintArray, jintArray)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,31 +39,88 @@
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "RenderingContext.h"
|
|
||||||
#include "org_lwjgl_opengl_BaseGL.h"
|
#include "org_lwjgl_opengl_BaseGL.h"
|
||||||
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
#include <OpenGL/OpenGL.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
CGDirectDisplayID displayID;
|
||||||
|
CGLContextObj contextObj;
|
||||||
|
|
||||||
|
CGGammaValue redMin, redMax, redGamma,
|
||||||
|
greenMin, greenMax, greenGamma,
|
||||||
|
blueMin, blueMax, blueGamma;
|
||||||
|
} RenderingContext;
|
||||||
|
|
||||||
|
static RenderingContext * renderingContext;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_lwjgl_opengl_BaseGL
|
* Class: org_lwjgl_opengl_BaseGL
|
||||||
* Method: nCreate
|
* Method: nCreate
|
||||||
* Signature: (IIII)Z
|
* Signature: (Ljava/lang/String;IIIIIIIIZ)V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
|
||||||
(JNIEnv * env, jobject obj, jint colorBits, jint alphaBits, jint depthBits, jint stencilBits)
|
(JNIEnv * env, jobject obj, jstring title, jint x, jint y, jint width, jint height, jint bpp, jint alpha, jint depth, jint stencil, jboolean fullscreen)
|
||||||
{
|
{
|
||||||
renderingContext->createGL( colorBits, alphaBits, depthBits, stencilBits );
|
if ( CGDisplayCapture( renderingContext->displayID ) != kCGErrorSuccess )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return JNI_TRUE;
|
CGDisplayHideCursor( renderingContext->displayID );
|
||||||
|
CGDisplayMoveCursorToPoint( renderingContext->displayID, CGPointZero );
|
||||||
|
CGAssociateMouseAndMouseCursorPosition( FALSE );
|
||||||
|
|
||||||
|
CGLPixelFormatObj pixelFormatObj;
|
||||||
|
long numPixelFormats;
|
||||||
|
|
||||||
|
CFDictionaryRef displayMode;
|
||||||
|
displayMode = CGDisplayBestModeForParametersAndRefreshRate( kCGDirectMainDisplay,
|
||||||
|
bpp,
|
||||||
|
width, height,
|
||||||
|
60,
|
||||||
|
NULL );
|
||||||
|
|
||||||
|
CGDisplaySwitchToMode( kCGDirectMainDisplay, displayMode );
|
||||||
|
|
||||||
|
CGLPixelFormatAttribute attribs[2];
|
||||||
|
attribs[0] = kCGLPFAFullScreen;
|
||||||
|
attribs[1] = NULL;
|
||||||
|
|
||||||
|
CGLChoosePixelFormat( attribs, &pixelFormatObj, &numPixelFormats );
|
||||||
|
if ( pixelFormatObj != NULL )
|
||||||
|
{
|
||||||
|
CGLCreateContext( pixelFormatObj, NULL, &renderingContext->contextObj );
|
||||||
|
CGLDestroyPixelFormat( pixelFormatObj );
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLSetCurrentContext( renderingContext->contextObj );
|
||||||
|
CGLSetFullScreen( renderingContext->contextObj );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_lwjgl_opengl_BaseGL
|
* Class: org_lwjgl_opengl_BaseGL
|
||||||
* Method: nDestroy
|
* Method: nDestroyGL
|
||||||
* Signature: ()V
|
* Signature: ()V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroyGL
|
||||||
(JNIEnv * env, jobject obj)
|
(JNIEnv * env, jobject obj)
|
||||||
{
|
{
|
||||||
renderingContext->destroyGL();
|
if ( renderingContext->contextObj != NULL )
|
||||||
|
{
|
||||||
|
CGLSetCurrentContext( NULL );
|
||||||
|
CGLClearDrawable( renderingContext->contextObj );
|
||||||
|
CGLDestroyContext( renderingContext->contextObj );
|
||||||
|
|
||||||
|
renderingContext->contextObj = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
CGAssociateMouseAndMouseCursorPosition( TRUE );
|
||||||
|
CGDisplayShowCursor( kCGDirectMainDisplay );
|
||||||
|
|
||||||
|
CGReleaseAllDisplays();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -71,29 +128,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy
|
||||||
* Method: swapBuffers
|
* Method: swapBuffers
|
||||||
* Signature: ()V
|
* Signature: ()V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers(JNIEnv * env, jobject obj)
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers
|
||||||
|
(JNIEnv *, jobject)
|
||||||
{
|
{
|
||||||
renderingContext->swap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_lwjgl_opengl_BaseGL
|
|
||||||
* Method: nMakeCurrent
|
|
||||||
* Signature: ()V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nMakeCurrent
|
|
||||||
(JNIEnv * env, jobject obj)
|
|
||||||
{
|
|
||||||
renderingContext->makeContextCurrent();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* * Class: org_lwjgl_opengl_BaseGL
|
|
||||||
* * Method: nFreeContext
|
|
||||||
* * Signature: ()V
|
|
||||||
* */
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nReleaseContext
|
|
||||||
(JNIEnv *, jobject)
|
|
||||||
{
|
|
||||||
renderingContext->releaseContext();
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue