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

WebGLCapabilities: add textureTypeReadable() and textureFormatReadable() #28087

Merged
merged 1 commit into from Apr 9, 2024

Conversation

sguimmara
Copy link
Contributor

@sguimmara sguimmara commented Apr 8, 2024

Fixed #28086

Description

WebGL only supports one texture type for reading: UnsignedByteType, and only one pixel format: RGBAFormat. Any other combination is optional and implementation dependent.

This PR exposes 2 conditional checks that previously ocurred in WebGLRenderer.readRenderTargetPixels():

  • the texture type check
  • the pixel format check

as two publicly accessible methods on WebGLCapabilities:

  • textureTypeReadable()
  • textureFormatReadable()

To be able to determine if the render target can be read, we can now use those two methods. If at least one of them returns false, we might have the opportunity to convert the texture to another format before calling readRenderTargetPixels().

This contribution is funded by Oslandia

Copy link

github-actions bot commented Apr 8, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
672.7 kB (166.7 kB) 672.8 kB (166.7 kB) +137 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
452.4 kB (109.2 kB) 452.5 kB (109.3 kB) +128 B

@sguimmara sguimmara force-pushed the webglrenderer-read-pixels-conditions branch from d1785dd to b5cc804 Compare April 8, 2024 09:54
@sguimmara sguimmara force-pushed the webglrenderer-read-pixels-conditions branch from b5cc804 to 0b0b695 Compare April 8, 2024 10:02
@Mugen87 Mugen87 added this to the r164 milestone Apr 8, 2024
@Mugen87 Mugen87 changed the title WebGLRenderer: add canReadTextureType() and canReadPixelFormat() WebGLCapabilities: add canReadTextureType() and canReadPixelFormat() Apr 8, 2024
@Mugen87 Mugen87 changed the title WebGLCapabilities: add canReadTextureType() and canReadPixelFormat() WebGLCapabilities: add canReadTextureType() and canReadPixelFormat(). Apr 8, 2024
@sguimmara
Copy link
Contributor Author

@Mugen87 is there any documentation to update somewhere ?

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 8, 2024

No, there isn't a doc page for WebGLCapabilities.

Apart from that, I'm curious to see if other devs prefer an API on WebGLRenderer level. We eventually need a similar API in context of WebGPURenderer (since it has an optional WebGL 2 backend). A method like getMaxAnisotropy() is placed in the Renderer class and calls the implementation from the respective backend implementation (meaning this.backend.getMaxAnisotropy()).

The PR in its current state is fine in context of WebGLRenderer. For WebGPURenderer the solution might be slightly different. Especially since I believe WebGPU hasn't the same readback restrictions like WebGL.

@sguimmara sguimmara force-pushed the webglrenderer-read-pixels-conditions branch from 0b0b695 to 0aae781 Compare April 8, 2024 11:40
@sguimmara sguimmara force-pushed the webglrenderer-read-pixels-conditions branch from 0aae781 to 3955116 Compare April 8, 2024 14:39
@sguimmara sguimmara changed the title WebGLCapabilities: add canReadTextureType() and canReadPixelFormat(). WebGLCapabilities: add textureTypeReadable() and textureFormatReadable() Apr 8, 2024
@Mugen87 Mugen87 merged commit 2fee1aa into mrdoob:dev Apr 9, 2024
12 checks passed
@Methuselah96 Methuselah96 mentioned this pull request Apr 21, 2024
27 tasks
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.

WebGLRenderer: expose methods to check if RenderTarget can be read
3 participants