-
Newbie to twgl here, in my use case position attribute changes let's say based on user mouse down event. For every click, we use mouse xy to set position attribute. Position is a vec2 attribute. Currently i create bufferinfo once with initial xy values. How do i go about setting values after mouse clicks. Should be recreating buffer info? All examples don't change position attributes Any help is greatly appreciated |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
So first off, I want to emphasize, TWGL is not a replacement for WebGL, it's just a helper. TWGL doesn't do everything. For example TWGL has no functions for setting up blending, enabling depth test, working in stencils, etc. It's just a collection of functions to help. If you want to update the buffer used by an attribute, there's an example here: If you have a value based attribute, first off, that's not common. You can set it like this though
Changing attribute values is not common. The entire point of attributes is to set them up to take values from a buffer. If you just want to pass a single value it's far more common to use a uniform. The only major use case for an attribute value is to feed in a constant to a vertex shader that normally expects different values per vertex. Imagine you have a pair of shaders that draws with vertex colors
Then you have lots of different sets of geometry (vertices) that have positions and vertex colors. You decide you'd also like to use the same shader to draw vertices that have no vertex colors. In that case you could to off the attribute ( Otherwise, if you're regularly passing in a constant value it's more common to use a uniform. Further, the TWGL code above is wasteful. Calling
|
Beta Was this translation helpful? Give feedback.
-
in the shader
In twgl
Example: https://jsgist.org/?src=892518b84abbd92810a9ee75a6f03fda |
Beta Was this translation helpful? Give feedback.
So first off, I want to emphasize, TWGL is not a replacement for WebGL, it's just a helper. TWGL doesn't do everything. For example TWGL has no functions for setting up blending, enabling depth test, working in stencils, etc. It's just a collection of functions to help.
If you want to update the buffer used by an attribute, there's an example here:
https://twgljs.org/examples/dynamic-buffers.html
If you have a value based attribute, first off, that's not common.
You can set it like this though