QUItCoding / qnanopainter

Library for implementing OpenGL accelerated Qt (Quick) C++ UI components.
http://quitcoding.com
Other
405 stars 79 forks source link

6.7 with "DEFINES += QNANO_USE_RHI" still links and includes OpenGL #76

Open NielsMayer opened 1 year ago

NielsMayer commented 1 year ago

For example when linking, it is linking with -lGLESv2 -lEGL and libQt6OpenGL_x86_64.so .

/opt/google/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-target x86_64-linux-android23 -fno-limit-debug-info
-Wl,-soname,libqnanopainter_vs_qpainter_demo_x86_64.so
-Wl,--build-id=sha1 -Wl,--no-undefined -Wl,-z,noexecstack -shared -o
libqnanopainter_vs_qpainter_demo_x86_64.so main.o demoqpitem.o
demoqnanoitem.o demoqnanoitempainter.o qnanopainter.o qnanocolor.o
qnanolineargradient.o qnanoimagepattern.o qnanoimage.o qnanofont.o
qnanoradialgradient.o qnanoboxgradient.o qnanowindow.o qnanodebug.o
qnanoquickitem.o qnanoquickitempainter.o qnanobackendrhi.o
nanovg_rhi.o nanovg.o qrc_qml.o qrc_libqnanopainterdata.o
moc_demoqpitem.o moc_demoqnanoitem.o moc_qnanowindow.o
moc_qnanoquickitem.o
/opt/QtCo/6.7.0/android_x86_64/lib/libQt6Quick_x86_64.so
/opt/QtCo/6.7.0/android_x86_64/lib/libQt6OpenGL_x86_64.so
/opt/QtCo/6.7.0/android_x86_64/lib/libQt6Gui_x86_64.so -lEGL
/opt/QtCo/6.7.0/android_x86_64/lib/libQt6QmlModels_x86_64.so
/opt/QtCo/6.7.0/android_x86_64/lib/libQt6Qml_x86_64.so
/opt/QtCo/6.7.0/android_x86_64/lib/libQt6Network_x86_64.so
/opt/QtCo/6.7.0/android_x86_64/lib/libQt6Core_x86_64.so -llog -pthread
-lGLESv2 -llog -lz -lm -ldl -lc

During compilation, it is including QtOpenGL and defining QNANO_QT_GL_INCLUDE and QNANO_ENABLE_GLES3.

/opt/google/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-c -target x86_64-linux-android23 -fno-limit-debug-info -fPIC
-fstack-protector-strong -DANDROID -O2 -std=gnu++1z -Wall -W -fPIC
-D_REENTRANT -DQNANO_QT_GL_INCLUDE -DQNANO_USE_RHI
-DQNANO_ENABLE_GLES3 -D_CRT_SECURE_NO_WARNINGS -DQT_NO_DEBUG
-DQT_QUICK_LIB -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_QMLMODELS_LIB
-DQT_QML_LIB -DQT_QMLINTEGRATION_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB
-I../../../qnanopainter/examples/qnanopainter_vs_qpainter_demo
-I. -I../../../qnanopainter/libqnanopainter
-I/opt/QtCo/6.7.0/android_x86_64/include
-I/opt/QtCo/6.7.0/android_x86_64/include/QtQuick
-I/opt/QtCo/6.7.0/android_x86_64/include/QtOpenGL
-I/opt/QtCo/6.7.0/android_x86_64/include/QtGui/6.7.0
-I/opt/QtCo/6.7.0/android_x86_64/include/QtGui/6.7.0/QtGui
-I/opt/QtCo/6.7.0/android_x86_64/include/QtGui
-I/opt/QtCo/6.7.0/android_x86_64/include/QtQmlModels
-I/opt/QtCo/6.7.0/android_x86_64/include/QtQml
-I/opt/QtCo/6.7.0/android_x86_64/include/QtQmlIntegration
-I/opt/QtCo/6.7.0/android_x86_64/include/QtNetwork
-I/opt/QtCo/6.7.0/android_x86_64/include/QtCore/6.7.0
-I/opt/QtCo/6.7.0/android_x86_64/include/QtCore/6.7.0/QtCore
-I/opt/QtCo/6.7.0/android_x86_64/include/QtCore
-I. -I/opt/QtCo/6.7.0/android_x86_64/mkspecs/android-clang -o
demoqnanoitem.o
../../../qnanopainter/examples/qnanopainter_vs_qpainter_demo/src/demoqnanoitem.cpp

Also, I'm seeing a windows-specific define -D_CRT_SECURE_NO_WARNINGS ( https://stackoverflow.com/questions/22450423/how-to-use-crt-secure-no-warnings ) for both Android and Linux compilation.

The full compilation output is here: qnanopainter-6.7-androidx86_64-compile.txt

NielsMayer commented 1 year ago

For Linux, during linkage, it links with -lGL and libQt6OpenGL.so :

g++ -Wl,-O1 -Wl,-rpath,/opt/QtCo/6.7.0/gcc_64/lib
-Wl,-rpath-link,/opt/QtCo/6.7.0/gcc_64/lib -o
qnanopainter_vs_qpainter_demo main.o demoqpitem.o demoqnanoitem.o
demoqnanoitempainter.o qnanopainter.o qnanocolor.o
qnanolineargradient.o qnanoimagepattern.o qnanoimage.o qnanofont.o
qnanoradialgradient.o qnanoboxgradient.o qnanowindow.o qnanodebug.o
qnanoquickitem.o qnanoquickitempainter.o qnanobackendrhi.o
nanovg_rhi.o nanovg.o main_qml.o qml_SettingsView_qml.o
qml_TabView_qml.o qml_DebugView_qml.o qml_FpsItem_qml.o
qml_Switch_qml.o qml_SliderSelector_qml.o qml_Button_qml.o
qml_shapeitem_CirclesComponent_qml.o qml_shapeitem_DemoShapeItem_qml.o
qml_shapeitem_BarsComponent_qml.o qml_shapeitem_RulerComponent_qml.o
qml_shapeitem_LinesComponent_qml.o qml_shapeitem_IconsComponent_qml.o
qml_shapeitem_FlowerComponent_qml.o qmlcache_loader.o
qrc_qml_qmlcache.o qrc_libqnanopainterdata.o moc_demoqpitem.o
moc_demoqnanoitem.o moc_qnanowindow.o moc_qnanoquickitem.o
/opt/QtCo/6.7.0/gcc_64/lib/libQt6Quick.so
/opt/QtCo/6.7.0/gcc_64/lib/libQt6OpenGL.so
/opt/QtCo/6.7.0/gcc_64/lib/libQt6Gui.so
/opt/QtCo/6.7.0/gcc_64/lib/libQt6QmlModels.so
/opt/QtCo/6.7.0/gcc_64/lib/libQt6Qml.so -pthread
/opt/QtCo/6.7.0/gcc_64/lib/libQt6Network.so
/opt/QtCo/6.7.0/gcc_64/lib/libQt6Core.so -lpthread -lxkbcommon -lGL

During compilation on Linux, -DQNANO_QT_GL_INCLUDE -DQNANO_ENABLE_GLES3 and -DQT_OPENGL_LIB are defined:

g++ -c -pipe -O2 -Wall -Wextra -fPIC -D_REENTRANT
-DQNANO_QT_GL_INCLUDE -DQNANO_USE_RHI -DQNANO_ENABLE_GLES3
-D_CRT_SECURE_NO_WARNINGS -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_OPENGL_LIB
-DQT_GUI_LIB -DQT_QMLMODELS_LIB -DQT_QML_LIB -DQT_QMLINTEGRATION_LIB
-DQT_NETWORK_LIB -DQT_CORE_LIB
-I../../../qnanopainter/examples/qnanopainter_vs_qpainter_demo
-I. -I../../../qnanopainter/libqnanopainter
-I/opt/QtCo/6.7.0/gcc_64/include
-I/opt/QtCo/6.7.0/gcc_64/include/QtQuick
-I/opt/QtCo/6.7.0/gcc_64/include/QtOpenGL
-I/opt/QtCo/6.7.0/gcc_64/include/QtGui/6.7.0
-I/opt/QtCo/6.7.0/gcc_64/include/QtGui/6.7.0/QtGui
-I/opt/QtCo/6.7.0/gcc_64/include/QtGui
-I/opt/QtCo/6.7.0/gcc_64/include/QtQmlModels
-I/opt/QtCo/6.7.0/gcc_64/include/QtQml
-I/opt/QtCo/6.7.0/gcc_64/include/QtQmlIntegration
-I/opt/QtCo/6.7.0/gcc_64/include/QtNetwork
-I/opt/QtCo/6.7.0/gcc_64/include/QtCore/6.7.0
-I/opt/QtCo/6.7.0/gcc_64/include/QtCore/6.7.0/QtCore
-I/opt/QtCo/6.7.0/gcc_64/include/QtCore
-I. -I/opt/QtCo/6.7.0/gcc_64/mkspecs/linux-g++ -o
demoqnanoitempainter.o
../../../qnanopainter/examples/qnanopainter_vs_qpainter_demo/src/demoqnanoitempainter.cpp

Also the windows-specific define -D_CRT_SECURE_NO_WARNINGS appears for Linux compilation.

Note that there are warnings in the code libqnanopainter/nanovg/stb_image.h

      1.42  (2014-07-09)
              don't define _CRT_SECURE_NO_WARNINGS (affects user code)
              fixes to stbi__cleanup_jpeg path
              added STBI_ASSERT to avoid requiring assert.h
NielsMayer commented 1 year ago

FYI, this is my current version of include.pri -- even attempting to remove some of the references to OpenGL doesn't actually cause Qt (via QMake, not cmake in above output) to omit OpenGL references:

$ diff -rc qnanopainter/libqnanopainter/include.pri ~/src/trainspodder/libqnanopainter6/include.pri
*** qnanopainter/libqnanopainter/include.pri    2023-10-10 22:36:31.931885845 -0700
--- /home/npm/src/trainspodder/libqnanopainter6/include.pri     2023-10-10 22:55:33.164436870 -0700
***************
*** 3,9 ****
INCLUDEPATH += $$PWD/

# Use c++11 features
! CONFIG += c++11

# Enable this to get the drawing debug information
# This is available in QNanoQuickItem data property.
--- 3,10 ----
INCLUDEPATH += $$PWD/

# Use c++11 features
! # NPM: is this needed anymore? why not use default which is C++17?
! # CONFIG += c++11

# Enable this to get the drawing debug information
# This is available in QNanoQuickItem data property.
***************
*** 13,26 ****
# This is rendered at the bottom of each item.
#DEFINES += QNANO_DEBUG_RENDER

- # Enable this to let Qt include OpenGL headers
- DEFINES += QNANO_QT_GL_INCLUDE
- 
# Enable this to use QRhi (available since Qt 6.7) instead of QQuickFramebufferObject
#DEFINES += QNANO_USE_RHI

! # This will enable GLES3 (disable to force GLES2)
! DEFINES += QNANO_ENABLE_GLES3

# This will enable signalling touch events
# Can be useful when using view/widget classes directly
--- 14,34 ----
# This is rendered at the bottom of each item.
#DEFINES += QNANO_DEBUG_RENDER

# Enable this to use QRhi (available since Qt 6.7) instead of QQuickFramebufferObject
#DEFINES += QNANO_USE_RHI

! contains(DEFINES, QNANO_USE_RHI) {
!     QT += gui-private                                   ##qRHI backend for qnanopainter requires access to ...include/QtGui/6.7.0/QtGui/rhior you get compile error "fatal error: QtGui/rhi/qrhi.h: No such file or directory"
! }
! else {
!     # Enable this to let Qt include OpenGL headers
!     DEFINES += QNANO_QT_GL_INCLUDE
!     # This will enable GLES3 (disable to force GLES2)
!     DEFINES += QNANO_ENABLE_GLES3
!     equals(QT_MAJOR_VERSION, 6) {                      ## Qt6.0-6.6 requires explicit use of OpenGL backend
!         QT += opengl
!     }
! }

# This will enable signalling touch events
# Can be useful when using view/widget classes directly
***************
*** 33,40 ****
# Enable this to use QRenderNode (available since Qt 5.8.0) instead of QQuickFramebufferObject
#DEFINES += QNANO_USE_RENDERNODE

! # Suppress fontstash warnings about fopen & strncpy usage
! DEFINES += _CRT_SECURE_NO_WARNINGS

SOURCES +=  \
$$PWD/qnanopainter.cpp \
--- 41,50 ----
# Enable this to use QRenderNode (available since Qt 5.8.0) instead of QQuickFramebufferObject
#DEFINES += QNANO_USE_RENDERNODE

! win32 {
!     # Suppress fontstash warnings about fopen & strncpy usage
!     DEFINES += _CRT_SECURE_NO_WARNINGS
! }

SOURCES +=  \
$$PWD/qnanopainter.cpp \
***************
*** 95,104 ****
$$PWD/nanovg/nanovg_rhi.h
}

- equals(QT_MAJOR_VERSION, 6) { ## for Qt6 need opengl module
-     QT += opengl              ## see https://doc-snapshots.qt.io/qt6-dev/qtopengl-index.html
- }                             ## NB: "Warning: This module should not be used anymore for new code. Please use the corresponding OpenGL classes in Qt GUI." ( https://doc-snapshots.qt.io/qt6-dev/qtgui-index.html#opengl-and-opengl-es-integration )
-
!contains(DEFINES, QNANO_USE_RHI) {

# Note: Due to Angle, windows might use either OpenGL (desktop) or
--- 105,110 ----
demiantres commented 11 months ago

After a quick glimpse at the project code you can see that the QNANO_USE_RHI flag makes sure that the library is compatible with the RHI but only when the RHI has "OpenGL" as backend. This is, because nanovg heavily relies on OpenGL. For backend-independent RHI support the library must use functions as described in this example: https://doc-snapshots.qt.io/qt6-6.6/qtquick-scenegraph-rhiunderqml-example.html (which requires a lot of porting work).

QUItCoding commented 11 months ago

@demiantres That is false information. QNanoPainter now supports OpenGL, Vulkan, Metal, Direct3D11 and Direct3D12 with the RHI backend (see https://github.com/QUItCoding/qnanopainter/blob/master/libqnanopainter/nanovg/nanovg_rhi.cpp ).

Steps: 1) Build Qt dev branch or use Qt 6.7 pre-release. 2) Enable QNANO_USE_RHI from CMakeList.txt (CMake) or include.pri (QMake). 3) Use QQuickWindow::setGraphicsApi or QSG_RHI_BACKEND to set the preferred RHI backend.

Here are screenshots with few different backends: qnanopainter_d3d12 qnanopainter_d3d11 qnanopainter_vulkan

I have only tested the RHI backend on Windows & Android and haven't tried to remove linking to OpenGL libs.

demiantres commented 11 months ago

Thanks for the clarification.