Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Texture2D does not work on Android #2017

Open
lattice0 opened this issue Jul 15, 2022 · 1 comment
Open

[Bug] Texture2D does not work on Android #2017

lattice0 opened this issue Jul 15, 2022 · 1 comment

Comments

@lattice0
Copy link

I believe this is a bug because the exact same code won't work on Android but works in PC, with exception to the context/window creation. For that I'm using @MarijnS95 updates to both glutin/glium because they don't compile for Android

Here's a minimum verifiable example: https://github.com/lattice0/AndroidNativeSurface/tree/texture (branch is texture) and the same cargo project of the Android project (https://github.com/lattice0/AndroidNativeSurface/tree/texture/android_native_surface) can also be run with cargo run on desktop, where it will produce a pattern in the texture:
Screenshot from 2022-07-14 20-52-56
(error is because I did not start the event loop correctly but whatever)

Screenshot-20220714-213351

In summary, the following won't work:

            let texture =
                Texture2d::empty_with_format(&display, format, mipmap, width, height).unwrap();
            let mut data: Vec<Vec<u8>> = Vec::new();
            for i in 0..width {
                let mut v: Vec<u8> = Vec::new();
                for j in 0..height {
                    v.push((i * j % 255) as u8);
                }
                data.push(v);
            }

            texture.write(
                glium::Rect {
                    left: 0,
                    bottom: 0,
                    width,
                    height,
                },
                data,
            );

On Android you can uncomment FragColor to be red so you can see that at least the square is being renderer:

                void main() {
                    vec4 a = texture(tex, v_tex_coords);
                    FragColor = vec4(a.r,0.0,0.0,1.0);
                    //Uncomment to see that at least rendering the red square works
                    //FragColor = vec4(1.0,0.0,0.0,1.0);
                },
@faern
Copy link
Contributor

faern commented Mar 24, 2024

I wonder if this is the same issue I'm seeing when using glium with a GTK4 application? I have the same behavior: When I draw a glium texture in a winit window (like the glium examples) it works, but when I try to draw with the exact same code on a GTK GLArea then nothing at all shows up. No errors are printed, so it's as if the texture(...) function in the fragment shader just always returns black). I reported it to gtk4-rs but did not get a response yet: gtk-rs/gtk4-rs#1647

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

No branches or pull requests

2 participants