code reduction w.r.t offscreen rendering

This commit is contained in:
wmayer
2018-01-07 17:12:50 +01:00
parent 8eaee314ac
commit 22ed0bce51
9 changed files with 67 additions and 199 deletions

View File

@@ -87,22 +87,9 @@ void Thumbnail::SaveDocFile (Base::Writer &writer) const
if (!this->viewer)
return;
QImage img;
#if !defined(HAVE_QT5_OPENGL)
bool pbuffer = QGLPixelBuffer::hasOpenGLPbuffers();
#else
bool pbuffer = false;
#endif
if (App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/Document")->GetBool("DisablePBuffers",!pbuffer)) {
this->createThumbnailFromFramebuffer(img);
}
else {
try {
this->viewer->savePicture(this->size, this->size, QColor(), img);
}
catch (...) {
this->createThumbnailFromFramebuffer(img);
}
if (this->viewer->isActiveWindow()) {
QColor invalid;
this->viewer->imageFromFramebuffer(this->size, this->size, 0, invalid, img);
}
QPixmap px = Gui::BitmapFactory().pixmap(App::Application::Config()["AppIcon"].c_str());
@@ -135,22 +122,3 @@ void Thumbnail::RestoreDocFile(Base::Reader &reader)
{
Q_UNUSED(reader);
}
void Thumbnail::createThumbnailFromFramebuffer(QImage& img) const
{
// Alternative way of off-screen rendering
if (this->viewer->isActiveWindow()) {
static_cast<QtGLWidget*>(this->viewer->getGLWidget())->makeCurrent();
QtGLFramebufferObjectFormat format;
format.setAttachment(QtGLFramebufferObject::Depth);
#if defined(HAVE_QT5_OPENGL)
format.setInternalTextureFormat(GL_RGB32F_ARB);
#else
format.setInternalTextureFormat(GL_RGB);
#endif
QtGLFramebufferObject fbo(this->size, this->size, format);
this->viewer->renderToFramebuffer(&fbo);
img = fbo.toImage();
}
}