下面所描述的对矢量成员的访问是非法的, 会引起编译错误:
float2 pos; pos.x = 1.0f; // is legal; so is y pos.z = 1.0f; // is illegal; so is w float3 pos; pos.z = 1.0f; // is legal pos.w = 1.0f; // is illegal
// illegal - 'x' used twice pos.xx = float2(3.0f, 4.0f); // illegal - mismatch between float2 and float4 pos.xy = float4(1.0f, 2.0f, 3.0f, 4.0f);
float4 pos = float4(1.0f, 2.0f, 3.0f, 4.0f); pos.x = 1.0f; // OK pos.g = 2.0f; // OK pos.xg = float2(3.0f, 4.0f); // illegal - mixed qualifiers used float3 coord = pos.ryz; // illegal - mixed qualifiers used
float4 pos = float4(1.0f, 2.0f, 3.0f, 4.0f); my_func(&pos.xy); // illegal