简体   繁体   English

在OpenGL ES中批处理多个矩形

[英]Batching Multiple Rectangles in OpenGL ES

I currently am experiencing very slow performance by iterating through quad triangle strips and drawing each one separately, so I would like to batch all of my rectangles into one single draw call. 我现在正在遍历四边形三角形的条带并分别绘制每个三角形,因此我的性能非常慢,因此我想将所有矩形批处理到一个绘制调用中。

Looking around, it seems the best way to do this is to simply occur the overhead of duplicating vertices and using GL_TRIANGLES instead of GL_TRIANGLE_STRIP, simply drawing two separate triangles for each rectangle. 环顾四周,似乎最好的方法是简单地产生复制顶点的开销,并使用GL_TRIANGLES而不是GL_TRIANGLE_STRIP,只需为每个矩形绘制两个单独的三角形。

The problem is that each rectangle can have a different color, and I need to programmatically change the color of any of the rectangles. 问题在于每个矩形可以具有不同的颜色,我需要以编程方式更改任何矩形的颜色。 So simply using one GL_TRIANGLES call does not do the trick. 因此,仅使用一个GL_TRIANGLES调用就不能解决问题。 Instead, it looks like I'll need to somehow index color data with my vertex data, associating a color with each rectangle. 取而代之的是,看起来我需要以某种方式用顶点数据为颜色数据建立索引,从而将颜色与每个矩形相关联。 How would I go about this? 我将如何处理?

Thank you! 谢谢!

You can use vertex coloring. 您可以使用顶点着色。

Vertices can each have multiple channels of data, including position, color, (multiple) texture, normal, and more. 每个顶点可以具有多个数据通道,包括位置,颜色,(多个)纹理,法线等。

I recommend interleaving your vertices to include position and color one after the other, directly. 我建议对顶点进行交织 ,以直接一个接一个地包含位置和颜色。 Although you can set up a separate array of just colors and do it that way as well (just make sure you line up the colors with the positions correctly). 尽管您可以设置单独的仅颜色数组并也可以这样做(只需确保将颜色与位置正确对齐)。

(Those tutorials are iPhone-oriented but the OpenGL ES code should work fine on Android) (这些教程都是面向iPhone的,但OpenGL ES代码在Android上应该可以正常工作)

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

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