我必须为每个webgl程序创建单独的缓冲区吗? [英] Do I have to create separate buffers per webgl program?
本文介绍了我必须为每个webgl程序创建单独的缓冲区吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有两个程序,是否必须创建单独的webglbuffers?或者我可以在每个程序中使用相同的程序吗?
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);
推荐答案
否,缓冲区,程序,属性,渲染缓冲区,帧缓冲区,纹理和纹理单位独立于程序
No, buffers, programs, attributes, renderbuffers, framebuffers, textures and texture units are independent from programs
制服是特定于程序的
这篇关于我必须为每个webgl程序创建单独的缓冲区吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文