From 30d3ffa66696628e03b1a28ccd8754da4eed5191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Kov=C3=A1cs?= Date: Sat, 20 Jan 2024 23:03:32 +0100 Subject: [PATCH] Fix OpenGL driver for Qt 6 --- .github/workflows/build.yml | 21 ++++++++++++--------- CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++-- src/engine/3d.cpp | 2 +- src/ui-hlp/autod.h | 2 +- src/ui-hlp/autopilot.cpp | 1 - src/ui-hlp/autopilot.h | 1 - src/ui-hlp/messg.cpp | 2 +- src/ui-hlp/play.cpp | 2 +- src/ui-hlp/play.h | 2 +- src/ui-hlp/playtext.cpp | 2 +- src/ui-hlp/render.cpp | 1 - src/ui-hlp/save.cpp | 2 +- src/ui-hlp/wstack.cpp | 2 +- src/ui/fractalwidget.cpp | 13 +++++++++---- src/ui/fractalwidget.h | 6 +++--- src/ui/image_qt.cpp | 2 +- src/ui/mainwindow.cpp | 2 +- src/ui/mainwindow.h | 2 +- 18 files changed, 67 insertions(+), 32 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d2bed463..158f6e2f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,10 +3,8 @@ name: build on: [push] jobs: - linux: - + linux-qmake: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v1 - name: prerequisites @@ -17,9 +15,7 @@ jobs: run: make linux-cmake-deepzoom: - runs-on: ubuntu-latest - steps: - uses: actions/checkout@v1 - name: prerequisites @@ -29,10 +25,19 @@ jobs: - name: make run: cd cbuild; make - mac: + linux-cmake-opengl: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: prerequisites + run: sudo apt update && sudo apt install build-essential qt6-base-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools linguist-qt6 libgl1-mesa-dev freeglut3-dev + - name: cmake + run: mkdir cbuild; cd cbuild; cmake -DOPENGL=ON .. + - name: make + run: cd cbuild; make + mac-qmake: runs-on: macos-latest - steps: - uses: actions/checkout@v1 - name: install-qt @@ -45,9 +50,7 @@ jobs: run: make mac-cmake: - runs-on: macos-latest - steps: - uses: actions/checkout@v1 - name: install-qt diff --git a/CMakeLists.txt b/CMakeLists.txt index 590bd525..c35c4363 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,18 @@ # -DDEEPZOOM=ON # # on the cmake command line. +# +# * Alternatively, it is possible to build XaoS with the OpenGL driver. For this, you may need +# additional libraries: +# +# - freeglut3-dev +# +# Add +# +# -DOPENGL=ON +# +# on the cmake command line to enable the driver. + ########################################################################### @@ -66,17 +78,25 @@ cmake_minimum_required(VERSION 3.14.0) project(XaoS) option(DEEPZOOM "Use 128-bit float for deep zoom" OFF) +option(OPENGL "Use OpenGL" OFF) + if(DEEPZOOM) add_definitions(-DUSE_FLOAT128) # may be unsupported on Mac, unless gcc/g++ is used else(DEEPZOOM) add_definitions(-DUSE_LONG_DOUBLE) endif(DEEPZOOM) +if(OPENGL) + add_definitions(-DUSE_OPENGL) +endif(OPENGL) + +# general definitions add_definitions(-DUSE_SFFE -DSFFE_CMPLX_GSL) # resolve symbolic links set(CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS TRUE) +# by default, build a release (a non-debug executable) if(NOT CMAKE_BUILD_TYPE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE Release) endif(NOT CMAKE_BUILD_TYPE) @@ -93,6 +113,13 @@ set(CMAKE_AUTORCC ON) find_package(QT NAMES Qt6 COMPONENTS Widgets PrintSupport REQUIRED) find_package(Qt6 COMPONENTS Widgets PrintSupport REQUIRED) +if(OPENGL) + find_package(QT NAMES Qt6 COMPONENTS OpenGL OpenGLWidgets REQUIRED) + find_package(Qt6 COMPONENTS OpenGL OpenGLWidgets REQUIRED) + find_package(GLUT REQUIRED) + find_package(OpenGL REQUIRED) +endif(OPENGL) + # OS specific stuff # on macOS the QT libraries are usually not installed into the system library folders if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") @@ -139,11 +166,14 @@ add_executable(XaoS MACOSX_BUNDLE XaoS.qrc ) -# Link +# link libraries target_link_libraries(XaoS Qt6::Widgets Qt6::PrintSupport) if(DEEPZOOM) -target_link_libraries(XaoS quadmath) + target_link_libraries(XaoS quadmath) endif(DEEPZOOM) +if(OPENGL) + target_link_libraries(XaoS Qt6::OpenGL Qt6::OpenGLWidgets) +endif(OPENGL) # install bundle install(TARGETS XaoS DESTINATION bin) diff --git a/src/engine/3d.cpp b/src/engine/3d.cpp index 7bcc35da..49a8155b 100644 --- a/src/engine/3d.cpp +++ b/src/engine/3d.cpp @@ -1,4 +1,4 @@ -#include "config.h" +#include "config.h" #include #include /*for NULL */ #include diff --git a/src/ui-hlp/autod.h b/src/ui-hlp/autod.h index 688c3d58..6ee28d2c 100644 --- a/src/ui-hlp/autod.h +++ b/src/ui-hlp/autod.h @@ -1,4 +1,4 @@ -#ifndef UNSUPPORTED +#ifndef UNSUPPORTED static inline int look1(uih_context *context, int x, int y, int range, int max) { cpixel_t *vbuff; diff --git a/src/ui-hlp/autopilot.cpp b/src/ui-hlp/autopilot.cpp index a2ae957d..6cc81f5d 100644 --- a/src/ui-hlp/autopilot.cpp +++ b/src/ui-hlp/autopilot.cpp @@ -1,4 +1,3 @@ - /* * XaoS, a fast portable realtime fractal zoomer * Copyright (C) 1996,1997 by diff --git a/src/ui-hlp/autopilot.h b/src/ui-hlp/autopilot.h index 8a17fddb..deb129ca 100644 --- a/src/ui-hlp/autopilot.h +++ b/src/ui-hlp/autopilot.h @@ -1,4 +1,3 @@ - /* * XaoS, a fast portable realtime fractal zoomer * Copyright (C) 1996,1997 by diff --git a/src/ui-hlp/messg.cpp b/src/ui-hlp/messg.cpp index 69e398bf..9d7e28da 100644 --- a/src/ui-hlp/messg.cpp +++ b/src/ui-hlp/messg.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "filter.h" #include "fractal.h" diff --git a/src/ui-hlp/play.cpp b/src/ui-hlp/play.cpp index 27f19bca..4a691bf9 100644 --- a/src/ui-hlp/play.cpp +++ b/src/ui-hlp/play.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include "config.h" diff --git a/src/ui-hlp/play.h b/src/ui-hlp/play.h index 70071422..19e85067 100644 --- a/src/ui-hlp/play.h +++ b/src/ui-hlp/play.h @@ -1,4 +1,4 @@ -#ifndef PLAY_H +#ifndef PLAY_H #define PLAY_H struct keyword { char *name; diff --git a/src/ui-hlp/playtext.cpp b/src/ui-hlp/playtext.cpp index cde2b497..2f96e361 100644 --- a/src/ui-hlp/playtext.cpp +++ b/src/ui-hlp/playtext.cpp @@ -1,4 +1,4 @@ -#include +#include #include "config.h" #include "filter.h" diff --git a/src/ui-hlp/render.cpp b/src/ui-hlp/render.cpp index 00815876..01a9fbd2 100644 --- a/src/ui-hlp/render.cpp +++ b/src/ui-hlp/render.cpp @@ -1,4 +1,3 @@ - #include #include #include diff --git a/src/ui-hlp/save.cpp b/src/ui-hlp/save.cpp index 53dbdd1a..6bbcdf99 100644 --- a/src/ui-hlp/save.cpp +++ b/src/ui-hlp/save.cpp @@ -1,4 +1,4 @@ -#define __USE_MINGW_ANSI_STDIO 1 // for long double support on Windows +#define __USE_MINGW_ANSI_STDIO 1 // for long double support on Windows #include #include #include diff --git a/src/ui-hlp/wstack.cpp b/src/ui-hlp/wstack.cpp index 71742927..4e65a5a2 100644 --- a/src/ui-hlp/wstack.cpp +++ b/src/ui-hlp/wstack.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/ui/fractalwidget.cpp b/src/ui/fractalwidget.cpp index c367f6a6..df4f9e59 100644 --- a/src/ui/fractalwidget.cpp +++ b/src/ui/fractalwidget.cpp @@ -1,4 +1,4 @@ -#include "fractalwidget.h" +#include "fractalwidget.h" #include #ifdef USE_OPENGL @@ -28,9 +28,14 @@ void FractalWidget::paintGL() if (m_image) { QImage *qimage = reinterpret_cast(m_image->data)[m_image->currimage]; - QImage glimage = QGLWidget::convertToGLFormat(*qimage); - glDrawPixels(glimage.width(), glimage.height(), GL_RGBA, - GL_UNSIGNED_BYTE, glimage.bits()); + // QImage glimage = QGLWidget::convertToOpenGLFormat(*qimage); + // glDrawPixels(glimage.width(), glimage.height(), GL_RGBA, + // GL_UNSIGNED_BYTE, glimage.bits()); + // For some reason, Qt 6 requires mirroring the image and using another color space. + // The old convertToOpenGLFormat is no longer supported in Qt 6. + QImage mirrored = qimage->mirrored(false, true); + glDrawPixels(qimage->width(), qimage->height(), GL_BGRA_EXT, + GL_UNSIGNED_BYTE, mirrored.bits()); } } diff --git a/src/ui/fractalwidget.h b/src/ui/fractalwidget.h index 26eaab42..90ae2ff8 100644 --- a/src/ui/fractalwidget.h +++ b/src/ui/fractalwidget.h @@ -1,16 +1,16 @@ -#ifndef FRACTALWIDGET_H +#ifndef FRACTALWIDGET_H #define FRACTALWIDGET_H #include "config.h" #include #ifdef USE_OPENGL -#include +#include #endif class QImage; class QPoint; #ifdef USE_OPENGL -class FractalWidget : public QGLWidget +class FractalWidget : public QOpenGLWidget #else class FractalWidget : public QWidget #endif diff --git a/src/ui/image_qt.cpp b/src/ui/image_qt.cpp index dce32620..725a5ec2 100644 --- a/src/ui/image_qt.cpp +++ b/src/ui/image_qt.cpp @@ -1,4 +1,4 @@ -#include +#include #include "config.h" #include "filter.h" #include "grlib.h" diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 73882ed6..3e214b23 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 3215e07d..54cc3d4f 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -1,4 +1,4 @@ -#ifndef MAINWINDOW_H +#ifndef MAINWINDOW_H #define MAINWINDOW_H #include