|
|
@ -112,56 +112,87 @@ public abstract class LwjglContext implements JmeContext { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected int determineMaxSamples(int requestedSamples) { |
|
|
|
protected int determineMaxSamples(int requestedSamples) { |
|
|
|
if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) { |
|
|
|
boolean displayWasCurrent = false; |
|
|
|
// No pbuffer, assume everything is supported.
|
|
|
|
try { |
|
|
|
return Integer.MAX_VALUE; |
|
|
|
// If we already have a valid context, determine samples using current
|
|
|
|
} else { |
|
|
|
// context.
|
|
|
|
Pbuffer pb = null; |
|
|
|
if (Display.isCreated() && Display.isCurrent()) { |
|
|
|
|
|
|
|
|
|
|
|
// 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) { |
|
|
|
if (GLContext.getCapabilities().GL_ARB_framebuffer_object) { |
|
|
|
return GL11.glGetInteger(ARBFramebufferObject.GL_MAX_SAMPLES); |
|
|
|
return GL11.glGetInteger(ARBFramebufferObject.GL_MAX_SAMPLES); |
|
|
|
} else if (GLContext.getCapabilities().GL_EXT_framebuffer_multisample) { |
|
|
|
} else if (GLContext.getCapabilities().GL_EXT_framebuffer_multisample) { |
|
|
|
return GL11.glGetInteger(EXTFramebufferMultisample.GL_MAX_SAMPLES_EXT); |
|
|
|
return GL11.glGetInteger(EXTFramebufferMultisample.GL_MAX_SAMPLES_EXT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Doesn't support any of the needed extensions .. continue down.
|
|
|
|
// OpenGL2 method failed.
|
|
|
|
displayWasCurrent = true; |
|
|
|
} catch (LWJGLException ex) { |
|
|
|
|
|
|
|
// Something else failed.
|
|
|
|
|
|
|
|
return Integer.MAX_VALUE; |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
if (pb != null) { |
|
|
|
|
|
|
|
pb.destroy(); |
|
|
|
|
|
|
|
pb = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} 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; |
|
|
|
|
|
|
|
|
|
|
|
// OpenGL1 method
|
|
|
|
if (!displayWasCurrent) { |
|
|
|
requestedSamples = FastMath.nearestPowerOfTwo(requestedSamples); |
|
|
|
// OpenGL2 method: Create pbuffer and query samples
|
|
|
|
while (requestedSamples > 1) { |
|
|
|
// from GL_ARB_framebuffer_object or GL_EXT_framebuffer_multisample.
|
|
|
|
try { |
|
|
|
try { |
|
|
|
pb = new Pbuffer(1, 1, new PixelFormat(0, 0, 0, requestedSamples), null); |
|
|
|
pb = new Pbuffer(1, 1, new PixelFormat(0, 0, 0), null); |
|
|
|
} catch (LWJGLException ex) { |
|
|
|
pb.makeCurrent(); |
|
|
|
if (ex.getMessage().startsWith("Failed to find ARB pixel format")) { |
|
|
|
|
|
|
|
// Unsupported format, so continue.
|
|
|
|
if (GLContext.getCapabilities().GL_ARB_framebuffer_object) { |
|
|
|
requestedSamples /= 2; |
|
|
|
return GL11.glGetInteger(ARBFramebufferObject.GL_MAX_SAMPLES); |
|
|
|
} else { |
|
|
|
} else if (GLContext.getCapabilities().GL_EXT_framebuffer_multisample) { |
|
|
|
// Something else went wrong ..
|
|
|
|
return GL11.glGetInteger(EXTFramebufferMultisample.GL_MAX_SAMPLES_EXT); |
|
|
|
return Integer.MAX_VALUE; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} finally { |
|
|
|
|
|
|
|
if (pb != null){ |
|
|
|
// OpenGL2 method failed.
|
|
|
|
|
|
|
|
} catch (LWJGLException ex) { |
|
|
|
|
|
|
|
// Something else failed.
|
|
|
|
|
|
|
|
return Integer.MAX_VALUE; |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
if (pb != null) { |
|
|
|
pb.destroy(); |
|
|
|
pb.destroy(); |
|
|
|
pb = null; |
|
|
|
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; |
|
|
|
return requestedSamples; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|