comparison libinterp/corefcn/gl-render.cc @ 18768:75f8926deef1

Fix Z-order stacking of patches and axes grid lines (bug #40722). * gl-render.h (set_polygon_offset): Change function prototype for offset argument to float. * gl-render.cc (set_polygon_offset): Change offset argument to type float. Now matches OpenGL prototype for glPolygonOffset. * gl-render.cc (patch_tesselator::patch_tesselator): Change constructor variable idx to a float, from int. * gl-render.cc (patch_tesselator::begin): Pass index directly to set_polygon_offset. * gl-render.cc (opengl_renderer::draw_patch): Call patch_tesselator with index of 1.0 for filled portion of patch to push it down below outline of patch. * patch.m: For 2-D patches, set zlim to [-1,1] so that axes 'layer' property works.
author Rik <rik@octave.org>
date Sat, 17 May 2014 12:56:11 -0700
parents 04adeda9b83d
children ff39ddf84a19
comparison
equal deleted inserted replaced
18766:10082673a8f0 18768:75f8926deef1
399 399
400 class 400 class
401 opengl_renderer::patch_tesselator : public opengl_tesselator 401 opengl_renderer::patch_tesselator : public opengl_tesselator
402 { 402 {
403 public: 403 public:
404 patch_tesselator (opengl_renderer *r, int cmode, int lmode, int idx = 0) 404 patch_tesselator (opengl_renderer *r, int cmode, int lmode, float idx = 0.0)
405 : opengl_tesselator (), renderer (r), 405 : opengl_tesselator (), renderer (r),
406 color_mode (cmode), light_mode (lmode), index (idx), 406 color_mode (cmode), light_mode (lmode), index (idx),
407 first (true), tmp_vdata () 407 first (true), tmp_vdata ()
408 { } 408 { }
409 409
417 glShadeModel (GL_SMOOTH); 417 glShadeModel (GL_SMOOTH);
418 else 418 else
419 glShadeModel (GL_FLAT); 419 glShadeModel (GL_FLAT);
420 420
421 if (is_filled ()) 421 if (is_filled ())
422 renderer->set_polygon_offset (true, 1+index); 422 renderer->set_polygon_offset (true, index);
423 423
424 glBegin (type); 424 glBegin (type);
425 } 425 }
426 426
427 void end (void) 427 void end (void)
435 { 435 {
436 vertex_data::vertex_data_rep *v 436 vertex_data::vertex_data_rep *v
437 = reinterpret_cast<vertex_data::vertex_data_rep *> (data); 437 = reinterpret_cast<vertex_data::vertex_data_rep *> (data);
438 //printf ("patch_tesselator::vertex (%g, %g, %g)\n", v->coords(0), v->coords(1), v->coords(2)); 438 //printf ("patch_tesselator::vertex (%g, %g, %g)\n", v->coords(0), v->coords(1), v->coords(2));
439 439
440 // NOTE: OpenGL can re-order vertices so "first" is basically meaningless 440 // NOTE: OpenGL can re-order vertices. For "flat" coloring of FaceColor
441 // in this callback routine. For "flat" coloring of FaceColor the first 441 // the first vertex must be identified in the draw_patch routine.
442 // vertex must be identified in the draw_patch routine.
443 442
444 if (color_mode == 2 || (color_mode == 1 && ! is_filled ())) 443 if (color_mode == 2 || (color_mode == 1 && ! is_filled ()))
445 { 444 {
446 Matrix col = v->color; 445 Matrix col = v->color;
447 446
2336 } 2335 }
2337 2336
2338 if (fl_mode > 0) 2337 if (fl_mode > 0)
2339 glEnable (GL_LIGHTING); 2338 glEnable (GL_LIGHTING);
2340 2339
2341 // FIXME: use __index__ property from patch object 2340 // NOTE: Push filled part of patch backwards to avoid Z-fighting with
2342 // -1.25 chosen to provide sufficient Z-offset for 2341 // tesselator outline. A value of 1.0 seems to work fine. Value
2343 // 'layer' property of 2-D plots and not to provoke 2342 // can't be too large or the patch will be pushed below the axes
2344 // Z-fighting with tesselator outline. 2343 // planes at +2.5.
2345 patch_tesselator tess (this, fc_mode, fl_mode, -1.25); 2344 patch_tesselator tess (this, fc_mode, fl_mode, 1.0);
2346 2345
2347 for (int i = 0; i < nf; i++) 2346 for (int i = 0; i < nf; i++)
2348 { 2347 {
2349 if (clip_f(i)) 2348 if (clip_f(i))
2350 continue; 2349 continue;
2429 glEnable (GL_LIGHTING); 2428 glEnable (GL_LIGHTING);
2430 2429
2431 set_linestyle (props.get_linestyle (), false); 2430 set_linestyle (props.get_linestyle (), false);
2432 set_linewidth (props.get_linewidth ()); 2431 set_linewidth (props.get_linewidth ());
2433 2432
2434 2433 // NOTE: patch contour cannot be offset. Offset must occur with the
2435 // FIXME: use __index__ property from patch object; 2434 // filled portion of the patch above. The tesselator uses
2436 // should we offset patch contour as well? 2435 // GLU_TESS_BOUNDARY_ONLY to get the outline of the patch and OpenGL
2436 // automatically sets the glType to GL_LINE_LOOP. This primitive is
2437 // not supported by glPolygonOffset which is used to do Z offsets.
2437 patch_tesselator tess (this, ec_mode, el_mode); 2438 patch_tesselator tess (this, ec_mode, el_mode);
2438 2439
2439 for (int i = 0; i < nf; i++) 2440 for (int i = 0; i < nf; i++)
2440 { 2441 {
2441 if (clip_f(i)) 2442 if (clip_f(i))
2817 props.get ("fontsize").double_value ()); 2818 props.get ("fontsize").double_value ());
2818 #endif 2819 #endif
2819 } 2820 }
2820 2821
2821 void 2822 void
2822 opengl_renderer::set_polygon_offset (bool on, double offset) 2823 opengl_renderer::set_polygon_offset (bool on, float offset)
2823 { 2824 {
2824 if (on) 2825 if (on)
2825 { 2826 {
2826 glPolygonOffset (offset, offset);
2827 glEnable (GL_POLYGON_OFFSET_FILL); 2827 glEnable (GL_POLYGON_OFFSET_FILL);
2828 glEnable (GL_POLYGON_OFFSET_LINE); 2828 glEnable (GL_POLYGON_OFFSET_LINE);
2829 glPolygonOffset (offset, offset);
2829 } 2830 }
2830 else 2831 else
2831 { 2832 {
2832 glDisable (GL_POLYGON_OFFSET_FILL); 2833 glDisable (GL_POLYGON_OFFSET_FILL);
2833 glDisable (GL_POLYGON_OFFSET_LINE); 2834 glDisable (GL_POLYGON_OFFSET_LINE);