You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
There is no way to initialize a compressed 2D or 3D texture with uninitialized contents #3686
According to GLES 3.0 spec, when calling glCompressedTexImage2D or glCompressedTexImage3D, if one passes a null data pointer, then a texture with uninitialized contents should be allocated in GPU memory:
This behavior is the same as with glTexImage2D and glTexImage3D. E.g. to create a 2D texture in WebGL with uninitialized memory contents, one can call
GL.texImage2D(target, level, internalFormat, width, height, border, format, type, null);
However, it looks like creating an uninitialized compressed 2D texture is not possible in WebGL. Attempting to run
Reading the spec, in case of texImage2D, the parameter pixels is marked with a ? to be optional:
However for compressedTexImage2D, this optionality is not present:
Reading section "Differences Between WebGL and OpenGL ES 2.0" on compressed textures, there is no mention of an intentional discrepancy between passing null to texImage2D() vs compressedTextImage2D():
suggesting that this may be an unintentional oversight? Or if there is a rationale, it might be good to note in the above section?
There is a supported method in WebGL 2.0 to allocate an empty compressed texture: use texStorage2D or texStorage3D. WebGL 2.0 (and OpenGL ES 3.0) added the ability to specify textures' internal formats; but only the texStorage entry points were updated to support compressed textures. See this comment in Chromium's (older) WebGL implementation path:
When WebGL 2.0 was underway I don't remember whether the working group noticed that glCompressedTexImage2D was changed in OpenGL ES 3.0 to allow NULL data. Either way it would have been difficult to support this in WebGL. Web IDL would not allow WebGL 2.0 to make the ArrayBufferView nullable while leaving it required in WebGL 1.0, in the undefined compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, [AllowShared] ArrayBufferView data); entry point. The WG probably determined that it was better to leave this argument required in the WebGL API rather than making it nullable and introducing a new INVALID_OPERATION or INVALID_VALUE error in WebGL 1.0 after the fact.
Does this address the question? I do not think a change to WebGL's entry points should be made, but a spec clarification could be added if you think it's warranted.
glCompressedTexImage2D was changed in OpenGL ES 3.0 to allow NULL data.
I am not so sure that in GLES2 -> GLES3 the spec was changed to allow null data, but rather, it seems to me that the GLES2 spec accidentally omitted mentioning what should happen on a null pointer.
The only mention about what data should mean in GLES2 spec for glCompressedTexImage2D I can find is this part:
I think there may just have been a casual use of speech ambiguity. I could see the wording to as well been written as
"The target, level, internalformat, width, height, border and data parameters have the same meaning as in TexImage2D, except that data points to compressed image data ..."
which would have implied that data can be null. But since data referred to compressed pixels instead of uncompressed pixels, they split out that one parameter to its own sentence, and then omitting declaring at all how data should be handled.
Reading through the whole part, it looks like the GLES2 spec does not state what would happen if null is passed to glCompressedTexImage2D at all, to positive or negative.
Anyhow, what was ambiguous/unspecified then is still unspecified now, so none of that really matters here.
I don't think it is worth the effort to consider changing spec or functional browser behavior, but probably good to address these kind of subtle gotchas in documentation in the spec.
E.g. maybe add in the differences between WebGL and OpenGL ES section about Compressed Textures a part
"In OpenGL ES 2.0 the specification omitted declaring whether it should be possible to create a compressed 2D texture with uninitialized data. In WebGL 1, this is explicitly disallowed.
In OpenGL ES 3.0 it is explicitly allowed to create a compressed 2D texture with uninitialized data by passing null to CompressedTexImage2D. In WebGL 2, this is however still explicitly disallowed. Users can call TexStorage2D to work around this functional difference."
or something along those lines.
Unfortunately Emscripten will not be able to transparently use TexStorage2D/3D as a workaround to allow users to specify uninitialized compressed 2D/3D textures. This is because there is a semantic difference between (Compressed)TexImage2D/3D and TexStorage2D/3D that TexStorage generates immutable-format textures (observable via glGetTexParameter of GL_TEXTURE_IMMUTABLE_FORMAT), so there is a functional difference and resulting semantical restrictions that follow.
Of course for any engine developers, migrating from (Compressed)TexImage2D/3D to TexStorage2D/3D in this manner may be possible.
Activity
kenrussell commentedon Aug 23, 2024
There is a supported method in WebGL 2.0 to allocate an empty compressed texture: use
texStorage2DortexStorage3D. WebGL 2.0 (and OpenGL ES 3.0) added the ability to specify textures' internal formats; but only thetexStorageentry points were updated to support compressed textures. See this comment in Chromium's (older) WebGL implementation path:https://source.chromium.org/chromium/chromium/src/+/main:gpu/command_buffer/service/gles2_cmd_decoder.cc;l=12378?q=GLES2DecoderImpl::ClearCompressedTextureLevel&ss=chromium
When WebGL 2.0 was underway I don't remember whether the working group noticed that
glCompressedTexImage2Dwas changed in OpenGL ES 3.0 to allow NULL data. Either way it would have been difficult to support this in WebGL. Web IDL would not allow WebGL 2.0 to make theArrayBufferViewnullable while leaving it required in WebGL 1.0, in theundefined compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, [AllowShared] ArrayBufferView data);entry point. The WG probably determined that it was better to leave this argument required in the WebGL API rather than making it nullable and introducing a newINVALID_OPERATIONorINVALID_VALUEerror in WebGL 1.0 after the fact.Does this address the question? I do not think a change to WebGL's entry points should be made, but a spec clarification could be added if you think it's warranted.
juj commentedon Aug 23, 2024
I am not so sure that in GLES2 -> GLES3 the spec was changed to allow null data, but rather, it seems to me that the GLES2 spec accidentally omitted mentioning what should happen on a null pointer.
The only mention about what
datashould mean in GLES2 spec for glCompressedTexImage2D I can find is this part:I think there may just have been a casual use of speech ambiguity. I could see the wording to as well been written as
"The target, level, internalformat, width, height, border and data parameters have the same meaning as in TexImage2D, except that data points to compressed image data ..."
which would have implied that data can be null. But since
datareferred to compressed pixels instead of uncompressed pixels, they split out that one parameter to its own sentence, and then omitting declaring at all howdatashould be handled.Reading through the whole part, it looks like the GLES2 spec does not state what would happen if null is passed to glCompressedTexImage2D at all, to positive or negative.
Anyhow, what was ambiguous/unspecified then is still unspecified now, so none of that really matters here.
I don't think it is worth the effort to consider changing spec or functional browser behavior, but probably good to address these kind of subtle gotchas in documentation in the spec.
E.g. maybe add in the differences between WebGL and OpenGL ES section about Compressed Textures a part
"In OpenGL ES 2.0 the specification omitted declaring whether it should be possible to create a compressed 2D texture with uninitialized data. In WebGL 1, this is explicitly disallowed.
In OpenGL ES 3.0 it is explicitly allowed to create a compressed 2D texture with uninitialized data by passing null to CompressedTexImage2D. In WebGL 2, this is however still explicitly disallowed. Users can call TexStorage2D to work around this functional difference."
or something along those lines.
Unfortunately Emscripten will not be able to transparently use TexStorage2D/3D as a workaround to allow users to specify uninitialized compressed 2D/3D textures. This is because there is a semantic difference between (Compressed)TexImage2D/3D and TexStorage2D/3D that TexStorage generates immutable-format textures (observable via glGetTexParameter of GL_TEXTURE_IMMUTABLE_FORMAT), so there is a functional difference and resulting semantical restrictions that follow.
Of course for any engine developers, migrating from (Compressed)TexImage2D/3D to TexStorage2D/3D in this manner may be possible.
Clarify GLES/WebGL difference with uninitialized compressed textures.
Clarify GLES/WebGL difference with uninitialized compressed textures. (…