难以理解 Vulkan 着色器
Trouble Understanding Vulkan Shader
#version 450
#extension GL_ARB_separate_shader_objects : enable
out gl_PerVertex {
vec4 gl_Position;
};
vec2 positions[3] = vec2[](
vec2(0.0, -0.5),
vec2(0.5, 0.5),
vec2(-0.5, 0.5)
);
void main() {
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
}
问题 1:这是什么意思?
out gl_PerVertex {
vec4 gl_Position;
};
问题 2: 什么解释了语法 vec2 positions[3] = vec2[](...)
?要初始化数组,语法不应该是
vec2 positions[3] = {
vec2(0.0, -0.5),
vec2(0.5, 0.5),
vec2(-0.5, 0.5)
};
这是特定于着色器的语法,还是 arrayType[](...)
也可以用作 C++ 中的构造函数?
Question 1: What does this designate?
这个
out gl_PerVertex {
vec4 gl_Position;
};
是一个Output Interface Block. (See further GLSL Specification - 4.3.9 Interface Blocks)
Question 2: What explains the syntax vec2 positions3 = vec2? To initialize the array, shouldn't the syntax be ...
没有
Arrays can be constructed using array constructor syntax. In this case, the
type also contains the [] array notation:
const float array[3] = float[3](2.5, 7.0, 1.5);
见 GLSL Specification - 4.1.11 Initializers:
If an initializer is a list of initializers enclosed in curly braces, the variable being declared must be a
vector, a matrix, an array, or a structure.
int i = { 1 }; // illegal, i is not a composite
....
All of the following declarations result in a compile-time error.
float a[2] = { 3.4, 4.2, 5.0 }; // illegal
....
If an initializer (of either form) is provided for an unsized array, the size of the array is determined by the
number of top-level (non-nested) initializers within the initializer. All of the following declarations create
arrays explicitly sized with five elements:
float a[] = float[](3.4, 4.2, 5.0, 5.2, 1.1);
float b[] = { 3.4, 4.2, 5.0, 5.2, 1.1 };
float c[] = a; // c is explicitly size 5
float d[5] = b; // means the same thing
#version 450
#extension GL_ARB_separate_shader_objects : enable
out gl_PerVertex {
vec4 gl_Position;
};
vec2 positions[3] = vec2[](
vec2(0.0, -0.5),
vec2(0.5, 0.5),
vec2(-0.5, 0.5)
);
void main() {
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
}
问题 1:这是什么意思?
out gl_PerVertex {
vec4 gl_Position;
};
问题 2: 什么解释了语法 vec2 positions[3] = vec2[](...)
?要初始化数组,语法不应该是
vec2 positions[3] = {
vec2(0.0, -0.5),
vec2(0.5, 0.5),
vec2(-0.5, 0.5)
};
这是特定于着色器的语法,还是 arrayType[](...)
也可以用作 C++ 中的构造函数?
Question 1: What does this designate?
这个
out gl_PerVertex {
vec4 gl_Position;
};
是一个Output Interface Block. (See further GLSL Specification - 4.3.9 Interface Blocks)
Question 2: What explains the syntax vec2 positions3 = vec2? To initialize the array, shouldn't the syntax be ...
没有
Arrays can be constructed using array constructor syntax. In this case, the type also contains the [] array notation:
const float array[3] = float[3](2.5, 7.0, 1.5);
见 GLSL Specification - 4.1.11 Initializers:
If an initializer is a list of initializers enclosed in curly braces, the variable being declared must be a vector, a matrix, an array, or a structure.
int i = { 1 }; // illegal, i is not a composite
....
All of the following declarations result in a compile-time error.
float a[2] = { 3.4, 4.2, 5.0 }; // illegal
....
If an initializer (of either form) is provided for an unsized array, the size of the array is determined by the number of top-level (non-nested) initializers within the initializer. All of the following declarations create arrays explicitly sized with five elements:
float a[] = float[](3.4, 4.2, 5.0, 5.2, 1.1); float b[] = { 3.4, 4.2, 5.0, 5.2, 1.1 }; float c[] = a; // c is explicitly size 5 float d[5] = b; // means the same thing