diff --git a/src/Gui/SoFCOffscreenRenderer.cpp b/src/Gui/SoFCOffscreenRenderer.cpp index a0670d8c96..5f88ee57fe 100644 --- a/src/Gui/SoFCOffscreenRenderer.cpp +++ b/src/Gui/SoFCOffscreenRenderer.cpp @@ -46,6 +46,11 @@ #include "SoFCOffscreenRenderer.h" #include "BitmapFactory.h" +#if defined(HAVE_QT5_OPENGL) +# include +# include +#endif + using namespace Gui; using namespace std; @@ -474,7 +479,7 @@ SoQtOffscreenRenderer::getViewportRegion(void) const before rendering. */ void -SoQtOffscreenRenderer::setBackgroundColor(const SbColor & color) +SoQtOffscreenRenderer::setBackgroundColor(const SbColor4f & color) { PRIVATE(this)->backgroundcolor = color; } @@ -482,7 +487,7 @@ SoQtOffscreenRenderer::setBackgroundColor(const SbColor & color) /*! Returns the background color. */ -const SbColor & +const SbColor4f & SoQtOffscreenRenderer::getBackgroundColor(void) const { return PRIVATE(this)->backgroundcolor; @@ -582,6 +587,9 @@ SoQtOffscreenRenderer::makeFrameBuffer(int width, int height, int samples) QtGLFramebufferObjectFormat fmt; fmt.setSamples(samples); fmt.setAttachment(QtGLFramebufferObject::Depth); +#if defined(HAVE_QT5_OPENGL) + fmt.setInternalTextureFormat(GL_RGB32F_ARB); +#endif #else QtGLFramebufferObject::Attachment fmt; fmt = QtGLFramebufferObject::Depth; @@ -596,6 +604,19 @@ SoQtOffscreenRenderer::renderFromBase(SoBase * base) { const SbVec2s fullsize = this->viewport.getViewportSizePixels(); +#if defined(HAVE_QT5_OPENGL) + QSurfaceFormat format; + format.setSamples(PRIVATE(this)->numSamples); + QOpenGLContext context; + context.setFormat(format); + if (!context.create()) + return false; + QOffscreenSurface offscreen; + offscreen.setFormat(format); + offscreen.create(); + context.makeCurrent(&offscreen); +#endif + #if !defined(HAVE_QT5_OPENGL) if (PRIVATE(this)->pbuffer) { if (!pixelbuffer) { @@ -631,7 +652,7 @@ SoQtOffscreenRenderer::renderFromBase(SoBase * base) glClearColor(this->backgroundcolor[0], this->backgroundcolor[1], this->backgroundcolor[2], - 0.0f); + this->backgroundcolor[3]); // needed to clear viewport after glViewport() is called from // SoGLRenderAction @@ -660,6 +681,11 @@ SoQtOffscreenRenderer::renderFromBase(SoBase * base) this->renderaction->setCacheContext(oldcontext); // restore old +#if defined(HAVE_QT5_OPENGL) + glImage = framebuffer->toImage(); + context.doneCurrent(); +#endif + return true; } @@ -730,12 +756,13 @@ SoQtOffscreenRenderer::writeToImage (QImage& img) const if (pixelbuffer) img = pixelbuffer->toImage(); } - else -#endif - { + else { if (framebuffer) img = framebuffer->toImage(); } +#else + img = this->glImage; +#endif } /*! diff --git a/src/Gui/SoFCOffscreenRenderer.h b/src/Gui/SoFCOffscreenRenderer.h index 2a8c260f02..cf6e3c26ab 100644 --- a/src/Gui/SoFCOffscreenRenderer.h +++ b/src/Gui/SoFCOffscreenRenderer.h @@ -26,11 +26,11 @@ #include #include +#include +#include #include #include -class QImage; - namespace Gui { /** @@ -108,8 +108,8 @@ public: void setViewportRegion(const SbViewportRegion & region); const SbViewportRegion & getViewportRegion(void) const; - void setBackgroundColor(const SbColor & color); - const SbColor & getBackgroundColor(void) const; + void setBackgroundColor(const SbColor4f & color); + const SbColor4f & getBackgroundColor(void) const; void setGLRenderAction(SoGLRenderAction * action); SoGLRenderAction * getGLRenderAction(void) const; @@ -142,11 +142,14 @@ private: uint32_t cache_context; // our unique context id SbViewportRegion viewport; - SbColor backgroundcolor; + SbColor4f backgroundcolor; SoGLRenderAction * renderaction; SbBool didallocation; SbBool pbuffer; int numSamples; +#if defined(HAVE_QT5_OPENGL) + QImage glImage; +#endif }; } // namespace Gui diff --git a/src/Gui/Thumbnail.cpp b/src/Gui/Thumbnail.cpp index f946b94e7a..7b038ee590 100644 --- a/src/Gui/Thumbnail.cpp +++ b/src/Gui/Thumbnail.cpp @@ -136,7 +136,14 @@ void Thumbnail::createThumbnailFromFramebuffer(QImage& img) const // Alternative way of off-screen rendering if (this->viewer->isActiveWindow()) { static_cast(this->viewer->getGLWidget())->makeCurrent(); - QtGLFramebufferObject fbo(this->size, this->size,QtGLFramebufferObject::Depth); +#if defined(HAVE_QT5_OPENGL) + QtGLFramebufferObjectFormat format; + format.setAttachment(QtGLFramebufferObject::Depth); + format.setInternalTextureFormat(GL_RGB32F_ARB); + QtGLFramebufferObject fbo(this->size, this->size, format); +#else + QtGLFramebufferObject fbo(this->size, this->size, QtGLFramebufferObject::Depth); +#endif this->viewer->renderToFramebuffer(&fbo); img = fbo.toImage(); static_cast(this->viewer->getGLWidget())->doneCurrent(); diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index d34bfa6a25..16b974a350 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -586,6 +586,9 @@ void View3DInventor::previewFromFramebuffer(const QRect& rect, QImage& img) QtGLFramebufferObjectFormat format; format.setSamples(8); format.setAttachment(QtGLFramebufferObject::Depth); +#if defined(HAVE_QT5_OPENGL) + format.setInternalTextureFormat(GL_RGB32F_ARB); +#endif QtGLFramebufferObject fbo(rect.width(), rect.height(), format); #else QtGLFramebufferObject fbo(rect.width(), rect.height(), QtGLFramebufferObject::Depth); diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index a3268f51c7..3c7460d129 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -931,7 +931,7 @@ void View3DInventorViewer::savePicture(int w, int h, const QColor& bg, QImage& i #if !defined(HAVE_QT5_OPENGL) bool useCoinOffscreenRenderer = !QGLPixelBuffer::hasOpenGLPbuffers(); #else - bool useCoinOffscreenRenderer = true; + bool useCoinOffscreenRenderer = false; #endif useCoinOffscreenRenderer = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/Document")-> @@ -1001,8 +1001,10 @@ void View3DInventorViewer::savePicture(int w, int h, const QColor& bg, QImage& i root->addChild(gl); root->addChild(pcViewProviderRoot); +#if !defined(HAVE_QT5_OPENGL) if (useBackground) root->addChild(cb); +#endif root->addChild(foregroundroot); @@ -1012,7 +1014,7 @@ void View3DInventorViewer::savePicture(int w, int h, const QColor& bg, QImage& i SoQtOffscreenRenderer renderer(vp); renderer.setNumPasses(4); if (bgColor.isValid()) - renderer.setBackgroundColor(SbColor(bgColor.redF(), bgColor.greenF(), bgColor.blueF())); + renderer.setBackgroundColor(SbColor4f(bgColor.redF(), bgColor.greenF(), bgColor.blueF(), bgColor.alphaF())); if (!renderer.render(root)) throw Base::Exception("Offscreen rendering failed"); diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index 9b141aa43b..057371fbfc 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -708,6 +708,9 @@ void View3DInventorPy::createImageFromFramebuffer(int width, int height, const Q QtGLFramebufferObjectFormat format; format.setSamples(8); format.setAttachment(QtGLFramebufferObject::Depth); +#if defined(HAVE_QT5_OPENGL) + format.setInternalTextureFormat(GL_RGB32F_ARB); +#endif QtGLFramebufferObject fbo(width, height, format); #else QtGLFramebufferObject fbo(width, height, QtGLFramebufferObject::Depth);