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

opengl: force using OpenGLES instead of OpenGL #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ahayzen-kdab
Copy link
Collaborator

No description provided.

cpp/helpers.cpp Outdated Show resolved Hide resolved
@@ -42,4 +42,4 @@ cxx-qt-lib-headers = { git = "https://github.com/kdab/cxx-qt.git", branch = "mai
qt-build-utils = { git = "https://github.com/kdab/cxx-qt.git", branch = "main" }

# We need a patched surfman to avoid OpenGL errors
surfman = { git = "https://github.com/ahayzen-kdab/surfman.git", branch = "patched-opengl-assert-0-9-1" }
surfman = { git = "https://github.com/ahayzen-kdab/surfman.git", branch = "patched-opengl-assert-and-gles-0-9-1" }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only need the surfman side of this, Qt picks GLES correctly when available.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the embedded world branch has this change and worked well :-) https://github.com/KDABLabs/cxx-qt-servo-webview/tree/demo-embedded-world

0c76d94

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep :)
So we can close this PR, as forcing GLES on desktop is probably not wanted?

Otherwise it would be best to make upstream aware of this problem (or more likely fix it directly ourself).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we create an issue on this repo for now? We had to hardcode surfman having it detect or have an option somewhere to pick GLES over GL on Linux is what we would need.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So looking at the patch, I actually don't think it would need much to fix this upstream.

I suppose instead of hardcoding a return value, instead look at the underlying EGL connection (for Wayland at least) and return the OpenGL version from there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right it somehow needs to determine from the connection or however Qt is doing it ? And potentially on X11 too ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right it somehow needs to determine from the connection

Yes, but that's pretty straight forward with EGL, there is eglQueryContext with the attribute EGL_CONTEXT_CLIENT_TYPE, which can return one of:

  • EGL_OPENGL_API
  • EGL_OPENGL_ES_API
  • EGL_OPENVG_API

I suppose the following patch should work (for Wayland platform):

diff --git a/surfman/src/platform/unix/wayland/connection.rs b/surfman/src/platform/unix/wayland/connection.rs
index 5fdcbbf..6161de6 100644
--- a/surfman/src/platform/unix/wayland/connection.rs
+++ b/surfman/src/platform/unix/wayland/connection.rs
@@ -63,7 +63,27 @@ impl Connection {
     /// Returns the OpenGL API flavor that this connection supports (OpenGL or OpenGL ES).
     #[inline]
     pub fn gl_api(&self) -> GLApi {
-        GLApi::GL
+        unsafe {
+            EGL_FUNCTIONS.with(|egl| {
+                let display = egl.GetCurrentDisplay();
+                let context = egl.GetCurrentContext();
+                if context != egl::NO_CONTEXT {
+                    let mut client_type: i32 = 0;
+                    egl.QueryContext(
+                        display,
+                        context,
+                        egl::CONTEXT_CLIENT_TYPE as i32,
+                        &mut client_type,
+                    );
+                    match client_type as u32 {
+                        egl::OPENGL_ES_API => GLApi::GLES,
+                        _ => GLApi::GL,
+                    }
+                } else {
+                    GLApi::GL
+                }
+            })
+        }
     }
 
     /// Returns the "best" adapter on this system, preferring high-performance hardware adapters.

I can't test it right now unfortunately, as the Pi is not online anymore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice! Maybe ask @LeonMatthesKDAB when he is around to leave the device on for a day, as then we could submit this upstream :-)

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