Hardware GLCapabiities not detected

Hello, i was asking a lot on this forum about why arent my hardware capabilities captured correctly when i use GLCapabilies.

As i was seeking an answer to this, i started digging into the code of RC8 (Latest release) and i would appreciate if some one could explain the folowing.

The constructor of GLCapabiities (which according to 1.1.0 javadocs detects the best configuration that my hardware can provide) does nothing :

ublic class GLCapabilities implements Cloneable {
  private boolean doubleBuffered = true;
  private boolean stereo         = false;
  private boolean hardwareAccelerated = true;
  private int     depthBits      = 24;
  private int     stencilBits    = 0;
  private int     redBits        = 8;
  private int     greenBits      = 8;
  private int     blueBits       = 8;
  private int     alphaBits      = 0;
  private int     accumRedBits   = 0;
  private int     accumGreenBits = 0;
  private int     accumBlueBits  = 0;
  private int     accumAlphaBits = 0;
  // Shift bits from PIXELFORMATDESCRIPTOR not present because they
  // are unlikely to be supported on Windows anyway

  // Support for full-scene antialiasing (FSAA)
  private boolean sampleBuffers = false;
  private int     numSamples    = 2;

  // Bits for pbuffer creation
  private boolean pbufferFloatingPointBuffers;
  private boolean pbufferRenderToTexture;
  private boolean pbufferRenderToTextureRectangle;

  /** Creates a GLCapabilities object. All attributes are in a default
      state.
    */
  public GLCapabilities() {}

The instance of this GLCapabiites should be passed to the GLCanvas which will on construction try to get the best set of capabilities close to the capabilities requested by the user!

The GLCanvas will call chooseGraphicsConfiguration(capabilities, chooser, device); which will query the hardware for the capabilites

  public GLCanvas(GLCapabilities capabilities,
                  GLCapabilitiesChooser chooser,
                  GLContext shareWith,
                  GraphicsDevice device) {
    // The platform-specific GLDrawableFactory will only provide a
    // non-null GraphicsConfiguration on platforms where this is
    // necessary (currently only X11, as Windows allows the pixel
    // format of the window to be set later and Mac OS X seems to
    // handle this very differently than all other platforms). On
    // other platforms this method returns null; it is the case (at
    // least in the Sun AWT implementation) that this will result in
    // equivalent behavior to calling the no-arg super() constructor
    // for Canvas.
    /*
     * Workaround for Xinerama, always pass null so we can detect whether
     * super.getGraphicsConfiguration() is returning the Canvas' GC (null),
     * or an ancestor component's GC (non-null) in the overridden version
     * below.
     */
    super();
    /*
     * Save the chosen capabilities for use in getGraphicsConfiguration().
     */
    chosen = chooseGraphicsConfiguration(capabilities, chooser, device);
    if (chosen != null) {
      /*
       * If we are running on a platform that
       * must select a GraphicsConfiguration now,
       * save these for later use in getGraphicsConfiguration().
       */
      this.glCapChooser = chooser;
      this.glCaps = capabilities;
    }
    if (!Beans.isDesignTime()) {
      drawable = GLDrawableFactory.getFactory().getGLDrawable(this, capabilities, chooser);
      context = (GLContextImpl) drawable.createContext(shareWith);
      context.setSynchronized(true);
    }
  }

Tracking this function down will lead to three implementations depending on your OS (MacOSX, X11, Windows)

Windows (WindowsGLDrawableFactory):

public AbstractGraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities,
                                                                   GLCapabilitiesChooser chooser,
                                                                   AbstractGraphicsDevice device) {
    return null;
  }

MacOSX (MacOSXGLDrawableFactory):

 public AbstractGraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities,
                                                                   GLCapabilitiesChooser chooser,
                                                                   AbstractGraphicsDevice device) {
    return null;
  }

X11 is the only one that does actualy something and doesnt return null!

Why is that ? And doesnt this mean that there is no querying of hardware capabilities on windows and MacOS unlike what JOGL says?

Regards,
Rami

Hello Rami,

At the beginning let me apalogize because i will not give you an answer. In fact i am facing the same problem like you and i think there is really somtehing wrong here. I was trying to turn on double-buffering which should be done (as i understand) like this

GLCapabilities caps = new GLCapabilities();
caps.setDoubleBufferd(true);
GLCanvas canvas = new GLCanvas(caps);

However the flickering was still present ( thats why i want double-buffering, i wanted to avoid this flickering). Later i managed that despite the code above
if i try to get back caps (i.e.) canvas.getChosenGLCapabilities() i got null obejct only. So the double-buffering can not be possibly turned onn it this is true.

As you show, there is explicly stated “retutn null” in jogl code. So what the hell does this mean ? Because if this is all true then the GLCapabilities features are only some dummy class ( at least for mac and win). I am wondering if this could be even possible, that would mean that even the totaly basic of hardware settings ( double-buffering ) are not included in laters realeses of jogl :confused: .

Allright,

Forget teh buffering, i used wrong get method (would get “chosen” object, not “capabilities” obejct). But still what points out remi is curis and still the double-buffering is not working (even with that gl.glClear(GL.GL_COLOR_BUFFER_BIT) stuff )

As far as I remember the capabilities are chosen short before the first paint happens and not in the constructor of the GLCanvas (maybe linux is a exception but I am not sure). (sorry currently no time to debug into the code)

So make sure your Canvas is visible. We use this technique for the capabilities viewer of the NetBeans OpenGL pack (thats the reason for the gears demo in the edge of the cap viewer this wont work with “hidden” drawables).
https://netbeans-opengl-pack.dev.java.net/servlets/ProjectProcess?tab=1 bottom of page

Also look at the CapsTableDemo of the JOGL demos.

hope that helps

First of all thanks for the replies.

Actually, as far as jogl is concerned you are right bienator. It is shown in the comments that they return null because just before the init function of opengl the hardware is identified when it comes to windows and mac.
But unfourtunatly this is not always the case. Let me explain my point here:
On init opengl will TRY to query the hardware which means that it will try to initialize all the features. (this is implemented by the hardware vendors like NVIDIA …etc) and you can check this in openGL specs. Anyway, back to my point, openGL will fail cuz if the hardware is busy it wont wait instead give default values. So, to assume that this would work everytime if it worked the first time you turned it on is not correct (cuz maybe the next time you will be out of sync, especially if you application is multithreaded or another application is using the hardware).

I know that what openGL initialize are the pixel formats but be aware that these values are the first checkers when querying for a feature (this is an optimization that is usually done). For example, assume that on initialize the application set 4 bits for each of RGB values (it is actaully 8 ) when during your run you query the hardware (using CG corresponding functions for the number of bits allowed it will return 8 ). So, if you send your data with 8 bits and you screen is set to 4 bits some data is lost if not corrupted. In heavy computation applications this would be a problem.

This might seem weird for some but this actually happens. And trust me when this happenns it very hard to debug it.

A very simple testcase (that will show the point but froma different perspective) for this would be to use two screens of different types (one with 16 bit colors and another with 32 bit colors) and draw a color scale quad that fills the canvas using a Primary color to White (interpolated) with another layer ontop blended with an alpha of 0.01 and move(dont drag it) this canvas from the 32bit screen to the 16bit one and see what happens (use large canvas to see the results better)

I hope that this helps! I am going into these details because we are implementing a CAD/construction related software for production and these details and stability (which we are not getting) are more important to us than the wonderfull features being added currently to JOGL!

Best Regards,
Rami

One more thing, It would have been nice to point out somewhere that most of the features wont work if you are working on a version older than JAVA 1.6!

The calling of the GLCapabilitiesChooser is implemented (for the GLCanvas) on all platforms. It is done at different times on different platforms due to differences in how the window system bindings for OpenGL work. On X11 platforms it needs to be done at the creation of the GLCanvas. On Mac and Windows platforms it is done when the peer for the GLCanvas is created.

All of the features of JOGL work as far back as JDK 1.4.2. JDK 6 enables performance improvements, but the core functionality is identical as far back as 1.4.2.

Thanks that really helped!