mgsx-dev/gdx-gltf

textureLod is not guaranteed to be supported in GLES3

fgnm opened this issue · 5 comments

fgnm commented

This happens in iOS backend, both in pure OpenGL ES 3 and in MetalANGL. Basically, the extension EXT_shader_texture_lod is not available on that platform (or at least on my testing hardware - iPhone 7, iOS 15.5), so shader compilation fails if useGL30 is enabled. To fix that issue I simple removed this first check:

if(isGL3()){
textureLodSupported = true;
}else if(Gdx.graphics.supportsExtension("EXT_shader_texture_lod")){

And let Gdx.graphics.supportsExtension decide if textureLod is supported or not.

textureLod is actually supported by GLSL 300 es so i think your device doesn't support GLES3. However parsing of version should not report a 3.0+ version in that case. Could you please check what version string you get for those backends on your test hardware?

as per libgdx documentation when GLES3 is not supported, it falls back to GLES2 (same goes for all other backends), so the check here :

return Gdx.graphics.getGLVersion().isVersionEqualToOrHigher(3, 0);

could be changed to Gdx.gl30 != null as a workaround.

Note that if neither EXT_shader_texture_lod or GLES3 are supported on that device, you can't really use PBR shaders because it hardly depending on it for material roughness.

Note for myself : isVersionEqualToOrHigher(3, 0) both handle the case of GLES3+ and GLES2 on desktop with OpenGL 3.0+. The latest being the minimum requirement for the PBR shader (GLSL 130). That isGL3 method is a bit confusing and those requirements should be better documented.

Note for myself (again) : the following code doesn't handle iOS :

}else if(Gdx.app.getType() == ApplicationType.Android){

fgnm commented

Uhm no, GLES3 is perfectly fine on iOS, I use it also for other stuff, its just that the EXT_shader_texture_lod not present in the system (I checked in GL_EXTENSIONS too), I guess because Apple never implemented full GLES3 support nor ANGLE (or MetalANGLE) yet...

2022-07-08 14:01:15.223809+0200 IOSLauncher[2463:96331] [debug] IOSApplication: iOS version: 15.5
2022-07-08 14:01:15.223876+0200 IOSLauncher[2463:96331] [debug] IOSApplication: Running in 64-bit mode
2022-07-08 14:01:15.234305+0200 IOSLauncher[2463:96331] [debug] IOSApplication: Pixels per point: 2.0
2022-07-08 14:01:15.263908+0200 IOSLauncher[2463:96331] [debug] IOSApplication: Status bar is not visible
2022-07-08 14:01:15.264006+0200 IOSLauncher[2463:96331] [debug] IOSApplication: Computed bounds are x=0 y=0 w=375 h=667 bbW= 750 bbH= 1334
2022-07-08 14:01:15.307917+0200 IOSLauncher[2463:96331] MGLKViewController resume
2022-07-08 14:01:15.309019+0200 IOSLauncher[2463:96331] [debug] IOSGraphics: Display: ppi=326, density=2.0375
2022-07-08 14:01:15.337771+0200 IOSLauncher[2463:96331] [debug] IOSApplication: created
2022-07-08 14:01:15.338794+0200 IOSLauncher[2463:96331] [debug] IOSApplication: Status bar is not visible
2022-07-08 14:01:15.338854+0200 IOSLauncher[2463:96331] [debug] IOSApplication: Computed bounds are x=0 y=0 w=375 h=667 bbW= 750 bbH= 1334
Shaders version OpenGL ES GLSL ES 3.00 (ANGLE 2.1.0.ffc603fabdfe)
Gdx.gl30 != null: true
2022-07-08 14:01:15.495994+0200 IOSLauncher[2463:96331] [info] ARTest: Google Inc. - ANGLE (Metal Renderer: Apple A10 GPU)
2022-07-08 14:01:15.496050+0200 IOSLauncher[2463:96331] [info] ARTest: Screen size 750 x 1334
2022-07-08 14:01:15.496077+0200 IOSLauncher[2463:96331] [info] ARTest: GL version OpenGL ES 3.0.0 (ANGLE 2.1.0.ffc603fabdfe)
2022-07-08 14:01:15.496099+0200 IOSLauncher[2463:96331] [info] ARTest: Shaders version OpenGL ES GLSL ES 3.00 (ANGLE 2.1.0.ffc603fabdfe)
2022-07-08 14:01:15.496131+0200 IOSLauncher[2463:96331] [info] ARTest: JVM Version: 0 (RoboVM)

As you can see if you change the check with Gdx.gl30 != null it will fails anyway since it will try to load textureLod which doesn't exists.
BTW with my workaround the model is correctly rendered, I know mine it's a very basic use of this library, but it's convenient to have the same rendering code for any platform.

i edited my previous comment and i think the issue is here :

}else if(Gdx.app.getType() == ApplicationType.Android){

It should be Gdx.app.getType() == ApplicationType.Android || Gdx.app.getType() == ApplicationType.iOS

Could you please confirm?

(i probably didn't know GLES3 was possible on iOS when i coded that)

fgnm commented

Yes, it works! I tried before some version instruction but didn't find the correct one.. But I'm wondering why EXT_shader_texture_lod is not present in the extensions list.. Anyway thanks!

nice! the reason why EXT_shader_texture_lod is not present is because it uses GLES3 which has it in core, so there is no need for extension and is removed from the list in that context.

I'll commit the fix right now. Thank you for your feedback.