gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 549 forks source link

Create new texture from id? #2909

Open jkelleyrtp opened 5 years ago

jkelleyrtp commented 5 years ago

I'm trying to port some glium code to gfx because I suspect a bug but can't find a corresponding method.

In glium, it is possible to render an externally created texture (from the same context) with just its texture ID (a c_uint ):

https://docs.rs/glium/0.25.1/glium/texture/texture2d/struct.Texture2d.html#method.from_id

I don't have the best understanding of what's going on behind the scenes for gfx, but nothing really pops out at me on how to create a gfx_texture from my id. Any help?

kvark commented 5 years ago

There is no type called gfx_texture in our crates. Are you using Piston? If that's the case, you should be aware that pre-ll version of gfx-rs is now deprecated (see our blog for more background, e.g. https://gfx-rs.github.io/2019/06/12/anniversary-5.html). We recommend users to check wgpu-rs or rendy for the graphics options.

As to your original question, external GL textures aren't supported officially. The actual type is public: https://github.com/gfx-rs/gfx/blob/009243e52e57381dad46365b56ee024c36b5d9a2/src/backend/gl/src/lib.rs#L103 , so you can technically construct NewTexture::Texture(your_id) and then convince the handle manager to use it, but I would not recommend going there unless strictly necessary.

jkelleyrtp commented 5 years ago

Unfortunately I'm holed into having to support OpenGL (gstreamer for the texture source). I'm using Piston which works with glium, raw opengl, and the v0.17.1 of gfx and 0.8 of gfx_core. There's not a whole lot of room to move in the gui space.

If I moved from Conrod to ggez, I could bump up to

gfx = "0.18"
gfx_core = "0.9"
gfx_device_gl = "0.16"

Still though, I would need to create textures from an existing texture ID not created by the renderer itself. Would either of these versions change how easy it is to render the texture to window?

Instead of just grabbing the texture ID, I can actually return the buffer

https://docs.rs/gstreamer/0.14.3/gstreamer/buffer/struct.Buffer.html https://docs.rs/gstreamer/0.14.3/gstreamer/buffer/struct.BufferRef.html

but I'm worried that this will copy the data off the gpu, into system memory, and then back onto the gpu when I go to render. Can you peek at at buffer ref and see if there's a better way of rendering it from the buffer with the old gfx and maybe with wgpu-rs/rendy?

kvark commented 5 years ago

I'm using Piston which works with glium, raw opengl, and the v0.17.1 of gfx and 0.8 of gfx_core.

You can try going the path I described. IIRC there was a commercial client doing video rendering with gfx pre-ll, and they were passing through the GL textures, so there is a way to get this work... but it's not well polished.

Overall, why are you even porting from glium to gfx pre-ll? Neither is actively supported today.