public final void swapBuffers() throws GLException { GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) surface.getGraphicsConfiguration().getChosenCapabilities(); if (caps.getDoubleBuffered()) { if (!surface.surfaceSwap()) { int lockRes = lockSurface(); // it's recursive, so it's ok within [makeCurrent .. release] if (NativeSurface.LOCK_SURFACE_NOT_READY == lockRes) { return; } try { if (NativeSurface.LOCK_SURFACE_CHANGED == lockRes) { updateHandle(); } swapBuffersImpl(); } finally { unlockSurface(); } } } else { GLContext ctx = GLContext.getCurrent(); if (null != ctx && ctx.getGLDrawable() == this) { ctx.getGL().glFinish(); } } surface.surfaceUpdated(this, surface, System.currentTimeMillis()); }
/** Display all informations about the currently activated OpenGL mode. */ @SuppressWarnings("nls") private void displayOpenGLStatusInfo() { final GLCapabilitiesImmutable activeCaps = getChosenGLCapabilities(); doubleBuffered = activeCaps.getDoubleBuffered(); if (activeCaps.getHardwareAccelerated()) { LOGGER.debug("OpenGL Hardware acceleration active"); } else { LOGGER.warn("OpenGL Hardware acceleration inactive"); } LOGGER.debug("Active Samples: " + Integer.toString(activeCaps.getNumSamples())); if (activeCaps.getGLProfile().isGLES1()) { LOGGER.debug("OpenGL ES 1.x supported"); } else { LOGGER.debug("OpenGL ES 1.x not supported"); } if (activeCaps.getGLProfile().isGLES2()) { LOGGER.debug("OpenGL ES 2.x supported"); } else { LOGGER.debug("OpenGL ES 2.x not supported"); } if (activeCaps.getGLProfile().isGL2()) { LOGGER.debug("OpenGL 1.x, 2.x, 3.0 supported"); } else { LOGGER.debug("OpenGL 1.x, 2.x, 3.0 not supported"); } if (activeCaps.getGLProfile().isGL3()) { LOGGER.debug("OpenGL 3.x supported"); } else { LOGGER.debug("OpenGL 3.x not supported"); } if (activeCaps.getGLProfile().isGL4()) { LOGGER.debug("OpenGL 4.x supported"); } else { LOGGER.debug("OpenGL 4.x not supported"); } if (activeCaps.getGLProfile().isGL2GL3()) { LOGGER.debug("OpenGL 2.x, 3.x supported"); } else { LOGGER.debug("OpenGL 2.x, 3.x not supported"); } if (activeCaps.getGLProfile().isGL2ES1()) { LOGGER.debug("OpenGL 1.x, 2.x, 3.0 and OpenGL ES 1.x supported"); } else { LOGGER.debug("OpenGL 1.x, 2.x, 3.0 and OpenGL ES 1.x not supported"); } if (activeCaps.getGLProfile().isGL2ES2()) { LOGGER.debug("OpenGL 1.x, 2.x, 3.0 and OpenGL ES 2.x supported"); } else { LOGGER.debug("OpenGL 1.x, 2.x, 3.0 and OpenGL ES 2.x not supported"); } if (activeCaps.getGLProfile().hasGLSL()) { LOGGER.debug("OpenGL shader language supported"); } else { LOGGER.debug("OpenGL shader language not supported"); } if (activeCaps.getGLProfile().usesNativeGLES()) { LOGGER.debug("OpenGL ES native supported"); } else { LOGGER.debug("OpenGL ES native not supported"); } if (activeCaps.getGLProfile().usesNativeGLES1()) { LOGGER.debug("OpenGL ES 1.x native supported"); } else { LOGGER.debug("OpenGL ES 1.x native not supported"); } if (activeCaps.getGLProfile().usesNativeGLES2()) { LOGGER.debug("OpenGL ES 2.x native supported"); } else { LOGGER.debug("OpenGL ES 2.x native not supported"); } }
/** * Takes a snapshot of the drawable's current front framebuffer. Example filenames: * * <pre> * TestGLDrawableAutoDelegateOnOffscrnCapsNEWT.testES2OffScreenFBOSglBuf____-n0001-msaa0-GLES2_-sw-fbobject-Bdbl-Frgb__Irgb_-S00_default-0400x0300.png * TestGLDrawableAutoDelegateOnOffscrnCapsNEWT.testES2OffScreenPbufferDblBuf-n0003-msaa0-GLES2_-sw-pbuffer_-Bdbl-Frgb__Irgb_-S00_default-0200x0150.png * TestGLDrawableAutoDelegateOnOffscrnCapsNEWT.testGL2OffScreenPbufferSglBuf-n0003-msaa0-GL2___-hw-pbuffer_-Bone-Frgb__Irgb_-S00_default-0200x0150.png * </pre> * * @param sn sequential number * @param postSNDetail optional detail to be added to the filename after <code>sn</code> * @param gl the current GL context object. It's read drawable is being used as the pixel source * and to gather some details which will end up in the filename. * @param readBufferUtil the {@link GLReadBufferUtil} to be used to read the pixels for the * screenshot. * @param fileSuffix Optional file suffix without a <i>dot</i> defining the file type, i.e. <code> * "png"</code>. If <code>null</code> the <code>"png"</code> as defined in {@link * TextureIO#PNG} is being used. * @param destPath Optional platform dependent file path. It shall use {@link File#separatorChar} * as is directory separator. It shall not end with a directory separator, {@link * File#separatorChar}. If <code>null</code> the current working directory is being used. */ public void snapshot( int sn, String postSNDetail, GL gl, GLReadBufferUtil readBufferUtil, String fileSuffix, String destPath) { if (null == fileSuffix) { fileSuffix = TextureIO.PNG; } final int maxSimpleTestNameLen = getMaxTestNameLen() + getClass().getSimpleName().length() + 1; final String simpleTestName = this.getSimpleTestName("."); final String filenameBaseName; { final GLDrawable drawable = gl.getContext().getGLReadDrawable(); final GLCapabilitiesImmutable caps = drawable.getChosenGLCapabilities(); final String accel = caps.getHardwareAccelerated() ? "hw" : "sw"; final String scrnm; if (caps.isOnscreen()) { scrnm = "onscreen"; } else if (caps.isFBO()) { scrnm = "fbobject"; } else if (caps.isPBuffer()) { scrnm = "pbuffer_"; } else if (caps.isBitmap()) { scrnm = "bitmap__"; } else { scrnm = "unknown_"; } final String dblb = caps.getDoubleBuffered() ? "dbl" : "one"; final String F_pfmt = readBufferUtil.hasAlpha() ? "rgba" : "rgb_"; final String pfmt = caps.getAlphaBits() > 0 ? "rgba" : "rgb_"; final int samples = caps.getNumSamples(); final String aaext = caps.getSampleExtension(); postSNDetail = null != postSNDetail ? "-" + postSNDetail : ""; filenameBaseName = String.format( "%-" + maxSimpleTestNameLen + "s-n%04d%s-%-6s-%s-%s-B%s-F%s_I%s-S%02d_%s-%04dx%04d.%s", simpleTestName, sn, postSNDetail, drawable.getGLProfile().getName(), accel, scrnm, dblb, F_pfmt, pfmt, samples, aaext, drawable.getWidth(), drawable.getHeight(), fileSuffix) .replace(' ', '_'); } final String filename = null != destPath ? destPath + File.separator + filenameBaseName : filenameBaseName; System.err.println( Thread.currentThread().getName() + ": ** screenshot: " + filename + ", maxTestNameLen " + maxSimpleTestNameLen + ", <" + simpleTestName + ">"); gl.glFinish(); // just make sure rendering finished .. if (readBufferUtil.readPixels(gl, false)) { readBufferUtil.write(new File(filename)); } }