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() {