-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render to QtQuickWindowSurface #48
Comments
Hi Luke,
Interesting! Render via a bitmapA good first step would be to render via an image, this can probably be done similar to how we do it with the QRenderWidget: rendercanvas/rendercanvas/qt.py Lines 305 to 318 in 9fc9627
and rendercanvas/rendercanvas/qt.py Lines 336 to 367 in 9fc9627
Not sure if this is what you meant with "render this via a QImage on a paintEvent in QQuickPaintedItem ". Render to screenAs for rendering directly to the window ... my knowledge of QtQuick / QRhi etc is near zero. I'll just share some ideas and questions.
From what I can see you can set the graphicsApi to e.g. Metal / 3D12 / Vulkan, but I don't think that will help because wgpu hides the backend (metal/vulkan) and does not support sharing native handles (yet). In other words, even if you get context information, like a Vulkan surface, that won't help, because wgpu has its own opaque surface object. Under the hood that will be a Vulkan surface, but there's no way for us to pass that Vulkan surface into wgpu. So my impression is that the best way to render directly to the window would be basically the same as we do for the I wonder what happens when you set the graphics api to Can you not simply embed a |
Thank you for your detailed reply. Yes it was as you suggested for the first example. It does work, although the copy of the buffer in _rc_present_bitmap is undesirable as acknowledged, whichever approach you take at this stage. QRenderClass (as derived from QWidget) cannot sadly be incorporated in the QtQuick Scenegraph in Qt6 (at one point I think there was a proxy widget in earlier releases of Qt5). Researching a bit more into what you said, there are no direct access to the texture or buffers in the context created by the webgpu-core. I believe the lack of an inter-op API for sharing the texture or buffers is not currently possible, as you previously referred to (gfx-rs/wgpu#4067) which would accomplish the following: https://doc.qt.io/qtforpython-6 For future reference, QtQuick can use a QRhi renderTarget if there is an externally managed texture (Vulkan, Metal, DirectX), but I do not think that we can get the pointer for this resource at the moment. |
And I don't suppose we can get the window-id for the region that you want to draw to? |
In QtQuick (v6.8) the window handle is provided, and there are ways to get (or set) the render surface/texture target handle, if the graphics backend is fixed or known from the operating environment. |
If this returns the same as |
The QQuickWindow (https://doc.qt.io/qt-6/qquickwindow.html) is a good potential bet (even now or in the long-term). This provides access to window events if needed additionally. Long-term, once there is access to the native backend context, texture creation then this can be used directly (example for DirectX is provided on the page. The native QWindow can be accessed via its inherent parent method, that provides access to winId via QWindow class. |
Firstly I wish to share a big thank you for your really great contribution and work across PyGFX. For the first time, I have come across a viable alternative 3D UI framework for general programming and also specifically for use with Python. Generally, there are really are no alternatives except three.js (Three React Fiber), which are inadequate for both scientific and desktop programming. Additionally, it would be nice in future if there was a community section on your website to share examples usage.
Specifically on the topic:
I am working on integrating pygfx into a qml/qtquick environment. Initial tests are quite promising.
The reason behind is QtQuick3D is clunky, difficult to customise (especially for scientific applications) and shares the similar issues with Qt3D, which I previoulsy used in the past. Also its license is undesirable.
I would like to directly use the native render surface that can be drawn asynchronously with a QtQuick environment compared to a QtWidget backend.
https://doc.qt.io/qtforpython-6/PySide6/QtQuick/QQuickWindow.html#PySide6.QtQuick.QQuickWindow.graphicsApi
I have found it is possible to render this via a QImage on a paintEvent in QQuickPaintedItem but appears slow and is both CPU/GPU heavy during dynamic call canges. I was wondering whether via QRhi from PySide6, it is possible to obtain the render context and directly draw within the QtQuickAppliction window like below:
https://doc.qt.io/qtforpython-6/examples/example_quick_scenegraph_openglunderqml.html
and a follow-on QRhi example:
https://doc.qt.io/qtforpython-6/examples/example_gui_rhiwindow.html
Thank you once again,
Luke
The text was updated successfully, but these errors were encountered: