Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGL2: Fix 2D array textures with RGTC compression not rendering #101909

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

BlueCube3310
Copy link
Contributor

@BlueCube3310 BlueCube3310 commented Jan 22, 2025

Fixes #101711

WebGL2 seemingly doesn't support 2D array RGTC-compressed textures (though it's not documented anywhere). This PR makes it so that under WebGL2 layered textures with RGTC compression are decompressed before being used.

The memory usage increase shouldn't be too significant, since the decompressed images only use either 1 or 2 color channels, so they will be twice as big (8 bytes vs 16 for RGTC_R and 16 bytes vs 32 for RGTC_RG)

@BlueCube3310 BlueCube3310 added this to the 4.4 milestone Jan 22, 2025
@BlueCube3310 BlueCube3310 changed the title [WIP] WebGL2: Fix 2D array textures with RGTC compression not rendering WebGL2: Fix 2D array textures with RGTC compression not rendering Jan 22, 2025
@BlueCube3310 BlueCube3310 marked this pull request as ready for review January 22, 2025 15:10
@BlueCube3310 BlueCube3310 requested a review from a team as a code owner January 22, 2025 15:10
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me.

@clayjohn
Copy link
Member

clayjohn commented Jan 22, 2025

WebGL uses the EXT_texture_compression_rgtc extension to support RGTC, which only supports 2D images (not 3D images which include array textures).

Compare that to the WEBGL_compressed_texture extension (for ETC) which specifically mentions array textures.

Implementations are required to support either ETC or S3TC/RGTC, but the wording of both the RGTC and S3TC extensions don't cover array textures. Therefore they are not required to be supported for RGTC or S3TC.

Have you checked whether S3TC array textures are supported on your device? I wonder if there is another optional extension that adds support that we could check for. The extension for S3TC mandates support for 3D textures EXT_texture_compression_s3tc. So there is nothing to worry about

Edit: The plot thickens. The RGTC extension says that it is basically just EXT_texture_compression_rgtc which specifically says that it errors with 1D or 3D texture types (this is true on any mobile device as well). The extensions for BPTC and ASTC have similar wording (in the sense that they only mention 2D variants, but refer to a different extension for more details). But in both cases the extension they refer to specifically includes 3D textures and/or texture arrays

@clayjohn
Copy link
Member

clayjohn commented Jan 22, 2025

On an unrelated note, it would be interesting to look into properly supporting ASTC in the web. I think all we need to do is check for WEBGL_compressed_texture_astc and then it should work just like BPTC. Also it seems very widely support so for web exports we may want to always use ASTC when available

@@ -1509,8 +1509,19 @@ void TextureStorage::_texture_set_data(RID p_texture, const Ref<Image> &p_image,
GLenum internal_format;
bool compressed = false;

bool needs_decompress = texture->resize_to_po2;

#ifdef WEB_ENABLED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking into it, this seems to be true for all GLES3 contexts since they rely on EXT_texture_compression_rgtc which explicitly does not support 3D textures.

Therefore, I think this needs to use is_gles_over_gl() instead to capture any time we use a GLES3 context (i.e. web, mobile, and ANGLE on desktop).

I am not 100% sure about ANGLE on desktop though, it might work anyway despite not being guaranteed by the spec

@BlueCube3310
Copy link
Contributor Author

On an unrelated note, it would be interesting to look into properly supporting ASTC in the web. I think all we need to do is check for WEBGL_compressed_texture_astc and then it should work just like BPTC. Also it seems very widely support so for web exports we may want to always use ASTC when available

Added in #101932

@Repiteo Repiteo merged commit 802cb0f into godotengine:master Jan 24, 2025
19 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jan 24, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shadowmasks broken on Web exports when using RGTC texture compression
4 participants