'updateTextureData' not work when the texture is not link to a material

hello everyone,

I want to update a part of texture and find that ‘engine.updateTextureData()’ is a good choise.

However, when the texture is not link to any material, ‘engine.updateTextureData()’ will not work.
Here is the PG. https://playground.babylonjs.com/#EVX1DH#45
When I delete line 71, ‘engine.updateTextureData’ will not work.


I don’t think this method is really meant to be called by the end user…

Anyway, to make it work you must bind the texture first:


‘engine._bindTextureDirectly’ is necessary

I find a new problem here,
in PG( https://playground.babylonjs.com/#EVX1DH#60 ), I could update three part of image .
but in PG( https://playground.babylonjs.com/#EVX1DH#62 ), only one part region could be updated.
it’s realy strange

You have some errors in the console log in the 2nd PG:

babylon.js:16 WebGL: INVALID_OPERATION: texSubImage2D: ArrayBufferView
not big enough for request

That’s because the subarray you extract is not big enough given the width/height of the texture you want to update (region.width * 0.5 and region.height * 0.5).


Sorry, I don’t understand. the subarray return an array with 37500 length, and the texture I want to update is 250x150. why this array is not big enough?

I find the reason.

The width or height cannot divide by 4, I need add gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);

I don’t know how to handle this one as I don’t know much of openGL…

After having read some docs, I think we could set the UNPACK_ALIGMENT to 1 in the whole engine as I think our buffers are always tightly packed (we only set it to 1 in the raw texture class when width can’t be divided by 4, and we don’t reset it to 4 afterward, meaning it stays to 1). But it’s not what we are doing, so I prefer @sebavan having a look at that.

As a quick fix, you can call pixelStorei yourself:

@Evgeni_Popov I agree we should be able to set it to 1 on start ??? what do you think