| 2892 | } |
| 2893 | |
| 2894 | QImage View3DInventorViewer::grabFramebuffer() |
| 2895 | { |
| 2896 | auto gl = static_cast<QOpenGLWidget*>(this->viewport()); // NOLINT |
| 2897 | gl->makeCurrent(); |
| 2898 | |
| 2899 | QImage res; |
| 2900 | const SbViewportRegion vp = this->getSoRenderManager()->getViewportRegion(); |
| 2901 | SbVec2s size = vp.getViewportSizePixels(); |
| 2902 | int width = size[0]; |
| 2903 | int height = size[1]; |
| 2904 | |
| 2905 | int samples = getNumSamples(); |
| 2906 | if (samples == 0) { |
| 2907 | // if anti-aliasing is off we can directly use glReadPixels |
| 2908 | QImage img(QSize(width, height), QImage::Format_RGB32); |
| 2909 | glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, img.bits()); |
| 2910 | res = img; |
| 2911 | } |
| 2912 | else { |
| 2913 | QOpenGLFramebufferObjectFormat fboFormat; |
| 2914 | fboFormat.setSamples(getNumSamples()); |
| 2915 | fboFormat.setAttachment(QOpenGLFramebufferObject::Depth); |
| 2916 | fboFormat.setTextureTarget(GL_TEXTURE_2D); |
| 2917 | fboFormat.setInternalTextureFormat(getInternalTextureFormat()); |
| 2918 | |
| 2919 | QOpenGLFramebufferObject fbo(width, height, fboFormat); |
| 2920 | renderToFramebuffer(&fbo); |
| 2921 | |
| 2922 | res = fbo.toImage(false); |
| 2923 | |
| 2924 | QImage image(res.width(), res.height(), QImage::Format_RGB32); |
| 2925 | QPainter painter(&image); |
| 2926 | painter.fillRect(image.rect(), Qt::black); |
| 2927 | painter.drawImage(0, 0, res); |
| 2928 | painter.end(); |
| 2929 | res = image; |
| 2930 | } |
| 2931 | |
| 2932 | return res; |
| 2933 | } |
| 2934 | |
| 2935 | void View3DInventorViewer::imageFromFramebuffer( |
| 2936 | int width, |
no test coverage detected