Login  Register

Re: Shader & texture - weird display

Posted by gouessej on Apr 21, 2020; 3:16pm
URL: https://forum.jogamp.org/Shader-texture-weird-display-tp4040540p4040544.html

Hello

We're not responsible for unofficial tutorials, especially when they infringe the most basic guidelines that I have repeated for about 14 years. Rather look at our rudimentary examples in our wiki:
https://jogamp.org/wiki/index.php?title=Jogl_Tutorial

The line "private GL2 gl = GLContextManager.getInstance().getOpenGLContext().getGL();" illustrates my warning, you mustn't store a GL instance that way, you mustn't store it into a field. You must get it from the GLEventListener or from GLContext.getCurrentGL(). When you store a GL instance into a field, you take the risk of using it when it's no longer valid, on the wrong thread or on the good thread but not when the OpenGL context is current. I don't want to make you believe that this source code is correct.

By the way, don't use indirect NIO buffers, rather create direct NIO buffers when you want to pass them to JOGL (otherwise, it will have to make the conversion under the hood anyway but it will increase the memory footprint because the indirect NIO buffers will still occupy some memory on the Java heap while the direct NIO buffers will occupy some memory on the native heap).
Julien Gouesse | Personal blog | Website