glCompileShader是可选的吗? [英] Is glCompileShader optional?

查看:113
本文介绍了glCompileShader是可选的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试系统时,我发现我使用的所有着色器都从未编译过.所有的GLSL程序都快乐地链接在一起,并且像一个魅力一样运作.

While debugging my system, I found out that all the shaders I used were never compiled. All the GLSL Programs were happily linked and working like a charm.

我已经在整个代码库中搜索了对glCompileShader的调用,但是没有找到.

I have searched the entire code base for calls to glCompileShader, but none were found.

然后我的问题是:这是我正在使用的实现的特定行为吗?链接程序时是否暗中进行着色器编译?它是可选的吗?如果是这样,除了检索错误日志外,显式执行此操作还有什么优势?

My question then is: Is this a specific behaviour of the implementation I am working with? Is shader compilation carried out implicitly when linking a program? Is it optional? If that is the case, what advantages are there in doing it explicitly, apart from retrieving the error log?

我在文档中找不到像我这样的任何情况,如果我错过了什么,您能指出我吗?

I could not find any case such as mine in the documentation, if I missed something can you please point me to it?

我的供应商是NVIDIA(驱动程序337.88)

My vendor is NVIDIA (driver 337.88)

另外,我使用glCreateShaderProgram(),而只是使用glCreateProgram()来创建着色器程序.

Also, I am NOT using glCreateShaderProgram(), but simply glCreateProgram() for the creation of shader programs.

推荐答案

此问题大部分在注释中得到了解决(感谢@ Andon,@ derhass等),但是由于这是一个有趣的问题,因此我将其总结为答案,并添加更多数据.

This was mostly resolved in the comments (thanks to @Andon, @derhass, and others), but since it's an interesting question, let me summarize it in an answer, and add some more data.

不考虑预编译的着色器,需要在将程序与glLinkProgram()链接之前通过调用glCompileShader()来编译着色器.根据我收集的数据,跳过glCompileShader()调用在以下情况下效果很好:

Not taking pre-compiled shaders into consideration, you need to compile your shaders by calling glCompileShader() before linking the program with glLinkProgram(). Based on the data I collected, skipping the glCompileShader() call works fine on:

  • Windows 8.1下的NVIDIA GeForce GT 740M.
  • Linux下的NVIDIA(来自@derhass).
  • Windows 8下的NVIDIA GeForce GT 620M(来自@cifz)

失败:

  • Windows 8.1下的Intel HD 4600.
  • Mac OS 10.9.2下的Intel Iris.
  • iOS 7.1下的iPad Air.
  • 两种不同的Android平板电脑.

因此,这种行为似乎对NVIDIA显然是孤立的.规范说,在链接之前编译着色器是必要的.根据3.3规范:

So this behavior seems clearly isolated to NVIDIA. The specs say that compiling the shaders before linking is necessary. From the 3.3 specs:

如果未成功编译附加到程序的一个或多个着色器对象,则链接也会失败.

Linking will also fail if one or more of the shader objects, attached to program are not compiled successfully.

4.4规范不太清晰,将可能的错误情况转换为以以下内容开头的列表:

The 4.4 specs are a little less clear, turning the possible error conditions into a list that starts with:

链接可能会失败...

Linking can fail ...

通常可以暗示行为是可选的,但是我不确定这是否是这里的意图.在我看来,规格只是重新格式化,并且预期的行为没有改变.恕我直言,这是一个错误.这不是很严格,因为所有合法用法仍然有效,但是我认为NVIDIA所做的工作并不严格遵循规范.

Normally can suggests that behavior is optional, but I'm not sure that this is the intention here. It looks to me like the specs were just reformatted, and the intended behavior has not changed. So IMHO, this is a bug. Not a very severe one, because all legal usage still works, but I don't think what NVIDIA is doing strictly follows the specs.

在任何情况下,都必须在glLinkProgram()之前调用glCompileShader()才能使代码跨平台工作.

In any case, calling glCompileShader() before glLinkProgram() is necessary for your code to work across platforms.

这篇关于glCompileShader是可选的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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