galacean / engine

A typescript interactive engine, support 2D, 3D, animation, physics, built on WebGL and glTF.
https://www.galacean.com/engine
MIT License
4.31k stars 308 forks source link

Need a dirty flag in texture for auto update texture binding #367

Open HypnosNova opened 3 years ago

HypnosNova commented 3 years ago

Is your feature request related to a problem? Please describe. For example, if I use a canvas as a texture image source or use a video, I have to update the texture manually. And oasis will have fbo features later that we can render scene into a texture. These cases, the image source is updating all the time.

Other engines like Three.js, texture has a "needsUpdate" flag or has CanvasTexture or VideoTexture that can auto update the texture.

Describe the solution you'd like I think the features could be:

  1. If a texture is dirty, oasis-engine can auto update the texture and then set the dirty flag false.
  2. If a texture has an autoUpdate flag, the texture could be updated every frame.

These features could help developers using engine easier.

But update texture each frame will cost more performance, so in API docs we can let developers know that we don't need to set autoUpdate true only if the image source is changing all the time.

GuoLei1990 commented 3 years ago

VideoTexture is better than needsUpdate and we can add play() or pause() API.

GuoLei1990 commented 3 years ago

There is a principle that Oasis' Texture2D will not record any image and canvas memory, because it is a pure gpu video memory texture, and image/canvas is only a kind of data source. needUpdate is only valid when the data source is image/canvas, and no useful for data source is pixel buffer. The needupdate design will make the Texture2D design dirty and waste memory, use another class videoTexture meybe better.