ggez / good-web-game

An alternative ggez implementation on top of miniquad.
MIT License
334 stars 30 forks source link

to_rgba8 support #63

Open ccie18473 opened 2 years ago

ccie18473 commented 2 years ago

I found that "pub fn to_rgba8(&self, ctx: &mut Context) -> GameResult<Vec>" is not implemented in gwg. Do we have any other method to do the same ? If not, what steps do we need to implement it in gwg ?

I'm looking to the source code at:

https://github.com/ggez/ggez/blob/master/src/graphics/image.rs

And I'm thinking that maybe this is too much for me :)

Thanks.

PSteinhaus commented 2 years ago

Hmm, good question. We'd probably need to look into miniquads Texture type and how it can be serialized.

From what I can see our only option would be to use gl_internal_id to get the raw OpenGL-handle which we could then probably use to copy the texture GPU-buffer into a CPU-one that we specify, similar to how it works in ggez.

That would require to use some raw OpenGL-calls, accessible through the gl-context that is provided through the miniquad-context which is part of the gwg-context. But, I am not that used to working with OpenGL directly, so I don't spontaneously know what the necessary steps / functions would be exactly and I'm currently sadly a bit busy, so it's not very likely that I'll look into it soon, but I'll try to do so once things get better (which will probably take a couple of weeks sadly). That and working out the asset-cache-thing so that we can finally upgrade to newer miniquad versions...

ccie18473 commented 2 years ago

No issues, I managed to do the same with the image crate. Something like: image = include_bytes!("../resources/image.png"); rgba = image::load_from_memory(image).unwrap().to_rgba().into_raw(); Thanks !