pex-renderer icon indicating copy to clipboard operation
pex-renderer copied to clipboard

Call getPexMaterialTexture per texture not per material

Open vorg opened this issue 2 years ago • 3 comments

For buster drone there is only 3 materials and 10 textures but in the current code:

  • handleMaterial is called 40 times
  • getPexMaterialTexture is called 38 times
  • ctx.texture2D is called 39 times in Chrome but 10 times in Safari (sth sth ImageBitmap?)

In old version of the loader we pre-processed textures, materials etc in first pass before traversing tree to avoid duplicated work like above. Not sure when this has changed.

vorg avatar Jun 08 '22 09:06 vorg

I'm also getting TypeError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': parameter 9 is not of type 'ArrayBufferView'. in Chrome despite last param being ImageBitmap with valid width and height. But only on the last texture.

vorg avatar Jun 08 '22 09:06 vorg

getPexMaterialTexture is called for every material texture (in handleMaterial) but texture2D creation is cached in _tex so no problem of loading textures twice:

https://github.com/pex-gl/pex-renderer/blob/bc51a9f385b841ebb46916d4dd4848778898e41a/loaders/glTF.js#L242

ctx.texture2D is called 39 times in Chrome but 10 times in Safari (sth sth ImageBitmap?)

Cannot reproduce with a webgl2 context: I get the same amount in chrome and safari, 10.

dmnsgn avatar Jun 08 '22 13:06 dmnsgn

Cannot reproduce with a webgl2 context: I get the same amount in chrome and safari, 10.

Most likely because https://github.com/pex-gl/pex-context/issues/120 (ImageBitmap bug) and while it is attempted 40x and if it fails then _tex is not set.

Now calling 40x handleMaterial instead of 3x can be either bug or feature. It definitely adds up for complex gltf scene with a benefit that each entity will have their own material component as they should be unique anyway. It is then up to renderer to notice that 40 materials need only 3 shaders via flags.

vorg avatar Jun 08 '22 14:06 vorg