Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to trigger a QQuickFramebufferObject repaint?

How to trigger a QQuickFramebufferObject repaint?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 114 Views 1 Watching
  • 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.
  • K Offline
    K Offline
    kaixoo
    wrote last edited by
    #1

    I am subclassing QQuickFramebufferObject and QQuickFramebufferObject::Renderer to embed an OpenGL canvas in my application. I am calling render() to queue a repaint, but that isn't working.
    Instead, the canvas is only being painted briefly when it is resized, and then goes back to white. Calling render() does nothing.

    Here is my QQuickFramebufferObject implementation:

    ApplicationCanvas::Renderer::Renderer(const ApplicationCanvas *app_canvas) : m_app_canvas(app_canvas) {
    	QObject::connect(m_app_canvas, &ApplicationCanvas::onDrawQueued, [=]() { render(); });
        // render() internally calls draw_to_screen()
    };
    
    void ApplicationCanvas::Renderer::draw_to_screen(SkCanvas* canvas) {
    	canvas->drawColor(SK_ColorBLACK); // does not work
            for (auto& viewlayer : m_viewlayer_list) {
                    viewlayer->draw_to_screen(canvas);
            };
    
    	// 'Flushing' is what actually renders this frame and shows it to screen
    	canvas->flush();
    };
    
    void ApplicationCanvas::keyPressEvent(QKeyEvent *event) {
            ...
    
    	emit onDrawQueued();
    };
    
    1 Reply Last reply
    0
    • GrecKoG Online
      GrecKoG Online
      GrecKo
      Qt Champions 2018
      wrote last edited by
      #5

      update() should be called on your QQuickFBO, not its renderer.

      Change all your emit onDrawQueued(); to just update();

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote last edited by
        #2

        Hi and welcome to devnet,

        Did you already took a look at the QQuickWidget - QQuickView Comparison Example ?

        It shows a usage example of this class.

        Hope it helps

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • K Offline
          K Offline
          kaixoo
          wrote last edited by kaixoo
          #3

          Thanks! I didn't know an example existed. I read how it works.

          Still, the example uses update() to trigger a repaint. I am using that too. And in my case it does not work and I don't know why.

          I am subclassing QQuickFramebufferObject::Renderer twice, I assume it has something to do with this?

          QQuickFramebufferObject::Renderer -> SkiaRenderer -> ApplicationCanvas::Renderer

          Full source code: https://gitlab.com/advanced-effects/Advanced-Effects/-/blob/implement-canvas-objects/src/projectscene/view/canvas/application_canvas.cpp?ref_type=heads

          Here is the full file:

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kaixoo
            wrote last edited by
            #4

            Here's a video demonstration of the issue: https://youtu.be/ojqcShBNmcI
            When it's WHITE, it's NOT rendering. When it's BLACK, it IS rendering.

            1 Reply Last reply
            0
            • GrecKoG Online
              GrecKoG Online
              GrecKo
              Qt Champions 2018
              wrote last edited by
              #5

              update() should be called on your QQuickFBO, not its renderer.

              Change all your emit onDrawQueued(); to just update();

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kaixoo
                wrote last edited by kaixoo
                #6

                I don't know why I though update() was a method of the FBO::Renderer. I changed it now, and I'm having the same issue.

                Image gets temporarily rendered when resizing the widget, and then goes back to blank.

                EDIT: Oh, actually, it was my own fault. Was calling canvas->flush() which deletes the canvas after drawing. :facepalm:

                1 Reply Last reply
                1
                • K kaixoo has marked this topic as solved

                • Login

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