Example #1
0
 public GLPbufferImpl(GLDrawableImpl pbufferDrawable, GLContext parentContext) {
   GLCapabilities caps =
       (GLCapabilities)
           pbufferDrawable
               .getNativeWindow()
               .getGraphicsConfiguration()
               .getNativeGraphicsConfiguration()
               .getChosenCapabilities();
   if (caps.isOnscreen()) {
     if (caps.isPBuffer()) {
       throw new IllegalArgumentException(
           "Error: Given drawable is Onscreen and Pbuffer: " + pbufferDrawable);
     }
     throw new IllegalArgumentException("Error: Given drawable is Onscreen: " + pbufferDrawable);
   } else {
     if (!caps.isPBuffer()) {
       throw new IllegalArgumentException(
           "Error: Given drawable is not Pbuffer: " + pbufferDrawable);
     }
   }
   this.pbufferDrawable = pbufferDrawable;
   context = (GLContextImpl) pbufferDrawable.createContext(parentContext);
   context.setSynchronized(true);
 }
  protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationFBConfig(
      GLCapabilities capabilities, GLCapabilitiesChooser chooser, X11GraphicsScreen x11Screen) {
    int recommendedIndex = -1;
    GLCapabilities[] caps = null;
    PointerBuffer fbcfgsL = null;
    int chosen = -1;
    int retFBID = -1;
    XVisualInfo retXVisualInfo = null;
    GLProfile glProfile = capabilities.getGLProfile();
    boolean onscreen = capabilities.isOnscreen();
    boolean usePBuffer = capabilities.isPBuffer();

    // Utilizing FBConfig
    //
    AbstractGraphicsDevice absDevice = x11Screen.getDevice();
    long display = absDevice.getHandle();
    try {
      NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
      X11Lib.XLockDisplay(display);
      int screen = x11Screen.getIndex();
      boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display);
      int[] attribs =
          X11GLXGraphicsConfiguration.GLCapabilities2AttribList(
              capabilities, true, isMultisampleAvailable, display, screen);
      int[] count = {-1};

      fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, attribs, 0, count, 0);
      if (fbcfgsL == null || fbcfgsL.limit() < 1) {
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXChooseFBConfig ("
                  + x11Screen
                  + ","
                  + capabilities
                  + "): "
                  + fbcfgsL
                  + ", "
                  + count[0]);
        }
        return null;
      }
      if (!X11GLXGraphicsConfiguration.GLXFBConfigValid(display, fbcfgsL.get(0))) {
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: ("
                  + x11Screen
                  + ","
                  + capabilities
                  + "): "
                  + fbcfgsL
                  + ", fbcfg: 0x"
                  + Long.toHexString(fbcfgsL.get(0)));
        }
        return null;
      }
      recommendedIndex = 0; // 1st match is always recommended ..
      caps = new GLCapabilities[fbcfgsL.limit()];
      for (int i = 0; i < fbcfgsL.limit(); i++) {
        caps[i] =
            X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(
                glProfile,
                display,
                fbcfgsL.get(i),
                false,
                onscreen,
                usePBuffer,
                isMultisampleAvailable);
      }

      if (null == chooser) {
        chosen = recommendedIndex;
      } else {
        try {
          chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex);
        } catch (NativeWindowException e) {
          if (DEBUG) {
            e.printStackTrace();
          }
          chosen = -1;
        }
      }
      if (chosen < 0) {
        // keep on going ..
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig Failed .. unable to choose config, using first");
        }
        chosen = 0; // default ..
      } else if (chosen >= caps.length) {
        throw new GLException(
            "GLCapabilitiesChooser specified invalid index (expected 0.."
                + (caps.length - 1)
                + ")");
      }

      retFBID = X11GLXGraphicsConfiguration.glXFBConfig2FBConfigID(display, fbcfgsL.get(chosen));

      retXVisualInfo = GLX.glXGetVisualFromFBConfigCopied(display, fbcfgsL.get(chosen));
      if (retXVisualInfo == null) {
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXGetVisualFromFBConfig ("
                  + x11Screen
                  + ", "
                  + fbcfgsL.get(chosen)
                  + " (Continue: "
                  + (false == caps[chosen].isOnscreen())
                  + "):\n\t"
                  + caps[chosen]);
        }
        if (caps[chosen].isOnscreen()) {
          // Onscreen drawables shall have a XVisual ..
          return null;
        }
      }
    } finally {
      X11Lib.XUnlockDisplay(display);
      NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
    }

    return new X11GLXGraphicsConfiguration(
        x11Screen,
        caps[chosen],
        capabilities,
        chooser,
        retXVisualInfo,
        fbcfgsL.get(chosen),
        retFBID);
  }