我正在尝试更新 REGL 中帧缓冲区内的纹理。但由于某种原因,它不会更新帧缓冲区。
这是完整的代码:
const regl = createREGL({
extensions: 'OES_texture_float'
})
const initialTexture = regl.texture([
[
[0, 255, 0, 255]
]
])
const fbo = regl.framebuffer({
color: initialTexture,
depth: false,
stencil: false,
})
const updateColor = regl({
framebuffer: () => fbo,
vert: `
precision mediump float;
attribute vec2 position;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
}
`,
frag: `
precision mediump float;
void main() {
gl_FragColor = vec4(255.0, 0.0, 0.0, 255.0);
}
`,
attributes: {
// a triangle big enough to fill the screen
position: [
-4, 0,
4, 4,
4, -4
],
},
count: 3,
})
regl.clear({
// background color (black)
color: [0, 0, 0, 1],
depth: 1,
});
updateColor(() => {
console.log(regl.read())
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/regl/1.3.11/regl.min.js"></script>
- 我设置
initialTexture
为绿色。 - 在
updateColor
命令中,我指定了帧缓冲区,使 regl 渲染到帧缓冲区 - 中的片段着色器
updateColor
呈现红色 - 命令运行后
updateColor
,我希望initialTexture
它是红色的,但它保持绿色。
我究竟做错了什么?