What should be the unit of parameter 'length' in GL.glShaderSource?

Hi @Momoko_Fan, @gouessej

During my experiment of JOGL, I got the following failure with a hand made shader :

Caused by: com.jme3.renderer.RendererException: compile error in: ShaderSource[name=Shaders/deferred/lighting.frag, defines, type=Fragment, language=GLSL150]
(0) : error C0000: syntax error, unexpected $end at token "<EOF>"

Than seems to be cause by wrong value of length on call to glShaderSource.

        intBuf1.put(0, stringBuf.length());
        gl.glShaderSource(id, new String[]{ stringBuf.toString() }, intBuf1);

and in fact in failing case nb of char != nb of bytes (33327 vs 33332)

stringBuf.toString().length() != + stringBuf.toString().getBytes().length);

If I inject the right nb of bytes, it no longer failed with JOGL. But the same shader source previously works with LWGL backend on linux (on mac I got an GL error without info so I don’t know if it related or not).

So should I made a patch on GLRenderer or on JOGL backend ?

I advise you to modify only the JOGL backend in my humble opinion. I can do it now.

So I ignore the length paramater provide by GLRenderer ? and sum getBytes().length of every string in String[].

I’m currently opening Eclipse, I’m looking at the source code…

Can’t you modify your own shader instead? Is this bug reproducible with the build-in shaders?

I’m currently fixing this bug…

Being able to create custom shader is a feature of jME3.
I can modify the shader (with out adding usless “/////////” at the end of file). But that will fix the issue only for me, not for other shader user (in future) and they will waste time to debug like me.

I guest anny shader with non-ASCII character will failed (eg comment using UTF-8 caractere).

My failing shader is validated by glslLangValidator (I re-downloaded it yesterday during debug).

Please look at my latest commit and thank you for reporting this bug.

I have to leave, I’ll look at my email on my smartphone anyway. Let me know whether something doesn’t work as expected.

I tested modification at GLRenderer level:

        String shaderSource = stringBuf.toString();

        intBuf1.clear();
        intBuf1.put(0, shaderSource.getBytes().length);
        gl.glShaderSource(id, new String[]{ shaderSource }, intBuf1);

And it works with JOGL and LWJGL. (modulo others differences: no display of some model, mouse pointer not captured/hidden,…)

with LWJGL

with JOGL

Thanks for your support.

This is the kind of support that you can expect when using the softwares and APIs maintained by the JogAmp community. I’m rarely on the forum but our end users and contributors (particularly in France) get accustomed with bumping me whenever they want. Thank you for the screen capture :smile: