[英]In TWGL, why are “setBuffersAndAttributes” and “drawBufferInfo” two seperate calls?
In TWGL , why do I have to pass the buffer information first to setBuffersAndAttributes and then pass it again to drawBufferInfo ?在TWGL 中,为什么我必须先将缓冲区信息传递给setBuffersAndAttributes ,然后再将其传递给drawBufferInfo ? I'm very new to WebGL and just try to understand the pipeline, why are these two seperate calls, in which scenario would I first set the buffer information and then do something else before drawing it or not draw it at all or draw a different buffer information?
我对 WebGL 很陌生,只是试图了解管道,为什么这两个单独的调用,在这种情况下,我会首先设置缓冲区信息,然后在绘制它之前做其他事情,或者根本不绘制它或绘制不同的缓冲信息?
why are these two seperate calls, in which scenario would I first set the buffer information and then do something else before drawing it or not draw it at all or draw a different buffer information?
为什么这两个单独的调用,在哪种情况下我会先设置缓冲区信息,然后在绘制它之前做其他事情,或者根本不绘制它或绘制不同的缓冲区信息?
The most common reason would be drawing many of the same thing.最常见的原因是绘制许多相同的东西。
twgl.setBuffersAndAttributes(gl, someProgramInfo, someBufferInfo);
// uniforms shared by all instances like projection or view
twgl.setUniforms(...);
for each instance
// uniforms unique this instance like material, texture or world matrix
twgl.setUniforms(...);
twgl.drawBufferInfo(...);
The only thing twgl.drawBufferInfo does is call gl.drawArrays
or gl.drawElements
and the only info it needs to do that is twgl.drawBufferInfo 唯一要做的就是调用
gl.drawArrays
或gl.drawElements
,它需要做的唯一信息是
UNSIGNED_BYTE
, UNSIGNED_SHORT
, or UNSIGNED_INT
UNSIGNED_BYTE
、 UNSIGNED_SHORT
还是UNSIGNED_INT
It's sole purpose is so you don't have to change your code from gl.drawArrays
to gl.drawElements
or visa versa if you change the data from non-indexed to indexed它的唯一目的是,如果您将数据从非索引更改为索引,
gl.drawArrays
gl.drawElements
代码从gl.drawArrays
更改为gl.drawElements
,反之亦然
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.