JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nCreate
  (JNIEnv *env , jclass clazz, jobject peer_handle, jobject attribs, jobject shared_context_handle) {
	jobject context_handle = newJavaManagedByteBuffer(env, sizeof(X11Context));
	if (context_handle == NULL) {
		throwException(env, "Could not allocate handle buffer");
		return NULL;
	}
	X11PeerInfo *peer_info = (*env)->GetDirectBufferAddress(env, peer_handle);
	X11Context *context_info = (*env)->GetDirectBufferAddress(env, context_handle);
	GLXExtensions extension_flags;
	if (!extgl_InitGLX(peer_info->display, peer_info->screen, &extension_flags)) {
		throwException(env, "Could not initialize GLX");
		return NULL;
	}
	GLXContext shared_context = NULL;
	if (shared_context_handle != NULL) {
		X11Context *shared_context_info = (*env)->GetDirectBufferAddress(env, shared_context_handle);
		shared_context = shared_context_info->context;
	}
	if (peer_info->glx13) {
		createContextGLX13(env, peer_info, context_info, extension_flags.GLX_ARB_create_context ? attribs : NULL, shared_context);
	} else {
		createContextGLX(env, peer_info, context_info, shared_context);
	}
	context_info->extension_flags = extension_flags;
	return context_handle;
}
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_WindowsPeerInfo_createHandle(JNIEnv *env, jclass clazz) {
	return newJavaManagedByteBuffer(env, sizeof(WindowsPeerInfo));
}
예제 #3
0
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_WindowsContextImplementation_nCreate
(JNIEnv *env, jclass clazz, jobject peer_info_handle, jobject attribs, jobject shared_context_handle) {
    WindowsPeerInfo *peer_info;
    WindowsContext *shared_context_info;
    WindowsContext *context_info;
    HGLRC context;
    HGLRC shared_context = NULL;

    // -- We need to create a temporary context to detect the presence of WGL_ARB_create_context
    HDC saved_current_hdc;
    HGLRC saved_current_hglrc;
    WGLExtensions extensions;
    const int *attribList = attribs == NULL ? NULL : ((const int *)(*env)->GetDirectBufferAddress(env, attribs));

    jobject context_handle = newJavaManagedByteBuffer(env, sizeof(WindowsContext));
    if (context_handle == NULL) {
        throwException(env, "Could not create handle buffer");
        return NULL;
    }

    peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
    if (shared_context_handle != NULL) {
        shared_context_info = (WindowsContext *)(*env)->GetDirectBufferAddress(env, shared_context_handle);
        shared_context = shared_context_info->context;
    }

    // Create the context
    context = wglCreateContext(peer_info->drawable_hdc);
    if (context == NULL) {
        throwException(env, "Could not create context");
        return NULL;
    }

    // Save the current HDC and HGLRC to avoid disruption
    saved_current_hdc = wglGetCurrentDC();
    saved_current_hglrc = wglGetCurrentContext();

    // Make context current and detect extensions
    if (!wglMakeCurrent(peer_info->drawable_hdc, context)) {
        throwException(env, "Could not bind dummy context");
        return NULL;
    }
    extgl_InitWGL(&extensions);
    peer_info->extensions = extensions;

    // Restore previous context
    wglMakeCurrent(saved_current_hdc, saved_current_hglrc);

    //
    if ( extensions.WGL_ARB_create_context ) { // We support WGL_ARB_create_context, use the new context creation routine
        // If we have no context to share and no special attributes, we don't have to recreate the context - wglCreateContext is equivalent to wglCreateContextAttribs(hdc,0,NULL).
        if ( shared_context != NULL || attribList != NULL ) {
            // Delete the oldschool context
            wglDeleteContext(context);
            // Create a new context using WGL_ARB_create_context
            context = (HGLRC)extensions.wglCreateContextAttribsARB(peer_info->drawable_hdc, shared_context, attribList);
            if (context == NULL) {
                throwException(env, "Could not create context (WGL_ARB_create_context)");
                return NULL;
            }
        }
    } else { // We don't support WGL_ARB_create_context, use the old context creation routine
        if (shared_context != NULL && !wglShareLists(shared_context, context)) { // Use wglShareLists to share context data
            wglDeleteContext(context);
            throwException(env, "Could not share contexts");
            return NULL;
        }
    }

    context_info = (WindowsContext *)(*env)->GetDirectBufferAddress(env, context_handle);
    context_info->context = context;
    return context_handle;
}
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxKeyboard_allocateComposeStatus(JNIEnv *env, jclass unused) {
	return newJavaManagedByteBuffer(env, sizeof(XComposeStatus));
}
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_AWTSurfaceLock_createHandle
  (JNIEnv *env, jclass clazz) {
	return newJavaManagedByteBuffer(env, sizeof(AWTSurfaceLock));
}
예제 #6
0
static jobject createNativeGammaBuffer(JNIEnv *env) {
	return newJavaManagedByteBuffer(env, sizeof(WORD)*3*org_lwjgl_opengl_WindowsDisplay_GAMMA_LENGTH);
}