在构建着色器时,我注意到有时会使用一个名为 main 的 void 函数来定义着色器。当一个属性被迭代时,它似乎main
被添加到着色器中。
我想弄清楚何时适合在内部定义着色器main
,而不是仅在着色器的顶级定义空间内。
regl 教程中的示例代码。
var drawTriangle = regl({
//
// First we define a vertex shader. This is a program which tells the GPU
// where to draw the vertices.
//
vert: `
// This is a simple vertex shader that just passes the position through
attribute vec2 position;
void main () {
gl_Position = vec4(position, 0, 1);
}
`,
//
// Next, we define a fragment shader to tell the GPU what color to draw.
//
frag: `
// This is program just colors the triangle white
void main () {
gl_FragColor = vec4(1, 1, 1, 1);
}
`,
// Finally we need to give the vertices to the GPU
attributes: {
position: [
[1, 0],
[0, 1],
[-1, -1]
]
},
// And also tell it how many vertices to draw
count: 3
})