Beispiel #1
0
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_WindowsContextImplementation_nSetSwapInterval
(JNIEnv *env, jclass clazz, jint value) {
    WGLExtensions extensions;
    extgl_InitWGL(&extensions);
    if (extensions.WGL_EXT_swap_control) {
        return extensions.wglSwapIntervalEXT(value) ? JNI_TRUE : JNI_FALSE;
    } else
        return JNI_FALSE;
}
static bool getExtensions(JNIEnv *env, WGLExtensions *extensions, jobject pixel_format, jobject pixelFormatCaps) {
	int origin_x = 0; int origin_y = 0;
	HWND dummy_hwnd;
	HDC dummy_hdc;
	HGLRC dummy_context;
	HDC saved_hdc;
	HGLRC saved_context;
	int pixel_format_id;

	dummy_hwnd = createDummyWindow(origin_x, origin_y);
	if (dummy_hwnd == NULL) {
		throwException(env, "Could not create dummy window");
		return false;
	}
	dummy_hdc = GetDC(dummy_hwnd);
	pixel_format_id = findPixelFormatOnDC(env, dummy_hdc, origin_x, origin_y, pixel_format, pixelFormatCaps, false, true, false, false);
	if (pixel_format_id == -1) {
		closeWindow(&dummy_hwnd, &dummy_hdc);
		return false;
	}
	if (!applyPixelFormat(env, dummy_hdc, pixel_format_id)) {
		closeWindow(&dummy_hwnd, &dummy_hdc);
		return false;
	}
	dummy_context = wglCreateContext(dummy_hdc);
	if (dummy_context == NULL) {
		closeWindow(&dummy_hwnd, &dummy_hdc);
		throwException(env, "Could not create dummy context");
		return false;
	}
	saved_hdc = wglGetCurrentDC();
	saved_context = wglGetCurrentContext();
	if (!wglMakeCurrent(dummy_hdc, dummy_context)) {
		wglMakeCurrent(saved_hdc, saved_context);
		closeWindow(&dummy_hwnd, &dummy_hdc);
		wglDeleteContext(dummy_context);
		throwException(env, "Could not make dummy context current");
		return false;
	}
	extgl_InitWGL(extensions);
	if (!wglMakeCurrent(saved_hdc, saved_context))
		printfDebugJava(env, "ERROR: Could not restore current context");
	closeWindow(&dummy_hwnd, &dummy_hdc);
	wglDeleteContext(dummy_context);
	return true;
}
Beispiel #3
0
static bool validateAndGetExtensions(JNIEnv *env, WGLExtensions *extensions, HDC dummy_hdc, HGLRC dummy_hglrc, int samples, int colorSamples, bool floating_point, bool floating_point_packed, bool sRGB, jobject pixelFormatCaps) {
	if (!wglMakeCurrent(dummy_hdc, dummy_hglrc)) {
		throwException(env, "Could not bind context to dummy window");
		return false;
	}
	extgl_InitWGL(extensions);

	if (!extensions->WGL_ARB_pixel_format) {
		throwException(env, "No support for WGL_ARB_pixel_format");
		return false;
	}
	if (samples > 0 && !extensions->WGL_ARB_multisample) {
		throwException(env, "No support for WGL_ARB_multisample");
		return false;
	}
	if (colorSamples > 0 && !extensions->WGL_NV_multisample_coverage) {
	    throwException(env, "No support for WGL_NV_multisample_coverage");
		return false;
	}
	/*
	 * Apparently, some drivers don't report WGL_ARB_pixel_format_float
	 * even though GL_ARB_color_buffer_float and WGL_ATI_color_format_float
	 * is supported.
	 */
	if (floating_point && !(extensions->WGL_ARB_pixel_format_float || extensions->WGL_ATI_pixel_format_float)) {
		throwException(env, "No support for WGL_ARB_pixel_format_float nor WGL_ATI_pixel_format_float");
		return false;
	}
	if (floating_point_packed && !(extensions->WGL_EXT_pixel_format_packed_float)) {
		throwException(env, "No support for WGL_EXT_pixel_format_packed_float");
		return false;
	}
	if (sRGB && !(extensions->WGL_ARB_framebuffer_sRGB)) {
		throwException(env, "No support for WGL_ARB_framebuffer_sRGB");
		return false;
	}
	if (pixelFormatCaps != NULL && !extensions->WGL_ARB_render_texture) {
		throwException(env, "No support for WGL_ARB_render_texture");
		return false;
	}
	return true;
}
Beispiel #4
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;
}