I found a temporary solution that is good for me for now. I just deleted the sampling:
OpenGLWidget()
{
// QSurfaceFormat surfaceFormat;
// surfaceFormat.setMajorVersion(3);
// surfaceFormat.setMinorVersion(0);
// surfaceFormat.setSamples(4);
// setFormat(surfaceFormat);
}
In this case I don't need to use GL_DRAW_FRAMEBUFFER and GL_READ_FRAMEBUFFER to read a pixel color using glReadPixels():
void paintGL() override
{
glClear(GL_COLOR_BUFFER_BIT);
// // Set draw buffer to be fbo. Read buffer is already the default one
// glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo->handle());
// // Blit from the default MSAA buffer to non-MSAA fbo
// glBlitFramebuffer(0, 0, m_fbo->width(), m_fbo->height(),
// 0, 0, m_fbo->width(), m_fbo->height(),
// GL_COLOR_BUFFER_BIT, GL_NEAREST);
// glBindFramebuffer(GL_DRAW_FRAMEBUFFER, context()->defaultFramebufferObject());
// // Set read buffer
// glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo->handle());
// Read the pixel
GLubyte pixel[4];
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
// Set read buffer back to default
// glBindBuffer(GL_READ_FRAMEBUFFER, context()->defaultFramebufferObject());
qDebug() << pixel[0] / 255.f << pixel[1] / 255.f << pixel[2] / 255.f;
emit showPixelColorSignal(QVector3D(pixel[0] / 255.f, pixel[1] / 255.f, pixel[2] / 255.f));
}
My applications works correctly on Android and WebAssembly. It read a pixel with green color (0, 1, 0):
Android:
a0b95b4f-30f1-4a9f-8c1f-d726fd90577e-image.png
WebAssembly:
730c5fca-dd06-454c-9f10-2320426c8a0a-image.png