This is rather a WebGL-specific question. I'm having trouble understanding the WebGL-specific implementation of drawElements. Here is the API specification. From the WebGL specification .
How exactly do I use offset? Is it possible to use offset to mimic the more classic glDrawRangeElements elements?
void drawElements ( GLenum mode, GLsizei counter, GLenum type, GLintptr offset) (OpenGL ES 2.0 ยง2.8, man page)
Drawing using the current buffer of an array of related items. This offset is in bytes and must be a valid multiple of the size of this type, or an INVALID_OPERATION error is generated; see "Buffer Offset" and "Step Requirements." If the counter is greater than zero, then a non-zero WebGLBuffer must be bound to the anchor point ELEMENT_ARRAY_BUFFER or an INVALID_OPERATION error will be generated.
I have a flat array of vertices and an array of flat indices, and drawing using a single call to drawElements works fine, but now I want to highlight parts of the vertices separately because they are different objects. For example, indices [0] to indices [99] are one object (for example, a hand), and indices [100] are indices [149] (for example, a leg) is another object. Groups must be rendered separately - ultimately, because they have different textures, and I will bind the texture before each drawElements call (maybe there is another way to do this at all?)
Thus, I want to call drawElements by indices [0] indices [99] and drawElements by indices [100] indices [149]. Can I do this with offset drawElements?
With the code that I have here, I draw the first group very well, but the rest of the groups are not displayed.
for(var g = 0; g < groups.length; g++) {
var group = groups[g];
var material = group.material;
material.bindTexture();
var offset = group.offset;
var num_items = group.num_items;
gl.drawElements(draw_mode, num_items, indices.type, offset);
}