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

Support for texStorage #21874

Closed
skbizport opened this issue May 22, 2021 · 10 comments · Fixed by #22951
Closed

Support for texStorage #21874

skbizport opened this issue May 22, 2021 · 10 comments · Fixed by #22951

Comments

@skbizport
Copy link

Can we please add support for texStorage2D & texStorage3D for more efficient uploading of data (not images).

WebGL 2.0 spec has a comment on this topic in section 3.7.6 Texture objects: "texStorage2D should be considered a preferred alternative to texImage2D. It may have lower memory costs than texImage2D in some implementations."

This is also mentioned in MDN.

https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices.
https://www.khronos.org/registry/webgl/specs/latest/2.0/

Some discussion on this on stackoverflow
https://stackoverflow.com/questions/63353873/how-to-handle-3d-texture-on-webgl2

Describe the solution you'd like

Describe alternatives you've considered

Additional context

@mrdoob
Copy link
Owner

mrdoob commented May 22, 2021

Interesting...

How do you propose the API for it to look like?

@skbizport
Copy link
Author

One possibility is DataStorageTexture, DataStorageTexture3D, DataStorageTexture2DArray. Another could be to pass additional parameters to existing class. E.g.

DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding, storage (true|false)).

Thx

@Mugen87
Copy link
Collaborator

Mugen87 commented May 23, 2021

Would it be possible to use texStorage2D() automatically with a WebGL 2 rendering context? It's easy to check for a WebGL 2 rendering context in the renderer classes (via capabilities.isWebGL2).

@mrdoob
Copy link
Owner

mrdoob commented Jun 10, 2021

@Mugen87 You mean when using DataTexture?

@Mugen87
Copy link
Collaborator

Mugen87 commented Jun 10, 2021

I thought the method could always be used when mipmaps are defined.

@mrdoob
Copy link
Owner

mrdoob commented Jun 10, 2021

Right... After reading greggman's explanation, seems to me that we should use texStorage2D and texStorage3D when possible indeed.

@mrdoob
Copy link
Owner

mrdoob commented Jun 10, 2021

@DavidPeicho @mbredif do you guys agree?

@DavidPeicho
Copy link
Contributor

Using texStorage* API whenever WebGL2 is used is the way to go I believe 👌

@mrdoob
Copy link
Owner

mrdoob commented Jun 11, 2021

Something to be aware of is that, Chrome currently doesn't have optimised support of texStorage* for video textures.

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 5, 2021

I've started to experiment with texStorage2D today and want to clarify one thing that confused be at the beginning:

texStorage2D is no 1:1 replacement for texImage2D. A call of texImage2D for uploading a single texture has to be replaced with a combination of texStorage2D and texSubImage2D. texStorage2D only allocates the memory whereas texSubImage2D actually defines the data. texImage2D does this all in one method call.

Besides, the approach looks different depending on the use case in WebGLTexture. A texture with manual mipmaps just needs a single call of texStorage2D but multiple ones with texSubImage2D. With texImage2D, one can treat all API calls uniformly. That makes the introduction of texStorage2D a bit trickier.

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

Successfully merging a pull request may close this issue.

4 participants