2011-09-03 14:52:45 -04:00
|
|
|
/*
|
2008-04-07 14:42:36 -04:00
|
|
|
* Copyright (c) 2002-2008 LWJGL Project
|
2005-03-30 03:49:02 -05:00
|
|
|
* All rights reserved.
|
2011-09-03 14:52:45 -04:00
|
|
|
*
|
2005-03-30 03:49:02 -05:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2011-09-03 14:52:45 -04:00
|
|
|
* modification, are permitted provided that the following conditions are
|
2005-03-30 03:49:02 -05:00
|
|
|
* met:
|
2011-09-03 14:52:45 -04:00
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
2005-03-30 03:49:02 -05:00
|
|
|
* 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.
|
|
|
|
*
|
2011-09-03 14:52:45 -04:00
|
|
|
* * Neither the name of 'LWJGL' nor the names of
|
|
|
|
* its contributors may be used to endorse or promote products derived
|
2005-03-30 03:49:02 -05:00
|
|
|
* from this software without specific prior written permission.
|
2011-09-03 14:52:45 -04:00
|
|
|
*
|
2005-03-30 03:49:02 -05:00
|
|
|
* 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
|
2011-09-03 14:52:45 -04:00
|
|
|
* 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
|
2005-03-30 03:49:02 -05:00
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
2011-09-03 14:52:45 -04:00
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
2005-03-30 03:49:02 -05:00
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
|
|
|
* @version $Revision$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <jni.h>
|
2011-10-06 16:16:37 -04:00
|
|
|
#import <OpenGL/CGLCurrent.h>
|
|
|
|
#import <OpenGL/CGLTypes.h>
|
|
|
|
#import <OpenGL/CGLDevice.h>
|
2005-03-30 03:49:02 -05:00
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
#import "org_lwjgl_opengl_MacOSXContextImplementation.h"
|
|
|
|
#import "context.h"
|
|
|
|
#import "common_tools.h"
|
|
|
|
|
|
|
|
typedef struct {
|
2012-11-01 16:54:17 -04:00
|
|
|
NSOpenGLContext *context;
|
2011-08-29 09:34:17 -04:00
|
|
|
MacOSXPeerInfo *peer_info;
|
2005-03-30 03:49:02 -05:00
|
|
|
} MacOSXContext;
|
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nCreate
|
2011-09-03 14:52:45 -04:00
|
|
|
(JNIEnv *env, jclass clazz, jobject peer_info_handle, jobject shared_context_handle) {
|
2005-03-30 03:49:02 -05:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
MacOSXPeerInfo *peer_info;
|
|
|
|
MacOSXContext *shared_context_info;
|
|
|
|
MacOSXContext *context_info;
|
2012-11-01 16:54:17 -04:00
|
|
|
NSOpenGLContext *context;
|
2012-11-03 14:06:08 -04:00
|
|
|
NSOpenGLContext *shared_context = NULL;
|
2012-11-25 15:24:51 -05:00
|
|
|
|
2005-03-30 03:49:02 -05:00
|
|
|
jobject context_handle = newJavaManagedByteBuffer(env, sizeof(MacOSXContext));
|
|
|
|
if (context_handle == NULL) {
|
|
|
|
throwException(env, "Could not create handle buffer");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
peer_info = (MacOSXPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
|
|
|
|
if (shared_context_handle != NULL) {
|
|
|
|
shared_context_info = (MacOSXContext *)(*env)->GetDirectBufferAddress(env, shared_context_handle);
|
2012-11-01 16:54:17 -04:00
|
|
|
shared_context = shared_context_info->context;
|
2005-03-30 03:49:02 -05:00
|
|
|
}
|
2012-11-01 16:54:17 -04:00
|
|
|
context = [[NSOpenGLContext alloc] initWithFormat:peer_info->pixel_format shareContext:shared_context];
|
|
|
|
if (context == NULL) {
|
|
|
|
throwException(env, "Could not create context");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
[peer_info->window_info->view setOpenGLContext:context];
|
|
|
|
peer_info->window_info->context = context;
|
2005-03-30 03:49:02 -05:00
|
|
|
context_info = (MacOSXContext *)(*env)->GetDirectBufferAddress(env, context_handle);
|
2012-11-01 16:54:17 -04:00
|
|
|
context_info->context = context;
|
2011-08-29 09:34:17 -04:00
|
|
|
context_info->peer_info = peer_info;
|
2012-11-01 16:54:17 -04:00
|
|
|
|
2005-03-30 03:49:02 -05:00
|
|
|
[pool release];
|
2011-09-03 14:52:45 -04:00
|
|
|
return context_handle;
|
2005-03-30 03:49:02 -05:00
|
|
|
}
|
|
|
|
|
2011-10-06 16:16:37 -04:00
|
|
|
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_getCGLShareGroup
|
|
|
|
(JNIEnv *env, jclass clazz, jobject context_handle) {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-11-01 16:54:17 -04:00
|
|
|
MacOSXPeerInfo *peer_info = ((MacOSXContext *)(*env)->GetDirectBufferAddress(env, context_handle))->peer_info;
|
|
|
|
CGLContextObj cgl_context = [[peer_info->window_info->view openGLContext] CGLContextObj];
|
2011-10-06 16:16:37 -04:00
|
|
|
CGLShareGroupObj share_group = CGLGetShareGroup(cgl_context);
|
|
|
|
[pool release];
|
2012-11-01 16:54:17 -04:00
|
|
|
return (jlong)share_group;
|
2011-10-06 16:16:37 -04:00
|
|
|
}
|
|
|
|
|
2005-03-30 03:49:02 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nSwapBuffers
|
|
|
|
(JNIEnv *env, jclass clazz, jobject context_handle) {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-11-01 16:54:17 -04:00
|
|
|
MacOSXPeerInfo *peer_info = ((MacOSXContext *)(*env)->GetDirectBufferAddress(env, context_handle))->peer_info;
|
|
|
|
[[peer_info->window_info->view openGLContext] flushBuffer];
|
|
|
|
peer_info->canDrawGL = true;
|
2005-03-30 03:49:02 -05:00
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nUpdate
|
|
|
|
(JNIEnv *env, jclass clazz, jobject context_handle) {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-11-01 16:54:17 -04:00
|
|
|
MacOSXPeerInfo *peer_info = ((MacOSXContext *)(*env)->GetDirectBufferAddress(env, context_handle))->peer_info;
|
|
|
|
[[peer_info->window_info->view openGLContext] update];
|
|
|
|
peer_info->canDrawGL = true;
|
2005-03-30 03:49:02 -05:00
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_clearDrawable
|
|
|
|
(JNIEnv *env, jclass clazz, jobject context_handle) {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-11-01 16:54:17 -04:00
|
|
|
MacOSXPeerInfo *peer_info = ((MacOSXContext *)(*env)->GetDirectBufferAddress(env, context_handle))->peer_info;
|
|
|
|
[[peer_info->window_info->view openGLContext] clearDrawable];
|
2005-03-30 03:49:02 -05:00
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nReleaseCurrentContext
|
|
|
|
(JNIEnv *env, jclass clazz) {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-11-25 15:24:51 -05:00
|
|
|
[NSOpenGLContext clearCurrentContext];
|
2005-03-30 03:49:02 -05:00
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_setView
|
2012-11-01 16:54:17 -04:00
|
|
|
(JNIEnv *env, jclass clazz, jobject peer_info_handle) {
|
2005-03-30 03:49:02 -05:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-11-01 16:54:17 -04:00
|
|
|
MacOSXPeerInfo *peer_info = (MacOSXPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
|
|
|
|
[[peer_info->window_info->view openGLContext] setView: peer_info->window_info->view];
|
2011-08-29 09:34:17 -04:00
|
|
|
peer_info->canDrawGL = true;
|
2005-03-30 03:49:02 -05:00
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nMakeCurrent
|
|
|
|
(JNIEnv *env, jclass clazz, jobject context_handle) {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-11-01 16:54:17 -04:00
|
|
|
MacOSXPeerInfo *peer_info = ((MacOSXContext *)(*env)->GetDirectBufferAddress(env, context_handle))->peer_info;
|
2012-11-25 15:24:51 -05:00
|
|
|
[[peer_info->window_info->view openGLContext] makeCurrentContext];
|
2005-03-30 03:49:02 -05:00
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nIsCurrent
|
|
|
|
(JNIEnv *env, jclass clazz, jobject context_handle) {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-11-01 16:54:17 -04:00
|
|
|
MacOSXPeerInfo *peer_info = ((MacOSXContext *)(*env)->GetDirectBufferAddress(env, context_handle))->peer_info;
|
|
|
|
bool result = [peer_info->window_info->view openGLContext] == [NSOpenGLContext currentContext];
|
2005-03-30 03:49:02 -05:00
|
|
|
[pool release];
|
|
|
|
return result ? JNI_TRUE : JNI_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-01 14:50:06 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nSetSwapInterval
|
|
|
|
(JNIEnv *env, jclass clazz, jobject context_handle, jint int_value) {
|
2005-03-30 03:49:02 -05:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-11-01 16:54:17 -04:00
|
|
|
MacOSXPeerInfo *peer_info = ((MacOSXContext *)(*env)->GetDirectBufferAddress(env, context_handle))->peer_info;
|
2008-04-07 09:01:52 -04:00
|
|
|
GLint value = int_value;
|
2012-11-01 16:54:17 -04:00
|
|
|
[[peer_info->window_info->view openGLContext] setValues:&value forParameter:NSOpenGLCPSwapInterval];
|
2005-03-30 03:49:02 -05:00
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nDestroy
|
|
|
|
(JNIEnv *env, jclass clazz, jobject context_handle) {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-11-01 16:54:17 -04:00
|
|
|
MacOSXPeerInfo *peer_info = ((MacOSXContext *)(*env)->GetDirectBufferAddress(env, context_handle))->peer_info;
|
2012-11-25 15:24:51 -05:00
|
|
|
[[peer_info->window_info->view openGLContext] clearDrawable];
|
2012-11-01 16:54:17 -04:00
|
|
|
[[peer_info->window_info->view openGLContext] release];
|
2005-03-30 03:49:02 -05:00
|
|
|
[pool release];
|
|
|
|
}
|