changeset 21459:385b67d48dda

Don't enable opengl lighting when no light object is present (bug #42006) * gl_render.h: Add private bool property has_light to opengl_renderer to indicate whether a light object is present and visible in the current axes. * gl_render.cc (draw_axes_children): Set value of has_ligh before drawing any children object. * gl_render.cc (draw_patch, draw_surface): Enable lighting for patch and surface objects only if has_light is true. * contributors.in: add contributor
author mmuetzel <markus.muetzel@gmx.de>
date Tue, 15 Mar 2016 13:46:22 +0100
parents 348e335c49dd
children 236163306596
files doc/interpreter/contributors.in libinterp/corefcn/gl-render.cc libinterp/corefcn/gl-render.h
diffstat 3 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/contributors.in	Wed Mar 16 20:52:55 2016 -0700
+++ b/doc/interpreter/contributors.in	Tue Mar 15 13:46:22 2016 +0100
@@ -222,6 +222,7 @@
 Victor Munoz
 PrasannaKumar Muralidharan
 Iain Murray
+Markus Mützel
 Carmen Navarrete
 Todd Neal
 Philip Nienhuis
--- a/libinterp/corefcn/gl-render.cc	Wed Mar 16 20:52:55 2016 -0700
+++ b/libinterp/corefcn/gl-render.cc	Tue Mar 15 13:46:22 2016 +0100
@@ -1512,6 +1512,7 @@
   // Start with the last element of the array of child objects to
   // display them in the order they were added to the array.
 
+  has_light = false;
   for (octave_idx_type i = children.numel () - 1; i >= 0; i--)
     {
       graphics_object go = gh_manager::get_object (children(i));
@@ -1519,7 +1520,10 @@
       if (go.get_properties ().is_visible ())
         {
           if (go.isa ("light"))
-            draw (go);
+            {
+              draw (go);
+              has_light = true;
+            }
           else
             obj_list.push_back (go);
         }
@@ -1877,7 +1881,7 @@
                 }
             }
 
-          if (fl_mode > 0)
+          if ((fl_mode > 0) && has_light)
             glEnable (GL_LIGHTING);
           glShadeModel ((fc_mode == INTERP || fl_mode == GOURAUD) ? GL_SMOOTH
                                                                   : GL_FLAT);
@@ -2052,7 +2056,7 @@
           if (fc_mode == TEXTURE)
             glDisable (GL_TEXTURE_2D);
 
-          if (fl_mode > 0)
+          if ((fl_mode > 0) && has_light)
             glDisable (GL_LIGHTING);
         }
       else
@@ -2080,7 +2084,7 @@
                 }
             }
 
-          if (el_mode > 0)
+          if ((el_mode > 0) && has_light)
             glEnable (GL_LIGHTING);
           glShadeModel ((ec_mode == INTERP || el_mode == GOURAUD) ? GL_SMOOTH
                                                                   : GL_FLAT);
@@ -2285,7 +2289,7 @@
           set_linestyle ("-");
           set_linewidth (0.5);
 
-          if (el_mode > 0)
+          if ((el_mode > 0) && has_light)
             glDisable (GL_LIGHTING);
         }
       else
@@ -2546,7 +2550,7 @@
                 }
             }
 
-          if (fl_mode > 0)
+          if ((fl_mode > 0) && has_light)
             glEnable (GL_LIGHTING);
 
           // NOTE: Push filled part of patch backwards to avoid Z-fighting with
@@ -2605,7 +2609,7 @@
               tess.end_polygon ();
             }
 
-          if (fl_mode > 0)
+          if ((fl_mode > 0) && has_light)
             glDisable (GL_LIGHTING);
         }
       else
@@ -2636,7 +2640,7 @@
                 }
             }
 
-          if (el_mode > 0)
+          if ((el_mode > 0) && has_light)
             glEnable (GL_LIGHTING);
 
           set_linestyle (props.get_linestyle (), false);
@@ -2728,7 +2732,7 @@
           set_linestyle ("-");
           set_linewidth (0.5);
 
-          if (el_mode > 0)
+          if ((el_mode > 0) && has_light)
             glDisable (GL_LIGHTING);
         }
       else
--- a/libinterp/corefcn/gl-render.h	Wed Mar 16 20:52:55 2016 -0700
+++ b/libinterp/corefcn/gl-render.h	Tue Mar 15 13:46:22 2016 +0100
@@ -191,6 +191,9 @@
 
   text_renderer txt_renderer;
 
+  // light object present and visible
+  bool has_light;
+
 private:
   class patch_tesselator;
 };