Skip to content

Commit

Permalink
opengl: force using OpenGLES instead of OpenGL
Browse files Browse the repository at this point in the history
  • Loading branch information
ahayzen-kdab committed Mar 18, 2024
1 parent a337a95 commit 6fb633d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions cpp/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QOpenGLFramebufferObject>
#include <QOpenGLContext>
#include <QOpenGLFunctions>
#include <QSurfaceFormat>

void
blitFramebuffer(QOpenGLFramebufferObject* target, ::std::unique_ptr<QOpenGLFramebufferObject> source)
Expand Down Expand Up @@ -41,3 +42,11 @@ qTouchEventPoint(QTouchEvent& event, ::rust::isize index)
{
return (event.point(static_cast<qsizetype>(index)));
}

void forceSurfaceFormat()
{
QSurfaceFormat fmt;
fmt.setVersion(3, 0);
fmt.setRenderableType(QSurfaceFormat::OpenGLES);
QSurfaceFormat::setDefaultFormat(fmt);
}
2 changes: 2 additions & 0 deletions cpp/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ QEventPoint const&
qTouchEventPoint(QTouchEvent& event, ::rust::isize index);

using QMouseEventButton = Qt::MouseButton;

void forceSurfaceFormat();
14 changes: 14 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 6fb633d

Please sign in to comment.