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

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

On Tue, Oct 16, 2012 at 4:07 PM, Florian Bösch <pyalot@gmail.com> wrote:
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.

Let me be more clear. My position is that how to figure out if a video is ready or a image is loaded is outside the scope of WebGL. WebGL should only do 1 of 3 things

1) if the URL is a different domain and there's no CORS permission throw a security exception
2) if the image/video is not loaded/ready/buffered then for texImage2D make 1 pixel black texture, for texSubImage2D do nothing.
3) otherwise upload the image/video into the texture.

So whether it's playing, bufferReady, onload, etc. is an HTML spec issue, not a WebGL issue. WebGL's spec only needs to handle the 3 cases above
Same with images. 

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

   function render() {
     gl.texImage2D(..., img);

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