コード例 #1
0
  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);
  }
コード例 #2
0
  protected void runTestGL(final GLCapabilitiesImmutable caps) throws InterruptedException {
    final Display nDisplay =
        NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null, false); // local display
    final Screen nScreen = NewtFactory.createScreen(nDisplay, 0); // screen 0
    final Window nWindow = NewtFactory.createWindow(nScreen, caps);

    final GLWindow glWindow = GLWindow.create(nWindow);
    Assert.assertNotNull(glWindow);
    glWindow.setTitle("Gears NewtAWTWrapper Test");

    glWindow.addGLEventListener(new GearsES2(1));

    final Animator animator = useAnimator ? new Animator(glWindow) : null;
    final QuitAdapter quitAdapter = new QuitAdapter();

    glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
    glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));

    if (useAnimator) {
      animator.start();
    }

    int div = 3;
    glWindow.setSize(width / div, height / div);
    glWindow.setVisible(true);
    if (doResizeTest) {
      glWindow.display();
      final int[] expSurfaceSize =
          glWindow.getNativeSurface().convertToPixelUnits(new int[] {width / div, height / div});
      Assert.assertTrue(
          "Surface Size not reached: Expected "
              + expSurfaceSize[0]
              + "x"
              + expSurfaceSize[1]
              + ", Is "
              + glWindow.getSurfaceWidth()
              + "x"
              + glWindow.getSurfaceHeight(),
          AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1]));
      Thread.sleep(600);

      div = 2;
      glWindow.setSize(width / div, height / div);
      glWindow.display();
      expSurfaceSize[0] = width / div;
      expSurfaceSize[1] = height / div;
      glWindow.getNativeSurface().convertToPixelUnits(expSurfaceSize);
      Assert.assertTrue(
          "Surface Size not reached: Expected "
              + expSurfaceSize[0]
              + "x"
              + expSurfaceSize[1]
              + ", Is "
              + glWindow.getSurfaceWidth()
              + "x"
              + glWindow.getSurfaceHeight(),
          AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1]));
      Thread.sleep(600);

      div = 1;
      glWindow.setSize(width / div, height / div);
      glWindow.display();
      expSurfaceSize[0] = width / div;
      expSurfaceSize[1] = height / div;
      glWindow.getNativeSurface().convertToPixelUnits(expSurfaceSize);
      Assert.assertTrue(
          "Surface Size not reached: Expected "
              + expSurfaceSize[0]
              + "x"
              + expSurfaceSize[1]
              + ", Is "
              + glWindow.getSurfaceWidth()
              + "x"
              + glWindow.getSurfaceHeight(),
          AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1]));
      Thread.sleep(600);
    }

    final long t0 = System.currentTimeMillis();
    long t1 = t0;
    while (!quitAdapter.shouldQuit() && t1 - t0 < duration) {
      Thread.sleep(100);
      t1 = System.currentTimeMillis();
    }

    if (useAnimator) {
      animator.stop();
    }
    glWindow.destroy();
  }