regl icon indicating copy to clipboard operation
regl copied to clipboard

Texture data inconsistency

Open dy opened this issue 8 years ago • 9 comments

//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])]
  })

dy avatar Jul 12 '17 22:07 dy

@dfcreative calling t() as a function re-evaluates the constructor and initializes the texture to a new value

instead use t.subimage()

jwerle avatar Aug 23 '17 16:08 jwerle

cc @mikolalysenko

jwerle avatar Aug 23 '17 16:08 jwerle

@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.

dy avatar Aug 23 '17 19:08 dy

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 avatar Aug 23 '17 20:08 jwerle

@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.

dy avatar Aug 23 '17 21:08 dy

@dfcreative ah yeah absolutely, you're right

jwerle avatar Aug 23 '17 22:08 jwerle

Not a bug, closing.

mikolalysenko avatar Jan 11 '18 21:01 mikolalysenko

Just for reference: flatten-vertex-data package unrolls nested arrays.

dy avatar Jan 12 '18 08:01 dy

If nobody minds of API consistency, I will revise it. There is a bunch of cases from flatten-vertex-data need to be tested.

dy avatar May 04 '18 00:05 dy