diff libgui/graphics/GLCanvas.h @ 24798:45470049a43f

Allow getframe and print to work without osmesa (bug #53186). * NEWS: Announce support for printing invisible qt figures without osmesa. * __opengl_print__.m: Allow invisible figures to be printed with qt if QOFFSCREENSURFACE is present. * getframe.m: Allow using __get_frame__ on invisible qt figures if QOFFSCREENSURFACE is present. * Backenc.cc (Backend::get_pixels): Don't restrict to visible figures. * Canvas.h/cc (Canvas::do_print): New pure virtual function (Canvas::print): Call do_print. * GLCanvas.h/cc (GLCanvas::begin_rendering): New methods to make sure a valid OpenGL context is made current before rendering. (GLCanvas::end_rendering): Call doneCurrent. (GLCanvas::getPixels): Make use of begin/end_rendering. If the figure is not visible or its size is frozen, draw on a framebuffer object of suitable size. (GLCanvas::do_print): Move code for OpenGL printing here. Make use of begin/end_rendering. * acinclude.m4: Add test for presence and usability of QOffscreenSurface. * configure.ac: Allow building the manual with qt if QOffscreenSurface is OK. * geometryimages.m, interpimages.m, plotimages.m, sparseimages.m, splineimages.m: Allow using qt toolkit to generate images for the manual when QOFFSCREENSURFACE is present.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Fri, 23 Feb 2018 14:33:55 +0100
parents 194eb4bd202b
children ae6679369a80
line wrap: on
line diff
--- a/libgui/graphics/GLCanvas.h	Mon Feb 26 15:43:28 2018 -0800
+++ b/libgui/graphics/GLCanvas.h	Fri Feb 23 14:33:55 2018 +0100
@@ -26,9 +26,17 @@
 #if defined (HAVE_QOPENGLWIDGET)
 #  include <QOpenGLWidget>
 #  define OCTAVE_QT_OPENGL_WIDGET QOpenGLWidget
+#  include <QOpenGLFramebufferObject>
+#  define OCTAVE_QT_OPENGL_FBO QOpenGLFramebufferObject
+#  if defined (HAVE_QOFFSCREENSURFACE)
+#    include <QOpenGLContext>
+#    include <QOffscreenSurface>
+#  endif  
 #elif defined (HAVE_QGLWIDGET)
 #  include <QGLWidget>
 #  define OCTAVE_QT_OPENGL_WIDGET QGLWidget
+#  include <QGLFramebufferObject>
+#  define OCTAVE_QT_OPENGL_FBO QGLFramebufferObject
 #else
 #  error "configuration error: must have <QOpenGLWidget> or <QGLWidget>."
 #endif
@@ -45,6 +53,8 @@
 
     void draw (const graphics_handle& handle);
     uint8NDArray  do_getPixels (const graphics_handle& handle);
+    void do_print (const QString& file_cmd, const QString& term,
+                   const graphics_handle& handle);
     void toggleAxes (const graphics_handle& handle);
     void toggleGrid (const graphics_handle& handle);
     void autoAxes (const graphics_handle& handle);
@@ -64,6 +74,16 @@
     void wheelEvent (QWheelEvent *event);
     void keyPressEvent (QKeyEvent *event);
     void keyReleaseEvent (QKeyEvent *event);
+    
+  private:
+    
+    bool begin_rendering (void);
+    void end_rendering (void);
+
+# if defined (HAVE_QOFFSCREENSURFACE)
+    QOpenGLContext m_os_context;    
+    QOffscreenSurface m_os_surface;
+# endif
   };
 
 }