【问题标题】:Trouble Understanding Vulkan Shader无法理解 Vulkan 着色器
【发布时间】:2017-11-08 23:57:48
【问题描述】:

来自Vulkan Tutorial

#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++ 中用作构造函数?

【问题讨论】:

    标签: glsl vulkan


    【解决方案1】:

    问题 1:这是指什么?

    这个

    out gl_PerVertex {
        vec4 gl_Position;
    };
    

    Output Interface Block。 (进一步查看GLSL Specification - 4.3.9 Interface Blocks


    问题 2:如何解释语法 vec2 position3 = vec2?要初始化数组,语法不应该是...

    没有


    Array constructors

    可以使用数组构造函数语法构造数组。在这种情况下, type 还包含 [] 数组表示法:

    const float array[3] = float[3](2.5, 7.0, 1.5);
    


    GLSL Specification - 4.1.11 Initializers

    如果初始化器是用花括号括起来的初始化器列表,则被声明的变量必须是 向量、矩阵、数组或结构。

    int i = { 1 }; // illegal, i is not a composite 
    

    ....

    以下所有声明都会导致编译时错误。

    float a[2] = { 3.4, 4.2, 5.0 }; // illegal
    

    ....

    如果为未调整大小的数组提供了初始化器(任一形式),则数组的大小由 初始化程序中的顶级(非嵌套)初始化程序的数量。以下所有声明创建 使用五个元素显式调整大小的数组:

    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
    

    【讨论】:

      猜你喜欢
      • 2016-12-19
      • 1970-01-01
      • 2022-09-21
      • 1970-01-01
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      相关资源
      最近更新 更多