00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include "OSGConfig.h"
00047
00048 #include <OSGGL.h>
00049
00050 #include "OSGDrawActionBase.h"
00051 #include "OSGWindow.h"
00052
00053 #include "OSGBlendChunk.h"
00054
00055
00056 #ifndef GL_EXT_blend_color
00057 #define GL_CONSTANT_COLOR_EXT 0x8001
00058 #define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002
00059 #define GL_CONSTANT_ALPHA_EXT 0x8003
00060 #define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004
00061 #define GL_BLEND_COLOR_EXT 0x8005
00062 #endif
00063
00064 #ifndef GL_EXT_blend_minmax
00065 #define GL_FUNC_ADD_EXT 0x8006
00066 #define GL_MIN_EXT 0x8007
00067 #define GL_MAX_EXT 0x8008
00068 #define GL_BLEND_EQUATION_EXT 0x8009
00069 #endif
00070
00071 #ifndef GL_EXT_blend_subtract
00072 #define GL_FUNC_SUBTRACT_EXT 0x800A
00073 #define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B
00074 #endif
00075
00076 #ifndef GL_EXT_blend_func_separate
00077 #define GL_BLEND_DST_RGB_EXT 0x80C8
00078 #define GL_BLEND_SRC_RGB_EXT 0x80C9
00079 #define GL_BLEND_DST_ALPHA_EXT 0x80CA
00080 #define GL_BLEND_SRC_ALPHA_EXT 0x80CB
00081 #endif
00082
00083 #ifndef GL_EXT_blend_equation_separate
00084 #define GL_BLEND_EQUATION_RGB_EXT GL_BLEND_EQUATION
00085 #define GL_BLEND_EQUATION_ALPHA_EXT 0x883D
00086 #endif
00087
00088
00089 OSG_USING_NAMESPACE
00090
00091
00092
00093
00094
00095
00109
00110
00111
00112
00113 StateChunkClass BlendChunk::_class("Blend");
00114
00115 UInt32 BlendChunk::_extBlend;
00116 UInt32 BlendChunk::_extImaging;
00117 UInt32 BlendChunk::_extBlendSubtract;
00118 UInt32 BlendChunk::_extBlendMinMax;
00119 UInt32 BlendChunk::_extBlendLogicOp;
00120 UInt32 BlendChunk::_extBlendFuncSeparate;
00121 UInt32 BlendChunk::_funcBlendColor;
00122 UInt32 BlendChunk::_funcBlendEquation;
00123 UInt32 BlendChunk::_funcBlendEquationExt;
00124 UInt32 BlendChunk::_funcBlendFuncSeparateExt;
00125
00126
00127
00128
00129
00130 void BlendChunk::initMethod (void)
00131 {
00132 Inherited::initMethod();
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 BlendChunk::BlendChunk(void) :
00146 Inherited()
00147 {
00148 _extBlend =
00149 Window::registerExtension("GL_EXT_blend_color");
00150 _extImaging =
00151 Window::registerExtension("GL_ARB_imaging");
00152 _extBlendSubtract =
00153 Window::registerExtension("GL_EXT_blend_subtract");
00154 _extBlendMinMax =
00155 Window::registerExtension("GL_EXT_blend_minmax");
00156 _extBlendLogicOp =
00157 Window::registerExtension("GL_EXT_blend_logic_op");
00158 _extBlendFuncSeparate =
00159 Window::registerExtension("GL_EXT_blend_func_separate");
00160 _funcBlendColor = Window::registerFunction(
00161 OSG_DLSYM_UNDERSCORE"glBlendColorEXT", _extBlend);
00162 _funcBlendEquation = Window::registerFunction(
00163 OSG_DLSYM_UNDERSCORE"glBlendEquation", _extImaging);
00164 _funcBlendEquationExt = Window::registerFunction(
00165 OSG_DLSYM_UNDERSCORE"glBlendEquationEXT", _extBlendLogicOp);
00166 _funcBlendFuncSeparateExt = Window::registerFunction(
00167 OSG_DLSYM_UNDERSCORE"glBlendFuncSeparateEXT", _extBlendFuncSeparate);
00168 }
00169
00170 BlendChunk::BlendChunk(const BlendChunk &source) :
00171 Inherited(source)
00172 {
00173 }
00174
00175 BlendChunk::~BlendChunk(void)
00176 {
00177 }
00178
00179
00180
00181 const StateChunkClass *BlendChunk::getClass(void) const
00182 {
00183 return &_class;
00184 }
00185
00186
00187
00188 void BlendChunk::changed(BitVector whichField, UInt32 origin)
00189 {
00190 Inherited::changed(whichField, origin);
00191 }
00192
00193
00194
00195 void BlendChunk::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00196 const BitVector OSG_CHECK_ARG(bvFlags )) const
00197 {
00198 SLOG << "Dump BlendChunk NI" << std::endl;
00199 }
00200
00201
00202
00203 void BlendChunk::activate(DrawActionBase *action, UInt32)
00204 {
00205 GLenum src = _sfSrcFactor.getValue();
00206 GLenum dest = _sfDestFactor.getValue();
00207 GLenum asrc = _sfAlphaSrcFactor.getValue();
00208 GLenum adest = _sfAlphaDestFactor.getValue();
00209
00210 if(src != GL_ONE || dest != GL_ZERO ||
00211 (asrc != OSG_GL_UNUSED && asrc != GL_ONE) ||
00212 (adest != OSG_GL_UNUSED && adest != GL_ZERO)
00213 )
00214 {
00215 if(asrc != OSG_GL_UNUSED || adest != OSG_GL_UNUSED)
00216 {
00217 if(asrc == OSG_GL_UNUSED || adest == OSG_GL_UNUSED)
00218 {
00219 FWARNING(("BlendChunk::activate: only one of alpha src and"
00220 " alpha dest is set. Ignored.\n"));
00221 glBlendFunc(src, dest);
00222 }
00223 else if(action->getWindow()->hasExtension(_extBlendFuncSeparate))
00224 {
00225
00226 void (OSG_APIENTRY* blendfuncsep)(GLenum,GLenum,GLenum,GLenum) =
00227 (void (OSG_APIENTRY*)(GLenum,GLenum,GLenum,GLenum))
00228 action->getWindow()->getFunction(_funcBlendFuncSeparateExt);
00229
00230 blendfuncsep(src, dest, asrc, adest);
00231 }
00232 else
00233 {
00234 FWARNING(("BlendChunk::activate: Window %p doesn't "
00235 "support EXT_blend_func_separate, ignored.\n"));
00236 glBlendFunc(src, dest);
00237 }
00238 }
00239 else
00240 glBlendFunc(src, dest);
00241
00242
00243
00244 if((src >= GL_CONSTANT_COLOR_EXT &&
00245 src <= GL_ONE_MINUS_CONSTANT_ALPHA_EXT ) ||
00246 (dest >= GL_CONSTANT_COLOR_EXT &&
00247 dest <= GL_ONE_MINUS_CONSTANT_ALPHA_EXT ) ||
00248 (asrc >= GL_CONSTANT_COLOR_EXT &&
00249 asrc <= GL_ONE_MINUS_CONSTANT_ALPHA_EXT ) ||
00250 (adest >= GL_CONSTANT_COLOR_EXT &&
00251 adest <= GL_ONE_MINUS_CONSTANT_ALPHA_EXT )
00252 )
00253 {
00254 if(action->getWindow()->hasExtension(_extBlend))
00255 {
00256
00257 void (OSG_APIENTRY*blendcolor)(GLclampf red,GLclampf green,GLclampf blue,
00258 GLclampf alpha ) =
00259 (void (OSG_APIENTRY*)(GLclampf red,GLclampf green,GLclampf blue,
00260 GLclampf alpha))
00261 action->getWindow()->getFunction(_funcBlendColor);
00262
00263 blendcolor(_sfColor.getValue().red(),
00264 _sfColor.getValue().green(),
00265 _sfColor.getValue().blue(),
00266 _sfColor.getValue().alpha());
00267 }
00268 }
00269
00270 glEnable(GL_BLEND);
00271 }
00272
00273 if(_sfEquation.getValue() != GL_NONE)
00274 {
00275 if(action->getWindow()->hasExtension(_extImaging))
00276 {
00277
00278 void (OSG_APIENTRY* blendeq)(GLenum mode) =
00279 (void (OSG_APIENTRY*)(GLenum mode))
00280 action->getWindow()->getFunction(_funcBlendEquation);
00281
00282 blendeq(_sfEquation.getValue());
00283 }
00284 else if(action->getWindow()->hasExtension(_extBlendSubtract) ||
00285 action->getWindow()->hasExtension(_extBlendMinMax) ||
00286 action->getWindow()->hasExtension(_extBlendLogicOp))
00287 {
00288
00289 void (OSG_APIENTRY* blendeq)(GLenum mode) =
00290 (void (OSG_APIENTRY*)(GLenum mode))
00291 action->getWindow()->getFunction(_funcBlendEquationExt);
00292
00293 blendeq(_sfEquation.getValue());
00294 }
00295 }
00296
00297 if(_sfAlphaFunc.getValue() != GL_NONE)
00298 {
00299 glAlphaFunc(_sfAlphaFunc.getValue(), _sfAlphaValue.getValue());
00300 glEnable(GL_ALPHA_TEST);
00301 }
00302 }
00303
00304 void BlendChunk::changeFrom(DrawActionBase *action,
00305 StateChunk * old_chunk,
00306 UInt32 )
00307 {
00308 BlendChunk *old = dynamic_cast<BlendChunk *>(old_chunk);
00309
00310 GLenum src = _sfSrcFactor.getValue();
00311 GLenum dest = _sfDestFactor.getValue();
00312 GLenum osrc = old->_sfSrcFactor.getValue();
00313 GLenum odest = old->_sfDestFactor.getValue();
00314 GLenum asrc = _sfAlphaSrcFactor.getValue();
00315 GLenum adest = _sfAlphaDestFactor.getValue();
00316 GLenum oasrc = old->_sfAlphaSrcFactor.getValue();
00317 GLenum oadest = old->_sfAlphaDestFactor.getValue();
00318
00319 if(src != GL_ONE || dest != GL_ZERO ||
00320 (asrc != OSG_GL_UNUSED && asrc != GL_ONE) ||
00321 (adest != OSG_GL_UNUSED && adest != GL_ZERO)
00322 )
00323 {
00324 if(asrc != OSG_GL_UNUSED || adest != OSG_GL_UNUSED)
00325 {
00326 if(asrc == OSG_GL_UNUSED || adest == OSG_GL_UNUSED)
00327 {
00328 FWARNING(("BlendChunk::changeFrom: only one of alpha src and"
00329 " alpha dest is set. Ignored.\n"));
00330 glBlendFunc(src, dest);
00331 }
00332 else if(action->getWindow()->hasExtension(_extBlendFuncSeparate))
00333 {
00334 if(osrc != src || odest != dest ||
00335 oasrc != asrc || oadest != adest
00336 )
00337 {
00338
00339 void (OSG_APIENTRY* blendfuncsep)(GLenum,GLenum,
00340 GLenum,GLenum) =
00341 (void (OSG_APIENTRY*)(GLenum,GLenum,GLenum,GLenum))
00342 action->getWindow()->getFunction(
00343 _funcBlendFuncSeparateExt);
00344
00345 blendfuncsep(src, dest, asrc, adest);
00346 }
00347 }
00348 else
00349 {
00350 FWARNING(("BlendChunk::changeFrom: Window %p doesn't "
00351 "support EXT_blend_func_separate, ignored.\n"));
00352 glBlendFunc(src, dest);
00353 }
00354 }
00355 else if(osrc != src || odest != dest)
00356 glBlendFunc(src, dest);
00357
00358
00359
00360 if((src >= GL_CONSTANT_COLOR_EXT &&
00361 src <= GL_ONE_MINUS_CONSTANT_ALPHA_EXT ) ||
00362 (dest >= GL_CONSTANT_COLOR_EXT &&
00363 dest <= GL_ONE_MINUS_CONSTANT_ALPHA_EXT ) ||
00364 (asrc >= GL_CONSTANT_COLOR_EXT &&
00365 asrc <= GL_ONE_MINUS_CONSTANT_ALPHA_EXT ) ||
00366 (adest >= GL_CONSTANT_COLOR_EXT &&
00367 adest <= GL_ONE_MINUS_CONSTANT_ALPHA_EXT )
00368 )
00369 {
00370 if ( action->getWindow()->hasExtension(_extBlend ))
00371 {
00372
00373 void (OSG_APIENTRY*blendcolor)(GLclampf red,GLclampf green,GLclampf blue,
00374 GLclampf alpha ) =
00375 (void (OSG_APIENTRY*)(GLclampf red,GLclampf green,GLclampf blue,
00376 GLclampf alpha))
00377 action->getWindow()->getFunction( _funcBlendColor );
00378
00379 blendcolor(_sfColor.getValue().red(),
00380 _sfColor.getValue().green(),
00381 _sfColor.getValue().blue(),
00382 _sfColor.getValue().alpha());
00383 }
00384 }
00385
00386 if(osrc == GL_ONE && odest == GL_ZERO)
00387 glEnable(GL_BLEND);
00388 }
00389 else
00390 {
00391 if(osrc != GL_ONE || odest != GL_ZERO ||
00392 (oasrc != OSG_GL_UNUSED && oasrc != GL_ONE) ||
00393 (oadest != OSG_GL_UNUSED && oadest != GL_ZERO)
00394 )
00395 glDisable(GL_BLEND);
00396 }
00397
00398 if(_sfEquation.getValue() != old->_sfEquation.getValue())
00399 {
00400 if(action->getWindow()->hasExtension(_extImaging))
00401 {
00402
00403 void (OSG_APIENTRY* blendeq)(GLenum mode) =
00404 (void (OSG_APIENTRY*)(GLenum mode))
00405 action->getWindow()->getFunction(_funcBlendEquation);
00406
00407 blendeq(_sfEquation.getValue());
00408 }
00409 else if(action->getWindow()->hasExtension(_extBlendSubtract) ||
00410 action->getWindow()->hasExtension(_extBlendMinMax) ||
00411 action->getWindow()->hasExtension(_extBlendLogicOp))
00412 {
00413
00414 void (OSG_APIENTRY* blendeq)(GLenum mode) =
00415 (void (OSG_APIENTRY*)(GLenum mode))
00416 action->getWindow()->getFunction(_funcBlendEquationExt);
00417
00418 blendeq(_sfEquation.getValue());
00419 }
00420 }
00421
00422 if(_sfAlphaFunc.getValue() != GL_NONE)
00423 {
00424 if(old->_sfAlphaFunc.getValue() != _sfAlphaFunc.getValue() ||
00425 old->_sfAlphaValue.getValue() != _sfAlphaValue.getValue())
00426 glAlphaFunc(_sfAlphaFunc.getValue(), _sfAlphaValue.getValue());
00427
00428 if(old->_sfAlphaFunc.getValue() == GL_NONE)
00429 glEnable(GL_ALPHA_TEST);
00430 }
00431 else
00432 {
00433 if(old->_sfAlphaFunc.getValue() != GL_NONE)
00434 glDisable(GL_ALPHA_TEST);
00435 }
00436
00437 }
00438
00439 void BlendChunk::deactivate(DrawActionBase *action, UInt32 )
00440 {
00441 GLenum src = _sfSrcFactor.getValue();
00442 GLenum dest = _sfDestFactor.getValue();
00443 GLenum asrc = _sfAlphaSrcFactor.getValue();
00444 GLenum adest = _sfAlphaDestFactor.getValue();
00445
00446 if(src != GL_ONE || dest != GL_ZERO ||
00447 (asrc != OSG_GL_UNUSED && asrc != GL_ONE) ||
00448 (adest != OSG_GL_UNUSED && adest != GL_ZERO)
00449 )
00450 {
00451 glDisable(GL_BLEND);
00452 }
00453
00454 if(_sfEquation.getValue() != GL_NONE)
00455 {
00456 if(action->getWindow()->hasExtension(_extImaging))
00457 {
00458
00459 void (OSG_APIENTRY* blendeq)(GLenum mode) =
00460 (void (OSG_APIENTRY*)(GLenum mode))
00461 action->getWindow()->getFunction(_funcBlendEquation);
00462
00463 blendeq(GL_FUNC_ADD_EXT);
00464 }
00465 else if(action->getWindow()->hasExtension(_extBlendSubtract) ||
00466 action->getWindow()->hasExtension(_extBlendMinMax) ||
00467 action->getWindow()->hasExtension(_extBlendLogicOp))
00468 {
00469
00470 void (OSG_APIENTRY* blendeq)(GLenum mode) =
00471 (void (OSG_APIENTRY*)(GLenum mode))
00472 action->getWindow()->getFunction(_funcBlendEquationExt);
00473
00474 blendeq(GL_FUNC_ADD_EXT);
00475 }
00476 }
00477
00478 if(_sfAlphaFunc.getValue() != GL_NONE)
00479 {
00480 glDisable(GL_ALPHA_TEST);
00481 }
00482 }
00483
00484
00485
00486 bool BlendChunk::isTransparent(void) const
00487 {
00488 return getDestFactor() != GL_ZERO;
00489 }
00490
00491 Real32 BlendChunk::switchCost(StateChunk *)
00492 {
00493 return 0;
00494 }
00495
00496 bool BlendChunk::operator < (const StateChunk &other) const
00497 {
00498 return this < &other;
00499 }
00500
00501 bool BlendChunk::operator == (const StateChunk &other) const
00502 {
00503 BlendChunk const *tother = dynamic_cast<BlendChunk const*>(&other);
00504
00505 if(!tother)
00506 return false;
00507
00508 if(tother == this)
00509 return true;
00510
00511 if(getSrcFactor() != tother->getSrcFactor() ||
00512 getDestFactor() != tother->getDestFactor() ||
00513 getEquation() != tother->getEquation() ||
00514 getColor() != tother->getColor() ||
00515 getAlphaFunc() != tother->getAlphaFunc() ||
00516 getAlphaValue() != tother->getAlphaValue() )
00517 return false;
00518
00519 return true;
00520 }
00521
00522 bool BlendChunk::operator != (const StateChunk &other) const
00523 {
00524 return ! (*this == other);
00525 }
00526
00527
00528
00529
00530
00531 #ifdef OSG_SGI_CC
00532 #pragma set woff 1174
00533 #endif
00534
00535 #ifdef OSG_LINUX_ICC
00536 #pragma warning( disable : 177 )
00537 #endif
00538
00539 namespace
00540 {
00541 static Char8 cvsid_cpp [] = "@(#)$Id: FCTemplate_cpp.h,v 1.13 2002/06/01 10:37:25 vossg Exp $";
00542 static Char8 cvsid_hpp [] = OSGBLENDCHUNK_HEADER_CVSID;
00543 static Char8 cvsid_inl [] = OSGBLENDCHUNK_INLINE_CVSID;
00544
00545 static Char8 cvsid_fields_hpp[] = OSGBLENDCHUNKFIELDS_HEADER_CVSID;
00546 }
00547
00548 #ifdef __sgi
00549 #pragma reset woff 1174
00550 #endif
00551
00552