OpenGL ES 2.0的多个程序或多个着色器还是什么?它是如何工作的? [英] OpenGL ES 2.0 Multiple Programs or Multiple Shaders or what? How does it work?

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

问题描述

我的问题,从根本上,是我不知道的OpenGL ES 2.0如何希望我写的,并使用多个着色器;或者,如果它是偶数可取/预期,一个人将这样做。

My problem, fundamentally, is that I do not know how OpenGL ES 2.0 expects me to write and use multiple shaders; or if it is even advisable/expected that a person will do so.

这里的基本问题是:如果我有一个苹果,一个发光的岩石和一个模糊的网格,都在同一个3D世界中,所有最好使用不同的着色器程序绘制但使用相同mvpMatrix那么我将如何去使用所有他们在同一的OpenGL渲染,使他们都用自己的,我已经写了最合适的着色器?

The fundamental question here is: if I have an apple, a glowing rock and a fuzzy mesh, all in the same 3D world, all best drawn with different shader programs but using the same mvpMatrix then how would I go about using all of them in the same OpenGL render such that they all use their most appropriate shaders that I have written?

所以,我写了一个基本的OpenGL ES 2.0的计划,我的安卓游戏,它可以借鉴的对象画面的轮廓完美的作品。但它确实没有别的; pretty的多,因为着色器是这样的:

So I have written a basic OpenGL ES 2.0 program for my Android Game that works perfectly in that it can draw the outline of the objects to the screen. But it does nothing else; pretty much because the shaders look like this:

uniform mat4 uMVPMatrix;
attribute vec4 aPosition;

void main() {
    gl_Position = uMVPMatrix * aPosition;
}

片段着色器

void main() {
    gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}

现在他们是pretty的基础。我还没有更进一步的原因是因为我想不通,如果我应该写一个着色器适用于所有的不同的物体,或者我应该使用多个着色器。如果我应该使用多个着色器绘制多个不同的对象,那我怎么去这样做,在一个有效的方式?

Now they are pretty basic. The reason that I have not gone further is because I cannot figure out if I am supposed to write one shader to apply to all of my different objects or if I am supposed to use multiple shaders. And if I am supposed to use multiple shaders to draw multiple different objects then how do I go about doing that in an efficient way?

我得到的感觉,这一定是基础知识的人,做的OpenGL ES 2.0日复一日出来,所以我希望有人能回答我的问题或点我在正确的方向。

I get the feeling that this must be basic knowledge to anybody that does OpenGL ES 2.0 day in and day out so I am hoping that somebody can answer my question or point me in the right direction.

我有:

  • 在看着多个教程;其中没有使用任何东西,但最基本的着色器。
  • 阅读完整的OpenGL ES 2.0 GLSL规格(其中没有提到它打算如何使用,这是刚才的一切做了什么,而不是它是如何组合在一起的)。
  • 在试图修改我的着色器了一下。

所以,我希望我靠近理解OpenGL的工作流程,但我似乎并没有在那里呢。

So I'm hoping that I am close to understanding the OpenGL workflow but I don't seem to be there yet.

编辑:我发现这口井算账:

I found this well afterwards:

如果您的应用程序的OpenGL ES 2.0的写,不要创建有很多交换机和条件执行每一项任务的应用程序需要渲染场景的单一着色器。相反,编译每个执行具体,有针对性的任务多重着色器程序。

If your application is written for OpenGL ES 2.0, do not create a single shader with lots of switches and conditionals that performs every task your application needs to render the scene. Instead, compile multiple shader programs that each perform a specific, focused task.

这是从<一个href="http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/Performance/Performance.html#//apple_ref/doc/uid/TP40008793-CH105-SW11">iOS OpenGL ES 2.0的指导方针。

推荐答案

您可以使用多个着色器,但它们之间的切换可以是相当昂贵所以推荐的做法是绘制着色器的每一个对象,然后切换到下一个着色并绘制所有使用一个等的对象。
为了着色器之间切换,你叫 glUseProgram()

You can use multiple shaders, but to switch between them can be quite costly so the recommended practise is to draw every object of a shader, then switch to the next shader and draw all the objects using that one and so on.
To switch between shaders, you call glUseProgram().

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

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