GLContext.getCurrentGL()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

GLContext.getCurrentGL()

Haroogan
Does GLContext.getCurrentGL().getGL2() snippet result in performance hits? I mean is it possible not to pass GL2 object everywhere, but rather call this snippet to get GL2 object when I need it without being worried of performance loss? (I'm asking because, I don't know whether there is some slow code or maybe synchronization behind the scenes...) I'm not happy with passing GL objects everywhere - that's ugly you know :) so just guide me if GLContext.getCurrentGL().getGL2() approach is safe and performance-friendly.
Reply | Threaded
Open this post in threaded view
|

Re: GLContext.getCurrentGL()

Sven Gothel
Administrator
On Wednesday, April 06, 2011 06:44:29 pm Haroogan [via jogamp] wrote:
>
> Does GLContext.getCurrentGL().getGL2() snippet result in performance hits? I
> mean is it possible not to pass GL2 object everywhere, but rather call this
> snippet to get GL2 object when I need it without being worried of
> performance loss? (I'm asking because, I don't know whether there is some
> slow code or maybe synchronization behind the scenes...)

Of course, GLContext.getCurrentGL() is using thread local storage (TLS)
and hence some impl. specific magic.
IMHO it's faster to pass the GL instance as we offer it in our API,
since stack/register operations are hard to beat.

You may offer a performance test, passing GL versus java TLS fetch,
would be nice to see it in action. But be aware that the result may vary
between OS and architecture, since TLS might be specific to CPU and maybe even the OS.

There is another benefit of passing the GL object,
it documents that a current context is required, which is also passed.
IMHO this way no surprise happens later on, and the user can be aware of the costs
and sideeffects.

> I'm not happy with
> passing GL objects everywhere - that's ugly you know :)
You are free to have an opinion :)

But IMHO, it's ugly API wise, since it intriduces a hidden requirement and state.

> so just guide me if
> GLContext.getCurrentGL().getGL2() approach is safe and performance-friendly.

As long you know what you are doing in your implementation / application, sure it is safe.
We use this method a few times in our implementation as well .. not as a public API though.

If it will hit performance .. I dunno, pls see above.

~Sven