regl
regl copied to clipboard
Texture data inconsistency
//we create texture with per-pixel data
let t = regl.texture({
type: 'uint8',
format: 'rgba',
shape: [2, 1],
data: [[0,0,0,0], [0,0,0,0]]
})
//updating it same way raises an error of incompat size
t({
shape: [2, 1],
data: [[0,0,0,0], [0,0,0,0]]
})
//same is for list of typed arrays
t({
shape: [2, 1],
data: [new Uint8Array([0,0,0,0]), new Uint8Array([0,0,0,0])]
})
@dfcreative calling t() as a function re-evaluates the constructor and initializes the texture to a new value
instead use t.subimage()
cc @mikolalysenko
@jwerle yes, thanks. The concern though is that sometimes we have pixel values represented as nested arrays [[r,g,b,a], [r,g,b,a], ...], not the one single unrolled array [r,g,b,a, r,g,b,a, ...]. That API forces us to flatten array every texture update, same is for t.subimage. That might be an issue with large textures, performance-wise.
ah yes, that makes sense. should regl be responsible for that? perhaps ndarray could be of use in a situation like that? what does gl-texture2d do?
@jwerle regl handles well nested arrays in constructor, but fails on update/subimage. I believe the behavior should be consistent, also that is pretty useful to have such simple cases covered, bc in userland there is no strictly defined single format for pixels data.
@dfcreative ah yeah absolutely, you're right
Not a bug, closing.
Just for reference: flatten-vertex-data package unrolls nested arrays.
If nobody minds of API consistency, I will revise it. There is a bunch of cases from flatten-vertex-data need to be tested.