Bug (and proposed fix): createTexture does not work with TEXTUREFORMAT_R (or _RG) on WebGL2

Repro: https://playground.babylonjs.com/#YCY2IL#1861

You’ll just see a black plane.
If you pop open the inspector you’ll see a warning in the log “WebGL: INVALID_VALUE: texImage2D: invalid internalformat”
Try commenting out the “format: Engine.TEXTUREFORMAT_R” line to see a tree in colour, or switch to WebGPU to see a tree in red (which is the expected behaviour).

(All these tests run on Chrome on an M1 MacBook Pro.)

I think I know what the problem is: In the createTexture() method of thinEngine.ts, the calls to gl.texImage2D are passing gl.RED for both “format” and “sized internal format” whereas they should pass legitimate combinations of values as described in table 2 here: https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml. In this case (since type == UNSIGNED_BYTE) that would mean using GL_R8 for the sized internal format.

Looking around in thinEngine.ts, I see that other forms of texture creation use _getRGBABufferInternalSizedFormat. I’ve tried coding a change to make createTexture use that too (while keeping its existing cleverness about automatically choosing things based on file extension) which appears to fix the problem in my local tests. I’ll open a PR so you can have a look at what I mean.