Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget::createWindowContainer not updating it's content when presenting vulkan swapchain
Forum Updated to NodeBB v4.3 + New Features

QWidget::createWindowContainer not updating it's content when presenting vulkan swapchain

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 371 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sitrep007
    wrote on last edited by
    #1

    I am creating a QWidget from a custom subclass of QWindow whose surface is set to VulkanSurface, by using QWidget::createWindowContainer(myWindow) function as shown in the code. I use my own vulkan swapchain to render and present to the window. And I use winId() function to get HWND to create a Win32 swapchain, bypassing all Qt Vulkan functions.

    The problem: the window renders and presents perfectly when QWidget::createWindowContainer() is not used and it is shown as a regular window. But if I use the createWindowContainer function and embed the returning widget in a layout of a current widget, it doesn't show the rendered output.

    Header File:
    class ViewportView : public QWidget
        {
            Q_OBJECT
        public:
            explicit ViewportView(QWidget* parent = nullptr);
            ~ViewportView();
    
        protected:
            virtual void showEvent(QShowEvent* event) override;
            virtual void hideEvent(QHideEvent* event) override;
    
        private slots:
            void OnRenderLoop();
    
        private:
            Ui::ViewportView* ui;
    
            QTimer* renderLoopTimer = nullptr;
            bool stopRenderLoop = false;
    
            RHIViewport* viewportRHI = nullptr; // Just a Vulkan object that holds swapchain resources, etc
            RHIGraphicsCommandList* cmdList = nullptr; // A vulkan object that holds command buffers, etc
            //
            ViewportWindow* renderViewport = nullptr; // A subclass of QWindow that setSurfaceType(QSurface::VulkanSurface) in its constructor and nothing else
            QWidget* renderViewportWidget = nullptr;
        };
    
    C++ File:
    ViewportView::ViewportView(QWidget* parent)
            : EditorViewBase(parent)
            , ui(new Ui::ViewportView)
        {
            ui->setupUi(this);
    
            setWindowTitle("Viewport");
    
            renderViewport = new ViewportWindow;
            // If below 2 lines are removed, the window renders and presents properly as an external window
            // However, if it is embedded using the 2 below lines, then it does not update.
            renderViewportWidget = QWidget::createWindowContainer(renderViewport);
            layout()->addWidget(renderViewportWidget);
        }
    
        ViewportView::~ViewportView()
        {
            delete renderViewport;
            delete ui;
        }
    
        void ViewportView::showEvent(QShowEvent* event)
        {
            Super::showEvent(event);
    
            // ... Create viewportRHI object and set clear color to blue
            //a Vulkan Swapchain is created from Win32 Surface obtained by using HWND from winId() of: ViewportWindow* renderViewport; which is just a  QWindow subclass with vulkan surfaceType
    
            renderViewport->show();
    
            // create command list
            cmdList = gDynamicRHI->CreateGraphicsCommandList(viewportRHI);
    
            QTimer::singleShot(2000, this, &ViewportView::OnRenderLoop);
        }
    
        void ViewportView::hideEvent(QHideEvent* event)
        {
            Super::hideEvent(event);
    
            renderViewport->hide();
    
            gDynamicRHI->DestroyCommandList(cmdList);
            cmdList = nullptr;
    
            gDynamicRHI->DestroyViewport(viewportRHI);
            viewportRHI = nullptr;
        }
    
        void ViewportView::OnRenderLoop()
        {
            CE_LOG(Info, All, "Render Loop");
    
            cmdList->Begin();
    
            cmdList->End();
    
            gDynamicRHI->ExecuteCommandList(cmdList); // execute render commands 
            gDynamicRHI->PresentViewport(cmdList); // present the swapchain image to the window
    
            // Do nothing else for now. Just render 1 frame, no loops
        }
    

    Screenshot when QWidget::createWindowContainer is NOT used:
    alt text

    Screenshot when QWidget::createWindowContainer is USED and the window is embedded as a widget in the layout.
    alt text

    As you can see in the first image, the blue clear color is being rendered and presented perfectly, but in the 2nd image, nothing happens at all - white is the default color.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved