【发布时间】:2019-03-19 22:08:21
【问题描述】:
我有一个顶点缓冲区,其中包含多个(在本例中为 2 个)图形,结构如下:
var vertices = [
x0, y00, y10,
x1, y01, y11,
x2, y02, y12,
...
xn, y0n, y1n
];
及其索引
var indices = [0, 1, 2, 3, ... n-1];
您会注意到,对于每个 x 值,都有 2 y 值,每个值都决定了图形。
我想要的是使用这个单一的缓冲区来渲染这两个图形,而不需要重复任何 x 值。
目前在渲染循环中我有这个:
function render() {
gl.bindBuffer(gl.ARRAY_BUFFER, vBuff); // bind our buffer
// with this setup it renders only first graph:
// x0, y00,
// x1, y01,
// x2, y02,
// ...
// xn, y0n
gl.vertexAttribPointer(vertexPositionLocation, 2, gl.FLOAT, false, 4*3, 0);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.drawElements(gl.LINE_STRIP, indices.length, gl.UNSIGNED_SHORT, 0);
// now how do I set up the vertexAttribPointer such that next draw call here
// would render second graph containing these points
// x0, y10,
// x1, y11,
// x2, y12,
// ...
// xn, y1n
// ?
}
【问题讨论】:
标签: webgl opengl-es-2.0 index-buffer