Пример #1
0
  /**
   * Moves all GLEventListenerState components to the given {@link GLAutoDrawable} from this
   * instance, while loosing {@link #isOwner() ownership}.
   *
   * <p>If the previous {@link GLAutoDrawable} was removed from a {@link GLAnimatorControl} by
   * previous {@link #moveFrom(GLAutoDrawable)}, the given {@link GLAutoDrawable} is added to the
   * cached {@link GLAnimatorControl}. This operation is skipped, if the given {@link
   * GLAutoDrawable} is already added to a {@link GLAnimatorControl} instance.
   *
   * <p>Note: After this operation, the GLEventListenerState reference should be released.
   *
   * @param a {@link GLAutoDrawable} destination to move GLEventListenerState components to
   * @throws GLException if the {@link GLAutoDrawable}'s configuration is incompatible, i.e.
   *     different {@link GLCapabilitiesImmutable}.
   * @see #moveFrom(GLAutoDrawable)
   * @see #isOwner()
   */
  public final void moveTo(GLAutoDrawable a) {
    final List<GLRunnable> aGLCmds = new ArrayList<GLRunnable>();
    final int aSz = listenerCount();

    final NativeSurface aSurface = a.getNativeSurface();
    final MutableGraphicsConfiguration aCfg =
        (MutableGraphicsConfiguration) aSurface.getGraphicsConfiguration();
    final GLCapabilitiesImmutable aCaps = (GLCapabilitiesImmutable) aCfg.getChosenCapabilities();
    if (caps.getVisualID(VisualIDHolder.VIDType.INTRINSIC)
            != aCaps.getVisualID(VisualIDHolder.VIDType.INTRINSIC)
        || caps.getVisualID(VisualIDHolder.VIDType.NATIVE)
            != aCaps.getVisualID(VisualIDHolder.VIDType.NATIVE)) {
      throw new GLException(
          "Incompatible Capabilities - Prev-Holder: " + caps + ", New-Holder " + caps);
    }
    // Destroy and remove currently associated GLContext, if any (will be replaced)
    {
      final GLContext ctx = a.getContext();
      if (null != ctx) {
        ctx.destroy();
      }
      a.setContext(null);
    }
    final boolean aRealized = a.isRealized();
    if (aRealized) {
      a.setRealized(false);
    }
    // Set new Screen and close previous one
    {
      if (DEBUG) {
        System.err.println(
            "XX0 NativeSurface:              " + aSurface.getClass().getName() + ", " + aSurface);
      }
      final AbstractGraphicsScreen aScreen1 = aCfg.getScreen();
      aCfg.setScreen(screen);
      aScreen1.getDevice().close();
      System.err.println(
          "XXX NativeSurface:              " + aSurface.getClass().getName() + ", " + aSurface);
    }
    // If using a ProxySurface w/ an upstream surface, set new Screen and close previous one on it
    {
      boolean upstreamSet = false;
      if (aSurface instanceof ProxySurface) {
        final ProxySurface aProxy = (ProxySurface) aSurface;
        final NativeSurface aUpSurface = aProxy.getUpstreamSurface();
        if (null != aUpSurface) {
          final MutableGraphicsConfiguration aUpCfg =
              (MutableGraphicsConfiguration) aUpSurface.getGraphicsConfiguration();
          final AbstractGraphicsScreen aUpScreen1 = aUpCfg.getScreen();
          if (null != upstreamScreen) {
            System.err.println(
                "XX0 UpstreamSurface:            "
                    + aUpSurface.getClass().getName()
                    + ", "
                    + aUpSurface);
            aUpCfg.setScreen(upstreamScreen);
            aUpScreen1.getDevice().close();
            upstreamSet = true;
            System.err.println(
                "XXX UpstreamSurface:            "
                    + aUpSurface.getClass().getName()
                    + ", "
                    + aUpSurface);
          } else {
            throw new GLException(
                "Incompatible Surface config - Has Upstream-Surface: Prev-Holder = false, New-Holder = true");
          }
        }
      }
      if (!upstreamSet && null != upstreamScreen) {
        throw new GLException(
            "Incompatible Surface config - Has Upstream-Surface: Prev-Holder = true, New-Holder = false");
      }
    }

    if (aRealized) {
      a.setRealized(true);
    }
    final boolean surfaceLocked =
        false; // NativeSurface.LOCK_SURFACE_NOT_READY < aSurface.lockSurface();
    try {
      a.setContext(context);
    } finally {
      if (surfaceLocked) {
        aSurface.unlockSurface();
      }
    }
    owner = false;

    //
    // Trigger GL-Viewport reset and reshape of all initialized GLEventListeners
    //
    aGLCmds.add(setViewport);
    for (int i = 0; i < aSz; i++) {
      if (listenersInit[i]) {
        aGLCmds.add(new ReshapeGLEventListener(listeners[i]));
      }
    }
    aGLCmds.add(glFinish);
    a.invoke(aRealized, aGLCmds); // only wait if already realized

    // add all cached GLEventListener to their destination and fix their init-state
    for (int i = 0; i < aSz; i++) {
      final GLEventListener l = listeners[i];
      a.addGLEventListener(l);
      a.setGLEventListenerInitState(l, listenersInit[i]);
      listeners[i] = null;
    }

    if (null != anim && null == a.getAnimator()) {
      anim.add(a); // also handles ECT
    }
  }
Пример #2
0
    @Override
    public void display(GLAutoDrawable drawable) {
      final GL2ES2 gl = drawable.getGL().getGL2ES2();

      gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

      final GLAnimatorControl anim = drawable.getAnimator();
      final float lfps = null != anim ? anim.getLastFPS() : 0f;
      final float tfps = null != anim ? anim.getTotalFPS() : 0f;

      // Note: MODELVIEW is from [ 0 .. height ]

      final long t1 = Platform.currentTimeMillis();

      // final float fontSize = TestTextRendererNEWT00.fontSize;

      fontSizeAnim += fontSizeDelta;
      if (fontSizeMin >= fontSizeAnim || fontSizeAnim >= fontSizeMax) {
        fontSizeDelta *= -1f;
      }

      final float pixelSize = font.getPixelSize(fontSizeFixed, dpiH);
      final float pixelSizeAnim = font.getPixelSize(fontSizeAnim, dpiH);

      final String modeS = Region.getRenderModeString(renderModes);

      if (false) {
        // renderString(drawable, font, pixelSize, "I - / H P 7 0", 0, 0, 0, 0, -1000f, true);
        // renderString(drawable, font, pixelSize, "A M > } ] ", 0, 0, 0, 0, -1000f, true);
        // renderString(drawable, font, pixelSize, "M", 0, 0, 0, 0, -1000f, true);
        // renderString(drawable, font, pixelSize, "0 6 9 a b O Q A M > } ] ", 0, 0, 0, 0, -1000f,
        // true);
        // renderString(drawable, font, pixelSize, "012345678901234567890123456789", 0, 0, 0, -1000,
        // true);
        // renderString(drawable, font, pixelSize, textX2,        0, 0,   0, 0, -1000f, true);
        // renderString(drawable, font, pixelSize, text1,         0,    0, 0, -1000f, regionFPS); //
        // no-cache
        final String text1 =
            lfps
                + " / "
                + tfps
                + " fps, vsync "
                + gl.getSwapInterval()
                + ", elapsed "
                + (t1 - t0) / 1000.0
                + " s, fontSize "
                + fontSizeFixed
                + ", msaa "
                + drawable.getChosenGLCapabilities().getNumSamples()
                + ", "
                + modeS
                + "-samples "
                + vbaaSampleCount[0];
        renderString(drawable, font, pixelSize, text1, 0, 0, 0, 0, -1000, regionFPS); // no-cache
      } else {
        final String text1 =
            String.format(
                "%03.1f/%03.1f fps, vsync %d, elapsed %4.1f s, fontSize %2.2f, msaa %d, %s-samples %d",
                lfps,
                tfps,
                gl.getSwapInterval(),
                (t1 - t0) / 1000.0,
                fontSizeFixed,
                drawable.getChosenGLCapabilities().getNumSamples(),
                modeS,
                vbaaSampleCount[0]);
        renderString(drawable, font, pixelSize, getFontInfo(), 0, 0, 0, 0, -1000, true);
        renderString(
            drawable, font, pixelSize, "012345678901234567890123456789", 0, 0, 0, -1000, true);
        renderString(
            drawable, font, pixelSize, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, "4567890123456", 4, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, "I like JogAmp", 4, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, textX2, 0, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, text1, 0, 0, 0, -1000, regionFPS); // no-cache
        if (TextAnim) {
          renderString(
              drawable, font, pixelSizeAnim, text1, 0, 0, 0, -1000, regionFPSAnim); // no-cache
        }
      }
    }
Пример #3
0
  /**
   * Moves all GLEventListenerState components from the given {@link GLAutoDrawable} to a newly
   * created instance.
   *
   * <p>Note that all components are removed from the {@link GLAutoDrawable}, i.e. the {@link
   * GLContext}, all {@link GLEventListener}.
   *
   * <p>If the {@link GLAutoDrawable} was added to a {@link GLAnimatorControl}, it is removed and
   * the {@link GLAnimatorControl} added to the GLEventListenerState.
   *
   * <p>The returned GLEventListenerState instance is the {@link #isOwner() owner of the
   * components}.
   *
   * @param a {@link GLAutoDrawable} source to move components from
   * @return new GLEventListenerState instance {@link #isOwner() owning} moved components.
   * @see #moveTo(GLAutoDrawable)
   */
  public static GLEventListenerState moveFrom(GLAutoDrawable a) {
    final int aSz = a.getGLEventListenerCount();

    // Create new AbstractGraphicsScreen w/ cloned AbstractGraphicsDevice for future GLAutoDrawable
    // allowing this AbstractGraphicsDevice to loose ownership -> not closing display/device!
    final NativeSurface aSurface = a.getNativeSurface();
    final AbstractGraphicsConfiguration aCfg = aSurface.getGraphicsConfiguration();
    final AbstractGraphicsScreen aScreen1 = aCfg.getScreen();
    final GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) aCfg.getChosenCapabilities();
    final AbstractGraphicsScreen aScreen2 = cloneScreen(aScreen1);
    if (DEBUG) {
      System.err.println(
          "X00 NativeSurface:              " + aSurface.getClass().getName() + ", " + aSurface);
    }
    aScreen1.getDevice().clearHandleOwner(); // don't close device handle

    final AbstractGraphicsScreen aUpScreen2;
    {
      AbstractGraphicsScreen _aUpScreen2 = null;
      if (aSurface instanceof ProxySurface) {
        final ProxySurface aProxy = (ProxySurface) aSurface;
        final NativeSurface aUpSurface = aProxy.getUpstreamSurface();
        if (null != aUpSurface) {
          System.err.println(
              "X00 UpstreamSurface:            "
                  + aUpSurface.getClass().getName()
                  + ", "
                  + aUpSurface);
        }
        aProxy.clearUpstreamOptionBits(
            ProxySurface.OPT_PROXY_OWNS_UPSTREAM_DEVICE); // don't close device handle
        if (null != aUpSurface) {
          final AbstractGraphicsScreen aUpScreen1 =
              aUpSurface.getGraphicsConfiguration().getScreen();
          _aUpScreen2 = cloneScreen(aUpScreen1);
          if (null != aUpScreen1) {
            aUpScreen1.getDevice().clearHandleOwner(); // don't close device handle
          }
          System.err.println(
              "X0X NativeSurface:              " + aSurface.getClass().getName() + ", " + aSurface);
          System.err.println(
              "X0X UpstreamSurface:            "
                  + aUpSurface.getClass().getName()
                  + ", "
                  + aUpSurface);
        }
      }
      aUpScreen2 = _aUpScreen2;
    }

    final GLAnimatorControl aAnim = a.getAnimator();
    if (null != aAnim) {
      aAnim.remove(a); // also handles ECT
    }

    final GLEventListenerState glls =
        new GLEventListenerState(aUpScreen2, aScreen2, caps, a.getContext(), aSz, aAnim);

    //
    // remove and cache all GLEventListener and their init-state
    //
    for (int i = 0; i < aSz; i++) {
      final GLEventListener l = a.getGLEventListener(0);
      glls.listenersInit[i] = a.getGLEventListenerInitState(l);
      glls.listeners[i] = a.removeGLEventListener(l);
    }

    //
    // trigger glFinish to sync GL ctx
    //
    a.invoke(true, glFinish);

    a.setContext(null);

    return glls;
  }