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

In TWGL, why are "setBuffersAndAttributes" and "drawBufferInfo" two seperate calls?

TWGL, why do I have to pass the buffer information first to setBuffersAndAttributes and then pass it again to drawBufferInfo?我是 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?

最常见的原因是绘制了很多相同的东西。

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(...);

twgl.drawBufferInfo 唯一要做的就是调用 gl.drawArraysgl.drawElements,它唯一需要做的信息是

  1. 绘制数取决于要处理的顶点数
  2. 数据是否被索引(换句话说,它应该调用 gl.drawArrays 还是 gl.drawElements
  3. 如果是索引,索引是什么类型,UNSIGNED_BYTEUNSIGNED_SHORT,或者UNSIGNED_INT

它的唯一目的是让您不必将代码从 gl.drawArrays 更改为 gl.drawElements,反之亦然,如果您将数据从 non-indexed 更改为索引 [=19] =]