你可以传递一个固定大小的数组作为GLSL函数参数吗?

时间:2021-02-05 19:35:17

In a GLSL shader, I want to create a function that looks a bit like this :

在GLSL着色器中,我想创建一个看起来像这样的函数:

void MyFunction(out float results[9])
{
   float value0 = 3.1546;
   float value1 = 42;     // whatever value      
   /* ... long, complicated code ... */

   results[0] = value0;  
   results[1] = value1;
   results[2] = value2;
   ...
}

Can such a function signature be used and compiled in GLSL ?
If no, are there any alternatives ?

可以在GLSL中使用和编译这样的函数签名吗?如果不是,还有其他选择吗?

1 个解决方案

#1


5  

Yes, this is legal GLSL code.

是的,这是合法的GLSL代码。

That doesn't mean it will certainly compile, but it is legal code. That being said, it's probably better to just return the array (which you can also do), rather than pass it as an output parameter.

这并不意味着它肯定会编译,但它是合法的代码。话虽如此,最好只返回数组(您也可以这样做),而不是将其作为输出参数传递。

#1


5  

Yes, this is legal GLSL code.

是的,这是合法的GLSL代码。

That doesn't mean it will certainly compile, but it is legal code. That being said, it's probably better to just return the array (which you can also do), rather than pass it as an output parameter.

这并不意味着它肯定会编译,但它是合法的代码。话虽如此,最好只返回数组(您也可以这样做),而不是将其作为输出参数传递。