Skip to content

Add the ability to handle external textures#363

Merged
grovesNL merged 4 commits into
grovesNL:mainfrom
AdrianEddy:main
May 21, 2026
Merged

Add the ability to handle external textures#363
grovesNL merged 4 commits into
grovesNL:mainfrom
AdrianEddy:main

Conversation

@AdrianEddy

Copy link
Copy Markdown
Contributor

This PR adds two methods on the webgl Context so external code can hand glow a WebGlTexture it does not own, and read
back the underlying handle from a glow Texture key.

On the webgl cfg, glow::Texture is a WebTextureKey (an opaque slotmap key) and the only way to create one today is create_texture, which allocates a fresh WebGlTexture via gl.createTexture().
There is no path for callers that already hold a web_sys::WebGlTexture (produced outside glow) to use it through glow.
There is also no public way to recover the web_sys::WebGlTexture from a glow::Texture key.

This blocks zero-copy texture import/export on top of glow on the web target.
In particular, wgpu_hal::gles::Device::texture_from_raw is not possible for webgl because of that missing API in glow.

Caller retains ownership of the underlying WebGlTexture. glow's slotmap entry is bookkeeping only for the key's lifetime. Passing the key to delete_texture releases the slot but does not touch the JS handle.

@grovesNL

grovesNL commented May 13, 2026

Copy link
Copy Markdown
Owner

Is this going to be problematic when calling any texture-related functions and passing the external texture we create here? I think we'd try to look up the key in the slotmap and fail.

@AdrianEddy

AdrianEddy commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

but it does insert into the slot map.

The only functional difference for external textures is that it doesn't call delete_texture on them. Otherwise - they look exactly like normal textures to the rest of the engine

@grovesNL

Copy link
Copy Markdown
Owner

Oh sorry - I completely missed the self.textures.borrow_mut().insert(handle);

Comment thread src/web_sys.rs Outdated
Comment thread src/web_sys.rs Outdated
@grovesNL
grovesNL merged commit de41829 into grovesNL:main May 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants