diff --git a/src/java/org/lwjgl/opengl/Pbuffer.java b/src/java/org/lwjgl/opengl/Pbuffer.java index 2f8f009d..17f0e8e3 100644 --- a/src/java/org/lwjgl/opengl/Pbuffer.java +++ b/src/java/org/lwjgl/opengl/Pbuffer.java @@ -175,8 +175,6 @@ public final class Pbuffer { * with the Display context (if created). */ public Pbuffer(int width, int height, PixelFormat pixel_format, RenderTexture renderTexture, Pbuffer shared_context) throws LWJGLException { - if ((getCapabilities() & PBUFFER_SUPPORTED) == 0) - throw new IllegalStateException("Pbuffers are not supported"); this.width = width; this.height = height; this.handle = createPbuffer(width, height, pixel_format, renderTexture, shared_context != null ? shared_context.handle : null); diff --git a/src/native/linux/org_lwjgl_opengl_Pbuffer.c b/src/native/linux/org_lwjgl_opengl_Pbuffer.c index de3f8fe7..eb6a1bf9 100644 --- a/src/native/linux/org_lwjgl_opengl_Pbuffer.c +++ b/src/native/linux/org_lwjgl_opengl_Pbuffer.c @@ -51,11 +51,15 @@ typedef struct _PbufferInfo { GLXContext context; } PbufferInfo; +static bool isPbuffersSupported() { + // Only support the GLX 1.3 Pbuffers and ignore the GLX_SGIX_pbuffer extension + return extgl_Extensions.GLX13 ? org_lwjgl_opengl_Pbuffer_PBUFFER_SUPPORTED : 0; +} + JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetPbufferCapabilities (JNIEnv *env, jobject this) { - // Only support the GLX 1.3 Pbuffers and ignore the GLX_SGIX_pbuffer extension - return extgl_Extensions.GLX13 ? org_lwjgl_opengl_Pbuffer_PBUFFER_SUPPORTED : 0; + return isPbuffersSupported() ? org_lwjgl_opengl_Pbuffer_PBUFFER_SUPPORTED : 0; } static void destroyPbuffer(PbufferInfo *buffer_info) { @@ -127,9 +131,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreatePbuffer(JNIEnv return; } int current_screen = getCurrentScreen(); - if (!extgl_InitGLX(env, disp, current_screen)) { + if (!extgl_InitGLX(env, disp, current_screen) || !isPbuffersSupported()) { decDisplay(); - throwException(env, "Could not init GLX"); + throwException(env, "No Pbuffer support"); return; } diff --git a/src/native/win32/org_lwjgl_opengl_Pbuffer.c b/src/native/win32/org_lwjgl_opengl_Pbuffer.c index 48523db0..d08b237b 100644 --- a/src/native/win32/org_lwjgl_opengl_Pbuffer.c +++ b/src/native/win32/org_lwjgl_opengl_Pbuffer.c @@ -55,20 +55,24 @@ typedef struct _PbufferInfo { HDC Pbuffer_dc; } PbufferInfo; +static bool isPbuffersSupported() { + return extgl_Extensions.WGL_ARB_pixel_format && extgl_Extensions.WGL_ARB_pbuffer; +} + JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_getPbufferCapabilities (JNIEnv *env, jobject self) { int caps = 0; - if ( extgl_Extensions.WGL_ARB_pixel_format && extgl_Extensions.WGL_ARB_pbuffer ) + if (isPbuffersSupported()) caps |= org_lwjgl_opengl_Pbuffer_PBUFFER_SUPPORTED; - if ( extgl_Extensions.WGL_ARB_render_texture ) + if (extgl_Extensions.WGL_ARB_render_texture) caps |= org_lwjgl_opengl_Pbuffer_RENDER_TEXTURE_SUPPORTED; - if ( extgl_Extensions.WGL_NV_render_texture_rectangle ) + if (extgl_Extensions.WGL_NV_render_texture_rectangle) caps |= org_lwjgl_opengl_Pbuffer_RENDER_TEXTURE_RECTANGLE_SUPPORTED; - if ( extgl_Extensions.WGL_NV_render_depth_texture ) + if (extgl_Extensions.WGL_NV_render_depth_texture) caps |= org_lwjgl_opengl_Pbuffer_RENDER_DEPTH_TEXTURE_SUPPORTED; return caps; @@ -110,17 +114,22 @@ static HPBUFFERARB createPbuffer(JNIEnv *env, int width, int height, jobject pix return NULL; } extgl_InitWGL(env); - + bool pbuffers_supported = isPbuffersSupported(); iPixelFormat = findPixelFormatARB(env, dummy_hdc, pixel_format, pixelFormatCaps, false, false, true, false); if (iPixelFormat == -1) iPixelFormat = findPixelFormatARB(env, dummy_hdc, pixel_format, pixelFormatCaps, false, false, true, true); wglDeleteContext(dummy_hglrc); + if (!pbuffers_supported) { + closeWindow(dummy_hwnd, dummy_hdc); + throwException(env, "No Pbuffer support."); + return NULL; + } if (iPixelFormat == -1) { closeWindow(dummy_hwnd, dummy_hdc); throwException(env, "Could not find suitable pixel format."); return NULL; } - Pbuffer = wglCreatePbufferARB(dummy_hdc, iPixelFormat, width, height, pBufferAttribs_ptr); + Pbuffer = wglCreatePbufferARB(dummy_hdc, iPixelFormat, width, height, pBufferAttribs_ptr); closeWindow(dummy_hwnd, dummy_hdc); return Pbuffer; }