Hi Jens,

On Sat, 2004-02-14 at 07:07, J. Hoffmann wrote:
> Hello,
> 
> While I was playing with shadow maps, i discovered a problem in OSGBlendChunk:
> 
> OSGBlendChunk.cpp tests with "if(_sfSrcFactor.getValue() != GL_NONE)" whether 
> blending should be enabled (or disabled on change).
> However GL_NONE is the same value as GL_ZERO, which of course, is a valid 
> mode 
> for glBlendFunc(..).
> 
> e.g.: the blend function i used was:
> 
>  blend->setSrcFactor(GL_ZERO);
>  blend->setDestFactor(GL_ONE_MINUS_SRC_COLOR);
> 
> but, OSG thought that there is no blending necessary (src == GL_NONE)
> and did not enable blending :(

Yeah, I was hoping nobody would come up with a sensible case for GL_ZERO
src, looks like I was wrong.

> The proper solution seems to add an extra flag to decide, when to set
> blending and when not...

Hm, I don't really like that, as there are many other places where
GL_NONE is used to indicated deactivation, and I wouldn't want to change
all of them to make things consistent.

I looked at it again, and it shouldn't be a problem to fix it. After
all, no blending is equivalent to having GL_ONE, GL_ZERO blend
functions, and that's just as easy to check for as a GL_NONE src. I
attached a patch that does that, can you try if that fixes your problem?

Thanks

        Dirk

--- .backup/OSGBlendChunk.cpp   2004-02-14 10:03:18.000000000 -0600
+++ OSGBlendChunk.cpp   2004-02-14 10:10:34.000000000 -0600
@@ -162,10 +162,11 @@
 
 void BlendChunk::activate(DrawActionBase *action, UInt32)
 {
-    if(_sfSrcFactor.getValue() != GL_NONE)
+    GLenum src  = _sfSrcFactor.getValue();
+    GLenum dest = _sfDestFactor.getValue();
+
+    if(src != GL_ONE || dest != GL_ZERO)
     {
-        GLenum src  = _sfSrcFactor.getValue();
-        GLenum dest = _sfDestFactor.getValue();
         
         glBlendFunc(src, dest);
 
@@ -238,14 +239,16 @@
                             UInt32 )
 {
     BlendChunk *old = dynamic_cast<BlendChunk *>(old_chunk);
-    
-    if(_sfSrcFactor.getValue() != GL_NONE)
+
+    GLenum src  = _sfSrcFactor.getValue();
+    GLenum dest = _sfDestFactor.getValue();
+    GLenum osrc  = old->_sfSrcFactor.getValue();
+    GLenum odest = old->_sfDestFactor.getValue();
+
+    if(src != GL_ONE || dest != GL_ZERO)
     {
-        GLenum src  = _sfSrcFactor.getValue();
-        GLenum dest = _sfDestFactor.getValue();
         
-        if(old->_sfSrcFactor.getValue()  != src ||
-           old->_sfDestFactor.getValue() != dest)
+        if(osrc != src || odest != dest)
             glBlendFunc(src, dest);
 
 #if GL_EXT_blend_color
@@ -273,12 +276,12 @@
             }
         }
 #endif
-        if(old->_sfSrcFactor.getValue() == GL_NONE)
+        if(src == GL_ONE && dest == GL_ZERO)
             glEnable(GL_BLEND);
     }
     else
     {
-        if(old->_sfSrcFactor.getValue() != GL_NONE)
+        if(osrc != GL_ONE || odest != GL_ZERO)
             glDisable(GL_BLEND);
     }
 
@@ -330,7 +333,8 @@
 
 void BlendChunk::deactivate(DrawActionBase *action, UInt32 )
 {
-    if(_sfSrcFactor.getValue() != GL_NONE)
+    if(_sfSrcFactor.getValue()  != GL_ONE ||
+       _sfDestFactor.getValue() != GL_ZERO  )
     {
         glDisable(GL_BLEND);
     }

Reply via email to