Thanks everyone for your useful replies.
Jukka Jylänki wrote:
> See here for a small example: https://github.com/juj/webgl_render_test
> , in particular this function that does the uploading:
> https://github.com/juj/webgl_render_test/blob/bb517e34dfaa13404feaa8a5ba8bf42c32581c44/src/library_js.js#L32
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.
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/emscripten-discuss/1613404449510%40dmwebmail.dmwebmail.chezphil.org.