gpt4 book ai didi

javascript - 我是否必须为每个 webgl 程序创建单独的缓冲区?

转载 作者:行者123 更新时间:2023-11-27 23:19:26 25 4
gpt4 key购买 nike

如果我有两个程序,我是否必须创建单独的 webglbuffer,或者我可以在每个程序中使用相同的 webglbuffer 吗?

    this.program = gl.createProgram();
gl.attachShader(this.program, vs);
gl.attachShader(this.program, fs);
gl.linkProgram(this.program);
//gl.useProgram(this.program);
this.cellProgram = gl.createProgram();
gl.attachShader(this.cellProgram, cvs);
gl.attachShader(this.cellProgram, cfs);
gl.linkProgram(this.cellProgram);
//gl.useProgram(this.cellProgram);


this.texCoordBuffer = gl.createBuffer();
this.posCoordBuffer = gl.createBuffer();

我还需要为每个程序绑定(bind)缓冲区并设置缓冲区数据吗?或者数据/缓冲区是否在程序之间共享?

gl.useProgram(program);

// look up where the vertex data needs to go.
var positionLocation = gl.getAttribLocation(program, "a_position");
var texCoordLocation = gl.getAttribLocation(program, "a_texCoord");


// provide texture coordinates for the rectangle.
//this will be what the texture gets displayed on?
gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
0.0, 1.0,
1.0, 0.0,
1.0, 1.0]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(texCoordLocation);
gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);

最佳答案

不,缓冲区、程序、属性、渲染缓冲区、帧缓冲区、纹理和纹理单元独立于程序

制服因项目而异

关于javascript - 我是否必须为每个 webgl 程序创建单独的缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35511480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com