Пример #1
0
  /**
   * 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));
    }
  }
Пример #2
0
  public static IntBuffer GLCapabilities2AttribList(GLCapabilitiesImmutable caps) {
    final IntBuffer attrs = Buffers.newDirectIntBuffer(32);
    int idx = 0;

    attrs.put(idx++, EGL.EGL_SURFACE_TYPE);
    final int surfaceType;
    if (caps.isOnscreen()) {
      surfaceType = EGL.EGL_WINDOW_BIT;
    } else if (caps.isFBO()) {
      surfaceType = EGL.EGL_PBUFFER_BIT; // native replacement!
    } else if (caps.isPBuffer()) {
      surfaceType = EGL.EGL_PBUFFER_BIT;
    } else if (caps.isBitmap()) {
      surfaceType = EGL.EGL_PIXMAP_BIT;
    } else {
      throw new GLException("no surface type set in caps: " + caps);
    }
    attrs.put(idx++, surfaceType);

    attrs.put(idx++, EGL.EGL_RED_SIZE);
    attrs.put(idx++, caps.getRedBits());

    attrs.put(idx++, EGL.EGL_GREEN_SIZE);
    attrs.put(idx++, caps.getGreenBits());

    attrs.put(idx++, EGL.EGL_BLUE_SIZE);
    attrs.put(idx++, caps.getBlueBits());

    if (caps.getAlphaBits() > 0) {
      attrs.put(idx++, EGL.EGL_ALPHA_SIZE);
      attrs.put(idx++, caps.getAlphaBits());
    }

    if (caps.getStencilBits() > 0) {
      attrs.put(idx++, EGL.EGL_STENCIL_SIZE);
      attrs.put(idx++, caps.getStencilBits());
    }

    attrs.put(idx++, EGL.EGL_DEPTH_SIZE);
    attrs.put(idx++, caps.getDepthBits());

    if (caps.getSampleBuffers()) {
      if (caps.getSampleExtension().equals(GLGraphicsConfigurationUtil.NV_coverage_sample)) {
        attrs.put(idx++, EGLExt.EGL_COVERAGE_BUFFERS_NV);
        attrs.put(idx++, 1);
        attrs.put(idx++, EGLExt.EGL_COVERAGE_SAMPLES_NV);
        attrs.put(idx++, caps.getNumSamples());
      } else {
        // try default ..
        attrs.put(idx++, EGL.EGL_SAMPLE_BUFFERS);
        attrs.put(idx++, 1);
        attrs.put(idx++, EGL.EGL_SAMPLES);
        attrs.put(idx++, caps.getNumSamples());
      }
    }

    attrs.put(idx++, EGL.EGL_TRANSPARENT_TYPE);
    attrs.put(idx++, caps.isBackgroundOpaque() ? EGL.EGL_NONE : EGL.EGL_TRANSPARENT_TYPE);

    // 22

    if (!caps.isBackgroundOpaque()) {
      attrs.put(idx++, EGL.EGL_TRANSPARENT_RED_VALUE);
      attrs.put(
          idx++,
          caps.getTransparentRedValue() >= 0 ? caps.getTransparentRedValue() : EGL.EGL_DONT_CARE);

      attrs.put(idx++, EGL.EGL_TRANSPARENT_GREEN_VALUE);
      attrs.put(
          idx++,
          caps.getTransparentGreenValue() >= 0
              ? caps.getTransparentGreenValue()
              : EGL.EGL_DONT_CARE);

      attrs.put(idx++, EGL.EGL_TRANSPARENT_BLUE_VALUE);
      attrs.put(
          idx++,
          caps.getTransparentBlueValue() >= 0 ? caps.getTransparentBlueValue() : EGL.EGL_DONT_CARE);

      /**
       * Not define in EGL attrs.put(idx++, EGL.EGL_TRANSPARENT_ALPHA_VALUE; attrs.put(idx++,
       * caps.getTransparentAlphaValue()>=0?caps.getTransparentAlphaValue():EGL.EGL_DONT_CARE;
       */
    }

    // 28
    attrs.put(idx++, EGL.EGL_RENDERABLE_TYPE);
    if (caps.getGLProfile().usesNativeGLES1()) {
      attrs.put(idx++, EGL.EGL_OPENGL_ES_BIT);
    } else if (caps.getGLProfile().usesNativeGLES2()) {
      attrs.put(idx++, EGL.EGL_OPENGL_ES2_BIT);
    } else if (caps.getGLProfile().usesNativeGLES3()) {
      if (GLRendererQuirks.existStickyDeviceQuirk(
          GLDrawableFactory.getEGLFactory().getDefaultDevice(),
          GLRendererQuirks.GLES3ViaEGLES2Config)) {
        attrs.put(idx++, EGL.EGL_OPENGL_ES2_BIT);
      } else {
        attrs.put(idx++, EGLExt.EGL_OPENGL_ES3_BIT_KHR);
      }
    } else {
      attrs.put(idx++, EGL.EGL_OPENGL_BIT);
    }

    // 30

    attrs.put(idx++, EGL.EGL_NONE);

    return attrs;
  }