简体   繁体   English

WebGL中的texImage2D需要多少数据?

[英]How much data does texImage2D in WebGL need?

I created a DataTexture in ThreeJS, which in turn will call texImage2D. 我在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);

As you can see, I used a size of 50x50 Texels and three 8Bit channels (THREE.RGB in threejs). 正如你所看到的,我使用了50x50 Texels和3个8Bit通道的大小(三个中的THREE.RGB)。 When I used a UInt8Array of size 7500 (50*50*3), Firefox tells me, that it needs more data: 当我使用大小为7500(50 * 50 * 3)的UInt8Array时,Firefox告诉我,它需要更多数据:

Error: WebGL: texImage2D: not enough data for operation (need 7598, have 7500)

I would like to know: where do this extra 98 bytes come from? 我想知道:这98个字节来自哪里? I would guess alignment, but 7598 is not even divisible by 4 while 7500 is. 我猜测对齐,但7598甚至不能被4整除,而7500则是。 (Now that I think of it, it is not divisible by 3, my number of channels, either) (现在我想起来了,它不能被3整除,我的通道数也是如此)

7600 would make sense, since that would mean 2 Bytes of padding per row, is the last row not padded? 7600是有意义的,因为这意味着每行2个字节的填充,是最后一行没有填充?

(I get that one should use only multiples of four for the dimensions, still I would like to know the answer) (我觉得那个尺寸应该只使用四个的倍数,我仍然想知道答案)

The row lengths are aligned to multiples of 4, except for the last row. 除最后一行外,行长度与4的倍数对齐。 In your case this means each row needs 2 bytes of padding, for a total of 152 bytes ( 3 * 50 + 2 ) per row. 在您的情况下,这意味着每行需要2个字节的填充,每行总共152个字节( 3 * 50 + 2 )。

152 * (50 - 1) + 3 * 50 = 7598

For reference, see the source code of Gecko . 供参考,请参阅Gecko源代码

As user1421750 pointed out the rows are padded 正如user1421750指出的那样,行被填充

But, you can set how much padding per row by setting texture.unpackAlignment . 但是,您可以通过设置texture.unpackAlignment来设置每行填充多少。 it defaults to 4 but you can set it to 8, 4, 2 or 1. 它默认为4,但您可以将其设置为8,4,2或1。

Personally I would have made the default 1 because I think you'd be less likely to be surprised like you were 就个人而言,我会默认1,因为我觉得你不太可能像你一样感到惊讶

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WebGL texImage2D 参数 - WebGL texImage2D parameters texImage2D接受什么样的数据? - What kind of data does texImage2D accept? “PhotoSphereViewer:无效的 XMP 数据”和“WebGL:INVALID_VALUE:texImage2D:错误的图像数据” - "PhotoSphereViewer: invalid XMP data" and "WebGL: INVALID_VALUE: texImage2D: bad image data" WebGL texImage2D问题:如何在单元/对象上获取纹理? - WebGL texImage2D Issues: How to get texture onto unit/object? WebGL texImage2D:转换需要重新格式化像素 - WebGL texImage2D: Conversion requires pixel reformatting 错误:WebGL警告:texImage2D:所需的上载需要的数据比可用的更多:(当使用三角形网格数据和法线加载纹理时) - error: WebGL warning: texImage2D: Desired upload requires more data than is available: (when loading the texture with triangle mesh data and normals) WebGL:INVALID_VALUE:texImage2D:无效的内部格式 - webgl2 中的 depthTexture - WebGL: INVALID_VALUE: texImage2D: invalid internalformat - depthTexture in webgl2 未捕获(承诺)DOMException:无法在“WebGL2RenderingContext”上执行“texImage2D”:可能无法加载受污染的画布 - Uncaught (in promise) DOMException: Failed to execute 'texImage2D' on 'WebGL2RenderingContext': Tainted canvases may not be loaded WebGL-INVALID_OPERATION:texImage2D:ArrayBufferView不足以容纳请求 - WebGL - INVALID_OPERATION: texImage2D: ArrayBufferView not big enough for request WebGL2 texImage2D 16 位然后 readPixels 16 位问题 - WebGL2 texImage2D 16-bit then readPixels 16-bit problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM