pex-gl / pex-context

Modern WebGL state wrapper for PEX: allocate GPU resources (textures, buffers), setup state pipelines and passes, and combine them into commands.
http://pex-gl.github.io/pex-context/
MIT License
160 stars 12 forks source link

Stop relying on existing buffer.type in updateBuffer #131

Closed dmnsgn closed 6 months ago

dmnsgn commented 1 year ago

Replacing: https://github.com/pex-gl/pex-context/blob/e27e6c260b25a0286065647ed3ccea488e6f2f14/buffer.js#L52

Failing use case: updating a buffer back and forth between array of arrays and a typed array. If the previously set typed array has a different type than the defaults for array of arrays, type will be wrong as it will not be set: https://github.com/pex-gl/pex-context/blob/e27e6c260b25a0286065647ed3ccea488e6f2f14/buffer.js#L56-L63

To auto-guess the default type for array of arrays though, we need the buffer.target to be set and fixed. That implies replacing opts.target with buffer.target in updateBuffer as well. Which is not really a problem since we're not reassigning buffer.target anyway and assume once created, the target will remain unchanged.