Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drawType in example conflicts with docs and type annotation #190

Open
bchirlsbiodigital opened this issue Dec 21, 2021 · 1 comment
Open

Comments

@bchirlsbiodigital
Copy link

Refer to the following code from the dynamic buffers example:

    const arrays = {
      spread: { data: spreadArray, numComponents: 1 },
      height: { data: heightArray, numComponents: 1, drawType: gl.DYNAMIC_DRAW },
    };
    const bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);

If I'm following the documentation correctly, each array passed to createBufferInfoFromArrays should be an ArraySpec, which does not include the drawType property. It looks like the function does actually use the property, so I think it's the docs/types that are incomplete not the example.

Could you please clarify here or update the example, docs or types to reflect the proper way to set drawType on an attribute?

Thanks!

@greggman
Copy link
Owner

greggman commented Dec 21, 2021

drawType is optional

* @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW

if it's not specified twgl will use STATIC_DRAW

gl.bufferData(type, array, drawType || STATIC_DRAW);

It's copied to the attribute info you linked to but if it's not set it will still be undefined and so still use STATIC_DRAW.

As for why set it, it's a hint to WebGL that you're going to update the buffer often, 'hint' means it's not required as it's only a hint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants