简体   繁体   English

在 TWGL 中,为什么“setBuffersAndAttributes”和“drawBufferInfo”是两个单独的调用?

[英]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.drawArraysgl.drawElements ,它需要做的唯一信息是

  1. the draw count as in how many vertices to process绘制计数为要处理的顶点数
  2. whether or the data is indexed (in other words, should it call gl.drawArrays or gl.drawElements或数据是否被索引(换句话说,它应该调用 gl.drawArrays 还是 gl.drawElements
  3. If it's index, what type of indices are, UNSIGNED_BYTE , UNSIGNED_SHORT , or UNSIGNED_INT如果是索引,那么索引的类型是UNSIGNED_BYTEUNSIGNED_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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM