regl-project / regl

👑 Functional WebGL
MIT License
5.19k stars 320 forks source link

website API docs have a bogus regl.texture() example #435

Open tomjakubowski opened 6 years ago

tomjakubowski commented 6 years ago

http://regl.party/api#textures

// From an image element
var image = new Image()
image.src = 'http://mydomain.com/myimage.png'
var imageTexture = regl.texture(image)

Trying this (with a real src) resulted in this exception being thrown (regl 1.3.0):

Error: (regl) invalid texture shape

Meanwhile, API.md as of now lists a similar example which does work:

// From an image element
var image = new Image()
image.src = 'http://mydomain.com/myimage.png'
image.onload = function () {
  var imageTexture = regl.texture(image)
}

Now, it would be pretty cool if regl.texture() could somehow gracefully handle a "load in progress" Image object, but it doesn't (probably for a good reason I can't think of), so I think the API doc on the website should be updated to reflect the existing behavior.

neiltron commented 6 years ago

This doesn't address the completeness of the docs, but checkout resl if you haven't already. https://github.com/regl-project/resl

Maybe a note about a loading strategy being required would help with confusion in the docs.

milcktoast commented 6 years ago

This might be a bug, according to the docs:

If an image element is specified and not yet loaded, then regl will upload a temporary image and hook a callback on the image