void doTest(final GLCapabilitiesImmutable reqGLCaps, final GLEventListener demo)
      throws InterruptedException {
    System.out.println("Requested  GL Caps: " + reqGLCaps);
    final GLDrawableFactory factory = GLDrawableFactory.getFactory(reqGLCaps.getGLProfile());
    final GLCapabilitiesImmutable expGLCaps =
        GLGraphicsConfigurationUtil.fixGLCapabilities(reqGLCaps, factory, null);
    System.out.println("Expected   GL Caps: " + expGLCaps);

    //
    // Create native OpenGL resources .. XGL/WGL/CGL ..
    // equivalent to GLAutoDrawable methods: setVisible(true)
    //
    final GLOffscreenAutoDrawable glad =
        factory.createOffscreenAutoDrawable(
            null, reqGLCaps, null, widthStep * szStep, heightStep * szStep);

    Assert.assertNotNull(glad);
    System.out.println(
        "Drawable    Pre-GL(0): "
            + glad.getClass().getName()
            + ", "
            + glad.getNativeSurface().getClass().getName());
    Assert.assertTrue(glad.isRealized());

    // Check caps of NativeWindow config w/o GL
    final CapabilitiesImmutable chosenCaps = glad.getChosenGLCapabilities();
    System.out.println("Drawable Caps Pre_GL : " + chosenCaps);
    Assert.assertNotNull(chosenCaps);
    Assert.assertTrue(chosenCaps.getGreenBits() > 4);
    Assert.assertTrue(chosenCaps.getBlueBits() > 4);
    Assert.assertTrue(chosenCaps.getRedBits() > 4);

    glad.display(); // force native context creation

    // Check caps of GLDrawable after realization
    final GLCapabilitiesImmutable chosenGLCaps = glad.getChosenGLCapabilities();
    System.out.println("Chosen     GL CTX (1): " + glad.getContext().getGLVersion());
    System.out.println("Chosen     GL Caps(1): " + chosenGLCaps);
    System.out.println(
        "Chosen     GL Caps(2): "
            + glad.getNativeSurface().getGraphicsConfiguration().getChosenCapabilities());

    Assert.assertNotNull(chosenGLCaps);
    Assert.assertTrue(chosenGLCaps.getGreenBits() > 4);
    Assert.assertTrue(chosenGLCaps.getBlueBits() > 4);
    Assert.assertTrue(chosenGLCaps.getRedBits() > 4);
    Assert.assertTrue(chosenGLCaps.getDepthBits() > 4);
    Assert.assertEquals(expGLCaps.isOnscreen(), chosenGLCaps.isOnscreen());
    Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps.isFBO());
    Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps.isPBuffer());
    Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps.isBitmap());
    /**
     * Single/Double buffer cannot be checked since result may vary .. if(chosenGLCaps.isOnscreen()
     * || chosenGLCaps.isFBO()) { // dbl buffer may be disabled w/ offscreen pbuffer and bitmap
     * Assert.assertEquals(expGLCaps.getDoubleBuffered(), chosenGLCaps.getDoubleBuffered()); }
     */
    glad.addGLEventListener(demo);

    final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener();
    glad.addGLEventListener(snapshotGLEventListener);

    glad.display(); // initial resize/display

    // 1 - szStep = 2
    Assert.assertTrue(
        "Size not reached: Expected "
            + (widthStep * szStep)
            + "x"
            + (heightStep * szStep)
            + ", Is "
            + glad.getSurfaceWidth()
            + "x"
            + glad.getSurfaceHeight(),
        AWTRobotUtil.waitForSize(glad, widthStep * szStep, heightStep * szStep));
    snapshotGLEventListener.setMakeSnapshot();
    glad.display();

    // 2, 3 (resize + display)
    szStep = 1;
    glad.setSurfaceSize(widthStep * szStep, heightStep * szStep);
    Assert.assertTrue(
        "Size not reached: Expected "
            + (widthStep * szStep)
            + "x"
            + (heightStep * szStep)
            + ", Is "
            + glad.getSurfaceWidth()
            + "x"
            + glad.getSurfaceHeight(),
        AWTRobotUtil.waitForSize(glad, widthStep * szStep, heightStep * szStep));
    snapshotGLEventListener.setMakeSnapshot();
    glad.display();

    // 4, 5 (resize + display)
    szStep = 4;
    glad.setSurfaceSize(widthStep * szStep, heightStep * szStep);
    Assert.assertTrue(
        "Size not reached: Expected "
            + (widthStep * szStep)
            + "x"
            + (heightStep * szStep)
            + ", Is "
            + glad.getSurfaceWidth()
            + "x"
            + glad.getSurfaceHeight(),
        AWTRobotUtil.waitForSize(glad, widthStep * szStep, heightStep * szStep));
    snapshotGLEventListener.setMakeSnapshot();
    glad.display();

    Thread.sleep(50);

    glad.destroy();
    System.out.println("Fin Drawable: " + glad);
  }
Exemplo n.º 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;
  }