OpenGL ES 2.0 - Multiple Programs or Shaders

佐手、 提交于 2019-12-11 05:57:02

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/23115112/opengl-es-2-0-multiple-programs-or-shaders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!