首页 > 解决方案 > 无法在 GLSL 中创建简单的结构数组

问题描述

我正在尝试uniform在 GLSL 的计算着色器中创建一个结构数组(不是)(在 C++ 中使用 GLFW)。但是我在着色器编译时遇到了几个错误:

error C7546: OpenGL does not allow abstract declarations in structs
error C0000: syntax error, unexpected reserved word, expecting ';' at token "active"

以下是有问题的行:

struct ControlNode
{
    vec3 pos;
    float value;
    bool active;
};

ControlNode controlNodes[8];

所以显然问题与bool active;结构中的定义有关,但我不知道为什么。在代码中我得到这个错误:error C0000: syntax error, unexpected reserved word, expecting identifier or template identifier or type identifier at token "active"当我在这里使用数组时:

for(int i = 0; i < 8; ++i){
    if(controlNodes[i].active){
        // some stuff here...
    }
}

我想这是由前两个错误引起的,所以摆脱这些错误也会删除这个错误。

标签: arraysstructglslcompute-shader

解决方案


推荐阅读