c++ - 为什么着色器和程序在 OpenGL 中存储为整数?

标签 c++ opengl opengl-es integer shader

我正在阅读“OpenGL Superbible”一书,我不禁注意到,当我们创建一个着色器并创建我们将着色器附加到的程序时,我们将它们存储为 GLuint,这是无符号整数。

为什么它们存储为数字?数字的值是什么意思?

例子:

GLuint vertex_shader;
GLuint fragment_shader;
GLuint program;

// Create and compile vertex shader
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex_shader, 1, vertex_shader_source, NULL);
glCompileShader(vertex_shader);

// Create program, attach shaders to it, and link it
program = glCreateProgram();
glAttachShader(program, vertex_shader);
glLinkProgram(program);

最佳答案

这些整数是句柄。这是许多 API 使用的常用习惯用法,用于通过不透明的间接级别隐藏资源访问。 OpenGL 有效地阻止您在不使用 API 调用的情况下访问句柄后面的内容。

From Wikipedia :

In computer programming, a handle is an abstract reference to a resource. [...] Resource handles can be opaque identifiers, in which case they are often integer numbers, or they can be pointers that allow access to further information.

关于c++ - 为什么着色器和程序在 OpenGL 中存储为整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30973668/

相关文章:

c++ - 构建 libsigc++ 失败(std::basic_ostream 显式实例化)

c++ - SwapBuffers 导致重绘

c++ - 保存数据以便从体素编辑器中重新使用的最佳方式

android - 绘制固定长度曲线

c++ - 我可以 std::bind 基类的构造函数,以便派生类不需要显式调用它吗?

c++ - 为什么重复使用条件变量的互斥量会导致死锁?

iphone - 当 UIView 低于 EAGLView 时,我的性能是否会受到很大影响?

opengl-es - OpenGL ES 2.0 中梯形的透视正确纹理

c++ - Netbeans 显示 unix 系统调用错误 "getcontext"

c++ - 带有用于 c/cpp 的 Material 文件的 Wavefront obj 加载器