GLContext.setRenderingThread strange code?

While browsing the code for GLContext i found difficult to understand this code at the beginning of setRenderingThread:


    Thread currentThread = Thread.currentThread();
    if (currentThreadOrNull != null && currentThreadOrNull != currentThread) {
      throw new GLException("Argument must be either the current thread or null");
    }

Why having to pass the currentThreadOrNull argument if it cannot be null or different from Thread.currentThread()?

Having the method written as:


public synchronized void setRenderingThread(Runnable initAction) {
Thread currentThread  = Thread.currentThread();
...
[s]    if (currentThreadOrNull != null && currentThreadOrNull != currentThread) {
      throw new GLException("Argument must be either the current thread or null");
    }
[/s]
...

shall avoid the many unexpected exceptions and related questions?

Or i missed something obvious ???

This API was intended as an optimization but later work showed that it caused significant problems. I would recommend just ignoring it. setRenderingThread is no longer present in the JSR-231 APIs.

FYI, you can check out the current JSR-231 code with

cvs co -r JSR-231 jogl jogl-demos

All of the new OpenGL context APIs are implemented though not all functionality has been tested. This is the direction JOGL is going so if you’re looking at the code I’d recommend looking at this branch instead.