Force Hardware Acceleration being turned OFF

Hi guys,

I’m working on improving the stability of my jogl-app.
As I encountered problems related to graphics drivers and cards, that I can’t influence, I would like to circumvent these by turning off hardware acceleration in case of errrors.
When does an errror occur?
Well, if a GLException is thrown (eg. in the display-function of my GLEventListener).
I’ve got the following code


public class MyJoglApp implements GLEventListener {

public GLCanvas canvas;

public void display(GLAutoDrawable drawable) {
        
    try {
        drawEverything();
    }
    catch(GLException e){
        System.out.println("GLException in display function catched!");
        e.printStackTrace();
        System.out.println("Switching to non-hardware-accelerated rendering now.");
        GLCapabilities glCaps = new GLCapabilities();
        glCaps.setRedBits(8);
        glCaps.setBlueBits(8);
        glCaps.setGreenBits(8);
        glCaps.setAlphaBits(8);
        
        glCaps.setHardwareAccelerated(false);
        
        // now exchange the canvas
    
        Container cont = canvas.getParent();
            
        cont.remove(canvas);
        cont.validate();
            
        canvas = null;
            
        canvas = new GLCanvas(glCaps);
        canvas.addGLEventListener(this);
        cont.add(canvas);
        cont.validate();
    }
}
}

But it falls into an infinite loop, since the call to setHardwareAccelerated(false) seems to have no effect:

If I initialize my canvas directly with this requirement, still hardware acceleration is turned on!!!

So, I think my problem could easily be solved, if I knew how to force hardware acceleration being turned off.

Best regards,
Oliver

Well, just for the case that somebody else has the same problem, here’s how I solved the problem:


private void display(...){
try{
render_scene();
}catch(GLException ex){
switchToFallbackMode();
}
}

private void switchToFallbackMode(){
        
        System.out.println("Switching to non-hardware-accelerated rendering now.");
        
        GLCapabilities glCaps = new GLCapabilities();
        glCaps.setRedBits(8);
        glCaps.setBlueBits(8);
        glCaps.setGreenBits(8);
        glCaps.setAlphaBits(8);
        glCaps.setHardwareAccelerated(false);
        glCaps.setDepthBits(24);
        glCaps.setDoubleBuffered(true);

        Container cont = canvas.getParent();

        cont.remove(canvas);
        cont.validate();

        canvas = null;

        canvas = new GLCanvas(glCaps, new CustomGLCapabilitiesChooser(), null, null);
        canvas.addGLEventListener(this);
        canvas.addMouseListener(this);
        canvas.addMouseMotionListener(this);
        canvas.addKeyListener(this);

        cont.add(canvas);
        cont.validate();
    }

and the CustomGLCapabilitiesChooser class reads


public class CustomGLCapabilitiesChooser implements GLCapabilitiesChooser{

    public int chooseCapabilities(
            GLCapabilities desired, 
            GLCapabilities[] available, 
            int windowSystemRecommendedChoice) {
/*
        for (int i = 0 ; i < available.length ; i++){
            if (i == windowSystemRecommendedChoice)
                System.out.println("Recommended choice:");
            if (available[i] != null   )
                System.out.println(i + " :  " + available[i].toString());
            else
                System.out.println(i + " :  null");
        }
*/
        int choice = windowSystemRecommendedChoice;

        for (int i = 0 ; i < available.length ; i++){
            if(available[i] != null)
                if (available[i].getHardwareAccelerated() == desired.getHardwareAccelerated()){
                    if(available[i].getRedBits() == desired.getRedBits()
                    && available[i].getGreenBits() == desired.getGreenBits()
                    && available[i].getBlueBits() == desired.getBlueBits()
                    && available[i].getAlphaBits() == desired.getAlphaBits()
                    && available[i].getDoubleBuffered() == desired.getDoubleBuffered()
                    && available[i].getDepthBits() >= desired.getDepthBits()){
                        choice = i;
                    }
                }
                else{ // if hardwareAccelearation does not match
                    if(available[i].getRedBits() == desired.getRedBits()
                    && available[i].getGreenBits() == desired.getGreenBits()
                    && available[i].getBlueBits() == desired.getBlueBits()
                    && available[i].getAlphaBits() == desired.getAlphaBits()){
                        //choice = i;
                    }
                }               
        }
        return choice;
    }

}

Hope this may help somebody.
Cheers