Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-108505

QOpenGLPaintDevice/QPainter doesn't paint in webassembly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • 6.4.1
    • 6.4.0
    • GUI: OpenGL, GUI: Painting
    • None
    • Kubuntu 22.04
      Firefox 107.0
      Chrome 107.0.5304.110
    • WebAssembly

    Description

      QPainter on a QOpenGLPaintDevice doesn't paint when compiling to webassembly.

      I've based the following minimal example on the hellogles3 demo (should work, when copy pasting over the main.cpp):

      #include <memory>
      #include <QGuiApplication>
      #include <QSurfaceFormat>
      #include <QOpenGLContext>
      #include <QOpenGLWindow>
      #include <QOpenGLPaintDevice>
      #include <QPainter>
      
      class GLWindow : public QOpenGLWindow
      {
          std::unique_ptr<QOpenGLPaintDevice> m_gl_paint_device;
      public:
          void initializeGL() { m_gl_paint_device = std::make_unique<QOpenGLPaintDevice>(); }
          void resizeGL(int w, int h) { m_gl_paint_device->setSize({ w, h }); }
          void paintGL() {
              QPainter painter(m_gl_paint_device.get());
              // QPainter painter(this);  // also does not work and gives the same java script console errors
              painter.setBrush(QBrush(QColor(0xFF0088)));
              painter.drawRect(5, 8, 120, 120);
          }
      };
      
      int main(int argc, char *argv[]) {
          QGuiApplication app(argc, argv);
          QSurfaceFormat fmt;
          fmt.setDepthBufferSize(24);
      
          bool webassembly = false;
          if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
              fmt.setVersion(3, 3);
              fmt.setProfile(QSurfaceFormat::CoreProfile);
          } else {
              fmt.setVersion(3, 0);
              webassembly = true;
          }
          QSurfaceFormat::setDefaultFormat(fmt);
      
          GLWindow glWindow;
          if (webassembly) glWindow.showFullScreen();
          else glWindow.showMaximized();
          return app.exec();
      }
      

      On desktop (Kubuntu 22.04) the code compiles and paints a pink rectangle. On webassembly it only compiles, both FF and Chrome show a black screen. The javascript console of FF shows:
      WebGL warning: vertexAttribI?Pointer: If ARRAY_BUFFER is null, byteOffset must be zero.
      WebGL warning: drawArraysInstanced: Vertex attrib array 0 is enabled but has no buffer bound.

      My own OpenGL code and the original hellogles3 work (originally I wanted to mix them).

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              lagocs Laszlo Agocs
              adamce Adam
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes