简体   繁体   English

用OpenGL进行Alpha混合的最佳方法?

[英]Best way to do alpha blending with OpenGL?

I'm drawing 2D Polygons, actually I'm drawing lots of triangles and using GLUOrtho2D. 我正在绘制2D多边形,实际上我正在绘制许多三角形并使用GLUOrtho2D。 I noticed that by zooming out I got much better frame rates. 我注意到通过缩小我可以获得更好的帧速率。 I realized I was maxing out the graphics card's fill rate, not drawing too many polygons as I had initially suspected. 我意识到我正在最大化图形卡的填充率,而不是像我最初怀疑的那样绘制太多的多边形。 I think this is because I'm drawing lots of overlapping polygons and using 我认为这是因为我正在绘制许多重叠的多边形并使用

glEnable(GL_BLEND);

    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Is this the blend function I should be using? 这是我应该使用的混合功能吗? How could I minimize the filling given the nature of what I'm doing? 考虑到我正在做的事情,我该如何减少填充量? I tried enabling the GL_DEPTH_TEST and Z ordered my polygons, but since I alpha blend, this won't help. 我尝试启用GL_DEPTH_TEST,并且Z对多边形进行了排序,但是由于我进行了alpha混合,所以这无济于事。 What is the most efficient way of doing this sort of thing? 做这种事情的最有效方法是什么?

Thanks 谢谢

I doubt using a different blend function would help. 我怀疑使用其他混合功能会有所帮助。 One generally chooses the correct blend function based on desired output, not performance. 人们通常根据期望的输出而不是性能来选择正确的混合功能。

Are all the polygons you render transparent/translucent? 您渲染的所有多边形都是透明/半透明的吗? If not, it might help to separate the rendering of those apart from the opaque polygons you have and set the proper GL states accordingly. 如果没有,则可能有助于将那些渲染与您拥有的不透明多边形分开,并相应地设置适当的GL状态。

Also are these textured polygons? 这些纹理多边形也是吗? You might be able to optimize your texture handling (ex: reduce context switches, use more efficient image formats, etc). 您也许可以优化纹理处理(例如:减少上下文切换,使用更有效的图像格式等)。

Finally, how are you rendering these triangles? 最后,您如何渲染这些三角形? If in immediate mode or using vertex arrays, consider using VBOs. 如果处于即时模式或使用顶点数组,请考虑使用VBO。

avoid alpha blending on as many triangles as possible. 避免在尽可能多的三角形上进行Alpha混合。 It adds up and yes, it gets really expensive. 它加起来,是的,它真的很贵。 There is no magic high-performance blend function. 没有神奇的高性能混合功能。

The only solution is "use less blending and more z-buffering" 唯一的解决方案是“使用更少的混合和更多的z缓冲”

Changing blend function leads only to changes in blending coefficients, but not in equation. 改变混合函数只会导致混合系数的改变,而不会导致方程式的改变。 Anyways, modern videocards do not use hardcoded equations. 无论如何,现代的视频卡不使用硬编码方程式。 You could try to write a pixel shader that satisfies your needs. 您可以尝试编写满足您需求的像素着色器

BTW, consider using VBO 's for yours "lots of triangles" if you still don't. 顺便说一句,如果您仍然不使用VBO ,请考虑将其用于“许多三角形”。

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

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