问题描述
运行一个非常简单的OpenGL ES示例,我已经看到顶点着色器中position属性的尺寸与用于将属性数据传输到GPU的尺寸不同,但是示例可以正确运行.
Running a very simple OpenGL ES example I've seen that the dimensions of the position attribute in the vertex shader and the ones used to transfer the attribute data to the GPU are different, but the example runs correctly.
这是顶点着色器中的属性声明:
This is the attribute declaration in the vertex shader:
attribute vec4 a_v4Position;
这是属性值的传输方式:
And this is how the attribute value is transferred:
const float triangleVertices[] =
{
0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
};
positionAttribLocation = glGetAttribLocation(GLProgram, "a_v4Position"); //GLProgram is the linked program
glEnableVertexAttribArray(positionAttribLocation);
glVertexAttribPointer(positionAttribLocation, 3, GL_FLOAT, GL_FALSE, 0, TriangleVertices);
那么,为什么这可以正常工作,并且此过程产生的默认值"w"是哪个?
So, why this works fine and which is the "w" default value that results from this process?
推荐答案
在这种情况下,w
的值为1.0.这是完全合法且定义明确的.只要指定的属性的值小于4,就会用(0.0,0.0,0.0,1.0)中的值填充缺失值.当然,如果顶点着色器中的属性矢量较短,则不会使用所有这些值.
The value of w
will be 1.0 in this case. This is perfectly legal and well defined. Whenever the specified attribute has fewer values than 4, the missing values are padded with values from (0.0, 0.0, 0.0, 1.0). Of course, if the attribute vector in the vertex shader is shorter, not all those values are used.
相关的规范语言在ES 2.0规范的第21页上的传输数组元素"下:
The relevant spec language is on page 21 of the ES 2.0 spec, under "Transferring Array Elements":
这篇关于尺寸不匹配时OpenGL ES属性传输默认行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!