启用客户端状态 vs 着色器属性位置

huangapple go评论41阅读模式
英文:

glEnableClientState vs shader's attribute location

问题

以下是代码部分的中文翻译:

// 使用以下函数将VBO数据与着色器的属性连接起来:

GLint attribVertexPosition = glGetAttribLocation(progId, "vertexPosition");
glEnableVertexAttribArray(attribVertexPosition);
glVertexAttribPointer(attribVertexPosition, 3, GL_FLOAT, false, 0, 0);

// 我分析了一个使用以下函数的旧版OpenGL代码,其中使用了VBO:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, 0);

旧版代码如何将VBO数据与着色器的属性"vertexPosition"建立连接:

attribute vec3 vertexPosition;
英文:

I can connect a VBO data with the shader's attribute using the followings functions:

GLint attribVertexPosition = glGetAttribLocation(progId, "vertexPosition");
glEnableVertexAttribArray(attribVertexPosition);
glVertexAttribPointer(attribVertexPosition, 3, GL_FLOAT, false, 0, 0);

I analyze a legacy OpenGL code where a VBO is used with the following functions:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, 0);

How that legacy code makes a connnection between a VBO data and the shader's attribute:

attribute vec3 vertexPosition;

?

答案1

得分: 3

对于这些固定功能函数,缓冲区与顶点属性之间的绑定是固定的。您不需要告诉 glVertexArray 它馈送哪个属性;它 始终 馈送属性 gl_Vertex,该属性在着色器中已为您定义。它无法馈送任何用户定义的属性。

用户定义的属性是与固定功能属性分开的一组属性。

请注意,NVIDIA 硬件已知违反了这个规则。它将某些属性位置与某些内置顶点数组别名,这允许用户定义的属性从固定功能数组中接收数据。也许您正在查看依赖于这种仅在NVIDIA实现中可用的非标准行为的代码。

英文:

For these fixed-function functions, the binding between the buffer and the vertex attribute is fixed. You don't tell glVertexArray which attribute it feeds; it always feeds the attribute gl_Vertex, which is defined for you in the shader. It cannot feed any user-defined attribute.

User-defined attributes are a separate set of attributes from the fixed-functioned ones.

Note that NVIDIA hardware is known to violate this rule. It aliases certain attribute locations with certain built-in vertex arrays, which allows user-defined attributes to receive data from fixed-function arrays. Perhaps you are looking at code that relies on this non-standard behavior that is only available on NVIDIA's implementation.

huangapple
  • 本文由 发表于 2023年2月6日 21:44:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75362104.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定