glUseProgram(0) 有什么作用? [英] What does glUseProgram(0) do?

查看:34
本文介绍了glUseProgram(0) 有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

glUseProgram 的 OpenGL 文档a> 声称使用 参数调用它会导致着色器执行的结果 undefined.

The OpenGL docs for glUseProgram claim that calling it with an argument of zero will cause the results of shader execution to be undefined.

然而,经过一些搜索,我看到了一些使用 glUseProgram卸载当前着色器程序的例子.

However, after a little searching I've seen a couple examples of people using glUseProgram to uninstall the current shader program.

这种行为可靠吗?如果不是,那么 glUseProgram(0) 到底做了什么?

Is this behavior reliable? If not, then what exactly does glUseProgram(0) do?

推荐答案

glUseProgram 表示给定的程序对象是将用于使用程序的事物的当前程序(glUniform、渲染命令等).0 很像 OpenGL 对象的 NULL.它代表的不是一个对象(对于大多数对象).因此,glUseProgram(0) 意味着没有程序是当前的,因此没有程序将用于使用程序的东西.

glUseProgram means that the given program object is the current program that will be used for things that use programs (glUniform, rendering commands, etc). 0 is a lot like NULL for OpenGL objects. It represents not an object (for most objects). Therefore, glUseProgram(0) means that no program is current, and therefore no program will be used for things that use programs.

如果您在当前没有程序时尝试调用 glUniform 函数,它们将失败并显示错误.如果您在当前没有程序的情况下尝试渲染,则会发生以下两种情况之一.在 OpenGL 3.1+ 核心配置文件中,您将获得未定义的行为,因为核心 OpenGL 必须 用程序渲染.在兼容性配置文件或 3.0 或更低版本中,您将获得固定功能渲染.

If you attempt to call the glUniform functions when no program is current, they will fail with an error. If you attempt to render when no program is current, one of two things will happen. In OpenGL 3.1+, core profile, you will get undefined behavior, because core OpenGL must render with a program. In compatibility profiles or version 3.0 or less, you will get fixed-function rendering.

这篇关于glUseProgram(0) 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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