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

Do I have to create separate buffers per webgl program?

本文关键字:创建 程序 单独 缓冲区 webgl 是否      更新时间:2023-09-26

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

    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();

我还需要为每个程序绑定缓冲区和设置缓冲区数据吗?还是数据/缓冲区在程序之间共享?

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);

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

制服是特定于程序的