문제

As far as I understand, each vertex attribute consists of one 4-element vector value regardless of the number of components per generic vertex attribute values provided in a call to glVertexAttribPointer​.

This means if I pass in a flat array of floats the vertex shader will receive these floats as vec4 where x will be set to the values provided and yzw fields will be set to 0, 0, 1 respectively, right?

도움이 되었습니까?

해결책

Mostly right. If you declare the attribute as a vec4 in the shader, the components that are not present in your input array will be filled with y = 0, z = 0, w = 1.

You don't have to declare attributes as vec4 in the shader, though. If your attribute is really just a float, you can declare it with type float in the shader. From the ES 2.0 spec:

The attribute qualifier can be used only with the data types float, vec2, vec3, vec4, mat2, mat3, and mat4.

Limits on how many attributes are supported are expressed in units of vec4, and a float attribute will use one of those attribute slots, just like a vec4 would. So if you need a bunch of float attributes, and run close to the supported limit of how many attributes are supported, it might be a good idea to start packing them into vectors. It would most likely be beneficial for performance anyway.

다른 팁

Location = glGetUniformLocation ( Program object , "u_scalar")

glUniform1f( Location, scalar); glUniform2f( Location, scalar); . . .

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top