0

I have a Element Array Buffer

var index_buffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, index_buffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.STATIC_DRAW);

And I want to be able to see the length of the buffer, but index_buffer.length is undefined and there is no function in the WebGLBuffer type to get the length of items

How do I go about seeing how large it is?

UPDATE: Thanks to gman for pointing out that I was using this for debugging, don't try this if using otherwise, better ways of getting the info

4
  • indices.length ? Commented Jan 15, 2017 at 13:20
  • I have this in a function where I return just the buffer and don't have the ability to see the data array in scope Commented Jan 15, 2017 at 13:41
  • 3
    I'm curious, how will knowing the length of the buffer help you? You'd also need to know what's in the buffer. Uint8s, Uint16s, Floats? In fact it could be a mixed buffer with different data at different offsets. So if you don't know what's in the buffer and where then knowing the length is not of much use but on the other hand if you do know what's in the buffer then you probably already know the length. Or to put it another way there's no reason to want to look up the length except possibly for debugging. Just checking there's not a better solution for whatever you're trying to do. Commented Jan 16, 2017 at 3:53
  • I totally agree @gman I was using it debug because I was getting out of bounds errors and was trying to pin it down Commented Jan 16, 2017 at 23:08

1 Answer 1

4

The spec has you covered:

gl.getBufferParameter(gl.ELEMENT_ARRAY_BUFFER, gl.BUFFER_SIZE);

Keep in mind that querying information from the GPU is expensive.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.