twgl.js
twgl.js copied to clipboard
User-error-prone dist/ directory structure
The drawBufferInfo docs say that the fourth argument is "An optional count. Defaults to bufferInfo.numElements". This was true in 3.2.2. When I updated to 3.8.0 my render call was not working anymore. Every time I called drawBufferInfo I got this warning, apparently because it was defaulting to 0:
[.Offscreen-For-WebGL-00000000075EBCE0]RENDER WARNING: Render count or primcount is 0.
When I added an explicit fourth argument with the number of elements in the buffer, I stopped getting that warning message, but the render calls still did not work correctly. (It was as if the render calls were being ignored.)
...I ended up solving the problem by going back to 3.2.2, I can't really say what's wrong except that the behavior changed in a weird way.
Do you have a repo? Here's working sample
Here is a project I made using twgl not too long ago; other than the twgl dependency these are the only two files needed:
http://pineapplemachine.com/demos/websand/sand.html http://pineapplemachine.com/demos/websand/sand.js
When I downloaded the 3.8.0 release and tried using the new version in a new project, I was running into the aforementioned errors that I finally resolved by using 3.2.2 instead. When I tried switching this websand project to use 3.8.0, it broke with the same error. ("Render count or primcount is 0.") When I added an explicit count argument, or tried also explicitly passing 0 for the following arguments, that warning stopped but the buffer didn't seem to render at all.
Here are the most relevant parts of the websand source:
Initializing a context
const gl = twgl.getWebGLContext(canvas, {
alpha: false,
antialias: false,
depth: false,
stencil: false,
});
twgl.setDefaults({
textureColor: [0, 0, 0, 1],
attribPrefix: "a_",
});
Creating a buffer info object
const bufferInfo = twgl.createBufferInfoFromArrays(gl, {
position: {
numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1]
},
});
Drawing the buffer info object
twgl.setBuffersAndAttributes(gl, programInfo, bufferInfo);
twgl.drawBufferInfo(gl, bufferInfo, gl.TRIANGLE_STRIP);
I downloaded your sample and replaced the library with 3.8.1 and it still worked for me. Any other ideas what I might be doing differently that it's working for me and not for you?
That's odd - when I was troubleshooting someone else was able to reproduce the problem on their machine too. When I'm back at my desk I will investigate further. In the meantime here's the specific js dependency I was loading. https://www.dropbox.com/s/fxaw4vcv9kbyb4h/twgl-full.min.js?dl=0
Sent from my Samsung SAMSUNG-SM-G891A using FastHub
That link leads to twgl 1.9.0 in which case I'd expect the error because one of the 2 big breaking change sbetween twgl 1.x and twgl 2.x was the order of arguments to twgl.drawBufferInfo. From the changelist
twgl.drawBufferInfo(gl, primitiveType, bufferInfo)Now in 2.x it's
twgl.drawBufferInfo(gl, bufferInfo, primitiveType)
A change in the order of arguments certainly explains the error, but I'm confused.
I downloaded 3.8.0 from here: https://github.com/greggman/twgl.js/releases/tag/v3.8.0
I used the js files in twgl.js-3.8.0/dist. I now notice there's also 2.x and 3.x subdirectories, is it that the ones here are from 1.9.0 and the 3.8.0 js is in the subdirectory? But, I could swear I got the 3.2.2 dependency the same way.
If that is the case, then as a solution to this issue I would really like to suggest making it clearer which files actually belong to the latest release.
update: Yeah, I tested with the file in the 3.x directory, which does say 3.8.0 in the comment on top, and everything works fine. So not an error with the new release, but the directory structure is definitely a source of confusion.
Okay, off the top of my head the best I can do is put a file in dist
dist/this-is-the-1.x-dist-folder-for-newer-dists-see-v.x-directories.md
Or something like that. The reason is people link directly to files in this repo (sadly) and I don't want to break them. If I change the files in dist their stuff will break
Ahhh why would people do that
What if you included links to download only the appropriate dist/ files rather than the entire repo in releases?
People do it for things like jsfiddle, codepen, jsbin, Stack Overflow Snippets, etc...
I still think that's silly
But I do think that adding the option to only download the dist files, like as a zip containing the relevant 4 js files, to releases would help a lot, and would be kind of convenient besides.