ClassiCube icon indicating copy to clipboard operation
ClassiCube copied to clipboard

internalformat should potentially be GL_BGRA with GLES build

Open UnknownShadow200 opened this issue 2 years ago • 0 comments

See https://f.classicube.net/topic/2192-on-toshiba-ac100-all-textures-and-interface-in-the-game-are-black/ for background

For efficiency, for desktop OpenGL ClassiCube uses an internalFormat of GL_RGBA and a format of GL_BGRA. (Since this is usually the fastest upload format)

This is because as per the OpenGL 2.0 (and OpenGL 1.2) spec for texImage2D, internalFormat can be different from format - and although GL_BGRA is supported for format, it is NOT supported for internalFormat. (This probably originated from the original EXT_bgra extension spec, which only added GL_BGRA as an acceptable format)

(note that trying to use an internalFormat of GL_BGRA anyways does not work)


In contrast though, the OpenGL ES 2.0 spec for texImage2D does not support GL_BGRA for either format or internalFormat by default.

Instead, support for GL_BGRA depends on whether the GPU driver supports either the EXT_texture_format_BGRA8888 (near universally supported, by ~99% of OpenGL ES reports on gpuinfo.org) or APPLE_texture_format_BGRA8888(pretty much just apple devices?) extensions.

For Android/WebGL, this issue is sidestepped because they instead use GL_RGBA for both format and internalFormat.


However, for other devices which do use GL_BGRA (such as iOS, Raspberry Pi, etc), reading the texImage2D spec closely reveals a problem - it explicitly states that format MUST be the same as internalFormat.

Reading the extensions introduces even more potential confusion because:

  • EXT_texture_format_BGRA8888 - if GL_BGRA is used for format, then GL_BGRA must also be used for internalFormat
  • APPLE_texture_format_BGRA8888 - if GL_BGRA is used for format, then GL_RGBA must be used for internalFormat

Which is corroborated by ImgTec's documentation for OpenGL extensions on PowerVR.

In practice though, just using GL_RGBA for internalFormat and GL_BGRA for format worked fine anyways.. except for the device in the linked forum thread. (nVidia Tegra 2 with proprietary NVIDIA drivers on lubuntu 13.04)

While switching to GL_BGRA for internalFormat fixed the issue for that device, need to investigate further switching to GL_BGRA will cause issues (or affect performance) with any other GPU drivers or not.

(also see https://www.g-truc.net/post-0734.html for some extra details)

UnknownShadow200 avatar Jun 07 '23 11:06 UnknownShadow200