changeset 19741:59ad278cfb98

__opengl_print__.m: Use OSMesa for offscreen rendering (Bug #33180) * __opengl_print__.m: Call __osmesa_print__ if figure is invisible * __osmesa_print__.cc: Add method to create process and pipe gl2ps output to it for compatibility with __opengl_print__ and drawnow. * NEWS: Mention offscreen rendering
author Andreas Weber <andy.weber.aw@gmail.com>
date Fri, 13 Feb 2015 17:24:38 +0100
parents 18fd412c7dc3
children 1170c849952b
files NEWS libinterp/dldfcn/__osmesa_print__.cc scripts/plot/util/private/__opengl_print__.m
diffstat 3 files changed, 42 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Feb 13 10:14:31 2015 +0100
+++ b/NEWS	Fri Feb 13 17:24:38 2015 +0100
@@ -263,6 +263,9 @@
     and DEFINE_OCTAVE_ALLOCATOR2) are now unconditionally defined to be
     empty.
 
+ ** Qt and FLTK graphics toolkit now support offscreen rendering,
+    i.e., print will work when figure visibility is off.
+
 ---------------------------------------------------------
 
 See NEWS.3 for old news.
--- a/libinterp/dldfcn/__osmesa_print__.cc	Fri Feb 13 10:14:31 2015 +0100
+++ b/libinterp/dldfcn/__osmesa_print__.cc	Fri Feb 13 17:24:38 2015 +0100
@@ -40,13 +40,14 @@
 
 DEFUN_DLD(__osmesa_print__, args, ,
           "-*- texinfo -*-\n\
-@deftypefn {Loadable Function}  __osmesa_print__ (@var{h}, @var{filename}, @var{term})\n\
+@deftypefn {Loadable Function}  __osmesa_print__ (@var{h}, @var{file}, @var{term})\n\
 @deftypefnx {Loadable Function} {@var{img}  =} __osmesa_print__ (@var{h})\n\
 Print figure @var{h} using OSMesa and gl2ps for vector formats.\n\
 \n\
 This is a private internal function.\n\
 The first method calls gl2ps with the appropriate @var{term} and writes\n\
-the output of gl2ps to @var{filename}.\n\
+the output of gl2ps to @var{file}. If the first character of @var{file}\n\
+is @qcode{|}, then a process is started and the output of gl2ps is piped to it.\n\
 \n\
 Valid options for @var{term}, which can be concatenated in one string, are:\n\
 @table @asis\n\
@@ -80,7 +81,7 @@
     {
       if(! (args(1).is_string () && args(2).is_string ()))
         {
-          error ("__osmesa_print__: FILENAME and TERM has to be strings");
+          error ("__osmesa_print__: FILE and TERM has to be strings");
           return retval;
         }
 
@@ -151,25 +152,37 @@
 
   if (nargin == 3)
     {
-      // write gl2ps output to file
-      std::string filename  = args(1).string_value ();
-      std::string term      = args(2).string_value ();
+      // use gl2ps
+      std::string file = args(1).string_value ();
+      std::string term = args(2).string_value ();
 
-      FILE *filep;
-      filep = fopen (filename.c_str (), "w");
-      if (filep)
+      if (! error_state)
         {
-          glps_renderer rend (filep, term);
-          rend.draw (fobj, "");
-
-          // Make sure buffered commands are finished!!!
-          glFinish ();
+          size_t pos = file.find_first_not_of ("|");
+          if (pos > 0)
+            {
+              // create process and pipe gl2ps output to it
+              std::string cmd = file.substr (pos);
+              gl2ps_print (fobj, cmd, term);
+            }
+          else
+            {
+              // write gl2ps output directly to file
+              FILE *filep;
+              filep = fopen (file.c_str (), "w");
+              if (filep)
+                {
+                  glps_renderer rend (filep, term);
+                  rend.draw (fobj, "");
 
-          fclose (filep);
+                  // Make sure buffered commands are finished!!!
+                  glFinish ();
+                  fclose (filep);
+                }
+              else
+                error ("__osmesa_print__: Couldn't create file \"%s\"", file.c_str ());
+            }
         }
-      else
-        error ("__osmesa_print__: Couldn't create file \"%s\"", filename.c_str ());
-
     }
   else
     {
--- a/scripts/plot/util/private/__opengl_print__.m	Fri Feb 13 10:14:31 2015 +0100
+++ b/scripts/plot/util/private/__opengl_print__.m	Fri Feb 13 17:24:38 2015 +0100
@@ -162,7 +162,14 @@
     if (opts.debug)
       fprintf ("opengl-pipeline: '%s'\n", pipeline{n});
     endif
-    drawnow (gl2ps_device{n}, strcat ('|',pipeline{n}));
+
+    if (strcmp (get (opts.figure, "visible"), "on"))
+      ## Use toolkits "print_figure" method
+      drawnow (gl2ps_device{n}, strcat ('|', pipeline{n}));
+    else
+      ## Use OpenGL offscreen rendering with OSMesa
+      __osmesa_print__ (opts.figure, strcat ('|', pipeline{n}), gl2ps_device{n});
+    endif
   endfor
 
   if (! isempty (strfind (opts.devopt, "standalone")))