我在 ThreeJS 中创建了一个 DataTexture,它会依次调用 texImage2D。
var twidth = 50;
var theight = 50;
var tsize = twidth * theight;
var tileData = new Uint8Array( tsize * 3);
//fill it with some data
tileDataTexture = new THREE.DataTexture(this.tileData, twidth, theight, THREE.RGBFormat);
如您所见,我使用了 50x50 纹素大小和三个 8 位 channel (threejs 中的 THREE.RGB)。当我使用大小为 7500 (50*50*3) 的 UInt8Array 时,Firefox 告诉我它需要更多数据:
Error: WebGL: texImage2D: not enough data for operation (need 7598, have 7500)
我想知道:这额外的 98 个字节是从哪里来的?我猜对齐,但 7598 甚至不能被 4 整除,而 7500 是。 (现在想起来,也不能被3整除,我的 channel 数也是)
7600 是有意义的,因为这意味着每行填充 2 个字节,最后一行没有填充吗?
(我知道应该只使用四的倍数作为尺寸,但我仍然想知道答案)
最佳答案
除最后一行外,行长度与 4 的倍数对齐。在您的情况下,这意味着每行需要 2 个字节的填充,每行总共 152 个字节(3 * 50 + 2
)。
152 * (50 - 1) + 3 * 50 = 7598
有关引用,请参阅 source code of Gecko .
关于javascript - WebGL 中的 texImage2D 需要多少数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30791819/