protected static X11GLXGraphicsConfiguration createDefaultGraphicsConfiguration(
      AbstractGraphicsScreen absScreen, boolean onscreen, boolean usePBuffer) {
    if (absScreen == null) {
      throw new IllegalArgumentException("AbstractGraphicsScreen is null");
    }
    if (!(absScreen instanceof X11GraphicsScreen)) {
      throw new IllegalArgumentException("Only X11GraphicsScreen are allowed here");
    }
    X11GraphicsScreen x11Screen = (X11GraphicsScreen) absScreen;

    GLProfile glProfile = GLProfile.getDefault();
    GLCapabilities caps = null;
    XVisualInfo xvis = null;
    long fbcfg = 0;
    int fbid = -1;

    // Utilizing FBConfig
    //
    GLCapabilities capsFB = null;
    long display = x11Screen.getDevice().getHandle();
    try {
      NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
      X11Lib.XLockDisplay(display);
      int screen = x11Screen.getIndex();
      boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display);

      long visID = X11Lib.DefaultVisualID(display, x11Screen.getIndex());
      xvis = X11GLXGraphicsConfiguration.XVisualID2XVisualInfo(display, visID);
      caps =
          X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities(
              glProfile, display, xvis, onscreen, usePBuffer, isMultisampleAvailable);

      int[] attribs =
          X11GLXGraphicsConfiguration.GLCapabilities2AttribList(
              caps, true, isMultisampleAvailable, display, screen);
      int[] count = {-1};
      PointerBuffer fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, attribs, 0, count, 0);
      if (fbcfgsL == null || fbcfgsL.limit() < 1) {
        throw new Exception("Could not fetch FBConfig for " + caps);
      }
      fbcfg = fbcfgsL.get(0);
      capsFB =
          X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(
              glProfile, display, fbcfg, true, onscreen, usePBuffer, isMultisampleAvailable);

      fbid = X11GLXGraphicsConfiguration.glXFBConfig2FBConfigID(display, fbcfg);

      xvis = GLX.glXGetVisualFromFBConfigCopied(display, fbcfg);
      if (xvis == null) {
        throw new GLException("Error: Choosen FBConfig has no visual");
      }
    } catch (Throwable t) {
    } finally {
      X11Lib.XUnlockDisplay(display);
      NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
    }

    return new X11GLXGraphicsConfiguration(
        x11Screen, (null != capsFB) ? capsFB : caps, caps, null, xvis, fbcfg, fbid);
  }
Ejemplo n.º 2
0
 @BeforeClass
 public static void initClass() {
   glp = GLProfile.getGL2ES2();
   Assert.assertNotNull(glp);
   width = 640;
   height = 480;
 }
Ejemplo n.º 3
0
  private void run(int type, PerfModule pm) {
    int width = 800;
    int height = 480;
    pmod = pm;
    System.err.println("Perftst.run()");
    try {
      GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2());
      // For emulation library, use 16 bpp
      caps.setRedBits(5);
      caps.setGreenBits(6);
      caps.setBlueBits(5);
      caps.setDepthBits(16);

      Window nWindow = null;
      if (0 != (type & USE_AWT)) {
        Display nDisplay =
            NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null); // local display
        Screen nScreen =
            NewtFactory.createScreen(NativeWindowFactory.TYPE_AWT, nDisplay, 0); // screen 0
        nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps);
        window = GLWindow.create(nWindow);
      } else {
        window = GLWindow.create(caps);
      }

      window.addMouseListener(this);
      window.addGLEventListener(this);
      // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_CURRENT); // default
      // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current ..

      // Size OpenGL to Video Surface
      window.setSize(width, height);
      window.setFullscreen(true);
      window.setVisible(true);

      window.display();

      // Shut things down cooperatively
      window.destroy();
      window.getFactory().shutdown();
      System.out.println("Perftst shut down cleanly.");
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
Ejemplo n.º 4
0
 static {
   GLProfile.initSingleton();
 }
Ejemplo n.º 5
0
  /**
   * Creates and initializes an appropriate OpenGl Context (NS). Should only be called by {@link
   * makeCurrentImpl()}.
   */
  protected boolean create(boolean pbuffer, boolean floatingPoint) {
    MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this);
    long share = 0;
    if (other != null) {
      if (!other.isNSContext()) {
        throw new GLException("GLContextShareSet is not a NS Context");
      }
      share = other.getHandle();
      if (share == 0) {
        throw new GLException("GLContextShareSet returned a NULL OpenGL context");
      }
    }
    MacOSXCGLGraphicsConfiguration config =
        (MacOSXCGLGraphicsConfiguration)
            drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
    GLCapabilitiesImmutable capabilitiesRequested =
        (GLCapabilitiesImmutable) config.getRequestedCapabilities();
    GLProfile glProfile = capabilitiesRequested.getGLProfile();
    if (glProfile.isGL3()) {
      throw new GLException(
          "GL3 profile currently not supported on MacOSX, due to the lack of a OpenGL 3.1 implementation");
    }
    // HACK .. bring in OnScreen/PBuffer selection to the DrawableFactory !!
    GLCapabilities capabilities = (GLCapabilities) capabilitiesRequested.cloneMutable();
    capabilities.setPBuffer(pbuffer);
    capabilities.setPbufferFloatingPointBuffers(floatingPoint);

    long pixelFormat = MacOSXCGLGraphicsConfiguration.GLCapabilities2NSPixelFormat(capabilities);
    if (pixelFormat == 0) {
      throw new GLException("Unable to allocate pixel format with requested GLCapabilities");
    }
    config.setChosenPixelFormat(pixelFormat);
    try {
      int[] viewNotReady = new int[1];
      // Try to allocate a context with this
      contextHandle = CGL.createContext(share, drawable.getHandle(), pixelFormat, viewNotReady, 0);
      if (contextHandle == 0) {
        if (viewNotReady[0] == 1) {
          if (DEBUG) {
            System.err.println("!!! View not ready for " + getClass().getName());
          }
          // View not ready at the window system level -- this is OK
          return false;
        }
        throw new GLException("Error creating NSOpenGLContext with requested pixel format");
      }

      if (!pbuffer && !capabilities.isBackgroundOpaque()) {
        // Set the context opacity
        CGL.setContextOpacity(contextHandle, 0);
      }

      GLCapabilitiesImmutable caps =
          MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(glProfile, pixelFormat);
      config.setChosenCapabilities(caps);
    } finally {
      CGL.deletePixelFormat(pixelFormat);
    }
    if (!CGL.makeCurrentContext(contextHandle)) {
      throw new GLException("Error making Context (NS) current");
    }
    isNSContext = true;
    setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT | CTX_OPTION_ANY);
    GLContextShareSet.contextCreated(this);
    return true;
  }