Beispiel #1
0
 public void setSmooth(int level) {
   pgl.reqNumSamples = level;
   GLCapabilities caps = new GLCapabilities(profile);
   caps.setAlphaBits(PGL.REQUESTED_ALPHA_BITS);
   caps.setDepthBits(PGL.REQUESTED_DEPTH_BITS);
   caps.setStencilBits(PGL.REQUESTED_STENCIL_BITS);
   caps.setSampleBuffers(true);
   caps.setNumSamples(pgl.reqNumSamples);
   caps.setBackgroundOpaque(true);
   caps.setOnscreen(true);
   NativeSurface target = window.getNativeSurface();
   MutableGraphicsConfiguration config =
       (MutableGraphicsConfiguration) target.getGraphicsConfiguration();
   config.setChosenCapabilities(caps);
 }
  /**
   * 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
    }
  }