Login  Register

Re: Can JOGL be used without requiring GLAutoDrawable instances?

Posted by Sven Gothel on Jul 26, 2015; 2:15am
URL: https://forum.jogamp.org/Can-JOGL-be-used-without-requiring-GLAutoDrawable-instances-tp4034953p4034973.html

On 07/25/2015 11:41 PM, xghost [via jogamp] wrote:

> The following seems to be possible, at arbitrary locations and without a need
> to use GLEventListener:
>
> GL4 gl = com.jogamp.opengl.GLContext.getCurrentGL().getGL4();
> gl.glUseProgram(0);
> // ...
>
>
> Please let me know if I'm running into a time-bomb waiting to go off or if
> this is just fine. If this is a good way to use JOGL, then it seems it might
> allow me to do exactly what I needed.
Well the above will work iff the desired OpenGL GLContext
is current. Otherwise a GLException is thrown or you receive
the wrong GLContext (if many different are in use).

Note: GLContext.getCurrent() will return null if none is current.

In short: Yes it can work, given above constraints.

However, it is still not the desired safe and recommended way to handle
to handle this task.

- GLContext.getCurrent() uses ThreadLocal<>, i.e. thread local storage (TLS),
  see
<http://forum.jogamp.org/Why-does-JOGL-use-Instances-of-GLContext-GL-instead-of-exposing-a-Static-API-td4034144.html>.

- Why querying an instance of a suppose to be known object
  within the workflow of a determined API/system?

In the end .. it is your design decision, of course!

Cheers, Sven



signature.asc (828 bytes) Download Attachment