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

ImageBitmap is only supported in WebGL2 #120

Closed vorg closed 3 months ago

vorg commented 2 years ago

As per https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texImage2D

Should we warn in pex-context or rely on browser to fail? Is creates issue here https://github.com/pex-gl/pex-renderer/blob/v4/loaders/glTF.js#L1234

dmnsgn commented 2 years ago

I'd say yes, warning in pex-context but also overwrite supportImageBitmap by checking isWebGL2 in pex-renderer.

vorg commented 2 years ago

Why do we not support in in gltf in Safari?

From https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap Screenshot 2022-06-08 at 12 04 38

vorg commented 2 years ago

Btw FF gives better error in WebGL1 WebGLRenderingContext.texImage2D: Argument 9 does not implement interface ArrayBufferViewOrNull.

vorg commented 2 years ago

Possible fix here https://stackoverflow.com/questions/42073596/webglrenderingcontext-teximage2d-does-not-implement-interface-arraybuffervieworn

Hmm if i do this in WebGL1 then it works.. does it mean ImageBitmap is considered HTMLElement in WebGL1 and ArrayBuffer view compatible in WebGL2 only?

Screenshot 2022-06-08 at 12 15 40

dmnsgn commented 2 years ago

Why do we not support in in gltf in Safari?

Because it doesn't support options.colorSpaceConversion which is GLTF spec: https://developer.mozilla.org/en-US/docs/Web/API/createImageBitmap#browser_compatibility FF >= 98 supports it so I didn't added a check for it.

dmnsgn commented 2 years ago

Proposed change: check if ImageBitmap in webgl.

   }

   const img = opts.data ? opts.data : opts;
-  if (img && img.nodeName) {
+  if (
+    (img && img.nodeName) ||
+    (!ctx.capabilities.isWebGL2 && img instanceof ImageBitmap)
+  ) {
vorg commented 2 years ago

Looks good to me