Do I have to create separate buffers per webgl program?

别来无恙 提交于 2019-12-24 13:50:37

问题


Do I have to create separate webglbuffers if I have two programs or can I use the same ones in each?

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

and also would I need to bindbuffer and set bufferdata for each program? Or are the data/buffers shared between programs?

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

回答1:


No, buffers, programs, attributes, renderbuffers, framebuffers, textures and texture units are independent from programs

Uniforms are program specific



来源:https://stackoverflow.com/questions/35511480/do-i-have-to-create-separate-buffers-per-webgl-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!