我試過這段代碼。如何在GLSL ES中定義2d數組?
varying vec2 blurCoordinates[2][2];
但它會導致錯誤:
頂點着色器編譯失敗。 錯誤:0:10:'[':語法錯誤:語法錯誤 錯誤:1編譯錯誤。沒有代碼生成。
我試過這段代碼。如何在GLSL ES中定義2d數組?
varying vec2 blurCoordinates[2][2];
但它會導致錯誤:
頂點着色器編譯失敗。 錯誤:0:10:'[':語法錯誤:語法錯誤 錯誤:1編譯錯誤。沒有代碼生成。
正如genpfault的回答中已經提到的那樣,GLSL從一開始就不支持多維數組。
擴展GL_ARB_arrays_of_arrays
確實提供了您正在尋找的功能。它在4.3版中被提升爲OpenGL核心功能,所以從GLSL 4.30開始,您可以在不依賴擴展的情況下使用它。
沒有#version
指令意味着#version 100
其中多維數組是禁止的:
Section 4.1.9, "Arrays" (page 24) :
Variables of the same type can be aggregated into arrays by declaring a name followed by brackets ([ ]) enclosing a size. The array size must be an integral constant expression (see Section 4.3.3 「Integral Constant Expressions」) greater than zero. It is illegal to index an array with an integral constant expression greater than or equal to its declared size. It is also illegal to index an array with a negative constant expression. Arrays declared as formal parameters in a function declaration must specify a size. Only one-dimensional arrays may be declared. All basic types and structures can be formed into arrays.
如果使用#version 320 es
你可以聲明數組的數組:
Section 4.1.9, "Arrays" (page 40) :
Variables of the same type can be aggregated into arrays by declaring a name followed by brackets ([ ]) enclosing an optional size. When present, the array size must be a constant integral expression (see section 4.3.3 「Constant Expressions」) greater than zero. The type of the size parameter can be a signed or unsigned integer and the choice of type does not affect the type of the resulting array. Arrays only have a single dimension (a single number within 「[ ]」), however, arrays of arrays can be declared. Any type can be formed into an array.
...