39 #if defined (HAVE_OSMESA_H)
41 #elif defined (HAVE_GL_OSMESA_H)
42 #include "GL/osmesa.h"
45 #if defined (HAVE_OSMESA) && defined (HAVE_OPENGL)
61 @deftypefn {Loadable Function} {} __osmesa_print__ (@var{h}, @var{file}, @var{term})\n\
62 @deftypefnx {Loadable Function} {@var{img} =} __osmesa_print__ (@var{h})\n\
63 Print figure @var{h} using OSMesa and gl2ps for vector formats.\n\
65 This is a private internal function.\n\
67 The first method calls gl2ps with the appropriate @var{term} and writes\n\
68 the output of gl2ps to @var{file}. If the first character of @var{file}\n\
69 is @qcode{|}, then a process is started and the output of gl2ps is piped\n\
72 Valid options for @var{term}, which can be concatenated in one string, are:\n\
75 @item @qcode{eps}, @qcode{pdf}, @qcode{ps}, @qcode{svg}, @qcode{pgf}, @qcode{tex}\n\
76 Select output format.\n\
79 Use GL2PS_SIMPLE_SORT instead of GL2PS_BSP_SORT as Z-depth sorting algorithm.\n\
81 @item @qcode{notext}\n\
85 The second method doesn't use gl2ps and returns a RGB image in @var{img}\n\
92 #if ! defined (HAVE_OSMESA)
96 int nargin = args.length ();
98 if (! (nargin == 1 || nargin == 3))
106 if (! (args(1).is_string () && args(2).is_string ()))
108 error (
"__osmesa_print__: FILE and TERM must be strings");
113 error (
"__osmesa_print__: Octave has been compiled without gl2ps");
118 int h = args(0).double_value ();
120 if (! (fobj && fobj.
isa (
"figure")))
122 error (
"__osmesa_print__: H must be a valid figure handle");
129 bool internal =
true;
132 GLsizei Width =
static_cast<GLsizei
> (bb(2));
133 GLsizei Height =
static_cast<GLsizei
> (bb(3));
136 OSMesaContext ctx = OSMesaCreateContextExt (OSMESA_RGBA, 16, 0, 0, NULL);
139 error (
"__osmesa_print__: OSMesaCreateContext failed!\n");
147 if (! OSMesaMakeCurrent (ctx, buffer, GL_UNSIGNED_BYTE, Width, Height))
149 error (
"__osmesa_print__: OSMesaMakeCurrent failed!\n");
159 glGetIntegerv (GL_DEPTH_BITS, &z);
160 glGetIntegerv (GL_STENCIL_BITS, &s);
161 if (z != 16 || s != 0)
162 error (
"__osmesa_print__: Depth and stencil doesn't match,"
163 " are you sure you are using OSMesa >= 9.0?");
171 outer_frame.
add_fcn (reset_visibility, &fp);
182 std::string file = args(1).string_value ();
183 std::string term = args(2).string_value ();
187 size_t pos_p = file.find_first_of (
"|");
188 size_t pos_c = file.find_first_not_of (
"| ");
190 if (pos_p == std::string::npos && pos_c == std::string::npos)
191 error (
"__osmesa_print__: empty output ''");
192 else if (pos_c == std::string::npos)
193 error (
"__osmesa_print__: empty pipe '|'");
194 else if (pos_p != std::string::npos && pos_p < pos_c)
197 std::string cmd = file.substr (pos_c);
203 FILE *filep = gnulib::fopen (file.substr (pos_c).c_str (),
"w");
211 glps_renderer rend (filep, term);
212 rend.draw (fobj,
"");
218 error (
"__osmesa_print__: Couldn't create file \"%s\"", file.c_str ());
236 assert (
sizeof (GLubyte) == 1);
238 unsigned char *p =
reinterpret_cast<unsigned char*
>(img.
fortran_vec ());
239 memcpy (p, buffer, (4 * Width * Height));
257 OSMesaDestroyContext (ctx);
bool is_visible(void) const
MArray< T > permute(const Array< octave_idx_type > &vec, bool inv=false) const
bool isa(const std::string &go_name) const
static const idx_vector colon
OCTINTERP_API void print_usage(void)
void error(const char *fmt,...)
void gl2ps_print(const graphics_object &fig, const std::string &cmd, const std::string &term)
static void close_fcn(FILE *f)
F77_RET_T const double const double * f
void add_fcn(void(*fcn)(void))
void gripe_disabled_feature(const std::string &func, const std::string &feature, const std::string &pkg)
base_properties & get_properties(void)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
static graphics_object get_object(double val)
#define DEFUN_DLD(name, args_name, nargout_name, doc)
const T * fortran_vec(void) const
static idx_vector make_range(octave_idx_type start, octave_idx_type step, octave_idx_type len)
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))