From a337a9532a6a178def71a8fb63a3e22ae8614d7e Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Mon, 18 Mar 2024 18:51:54 +0000 Subject: [PATCH 1/2] build: ensure that changes to helpers.cpp is picked up --- build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build.rs b/build.rs index c6b286b..1806978 100644 --- a/build.rs +++ b/build.rs @@ -24,6 +24,7 @@ fn main() { .cc_builder(|cc| { cc.include("cpp"); cc.file("cpp/helpers.cpp"); + println!("cargo:rerun-if-changed=cpp/helpers.cpp"); }) .file("src/renderer.rs") .qobject_header("cpp/helpers.h") From 6fb633db5f70c835297c98f37ce607f02f4aa1ae Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Mon, 18 Mar 2024 18:16:24 +0000 Subject: [PATCH 2/2] opengl: force using OpenGLES instead of OpenGL --- Cargo.lock | 2 +- Cargo.toml | 2 +- build.rs | 2 +- cpp/helpers.cpp | 9 +++++++++ cpp/helpers.h | 2 ++ src/main.rs | 14 ++++++++++++++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e68c82..e96907a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4625,7 +4625,7 @@ dependencies = [ [[package]] name = "surfman" version = "0.9.1" -source = "git+https://github.com/ahayzen-kdab/surfman.git?branch=patched-opengl-assert-0-9-1#1fab87d6da89363088dcbda5ea069c2a84915e67" +source = "git+https://github.com/ahayzen-kdab/surfman.git?branch=patched-opengl-assert-and-gles-0-9-1#47ceeda56e4b407adb1346911bd80b52ae871478" dependencies = [ "bitflags 1.3.2", "cfg_aliases", diff --git a/Cargo.toml b/Cargo.toml index f9f036c..ae4c9c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/build.rs b/build.rs index 1806978..237837c 100644 --- a/build.rs +++ b/build.rs @@ -12,7 +12,7 @@ fn main() { .qt_module("OpenGL") .qml_module(QmlModule { uri: "com.kdab.servo", - rust_files: &["src/webview.rs"], + rust_files: &["src/webview.rs", "src/main.rs"], qml_files: &["qml/main.qml", "qml/ServoToolbar.qml"], qrc_files: &[ "images/arrow-back.png", diff --git a/cpp/helpers.cpp b/cpp/helpers.cpp index 2e52a52..fb915d2 100644 --- a/cpp/helpers.cpp +++ b/cpp/helpers.cpp @@ -10,6 +10,7 @@ #include #include #include +#include void blitFramebuffer(QOpenGLFramebufferObject* target, ::std::unique_ptr source) @@ -41,3 +42,11 @@ qTouchEventPoint(QTouchEvent& event, ::rust::isize index) { return (event.point(static_cast(index))); } + +void forceSurfaceFormat() +{ + QSurfaceFormat fmt; + fmt.setVersion(3, 0); + fmt.setRenderableType(QSurfaceFormat::OpenGLES); + QSurfaceFormat::setDefaultFormat(fmt); +} diff --git a/cpp/helpers.h b/cpp/helpers.h index 8b83c11..0354710 100644 --- a/cpp/helpers.h +++ b/cpp/helpers.h @@ -47,3 +47,5 @@ QEventPoint const& qTouchEventPoint(QTouchEvent& event, ::rust::isize index); using QMouseEventButton = Qt::MouseButton; + +void forceSurfaceFormat(); diff --git a/src/main.rs b/src/main.rs index 832ca7b..4371c9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,11 +13,25 @@ mod servothread; mod webview; mod windowheadless; +#[cxx::bridge] +mod ffi { + unsafe extern "C++" { + include!("helpers.h"); + + #[cxx_name = "forceSurfaceFormat"] + fn force_surface_format(); + } +} + fn main() { // We need the OpenGL backend for QQuickFramebufferObject std::env::set_var("QSG_RHI_BACKEND", "opengl"); let mut app = QGuiApplication::new(); + + // Force that we want OpenGLES + ffi::force_surface_format(); + let mut engine = QQmlApplicationEngine::new(); if let Some(engine) = engine.as_mut() {