我正在使用渲染模式LINE_STRIP绘制一个充满如下所示顶点的vbo:[x,y,r,g,b,...]。
我使用以下功能向vbo添加值:
this.gameBuffer.vertices[this.gameBuffer.vertices.count * this.gameBuffer.vertices.step + 0] = circle.x;
this.gameBuffer.vertices[this.gameBuffer.vertices.count * this.gameBuffer.vertices.step + 1] = circle.y;
this.gameBuffer.vertices[this.gameBuffer.vertices.count * this.gameBuffer.vertices.step + 2] = circle.r;
this.gameBuffer.vertices[this.gameBuffer.vertices.count * this.gameBuffer.vertices.step + 3] = circle.g;
this.gameBuffer.vertices[this.gameBuffer.vertices.count * this.gameBuffer.vertices.step + 4] = circle.b;
this.gameBuffer.vertices.count++;
this.setFloatValues();
Run Code Online (Sandbox Code Playgroud)
然后我这样称呼它:
this.addBufferValue({x: x, y: y, r: 1, g: 1, b: 1});
Run Code Online (Sandbox Code Playgroud)
这是我的渲染代码:
this.gl.vertexAttribPointer(this.defaultShader.prog.attribs['vertexPos'], 2, this.gl.FLOAT, false, 20, 0);
this.gl.vertexAttribPointer(this.defaultShader.prog.attribs['acolour'], 3, this.gl.FLOAT, false, 20, 8);
this.drawDynamic(this.gameBuffer, this.gl.LINE_STRIP, this.gameBuffer.vertices.length / this.gameBuffer.vertices.step, 1);
Game.prototype.drawDynamic = function(updatedData, method, count, step) {
this.gl.bufferSubData(this.gl.ARRAY_BUFFER, 0, updatedData.floatVertices);
this.gl.drawArrays(method, …Run Code Online (Sandbox Code Playgroud)