# HG changeset patch
# User Markus Mützel <markus.muetzel@gmx.de>
# Date 1489338521 -3600
#      Sun Mar 12 18:08:41 2017 +0100
# Node ID 8831523beb1439d61b956adeae7c8ee8cfa29a57
# Parent  f80dc6db9d185d88f10171becb382ac74694d02e
Add basic support of "FaceAlpha" for patches in OpenGL. (bug #39535)

* gl-render.cc (draw_patch): Pass alpha value of faces to OpenGL.
* doc/interpreter/genpropdoc.m: Add documentation for patch facealpha.
* scripts/plot/draw/patch.m: Add cross-reference to Patch Properties.

diff -r f80dc6db9d18 -r 8831523beb14 doc/interpreter/genpropdoc.m
--- a/doc/interpreter/genpropdoc.m	Tue Jul 12 22:19:54 2016 -0700
+++ b/doc/interpreter/genpropdoc.m	Sun Mar 12 18:08:41 2017 +0100
@@ -1292,8 +1292,16 @@
 @qcode{\"gouraud\"}.";
 
       case "facealpha"
-        s.doc = sprintf (doc_notimpl, "Transparency");
-        s.valid = valid_scalmat;
+        s.doc = "Transparency level of the faces of the patch object.  Only \
+double values are supported at present where a value of 0 means complete \
+transparency and a value of 1 means solid faces without transparency.  Setting \
+the property to @qcode{\"flat\"} or @qcode{\"interp\"} causes the faces to not \
+being rendered.  Additionally, the faces are not sorted from back to front \
+which might lead to unexpected results when rendering layered transparent \
+faces.";
+        s.valid = packopt ({"scalar", ...
+                            "@qcode{\"flat\"}", ...
+                            "@qcode{\"interp\"}"});
 
       case "facecolor"
         ## Don't provide a default value, and mark colorspec with
diff -r f80dc6db9d18 -r 8831523beb14 libinterp/corefcn/gl-render.cc
--- a/libinterp/corefcn/gl-render.cc	Tue Jul 12 22:19:54 2016 -0700
+++ b/libinterp/corefcn/gl-render.cc	Sun Mar 12 18:08:41 2017 +0100
@@ -488,7 +488,7 @@
 
           if (col.numel () == 3)
             {
-              glColor3dv (col.data ());
+              glColor4d (col(0), col(1), col(2), v->alpha);
               if (light_mode > 0)
                 {
                   float buf[4] = { 0, 0, 0, 1 };
@@ -2916,6 +2916,7 @@
     Matrix c;
     const Matrix n = props.get_vertexnormals ().matrix_value ();
     Matrix a;
+    double fa = 1.0;
 
     int nv = v.rows ();
     int nf = f.rows ();
@@ -3010,6 +3011,9 @@
         has_facealpha = ((a.numel () > 0) && (a.rows () == f.rows ()));
       }
 
+    if (fa_mode == 0)
+      fa = props.get_facealpha_double ();
+
     octave_idx_type fr = f.rows ();
     std::vector<vertex_data> vdata (f.numel ());
 
@@ -3046,7 +3050,9 @@
               else
                 cc(0) = c(idx,0), cc(1) = c(idx,1), cc(2) = c(idx,2);
             }
-          if (a.numel () > 0)
+          if (fa_mode == 0)
+            aa = fa;
+          else if (a.numel () > 0)
             {
               if (has_facealpha)
                 aa = a(i);
@@ -3063,11 +3069,11 @@
     if (! props.facecolor_is ("none"))
       {
         // FIXME: adapt to double-radio property
-        if (props.get_facealpha_double () == 1)
+        if (fa_mode == 0)
           {
             if (fc_mode == UNIFORM)
               {
-                glColor3dv (fcolor.data ());
+                glColor4d (fcolor(0), fcolor(1), fcolor(2), fa);
                 if (fl_mode > 0)
                   {
                     float cb[4] = { 0, 0, 0, 1 };
@@ -3122,7 +3128,7 @@
 
                         if (col.numel () == 3)
                           {
-                            glColor3dv (col.data ());
+                            glColor4d (col(0), col(1), col(2), fa);
                             if (fl_mode > 0)
                               {
                                 float cb[4] = { 0, 0, 0, 1 };
diff -r f80dc6db9d18 -r 8831523beb14 scripts/plot/draw/patch.m
--- a/scripts/plot/draw/patch.m	Tue Jul 12 22:19:54 2016 -0700
+++ b/scripts/plot/draw/patch.m	Sun Mar 12 18:08:41 2017 +0100
@@ -65,9 +65,10 @@
 ## object.
 ##
 ## Implementation Note: Patches are highly configurable objects.  To truly
-## customize them requires setting patch properties directly.  Useful patch
-## properties are: @qcode{"cdata"}, @qcode{"edgecolor"},
-## @qcode{"facecolor"}, @qcode{"faces"}, @qcode{"facevertexcdata"}.
+## customize them requires setting patch properties directly 
+## (@pxref{Patch Properties}).  Useful patch properties include: @qcode{"cdata"},
+## @qcode{"edgecolor"}, @qcode{"facecolor"}, @qcode{"faces"},
+## @qcode{"facevertexcdata"}.
 ## @seealso{fill, get, set}
 ## @end deftypefn
 
