gl4es icon indicating copy to clipboard operation
gl4es copied to clipboard

Uniform locations of array needs to be fetched for each

Open okuoku opened this issue 2 years ago • 2 comments

at: https://github.com/ptitSeb/gl4es/commit/f5dda93ac7eaf1e3a44b1ee5585a6bf61d0656c5 found by: (internal validation tool)

Strictly speaking, glGetUniformLocation needs to be called for each element of an array. GL spec says:

  • https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glGetUniformLocation.xhtml

Locations for sequential array indices are not required to be sequential. The location for "a[1]" may or may not be equal to the location for "a[0]" + 1. ... Applications that wish to set individual array elements should query the locations of each element separately.

In fill_program function, it just id++ for each elements as it assume locations for sequential array indices are sequential. The function could be patched like https://github.com/okuoku/gl4es/commit/328e404b9f74947fc8047f5cf0cb72e25d276658 and there might be other functions need to be fixed.

okuoku avatar Jan 18 '23 11:01 okuoku

Out of curiosity @okuoku how does the error manifests itself when it is unpatched ?

Mathias-Boulay avatar Feb 19 '23 21:02 Mathias-Boulay

As far as i know, it won't be issue on existing OpenGLES2 hardware implementations on the market and ANGLE. So no error will be detected on these. It was detected with my own GLES call validator and my implementation of GLES to WebGL wrapper.

Although the spec allows to optimize-out specific array element during shader compilation by allowing non-contiguous uniform locations, I never experienced such optimization..

okuoku avatar Feb 20 '23 00:02 okuoku