【问题标题】:Do I have to create separate buffers per webgl program?我必须为每个 webgl 程序创建单独的缓冲区吗?
【发布时间】:2016-02-20 04:17:14
【问题描述】:

如果我有两个程序,我是否必须创建单独的 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);

【问题讨论】:

    标签: javascript buffer webgl


    【解决方案1】:

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

    制服是针对特定项目的

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    相关资源
    最近更新 更多