# HG changeset patch # User Andreas Weber # Date 1423844678 -3600 # Node ID 59ad278cfb98cff2e0a33ec798d86be7911cb97d # Parent 18fd412c7dc3bc9238e6f938422c026735252ada __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 diff -r 18fd412c7dc3 -r 59ad278cfb98 NEWS --- 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. diff -r 18fd412c7dc3 -r 59ad278cfb98 libinterp/dldfcn/__osmesa_print__.cc --- 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 { diff -r 18fd412c7dc3 -r 59ad278cfb98 scripts/plot/util/private/__opengl_print__.m --- 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")))