OpenGL ES 2.0-多个程序或着色器 [英] OpenGL ES 2.0 - Multiple Programs or Shaders

查看:133
本文介绍了OpenGL ES 2.0-多个程序或着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有两个程序,一个程序用于实线,并为实体填充一个顶点着色器,一个片段为实体的着色器填充,第二个程序针对纹理和纹理的顶点着色器,用于纹理的片段着色器.我使用glUseProgram交换两个程序,具体取决于我要绘制的内容.这是一个好的解决方案吗?还是应该通过单个程序来glAttachShader/glDetachShader?

I currently have two programs, one program for solid lines and fills with a vertex-shader-for-solids and a fragment-shader-for-solids and a second program for textures with a vertex-shader-for-textures and a fragment-shader-for-textures. I swap the the two programs in and out using glUseProgram depending on what I am drawing. Is this a good solution? Or should I glAttachShader/glDetachShader from a single program?

推荐答案

当然,您使用的是正确的解决方案.绑定其他程序应该开销很小.您显然不想做得比需要的多,就像任何状态更改一样.例如,如果可以的话,首先渲染使用一个程序的所有内容,然后绑定另一个程序,并渲染使用该程序的所有原语,这比更频繁地绑定其他着色器更好.

Definitely, you're using the right solution. Binding a different program should be low overhead. You obviously don't want to do it more than needed, like any state changes. For example, if you can, render everything that uses one program first, then bind the other program, and render all the primitives that use it, that would be preferable over binding a different shader more frequently.

将不同的着色器附加到程序意味着必须重新链接它,这比仅绑定其他程序要昂贵得多.

Attaching a different shader to a program means that you'll have to relink it, which is much more expensive than just binding a different program.

这篇关于OpenGL ES 2.0-多个程序或着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆