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

Re: [Public WebGL] texImage2D on unfinished images and video



On Wed, Oct 17, 2012 at 12:54 AM, Gregg Tavares (社用) <gman@google.com> wrote:
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.
Seeing a black texture is nearly universally accepted as "stuff's not uploaded" for 3D programmers. So imo that's a perfectly fine idea.
 
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.
Although "playing" is not synonymous with "buffer ready". A video can be paused and you'd like to show the still image from where it stands.
 
Same with images. 

   img = document.createElement("img");
   img.src = "" href="http://mysite.com/myimage" target="_blank">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?
I usually wait for onload in images before usage. Usually in the form of a bulk loader before drawing commences. But image onload signals "buffer ready" better than videos "playing".