From f4bc889b4d69ec35dfcc52e4eec1a5a5f97d8140 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 17 Sep 2019 15:55:05 +0200 Subject: [PATCH] fixes #0004103: Black screen when using rubberband selection --- src/Gui/SoFCOffscreenRenderer.cpp | 27 +++++++++---- src/Gui/SoFCOffscreenRenderer.h | 4 ++ src/Gui/View3DInventorViewer.cpp | 64 ++++++++++++++++++++++++------- src/Gui/View3DInventorViewer.h | 1 + 4 files changed, 76 insertions(+), 20 deletions(-) diff --git a/src/Gui/SoFCOffscreenRenderer.cpp b/src/Gui/SoFCOffscreenRenderer.cpp index 0165befb47..b89bcd7b51 100644 --- a/src/Gui/SoFCOffscreenRenderer.cpp +++ b/src/Gui/SoFCOffscreenRenderer.cpp @@ -416,6 +416,13 @@ void SoQtOffscreenRenderer::init(const SbViewportRegion & vpr, #endif this->framebuffer = NULL; this->numSamples = -1; +#if defined(HAVE_QT5_OPENGL) + //this->texFormat = GL_RGBA32F_ARB; + this->texFormat = GL_RGB32F_ARB; +#else + //this->texFormat = GL_RGBA; + this->texFormat = GL_RGB; +#endif this->cache_context = 0; this->pbuffer = false; } @@ -532,6 +539,18 @@ SoQtOffscreenRenderer::getNumPasses(void) const return PRIVATE(this)->numSamples; } +void +SoQtOffscreenRenderer::setInternalTextureFormat(GLenum internalTextureFormat) +{ + PRIVATE(this)->texFormat = internalTextureFormat; +} + +GLenum +SoQtOffscreenRenderer::internalTextureFormat() const +{ + return PRIVATE(this)->texFormat; +} + void SoQtOffscreenRenderer::setPbufferEnable(SbBool enable) { @@ -603,13 +622,7 @@ SoQtOffscreenRenderer::makeFrameBuffer(int width, int height, int samples) // is to use a certain background color using GL_RGB as texture // format and in the output image search for the above color and // replaces it with the color requested by the user. -#if defined(HAVE_QT5_OPENGL) - //fmt.setInternalTextureFormat(GL_RGBA32F_ARB); - fmt.setInternalTextureFormat(GL_RGB32F_ARB); -#else - //fmt.setInternalTextureFormat(GL_RGBA); - fmt.setInternalTextureFormat(GL_RGB); -#endif + fmt.setInternalTextureFormat(this->texFormat); #else QtGLFramebufferObject::Attachment fmt; fmt = QtGLFramebufferObject::Depth; diff --git a/src/Gui/SoFCOffscreenRenderer.h b/src/Gui/SoFCOffscreenRenderer.h index 11465e79d6..ce4b0ffa65 100644 --- a/src/Gui/SoFCOffscreenRenderer.h +++ b/src/Gui/SoFCOffscreenRenderer.h @@ -117,6 +117,9 @@ public: void setNumPasses(const int num); int getNumPasses(void) const; + void setInternalTextureFormat(GLenum internalTextureFormat); + GLenum internalTextureFormat() const; + void setPbufferEnable(SbBool enable); SbBool getPbufferEnable(void) const; @@ -148,6 +151,7 @@ private: SbBool didallocation; SbBool pbuffer; int numSamples; + GLenum texFormat; #if defined(HAVE_QT5_OPENGL) QImage glImage; #endif diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 4cbe9ba1f9..8a22b54977 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -1557,6 +1557,7 @@ void View3DInventorViewer::savePicture(int w, int h, int s, const QColor& bg, QI if (!useCoinOffscreenRenderer) { SoQtOffscreenRenderer renderer(vp); renderer.setNumPasses(s); + renderer.setInternalTextureFormat(getInternalTextureFormat()); renderer.setPbufferEnable(usePixelBuffer); if (bgColor.isValid()) renderer.setBackgroundColor(SbColor4f(bgColor.redF(), bgColor.greenF(), bgColor.blueF(), bgColor.alphaF())); @@ -1859,6 +1860,53 @@ int View3DInventorViewer::getNumSamples() } } +GLenum View3DInventorViewer::getInternalTextureFormat() const +{ +#if defined(HAVE_QT5_OPENGL) + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/View"); + std::string format = hGrp->GetASCII("InternalTextureFormat", "Default"); + + if (format == "GL_RGB") { + return GL_RGB; + } + else if (format == "GL_RGBA") { + return GL_RGBA; + } + else if (format == "GL_RGB8") { + return GL_RGB8; + } + else if (format == "GL_RGBA8") { + return GL_RGBA8; + } + else if (format == "GL_RGB10") { + return GL_RGB10; + } + else if (format == "GL_RGB10_A2") { + return GL_RGB10_A2; + } + else if (format == "GL_RGB16") { + return GL_RGB16; + } + else if (format == "GL_RGBA16") { + return GL_RGBA16; + } + else if (format == "GL_RGB32F") { + return GL_RGB32F_ARB; + } + else if (format == "GL_RGBA32F") { + return GL_RGBA32F_ARB; + } + else { + QOpenGLFramebufferObjectFormat fboFormat; + return fboFormat.internalTextureFormat(); + } +#else + //return GL_RGBA; + return GL_RGB; +#endif +} + void View3DInventorViewer::setRenderType(const RenderType type) { renderType = type; @@ -1946,7 +1994,7 @@ QImage View3DInventorViewer::grabFramebuffer() fboFormat.setSamples(getNumSamples()); fboFormat.setAttachment(QOpenGLFramebufferObject::Depth); fboFormat.setTextureTarget(GL_TEXTURE_2D); - fboFormat.setInternalTextureFormat(GL_RGB32F_ARB); + fboFormat.setInternalTextureFormat(getInternalTextureFormat()); QOpenGLFramebufferObject fbo(width, height, fboFormat); renderToFramebuffer(&fbo); @@ -1978,18 +2026,8 @@ void View3DInventorViewer::imageFromFramebuffer(int width, int height, int sampl // is to use a certain background color using GL_RGB as texture // format and in the output image search for the above color and // replaces it with the color requested by the user. -#if defined(HAVE_QT5_OPENGL) - if (App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Document")->GetBool("SaveThumbnailFix",false)) { - fboFormat.setInternalTextureFormat(GL_RGBA32F_ARB); - } - else { - fboFormat.setInternalTextureFormat(GL_RGB32F_ARB); - } -#else - //fboFormat.setInternalTextureFormat(GL_RGBA); - fboFormat.setInternalTextureFormat(GL_RGB); -#endif + fboFormat.setInternalTextureFormat(getInternalTextureFormat()); + QtGLFramebufferObject fbo(width, height, fboFormat); const QColor col = backgroundColor(); diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index 2710f973ff..07b67448cc 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -377,6 +377,7 @@ public: virtual PyObject *getPyObject(void); protected: + GLenum getInternalTextureFormat() const; void renderScene(); void renderFramebuffer(); void renderGLImage();