[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Public WebGL] texImage2D on unfinished images and video



I don't think the spec makes this clear what happens when you try to call texImage2D or texSubImage2D on an image or video that is not yet loaded.

Example

   video = document.createElement("video");
   video.src = "" href="http://mysite.com/myvideo">http://mysite.com/myvideo";
   video.play();

   function render() {
     gl.bindTexture(...)
     gl.texImage2D(..., video);
     gl.drawArrays(...);
     window.requestAnimationFrame(render);
  }

Chrome right now will synthesize a GL error if the system hasn't actually gotten the video to start (as in if it's still buffering).

Off the top of my head, it seems like it would just be friendlier to make a black texture (0,0,0,1) or (0,0,0,0) 1x1 pixels for videos that aren't loaded yet.

Otherwise, having to check that the video is ready before calling texImage2D seems kind of burdensome on the developer. If they want to check they should use video.addEventListener('playing') or similar. If they were making a video player they'd have to add a bunch of logic when queuing the next video.

Same with images. 

   img = document.createElement("img");
   img.src = "" href="http://mysite.com/myimage">http://mysite.com/myimage";

   function render() {
     gl.bindTexture(...)
     gl.texImage2D(..., img);
     gl.drawArrays(...);
     window.requestAnimationFrame(render);
  }

If you want to know if the image has loaded use img.onload but otherwise don't fail the call?

What do you think? Good idea? Bad idea?