public void setMultipleTargets(final boolean force) { if (force) { logger.fine("Copy Texture Pbuffer used!"); _useDirectRender = false; _texture = null; if (_pbuffer != null) { try { giveBackContext(); } catch (final LWJGLException ex) { } ContextManager.removeContext(_pbuffer); } } else { if ((Pbuffer.getCapabilities() & Pbuffer.RENDER_TEXTURE_SUPPORTED) != 0) { logger.fine("Render to Texture Pbuffer supported!"); if (_texture == null) { logger.fine("No RenderTexture used in init, falling back to Copy Texture PBuffer."); _useDirectRender = false; } else { _useDirectRender = true; } } else { logger.fine("Copy Texture Pbuffer supported!"); _texture = null; } } }
protected void initInThread() { if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) { logger.severe("Offscreen surfaces are not supported."); return; } int samples = getNumSamplesToUse(); pixelFormat = new PixelFormat( settings.getBitsPerPixel(), 0, settings.getDepthBits(), settings.getStencilBits(), samples); width = settings.getWidth(); height = settings.getHeight(); try { Thread.setDefaultUncaughtExceptionHandler( new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread thread, Throwable thrown) { listener.handleError("Uncaught exception thrown in " + thread.toString(), thrown); } }); pbuffer = new Pbuffer(width, height, pixelFormat, null, null, createContextAttribs()); pbuffer.makeCurrent(); renderable.set(true); logger.fine("Offscreen buffer created."); printContextInitInfo(); } catch (LWJGLException ex) { listener.handleError("Failed to create display", ex); } finally { // TODO: It is possible to avoid "Failed to find pixel format" // error here by creating a default display. } super.internalCreate(); listener.initialize(); }
protected int determineMaxSamples(int requestedSamples) { boolean displayWasCurrent = false; try { // If we already have a valid context, determine samples using current // context. if (Display.isCreated() && Display.isCurrent()) { if (GLContext.getCapabilities().GL_ARB_framebuffer_object) { return GL11.glGetInteger(ARBFramebufferObject.GL_MAX_SAMPLES); } else if (GLContext.getCapabilities().GL_EXT_framebuffer_multisample) { return GL11.glGetInteger(EXTFramebufferMultisample.GL_MAX_SAMPLES_EXT); } // Doesn't support any of the needed extensions .. continue down. displayWasCurrent = true; } } catch (LWJGLException ex) { listener.handleError("Failed to check if display is current", ex); } if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) { // No pbuffer, assume everything is supported. return Integer.MAX_VALUE; } else { Pbuffer pb = null; if (!displayWasCurrent) { // OpenGL2 method: Create pbuffer and query samples // from GL_ARB_framebuffer_object or GL_EXT_framebuffer_multisample. try { pb = new Pbuffer(1, 1, new PixelFormat(0, 0, 0), null); pb.makeCurrent(); if (GLContext.getCapabilities().GL_ARB_framebuffer_object) { return GL11.glGetInteger(ARBFramebufferObject.GL_MAX_SAMPLES); } else if (GLContext.getCapabilities().GL_EXT_framebuffer_multisample) { return GL11.glGetInteger(EXTFramebufferMultisample.GL_MAX_SAMPLES_EXT); } // OpenGL2 method failed. } catch (LWJGLException ex) { // Something else failed. return Integer.MAX_VALUE; } finally { if (pb != null) { pb.destroy(); pb = null; } } } // OpenGL1 method (DOESNT WORK RIGHT NOW ..) requestedSamples = FastMath.nearestPowerOfTwo(requestedSamples); try { requestedSamples = Integer.MAX_VALUE; /* while (requestedSamples > 1) { try { pb = new Pbuffer(1, 1, new PixelFormat(16, 0, 8, 0, requestedSamples), null); } catch (LWJGLException ex) { if (ex.getMessage().startsWith("Failed to find ARB pixel format")) { // Unsupported format, so continue. requestedSamples = FastMath.nearestPowerOfTwo(requestedSamples / 2); } else { // Something else went wrong .. return Integer.MAX_VALUE; } } finally { if (pb != null){ pb.destroy(); pb = null; } } }*/ } finally { if (displayWasCurrent) { try { Display.makeCurrent(); } catch (LWJGLException ex) { listener.handleError("Failed to make display current after checking samples", ex); } } } return requestedSamples; } }