From fc2dfcb1abd0e687c193e17659c896b6da859988 Mon Sep 17 00:00:00 2001
From: Ansgar Philippsen <ansgar.philippsen@gmail.com>
Date: Fri, 28 Jan 2011 12:23:17 -0500
Subject: [PATCH] fixed outline transparency; switched outline mode 1/2
 algorithms

---
 modules/gfx/src/gfx_object.cc   | 21 +++++++++++++--------
 modules/gfx/src/vertex_array.cc | 25 ++++++++++++++++---------
 modules/gfx/src/vertex_array.hh |  1 +
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/modules/gfx/src/gfx_object.cc b/modules/gfx/src/gfx_object.cc
index c6eec4a3a..c5f7fd2ac 100644
--- a/modules/gfx/src/gfx_object.cc
+++ b/modules/gfx/src/gfx_object.cc
@@ -148,17 +148,22 @@ void GfxObj::RenderGL(RenderPass pass)
       render_depth_only();
     } else if(pass==TRANSPARENT_RENDER_PASS) {
       if(GetOpacity()<1.0) {
-	render_depth_only();
-	CustomRenderGL(STANDARD_RENDER_PASS);
+        render_depth_only();
+        CustomRenderGL(STANDARD_RENDER_PASS);
+        if(outline_flag_) {
+          va_.SetOutlineMode(outline_mode_);
+          CustomRenderGL(pass);
+          va_.SetOutlineMode(0);
+        }
       }
     } else if(pass==STANDARD_RENDER_PASS) {
       if(GetOpacity()>=1.0) {
-	CustomRenderGL(STANDARD_RENDER_PASS);
-      }
-      if(outline_flag_) {
-	va_.SetOutlineMode(outline_mode_);
-	CustomRenderGL(pass);
-	va_.SetOutlineMode(0);
+        CustomRenderGL(STANDARD_RENDER_PASS);
+        if(outline_flag_) {
+          va_.SetOutlineMode(outline_mode_);
+          CustomRenderGL(pass);
+          va_.SetOutlineMode(0);
+        }
       }
     } else if(pass==GLOW_RENDER_PASS) {
       CustomRenderGL(GLOW_RENDER_PASS);
diff --git a/modules/gfx/src/vertex_array.cc b/modules/gfx/src/vertex_array.cc
index ce0f4b731..da22a3272 100644
--- a/modules/gfx/src/vertex_array.cc
+++ b/modules/gfx/src/vertex_array.cc
@@ -382,6 +382,7 @@ void IndexedVertexArray::SetOpacity(float o)
   for(EntryList::iterator it=entry_list_.begin();it!=entry_list_.end();++it) {
     it->c[3]=o;
   }
+  opacity_=o;
   FlagRefresh();
 }
 
@@ -436,7 +437,7 @@ void IndexedVertexArray::RenderGL()
     glCullFace(GL_FRONT);
     glEnable(GL_CULL_FACE);
     glShadeModel(GL_FLAT);
-    if(outline_mode_==1) {
+    if(outline_mode_==2) {
       glCallList(outline_mat_dlist_);
       glEnable(GL_POLYGON_OFFSET_LINE);
       glEnable(GL_POLYGON_OFFSET_POINT);
@@ -446,7 +447,7 @@ void IndexedVertexArray::RenderGL()
       glEnable(GL_LINE_SMOOTH);
       glDisable(GL_POINT_SMOOTH); // kills selfx fragment shader if enabled
       glDisable(GL_POLYGON_SMOOTH);
-    } else if(outline_mode_==2) {
+    } else if(outline_mode_==1) {
       glCallList(outline_mat_dlist_);
       glEnable(GL_POLYGON_OFFSET_LINE);
       glPolygonOffset(10.0,1.0);
@@ -459,7 +460,12 @@ void IndexedVertexArray::RenderGL()
       glDisable(GL_POLYGON_OFFSET_LINE);
       glDisable(GL_POLYGON_OFFSET_POINT);
       glDisable(GL_LINE_SMOOTH);
-      glDisable(GL_BLEND);
+      if(opacity_<1.0) {
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+      } else {
+        glDisable(GL_BLEND);
+      }
     }
   } else {
     // not in outline mode
@@ -473,17 +479,17 @@ void IndexedVertexArray::RenderGL()
     } else {
       glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
     }
-    if(color_mat_) {
-      glEnable(GL_COLOR_MATERIAL); 
-    } else {
-      glDisable(GL_COLOR_MATERIAL);
-    }
     if(cull_face_) {
       glEnable(GL_CULL_FACE);
     } else { 
       glDisable(GL_CULL_FACE); 
     }
   }
+  if(color_mat_) {
+    glEnable(GL_COLOR_MATERIAL); 
+  } else {
+    glDisable(GL_COLOR_MATERIAL);
+  }
   
   if(mode_&0x1) {
     if(outline_mode_>0) {
@@ -516,7 +522,7 @@ void IndexedVertexArray::RenderGL()
       glUniform1f(glGetUniformLocation(Shader::Instance().GetCurrentProgram(),"scalef"),outline_exp_factor_);
       glUniform4f(glGetUniformLocation(Shader::Instance().GetCurrentProgram(),"color"),
                   outline_exp_color_[0],outline_exp_color_[1],
-                  outline_exp_color_[2],outline_exp_color_[3]);
+                  outline_exp_color_[2],opacity_);
       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
       draw_ltq(use_buff);
 
@@ -663,6 +669,7 @@ void IndexedVertexArray::Reset()
   aalines_flag_=false;
   point_size_=2.0;
   line_halo_=0.0;
+  opacity_=1.0;
   outline_mode_=0;
   outline_width_=4.0;
   outline_mat_=Material(0.3,1.0,0.0,0.0,0.0);
diff --git a/modules/gfx/src/vertex_array.hh b/modules/gfx/src/vertex_array.hh
index 3883c2abe..240251948 100644
--- a/modules/gfx/src/vertex_array.hh
+++ b/modules/gfx/src/vertex_array.hh
@@ -211,6 +211,7 @@ class DLLEXPORT_OST_GFX IndexedVertexArray {
   bool aalines_flag_;
   float point_size_;
   float line_halo_;
+  float opacity_;
 
   int outline_mode_;
   float outline_width_;
-- 
GitLab