4
$\begingroup$

WebGL 1.0 specification does not allow to create 32-bit index buffers. Now I'm in trouble, I'm trying to render huge objects with 100 thousands to 1 million indices. In OpenGL this is no issue at all, and I think it will be no issue in WebGL too, in most cases.

I am not able to split my data into smaller subsets as I'm already working with split data sets and can't divide it further without breaking up my full program logic.

Now I came across a new extension for WebGL from 2012, OES_element_index_uint, which looks like it enables unsigned integers (32 bit) for drawElements calls.

/* draw geometry lines by indices */
gl.drawElements(gl.LINES, getIndexBuffer().length, gl.UNSIGNED_INT, idxBuffer);

But when I try to use the gl.UNSIGNED_INT I run into the following error:

Error: WebGL: drawElements: Invalid `type`: 0x1405
uncaught exception: gl.INVALID_ENUM was caused by call to drawElements

How to use 32 bit Integers for Element Indices in WebGL 1.0? How to enable this extension in Chrome or Firefox?

Does this mean in general such a call won't be compatible with most devices running WebGL 1.0?

$\endgroup$
4
$\begingroup$

Enabling the extension is as simple as:

var uints_for_indices = gl.getExtension("OES_element_index_uint");

if uints_for_indices is null then the extension is not available and you'll have to split your data anyway.

If it's not null then you can now pass gl.UNSIGNED_INT for the index type into gl.drawElements.

$\endgroup$
  • $\begingroup$ OES_element_index_uint extension is available but it's not rendering the buffers. Strange. $\endgroup$ – Waqar Lim Jun 17 '16 at 13:00
  • $\begingroup$ have you changed the index buffer to store ints? $\endgroup$ – ratchet freak Jun 17 '16 at 13:10
  • $\begingroup$ Yeah, forgot about that. Now it works. Thanks. $\endgroup$ – Waqar Lim Jun 20 '16 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.