Thanks everyone for your useful replies.
Right, that's close to what I need. I have a couple of questions:
1. Can anyone suggest how I can add a callback from the Javascript
to the C++ when the texture is loaded? I can't see a simple JS
call to which I can pass a C function pointer. (Or something
using a std::function?)
2. Any ideas about how to cancel an in-progress load? Maybe
deleting the Image object will abandon any in-progress download?
Pseudo-code:
// fetch_texture.js
fetch_texture: function(url, texturenum, callback)
{
url = UTF8ToString*url);
const texture = GL.textures[texturenum];
const image = new Image();
image.onload = function() {
GLctx.bindTexture(GLctx.TEXTURE_2D, texture);
GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, GLctx.UNSIGNED_BYTE, image);
callback(); // <---- ???
};
image.src = url;
return handle_to_image; // <--- ???
}
cancel_fetch_texture: function(handle)
{
delete image_from_handle; // ????
}
// fetch_texture.hh
extern "C" {
handle_t fetch_texture(const char* url, int texturenum, void(*callback)());
void cancel_fetch_texture(handle_t handle);
};
Many thanks, Phil.