Skip to content

Conversation

krapnikkk
Copy link
Contributor

  • TextureOptions added compressed property
  • supportedExtensions added EXT_texture_compression_bptc and EXT_texture_compression_rgtc
  • s_textureInternalFormatInfo added compressed texture formats

@greggman greggman self-requested a review July 11, 2025 08:08
Copy link
Owner

@greggman greggman left a comment

Choose a reason for hiding this comment

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

Thank you for the PR.

Are you actually using this?

  • createTexture(gl, { src, width, height, internalFormat })

    This version would work. Do we care about other versions?

    For example, the non-compressed version will try to guess
    the width and/or height. Maybe that's not useful for compressed
    textures though. If we did want to do it, the code doing
    the guessing needs to take block sizes into account.

    If not, should we error if it's compressed and you don't
    pass in width and height?

  • options.compressed

    Is this needed? It seems like you could have an internal function,
    isCompressedInternalFormat that you can call to decide
    whether or not to call compressedTexImage2D.

  • can you add some tests?

    At least WebGL2 requires a few compressed formats to work
    so would be good to pick 1 or 2 and add a test that it works.

- Optimize the calling parameters of `compressedTexImage2D`
- add `test compressed texture format`
@krapnikkk
Copy link
Contributor Author

Thanks for your reminder. The previous code application is often narrow.

  • Added a prompt for direct error if width and height are not set.

  • Added the compressed attribute to simplify the code, because before calling createTexture, getting internalFormat and srcData requires a lot of code. If an internal function isCompressedInternalFormat is added, it can only manage an array internally, and then judge according to the internalFormat passed in. It is better to leave this configuration to the user.

  • Added test compressed texture format

@greggman greggman merged commit 3a4c880 into greggman:main Jul 12, 2025
1 check passed
@greggman
Copy link
Owner

greggman commented Jul 12, 2025

I merged it. Thanks again for the PR.

I made several changes. See 8f53aa8 and 0128db9

Note: I got rid of the compressed option like I suggested. Internally there's a isCompressedInternalFormat type function. It did not require a large table. Also, I'm not sure what you were trying to do with looping on levels is not how twgl is designed so I removed that code.

Normally in twgl you upload level 0 and it auto geneartes mipmaps if possible. Of course it can't do this for compressed textures. For both compressed and uncompressed textures, you can only set mip level > 0 using setTextureFromElement or setTextureFromArray. You can't do with createTexture.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants