comparison libinterp/corefcn/gl2ps-print.cc @ 24179:8365e584ebd8

Add support for transparent polygons in svg output (bug #39535) * gl2ps-print.cc (gl2ps_renderer::has_alpha): new static method to determine if an axes object has transparent children. (gl2ps_renderer::draw_axes): set GL2PS_OCCLUSION_CULL and enable GL2PS_BLEND conditioned on the presence of transparent polygons . (gl2ps_renderer::draw): remove GL2PS_NO_BLENDING and GL2PS_OCCLUSION_CULL from gl2psBeginPage options
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Mon, 23 Oct 2017 12:10:31 +0200
parents 730227072acb
children eec262017c6a
comparison
equal deleted inserted replaced
24178:857b553177a5 24179:8365e584ebd8
91 Matrix render_text (const std::string& txt, 91 Matrix render_text (const std::string& txt,
92 double x, double y, double z, 92 double x, double y, double z,
93 int halign, int valign, double rotation = 0.0); 93 int halign, int valign, double rotation = 0.0);
94 94
95 void set_font (const base_properties& props); 95 void set_font (const base_properties& props);
96
97 static bool has_alpha (const graphics_handle& h)
98 {
99 bool retval = false;
100 graphics_object go = gh_manager::get_object (h);
101
102 if (! go.valid_object ())
103 return retval;
104
105 if (go.isa ("axes") || go.isa ("hggroup"))
106 {
107 Matrix children = go.get ("children").matrix_value ();
108 for (octave_idx_type ii = 0; ii < children.numel (); ii++)
109 {
110 retval = has_alpha (graphics_handle (children(ii)));
111 if (retval)
112 break;
113 }
114 }
115 else if (go.isa ("patch") || go.isa ("surface"))
116 {
117 octave_value fa = go.get ("facealpha");
118 if (fa.is_scalar_type () && fa.is_double_type ()
119 && fa.double_value () < 1)
120 retval = true;
121 }
122
123 return retval;
124 }
96 125
97 void draw_axes (const axes::properties& props) 126 void draw_axes (const axes::properties& props)
98 { 127 {
99 // Initialize a sorting tree (viewport) in gl2ps for each axes 128 // Initialize a sorting tree (viewport) in gl2ps for each axes
100 GLint vp[4]; 129 GLint vp[4];
101 glGetIntegerv (GL_VIEWPORT, vp); 130 glGetIntegerv (GL_VIEWPORT, vp);
102 gl2psBeginViewport (vp); 131 gl2psBeginViewport (vp);
103 132
104 // Draw and finish () or there may primitives missing in the gl2ps output. 133
134 // Don't remove hidden primitives when some of them are transparent
135 GLint opts;
136 gl2psGetOptions (&opts);
137 if (has_alpha (props.get___myhandle__ ()))
138 {
139 opts &= ~GL2PS_OCCLUSION_CULL;
140 // FIXME: currently the GL2PS_BLEND (which is more an equivalent of
141 // GL_ALPHA_TEST than GL_BLEND) is not working on a per primitive
142 // basis. We thus set it once per viewport.
143 gl2psEnable (GL2PS_BLEND);
144 }
145 else
146 {
147 opts |= GL2PS_OCCLUSION_CULL;
148 gl2psDisable (GL2PS_BLEND);
149 }
150
151 gl2psSetOptions (opts);
152
153 // Draw and finish () or there may be primitives missing in the gl2ps
154 // output.
105 opengl_renderer::draw_axes (props); 155 opengl_renderer::draw_axes (props);
106 finish (); 156 finish ();
107 157
108 // Finalize viewport 158 // Finalize viewport
109 GLint state = gl2psEndViewport (); 159 GLint state = gl2psEndViewport ();
112 else if (state == GL2PS_ERROR) 162 else if (state == GL2PS_ERROR)
113 error ("gl2ps_renderer::draw_axes: gl2psEndPage returned GL2PS_ERROR"); 163 error ("gl2ps_renderer::draw_axes: gl2psEndPage returned GL2PS_ERROR");
114 164
115 buffer_overflow |= (state == GL2PS_OVERFLOW); 165 buffer_overflow |= (state == GL2PS_OVERFLOW);
116 166
117 // Don't draw background for subsequent viewports (legends, subplots, etc.) 167 // Don't draw background for subsequent viewports (legends, subplots,
118 GLint opts; 168 // etc.)
119 gl2psGetOptions (&opts); 169 gl2psGetOptions (&opts);
120 opts &= ~GL2PS_DRAW_BACKGROUND; 170 opts &= ~GL2PS_DRAW_BACKGROUND;
121 gl2psSetOptions (opts); 171 gl2psSetOptions (opts);
122 } 172 }
123 173
333 } 383 }
334 else 384 else
335 include_graph = "foobar-inc"; 385 include_graph = "foobar-inc";
336 386
337 // GL2PS_SILENT was removed to allow gl2ps to print errors on stderr 387 // GL2PS_SILENT was removed to allow gl2ps to print errors on stderr
338 GLint ret = gl2psBeginPage ("gl2ps_renderer figure", "Octave", nullptr, 388 GLint ret = gl2psBeginPage ("gl2ps_renderer figure", "Octave",
339 gl2ps_term, gl2ps_sort, 389 nullptr, gl2ps_term, gl2ps_sort,
340 (GL2PS_NO_BLENDING 390 (GL2PS_BEST_ROOT
341 | GL2PS_OCCLUSION_CULL
342 | GL2PS_BEST_ROOT
343 | gl2ps_text 391 | gl2ps_text
344 | GL2PS_DRAW_BACKGROUND 392 | GL2PS_DRAW_BACKGROUND
345 | GL2PS_NO_PS3_SHADING 393 | GL2PS_NO_PS3_SHADING
346 | GL2PS_USE_CURRENT_VIEWPORT), 394 | GL2PS_USE_CURRENT_VIEWPORT),
347 GL_RGBA, 0, nullptr, 0, 0, 0, 395 GL_RGBA, 0, nullptr, 0, 0, 0,