changeset 23546:06805aabbdd1

Draw 2D axes primitives in the children stack order (bug #50750) * gl-render.h/cc: (opengl_renderer::draw_axes_grids): new method to group all grids rendering (opengl_renderer::draw_axes): for 2D axes disable DEPTH_TEST. Draw grids before/after primitives depending on the "layer" property * gl2ps-print.cc (gl2ps_renderer::draw): if all axes are 2D disable primitive sorting
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Sun, 28 May 2017 14:21:07 +0200
parents 7f2fc79d07ad
children 05bbca224a14
files libinterp/corefcn/gl-render.cc libinterp/corefcn/gl-render.h libinterp/corefcn/gl2ps-print.cc
diffstat 3 files changed, 38 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/gl-render.cc	Wed May 31 22:59:46 2017 +0200
+++ b/libinterp/corefcn/gl-render.cc	Sun May 28 14:21:07 2017 +0200
@@ -1912,6 +1912,28 @@
   }
 
   void
+  opengl_renderer::draw_axes_grids (const axes::properties& props)
+  {
+    // Disable line smoothing for axes
+    GLboolean antialias;
+    glGetBooleanv (GL_LINE_SMOOTH, &antialias);
+    if (antialias == GL_TRUE)
+      glDisable (GL_LINE_SMOOTH);
+
+    set_linecap ("square");
+    set_linewidth (props.get_linewidth ());
+    set_font (props);
+    set_interpreter (props.get_ticklabelinterpreter ());
+
+    draw_axes_x_grid (props);
+    draw_axes_y_grid (props);
+    draw_axes_z_grid (props);
+
+    if (antialias == GL_TRUE)
+      glEnable (GL_LINE_SMOOTH);
+  }
+
+  void
   opengl_renderer::draw_all_lights (const base_properties& props,
                                     std::list<graphics_object>& obj_list)
   {
@@ -2026,8 +2048,6 @@
         draw (go);
       }
 
-    glEnable (GL_DEPTH_TEST);
-
     set_clipping (false);
 
     // FIXME: finalize rendering (transparency processing)
@@ -2072,23 +2092,17 @@
 
     setup_opengl_transformation (props);
 
-    // Disable line smoothing for axes
-    GLboolean antialias;
-    glGetBooleanv (GL_LINE_SMOOTH, &antialias);
-    if (antialias == GL_TRUE)
-      glDisable (GL_LINE_SMOOTH);
-
-    set_font (props);
-    set_interpreter (props.get_ticklabelinterpreter ());
-    set_linecap ("square");
-    set_linewidth (props.get_linewidth ());
-
-    // draw axes object
+    // For 2D axes, draw from back to front without depth sorting
+    bool is2D = props.get_is2D ();
+    if (is2D)
+      glDisable (GL_DEPTH_TEST);
+    else
+      glEnable (GL_DEPTH_TEST);
+
     draw_axes_planes (props);
 
-    draw_axes_x_grid (props);
-    draw_axes_y_grid (props);
-    draw_axes_z_grid (props);
+    if (! is2D || props.layer_is ("bottom"))
+      draw_axes_grids (props);
 
     if (props.get_tag () != "legend" || props.get_box () != "off")
       draw_axes_boxes (props);
@@ -2097,11 +2111,10 @@
 
     set_clipbox (x_min, x_max, y_min, y_max, z_min, z_max);
 
-    // Re-enable line smoothing for children
-    if (antialias == GL_TRUE)
-      glEnable (GL_LINE_SMOOTH);
-
     draw_axes_children (props);
+    
+    if (is2D && props.layer_is ("top"))
+      draw_axes_grids (props);
 
 #else
 
--- a/libinterp/corefcn/gl-render.h	Wed May 31 22:59:46 2017 +0200
+++ b/libinterp/corefcn/gl-render.h	Sun May 28 14:21:07 2017 +0200
@@ -173,6 +173,7 @@
     void draw_axes_planes (const axes::properties& props);
     void draw_axes_boxes (const axes::properties& props);
 
+    void draw_axes_grids (const axes::properties& props);
     void draw_axes_x_grid (const axes::properties& props);
     void draw_axes_y_grid (const axes::properties& props);
     void draw_axes_z_grid (const axes::properties& props);
--- a/libinterp/corefcn/gl2ps-print.cc	Wed May 31 22:59:46 2017 +0200
+++ b/libinterp/corefcn/gl2ps-print.cc	Sun May 28 14:21:07 2017 +0200
@@ -227,8 +227,10 @@
         GLint gl2ps_sort = GL2PS_BSP_SORT;
 
         // For 2D plots we can use a simpler Z-depth sorting algorithm
+        // FIXME: gl2ps does not provide a way to change the sorting algorythm
+        // on a viewport basis, we thus disable sorting only if all axes are 2D
         if (term.find ("is2D") != std::string::npos)
-          gl2ps_sort = GL2PS_SIMPLE_SORT;
+          gl2ps_sort = GL2PS_NO_SORT;
 
         // Use a temporary file in case an overflow happens
         FILE *tmpf = octave_tmpfile_wrapper ();