spite / THREE.UpdatableTexture

73 stars 12 forks source link

When upgrading to latest THREE (v142), get "GL_INVALID_OPERATION: Texture is immutable." #3

Closed radman-x closed 2 years ago

radman-x commented 2 years ago

Have been using this THREE.UpdatableTexture for a year on an older version of THREE (v122) and it works great (thanx for the excellent code!). But now updated to THREE v142 and I'm getting the following errors:

GL_INVALID_OPERATION: Texture is immutable. (Get this once) GL_INVALID_VALUE: Offset overflows texture dimensions. (Get this at each UpdatableTexture.prototype.update() call).

I have tried it both calling generateMipmap() per your original code and removing that line but either way get the above errors.

Any ideas on what could be causing this?

radman-x commented 2 years ago

Answering my own issue, in case others find it helpful...

Turns out UpdatableTexture is not compatible with gl.TexStorage2D (at least as of 2017 code) so you need to suppress this in THREE.WebGLTextures to use the latest THREE version. I did this by modifying THREE.WebGLTextures in uploadTexture() something like:

const useTexStorage = !texture.__suppressTexStorage && isWebGL2 && texture.isVideoTexture !== true; //Added 
 "!texture.__suppressTexStorage" test

Then, add this line to function UpdatableTexture():

this.__SuppressTexStorage = true;

Perhaps not ideal, since it requires modifying THREE, but it does work.