Would you like to provide integration to QT6 (QWindow)? Thanks!
Hi, @zhangfq-chemistry
Sorry for the late reply (I was too busy and had sorrily forgotten this issue).
We already have an ImGUI display here. If you just want to interactively view the rendering, it might be useful.
If you prefer integration with an existing Qt app, it can be done by implementing a custom widget and presenting LuisaCompute images to its window surface, as demonstrated here.
Another choice is to combine the existing ImGUI display with a Qt widget, but this might require some modifications to the LuisaCompute code as it's using GLFW for window management by default.
Thanks a lot! Is there one way to subclass directly from QWindow instead of QWidget ? The QWidget encapsulates a lots and runs very slowly. In addition, I cannot find exe of test_swapchain_qt.cpp after compiling.
Thanks a lot! Is there one way to subclass directly from QWindow instead of QWidget ? The QWidget encapsulates a lots and runs very slowly. In addition, I cannot find exe of test_swapchain_qt.cpp after compiling.
I guess it would work with QWindow but I need to check it for sure.
Did you see other test_*.exe? It might be because LuisaRender disables tests, or CMake failed to find the Qt package.
There are a lot of test_*.exe including test_swapchain_static and test_swapchain_static. And I cannot find test_swapchain_qt. Would you like to add it to tests? Thanks!
There are a lot of test_*.exe including test_swapchain_static and test_swapchain_static. And I cannot find test_swapchain_qt. Would you like to add it to tests? Thanks!
test_swapchain_qt is turned on by default in the tests. If it's not compiled, then CMake might have failed to find the Qt libraries. Would you please post the CMake configuration log?
home/zhangfq/engine/LuisaRender/src/compute/src/gui/../ext/imgui/imgui_internal.h:112:2: error: Please '#define IMGUI_DEFINE_MATH_OPERATORS' BEFORE including imgui.h! #error Please '#define IMGUI_DEFINE_MATH_OPERATORS' BEFORE including imgui.h! ^ 1 error generated.
I have just added this macro definition in LuisaCompute. Please
git pull && git submodule update --recursive
and compile the project again.
imgui ok! How to build tests/test_swapchain_qt.cpp? I cannot find any information about qt with cmake-gui.
Hi, @zhangfq-chemistry
Qt is automatically detected by CMake's find_package and test_swapchain_qt will be built if Qt is found:
https://github.com/LuisaGroup/LuisaCompute/blob/adbd67effe5b3ede6c97efa40b65ad92f6194dc6/src/tests/CMakeLists.txt#L182-L196
Did you see any configuration warnings related to Qt?
OK now! I want to use LuisaRender to replace QVulkanWindow/QVulkanWindowRenderer. Would you like to provide some examples including instancing(a lot of atoms/spheres, bonds/cylinders, lines), mouse-picking? In addition, the class Canvas : public QWidget, in which QWidget is inefficient than QWindow. I tried but failed. Please build one for me. Thanks a lot!
Hi, you can use the following code to create a QWindow, bind a swap chain to it, and embed it into another widget:
QWindow canvas;
auto swapchain = device.create_swapchain(
stream,
SwapchainOption{
.display = 0u,
.window = static_cast<uint64_t>(canvas.winId()),
.size = make_uint2(width, height),
.wants_hdr = false,
.wants_vsync = false,
.back_buffer_count = 2,
});
auto canvas_widget = QWidget::createWindowContainer(&canvas);
// Now you can embed canvas_widget into other Qt widgets
Would you like to provide some examples including instancing(a lot of atoms/spheres, bonds/cylinders, lines), mouse-picking?
Currently, we support rendering triangle meshes, curves, and procedural geometry with AABB. You'll be able to find out how to render them in the linked examples.
We currently don't have a built-in tool for mouse picking. You might need to render an object ID map and download the chosen pixel to find which object is picked.
Feel free to ask me anything if you still have questions.
I have updated the Qt integration example to show how to directly interact with a QWindow: https://github.com/LuisaGroup/LuisaCompute/blob/next/src/tests/test_swapchain_qt.cpp
Dear Sir, please help me to build following codes:
int main(int argc, char *argv[]) {
Context context{argv[0]};
if (argc <= 1) {
LUISA_INFO("Usage: {} <backend>. <backend>: cuda, dx, cpu, metal", argv[0]);
exit(1);
}
Device device = context.create_device(argv[1]);
static constexpr auto width = 1280u;
static constexpr auto height = 720u;
static constexpr auto resolution = make_uint2(width, height);
auto draw = device.compile<2>([](ImageFloat image, Float time) noexcept {
auto p = dispatch_id().xy();
auto uv = make_float2(p) / make_float2(resolution) * 2.0f - 1.0f;
auto color = def(make_float4());
Constant<float> scales{pi, luisa::exp(1.f), luisa::sqrt(2.f)};
for (auto i = 0u; i < 3u; i++) {
color[i] = cos(time * scales[i] + uv.y * 11.f +
sin(-time * scales[2u - i] + uv.x * 7.f) * 4.f) *
.5f +
.5f;
}
color[3] = 1.0f;
image.write(p, color);
});
Stream stream = device.create_stream(StreamTag::GRAPHICS);
auto image = device.create_image<float>(PixelStorage::BYTE4, resolution);
QApplication app{argc, argv};
QMainWindow window;
window.setFixedSize(width, height);
window.setWindowTitle("Display");
window.setAutoFillBackground(true);
QWidget overlay{&window};
overlay.setFixedSize(window.contentsRect().size() / 2);
overlay.move(window.contentsRect().center() - overlay.rect().center());
overlay.setAutoFillBackground(true);
QPushButton button{"Quit", &overlay};
button.move(overlay.contentsRect().center() - button.rect().center());
QObject::connect(&button, &QPushButton::clicked, [&] {
window.setVisible(false);
});
QWindow _canvas;
auto swapchain = device.create_swapchain(
stream,
SwapchainOption{
.display = 0u,
.window = static_cast<uint64_t>(_canvas.winId()),
.size = make_uint2(width, height),
.wants_hdr = false,
.wants_vsync = false,
.back_buffer_count = 2,
});
auto Canvas = QWidget::createWindowContainer(&_canvas);
window.show();
Clock clk;
Framerate framerate;
while (window.isVisible()) {
QApplication::processEvents();
auto time = static_cast<float>(clk.toc() * 1e-3);
stream << draw(image, time).dispatch(resolution)
<< swapchain.present(image);
framerate.record();
auto title = luisa::format("Display - {:.2f} fps", framerate.report());
window.setWindowTitle(title.c_str());
}
stream << synchronize();
QApplication::quit();
}
I see two problems in your code:
-
After
auto Canvas = QWidget::createWindowContainer(&_canvas);you need to add it to a parent widget. Or, you can specify its parent upon creation:auto Canvas = QWidget::createWindowContainer(&_canvas, &window); -
You need to tell
overlayto use a native window, otherwise it might not be drawn above_canvas:QWidget overlay{&window}; overlay.setAttribute(Qt::WA_NativeWindow);// Note: this is required for overlay to be displayed above the canvas