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$
0

1 Answer 1

5
$\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$
2
  • $\begingroup$ OES_element_index_uint extension is available but it's not rendering the buffers. Strange. $\endgroup$
    – q9f
    Jun 17, 2016 at 13:00
  • $\begingroup$ have you changed the index buffer to store ints? $\endgroup$ Jun 17, 2016 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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