我可以用着色器语言将vec2数组绑定到vec4变量吗?
例如,在代码打击中,变量“position”是vec4类型,我试图将变量“squareVertices”绑定到它,但squareVertices是一个vec2类型数组,只有(x,y)coodinates,也许默认(x,y,z,w)=(x,y,0,1)?
我的顶点着色器和属性绑定代码:
attribute vec4 position;
attribute vec2 textureCoordinate;
varying vec2 coordinate;
void main()
{
gl_Position = position;
coordinate = textureCoordinate;
}
glBindAttribLocation(gProgram, ATTRIB_VERTEX, "position");
glBindAttribLocation(gProgram, ATTRIB_TEXTURE, "textureCoordinate");
// bind attribute values
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
glEnableVertexAttribArray(ATTRIB_VERTEX);
glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, coordVertices);
glEnableVertexAttribArray(ATTRIB_TEXTURE);
// squareVertices definition
static const GLfloat squareVertices[] = {
-1.0f, -1.0f,
0.0f, -1.0f,
-1.0f, 0.0f,
0.0f, 0.0f,
};
答案 0 :(得分:0)
是的,这是合法的。并且,你是正确的,z和w的默认值分别是0和1。这在OpenGL ES 2.0规范的第2.7节中有所介绍。