1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include <boost/bind.hpp>
48 #include "OSGConfig.h"
55 #include "OSGDrawEnv.h"
57 #include "OSGTextureEnvChunk.h"
58 #include "OSGTextureBaseChunk.h"
60 //#define OSG_DUMP_TEX
64 // Documentation for this class is emited in the
65 // OSGTextureEnvChunkBase.cpp file.
66 // To modify it, please change the .fcd file (OSGTextureEnvChunk.fcd) and
67 // regenerate the base file.
69 /***************************************************************************\
71 \***************************************************************************/
73 StateChunkClass
TextureEnvChunk::_class("TextureEnv", osgMaxTexImages
, 120);
75 UInt32
TextureEnvChunk::_extPointSprite
= Window::invalidExtensionID
;
76 UInt32
TextureEnvChunk::_extTextureShader
= Window::invalidExtensionID
;
77 UInt32
TextureEnvChunk::_extTextureShader2
= Window::invalidExtensionID
;
78 UInt32
TextureEnvChunk::_extTextureShader3
= Window::invalidExtensionID
;
79 UInt32
TextureEnvChunk::_extTextureLodBias
= Window::invalidExtensionID
;
81 /***************************************************************************\
83 \***************************************************************************/
85 /*-------------------------------------------------------------------------*\
87 \*-------------------------------------------------------------------------*/
89 void TextureEnvChunk::initMethod(InitPhase ePhase
)
91 Inherited::initMethod(ePhase
);
93 if(ePhase
== TypeObject::SystemPost
)
96 Window::registerExtension("GL_ARB_point_sprite" );
98 Window::registerExtension("GL_NV_texture_shader" );
100 Window::registerExtension("GL_NV_texture_shader2" );
102 Window::registerExtension("GL_NV_texture_shader3" );
104 Window::registerExtension("GL_EXT_texture_lod_bias");
106 Window::registerConstant(GL_MAX_TEXTURE_UNITS_ARB
);
107 Window::registerConstant(GL_MAX_TEXTURE_IMAGE_UNITS_ARB
);
108 Window::registerConstant(GL_MAX_TEXTURE_COORDS_ARB
);
112 /***************************************************************************\
114 \***************************************************************************/
116 /*-------------------------------------------------------------------------*\
118 \*-------------------------------------------------------------------------*/
121 /*------------- constructors & destructors --------------------------------*/
123 TextureEnvChunk::TextureEnvChunk(void) :
128 TextureEnvChunk::TextureEnvChunk(const TextureEnvChunk
&source
) :
133 TextureEnvChunk::~TextureEnvChunk(void)
137 /*------------------------- Chunk Class Access ---------------------------*/
139 const StateChunkClass
*TextureEnvChunk::getClass(void) const
144 /*------------------------------ State ------------------------------------*/
146 /*! Texture handler. Create/update a single texture.
147 Also used by derived CubeMap chunk.
150 void TextureEnvChunk::handleTextureShader(Window
*win
, GLenum bindtarget
)
152 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
153 if(!win
->hasExtension(_extTextureShader
))
155 if(getShaderOperation() != GL_NONE
)
156 FINFO(("NV Texture Shaders not supported on Window %p!\n",
157 static_cast<void *>(win
)));
161 glErr("textureShader precheck");
163 glTexEnvi(GL_TEXTURE_SHADER_NV
, GL_SHADER_OPERATION_NV
,
164 getShaderOperation());
166 glErr("textureShader setup: operation");
168 if(getShaderOperation() == GL_NONE
)
171 if(bindtarget
== GL_TEXTURE_3D
&& !win
->hasExtension(_extTextureShader2
))
173 FINFO(("NV Texture Shaders 2 not supported on Window %p!\n",
174 static_cast<void *>(win
)));
178 if(getShaderInput() != GL_NONE
)
180 glTexEnvi(GL_TEXTURE_SHADER_NV
, GL_PREVIOUS_TEXTURE_INPUT_NV
,
184 glErr("textureShader setup: input");
186 if(getShaderRGBADotProduct() != GL_NONE
)
188 glTexEnvi(GL_TEXTURE_SHADER_NV
,
189 GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV
,
190 getShaderRGBADotProduct());
193 glErr("textureShader setup: rgba dotprod");
195 if(getMFShaderOffsetMatrix()->size() == 4)
197 glTexEnvfv(GL_TEXTURE_SHADER_NV
, GL_OFFSET_TEXTURE_MATRIX_NV
,
198 &((*getMFShaderOffsetMatrix())[0]));
200 glErr("textureShader setup: offset matrix");
202 else if(getMFShaderOffsetMatrix()->size() != 0)
204 FWARNING(("TextureEnvChunk::handleTextureShader: shaderOffsetMatrix "
205 "has to have 4 entries, not %" PRISize
"!\n",
206 getMFShaderOffsetMatrix()->size() ));
209 glTexEnvf(GL_TEXTURE_SHADER_NV
, GL_OFFSET_TEXTURE_SCALE_NV
,
210 getShaderOffsetScale());
212 glErr("textureShader setup: offset scale");
214 glTexEnvf(GL_TEXTURE_SHADER_NV
, GL_OFFSET_TEXTURE_BIAS_NV
,
215 getShaderOffsetBias());
217 glErr("textureShader setup: offset bias");
221 if(getShaderCullModes() & 0x1)
223 cullmodes
[0] = GL_GEQUAL
;
227 cullmodes
[0] = GL_LESS
;
230 if(getShaderCullModes() & 0x2)
232 cullmodes
[1] = GL_GEQUAL
;
236 cullmodes
[1] = GL_LESS
;
239 if(getShaderCullModes() & 0x4)
241 cullmodes
[2] = GL_GEQUAL
;
245 cullmodes
[2] = GL_LESS
;
248 if(getShaderCullModes() & 0x8)
250 cullmodes
[3] = GL_GEQUAL
;
254 cullmodes
[3] = GL_LESS
;
257 glTexEnviv(GL_TEXTURE_SHADER_NV
, GL_CULL_MODES_NV
,
260 glErr("textureShader setup: cull modes");
262 glTexEnvfv(GL_TEXTURE_SHADER_NV
, GL_CONST_EYE_NV
,
263 getShaderConstEye().getValues());
265 glErr("textureShader setup: const eye");
271 glGetTexEnviv(GL_TEXTURE_SHADER_NV
, GL_SHADER_CONSISTENT_NV
,
275 FWARNING(("Texture shaders not consistent!\n"));
281 /*------------------------------- Sync -----------------------------------*/
283 /*! React to field changes.
284 Note: this function also handles CubeTexture changes, make sure to keep
285 it consistent with the cubeTexture specifics
288 void TextureEnvChunk::changed(ConstFieldMaskArg whichField
,
292 Inherited::changed(whichField
, origin
, details
);
295 bool TextureEnvChunk::isTransparent(void) const
297 // Even if the texture has alpha, the Blending is makes the sorting
298 // important, thus textures per se are not transparent
303 /*----------------------------- onCreate --------------------------------*/
305 void TextureEnvChunk::onCreate(const TextureEnvChunk
*source
)
307 Inherited::onCreate(source
);
310 void TextureEnvChunk::onCreateAspect(const TextureEnvChunk
*createAspect
,
311 const TextureEnvChunk
*source
)
313 Inherited::onCreateAspect(createAspect
, source
);
316 /*------------------------------ Output ----------------------------------*/
318 void TextureEnvChunk::dump( UInt32 uiIndent
,
319 const BitVector bvFlags
) const
321 Inherited::dump(uiIndent
, bvFlags
);
323 if((bvFlags
& EnvModeFieldMask
) != 0)
325 indentLog(uiIndent
, PLOG
);
327 << GLDefineMapper::the()->toString(_sfEnvMode
.getValue())
331 if((bvFlags
& EnvColorFieldMask
) != 0)
333 indentLog(uiIndent
, PLOG
);
334 PLOG
<< "envColor " << _sfEnvColor
.getValue() << "\n";
337 if((bvFlags
& EnvCombineRGBFieldMask
) != 0)
339 indentLog(uiIndent
, PLOG
);
340 PLOG
<< "envCombineRGB "
341 << GLDefineMapper::the()->toString(_sfEnvCombineRGB
.getValue())
345 if((bvFlags
& EnvCombineAlphaFieldMask
) != 0)
347 indentLog(uiIndent
, PLOG
);
348 PLOG
<< "envCombineAlpha "
349 << GLDefineMapper::the()->toString(_sfEnvCombineAlpha
.getValue())
353 if((bvFlags
& EnvScaleRGBFieldMask
) != 0)
355 indentLog(uiIndent
, PLOG
);
356 PLOG
<< "envScaleRGB "
357 << _sfEnvScaleRGB
.getValue()
361 if((bvFlags
& EnvScaleAlphaFieldMask
) != 0)
363 indentLog(uiIndent
, PLOG
);
364 PLOG
<< "envScaleAlpha "
365 << _sfEnvScaleAlpha
.getValue()
369 if((bvFlags
& EnvSource0RGBFieldMask
) != 0)
371 indentLog(uiIndent
, PLOG
);
372 PLOG
<< "envSource0RGB "
373 << GLDefineMapper::the()->toString(_sfEnvSource0RGB
.getValue())
377 if((bvFlags
& EnvSource1RGBFieldMask
) != 0)
379 indentLog(uiIndent
, PLOG
);
380 PLOG
<< "envSource1RGB "
381 << GLDefineMapper::the()->toString(_sfEnvSource1RGB
.getValue())
385 if((bvFlags
& EnvSource2RGBFieldMask
) != 0)
387 indentLog(uiIndent
, PLOG
);
388 PLOG
<< "envSource2RGB "
389 << GLDefineMapper::the()->toString(_sfEnvSource2RGB
.getValue())
393 if((bvFlags
& EnvSource0AlphaFieldMask
) != 0)
395 indentLog(uiIndent
, PLOG
);
396 PLOG
<< "envSource0Alpha "
397 << GLDefineMapper::the()->toString(_sfEnvSource0Alpha
.getValue())
401 if((bvFlags
& EnvSource1AlphaFieldMask
) != 0)
403 indentLog(uiIndent
, PLOG
);
404 PLOG
<< "envSource1Alpha "
405 << GLDefineMapper::the()->toString(_sfEnvSource1Alpha
.getValue())
409 if((bvFlags
& EnvSource2AlphaFieldMask
) != 0)
411 indentLog(uiIndent
, PLOG
);
412 PLOG
<< "envSource2Alpha "
413 << GLDefineMapper::the()->toString(_sfEnvSource2Alpha
.getValue())
417 if((bvFlags
& EnvOperand0RGBFieldMask
) != 0)
419 indentLog(uiIndent
, PLOG
);
420 PLOG
<< "envOperand0RGB "
421 << GLDefineMapper::the()->toString(_sfEnvOperand0RGB
.getValue())
425 if((bvFlags
& EnvOperand1RGBFieldMask
) != 0)
427 indentLog(uiIndent
, PLOG
);
428 PLOG
<< "envOperand1RGB "
429 << GLDefineMapper::the()->toString(_sfEnvOperand1RGB
.getValue())
433 if((bvFlags
& EnvOperand2RGBFieldMask
) != 0)
435 indentLog(uiIndent
, PLOG
);
436 PLOG
<< "envOperand2RGB "
437 << GLDefineMapper::the()->toString(_sfEnvOperand2RGB
.getValue())
441 if((bvFlags
& EnvOperand0AlphaFieldMask
) != 0)
443 indentLog(uiIndent
, PLOG
);
444 PLOG
<< "envOperand0Alpha "
445 << GLDefineMapper::the()->toString(_sfEnvOperand0Alpha
.getValue())
449 if((bvFlags
& EnvOperand1AlphaFieldMask
) != 0)
451 indentLog(uiIndent
, PLOG
);
452 PLOG
<< "envOperand1Alpha "
453 << GLDefineMapper::the()->toString(_sfEnvOperand1Alpha
.getValue())
457 if((bvFlags
& EnvOperand2AlphaFieldMask
) != 0)
459 indentLog(uiIndent
, PLOG
);
460 PLOG
<< "envOperand2Alpha "
461 << GLDefineMapper::the()->toString(_sfEnvOperand2Alpha
.getValue())
465 if((bvFlags
& PointSpriteFieldMask
) != 0)
467 indentLog(uiIndent
, PLOG
);
468 PLOG
<< "pointSprite " << _sfPointSprite
.getValue() << "\n";
471 if((bvFlags
& ShaderOperationFieldMask
) != 0)
473 indentLog(uiIndent
, PLOG
);
474 PLOG
<< "shaderOperationAlpha "
475 << GLDefineMapper::the()->toString(_sfShaderOperation
.getValue())
479 if((bvFlags
& ShaderInputFieldMask
) != 0)
481 indentLog(uiIndent
, PLOG
);
482 PLOG
<< "shaderInputAlpha "
483 << GLDefineMapper::the()->toString(_sfShaderInput
.getValue())
487 if((bvFlags
& ShaderOffsetMatrixFieldMask
) != 0)
489 indentLog(uiIndent
, PLOG
);
490 PLOG
<< "shaderOffsetMatrix " << "NIY" << "\n";
493 if((bvFlags
& ShaderOffsetScaleFieldMask
) != 0)
495 indentLog(uiIndent
, PLOG
);
496 PLOG
<< "shaderOffsetScale " << _sfShaderOffsetScale
.getValue() << "\n";
499 if((bvFlags
& ShaderOffsetBiasFieldMask
) != 0)
501 indentLog(uiIndent
, PLOG
);
502 PLOG
<< "shaderOffsetBias " << _sfShaderOffsetBias
.getValue() << "\n";
505 if((bvFlags
& ShaderRGBADotProductFieldMask
) != 0)
507 indentLog(uiIndent
, PLOG
);
508 PLOG
<< "shaderRGBADotProduct "
509 << GLDefineMapper::the()->toString(_sfShaderRGBADotProduct
.getValue())
513 if((bvFlags
& ShaderCullModesFieldMask
) != 0)
515 indentLog(uiIndent
, PLOG
);
516 PLOG
<< "shaderCullModes " << _sfShaderCullModes
.getValue() << "\n";
519 if((bvFlags
& ShaderConstEyeFieldMask
) != 0)
521 indentLog(uiIndent
, PLOG
);
522 PLOG
<< "shaderConstEye " << _sfShaderConstEye
.getValue() << "\n";
525 if((bvFlags
& LodBiasFieldMask
) != 0)
527 indentLog(uiIndent
, PLOG
);
528 PLOG
<< "lodBias " << _sfLodBias
.getValue() << "\n";
533 /*------------------------------ State ------------------------------------*/
536 void TextureEnvChunk::activate(DrawEnv
*pEnv
, UInt32 idx
)
538 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
539 pEnv
->incNumChunkChanges();
541 Window
*win
= pEnv
->getWindow();
543 Real32 nteximages
, ntexcoords
;
545 if((nteximages
= win
->getConstantValue(GL_MAX_TEXTURE_IMAGE_UNITS_ARB
)) ==
546 Window::unknownConstant
)
548 nteximages
= win
->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB
);
550 // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
551 if(nteximages
== Window::unknownConstant
)
555 if((ntexcoords
= win
->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB
)) ==
556 Window::unknownConstant
)
558 ntexcoords
= win
->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB
);
560 // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
561 if(ntexcoords
== Window::unknownConstant
)
565 if(idx
>= static_cast<UInt32
>(nteximages
))
568 FWARNING(("TextureEnvChunk::activate: Trying to bind image unit %d,"
569 " but Window %p only supports %lf!\n",
571 static_cast<void *>(win
),
577 if(TextureBaseChunk::activateTexture(win
, idx
) == true)
580 #ifdef GL_ARB_point_sprite
581 if(getPointSprite() && win
->hasExtOrVersion(_extPointSprite
, 0x0200))
583 if(idx
< static_cast<UInt32
>(ntexcoords
))
585 glTexEnvi(GL_POINT_SPRITE_ARB
, GL_COORD_REPLACE_ARB
, GL_TRUE
);
590 if(getLodBias() != 0.0f
&& win
->hasExtOrVersion(_extTextureLodBias
, 0x0104))
592 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
593 GL_TEXTURE_LOD_BIAS_EXT
,
597 Real32 ntexunits
= win
->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB
);
599 // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
600 if(ntexunits
== Window::unknownConstant
)
603 if(idx
< static_cast<UInt32
>(ntexunits
))
606 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, getEnvMode());
608 glTexEnvfv(GL_TEXTURE_ENV
,
609 GL_TEXTURE_ENV_COLOR
,
610 getEnvColor().getValuesRGBA());
612 if(getEnvMode() == GL_COMBINE_EXT
)
614 glTexEnvi(GL_TEXTURE_ENV
,
616 getEnvCombineRGB ());
618 glTexEnvf(GL_TEXTURE_ENV
,
622 glTexEnvi(GL_TEXTURE_ENV
,
624 getEnvSource0RGB ());
626 glTexEnvi(GL_TEXTURE_ENV
,
628 getEnvSource1RGB ());
630 glTexEnvi(GL_TEXTURE_ENV
,
632 getEnvSource2RGB ());
634 glTexEnvi(GL_TEXTURE_ENV
,
636 getEnvOperand0RGB());
638 glTexEnvi(GL_TEXTURE_ENV
,
640 getEnvOperand1RGB());
642 glTexEnvi(GL_TEXTURE_ENV
,
644 getEnvOperand2RGB());
647 glTexEnvi(GL_TEXTURE_ENV
,
648 GL_COMBINE_ALPHA_EXT
,
649 getEnvCombineAlpha ());
651 glTexEnvf(GL_TEXTURE_ENV
,
653 getEnvScaleAlpha ());
655 glTexEnvi(GL_TEXTURE_ENV
,
656 GL_SOURCE0_ALPHA_EXT
,
657 getEnvSource0Alpha ());
659 glTexEnvi(GL_TEXTURE_ENV
,
660 GL_SOURCE1_ALPHA_EXT
,
661 getEnvSource1Alpha ());
663 glTexEnvi(GL_TEXTURE_ENV
,
664 GL_SOURCE2_ALPHA_EXT
,
665 getEnvSource2Alpha ());
667 glTexEnvi(GL_TEXTURE_ENV
,
668 GL_OPERAND0_ALPHA_EXT
,
669 getEnvOperand0Alpha());
671 glTexEnvi(GL_TEXTURE_ENV
,
672 GL_OPERAND1_ALPHA_EXT
,
673 getEnvOperand1Alpha());
675 glTexEnvi(GL_TEXTURE_ENV
,
676 GL_OPERAND2_ALPHA_EXT
,
677 getEnvOperand2Alpha());
680 TextureEnvChunk::handleTextureShader(
682 pEnv
->getActiveTexTarget(idx
));
685 getShaderOperation() != GL_NONE
&&
686 win
->hasExtension(_extTextureShader
) == true )
688 glEnable(GL_TEXTURE_SHADER_NV
);
695 glErr("TextureEnvChunk::activate");
698 void TextureEnvChunk::changeFrom(DrawEnv
*pEnv
,
702 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
703 // change from me to me?
704 // this assumes I haven't changed in the meantime.
705 // is that a valid assumption?
709 pEnv
->incNumChunkChanges();
711 TextureEnvChunk
*oldp
= dynamic_cast<TextureEnvChunk
*>(old
);
713 glErr("TextureEnvChunk::changeFrom precheck");
715 Window
*win
= pEnv
->getWindow();
717 Real32 nteximages
, ntexcoords
;
719 if((nteximages
= win
->getConstantValue(GL_MAX_TEXTURE_IMAGE_UNITS_ARB
)) ==
720 Window::unknownConstant
)
722 nteximages
= win
->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB
);
724 // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
725 if(nteximages
== Window::unknownConstant
)
729 if((ntexcoords
= win
->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB
)) ==
730 Window::unknownConstant
)
732 ntexcoords
= win
->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB
);
734 // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
735 if(ntexcoords
== Window::unknownConstant
)
739 if(idx
>= nteximages
)
742 FWARNING(("TextureEnvChunk::changeFrom: Trying to bind image unit %d,"
743 " but Window %p only supports %lf!\n",
745 static_cast<void *>(win
),
751 if(TextureBaseChunk::activateTexture(win
, idx
))
752 return; // trying to use too many textures
754 #ifdef GL_ARB_point_sprite
757 if(oldp
->getPointSprite() != getPointSprite() &&
758 win
->hasExtOrVersion(_extPointSprite
, 0x0200))
760 glTexEnvi(GL_POINT_SPRITE_ARB
,
761 GL_COORD_REPLACE_ARB
,
767 if(oldp
->getLodBias() != getLodBias() &&
768 win
->hasExtOrVersion(_extTextureLodBias
, 0x0104))
770 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
771 GL_TEXTURE_LOD_BIAS_EXT
,
775 Real32 ntexunits
= win
->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB
);
777 // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
778 if(ntexunits
== Window::unknownConstant
)
783 if(oldp
->getEnvMode() != getEnvMode())
785 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, getEnvMode());
788 glTexEnvfv(GL_TEXTURE_ENV
,
789 GL_TEXTURE_ENV_COLOR
,
790 getEnvColor().getValuesRGBA());
792 if(getEnvMode() == GL_COMBINE_EXT
)
794 glTexEnvi(GL_TEXTURE_ENV
,
796 getEnvCombineRGB ());
798 glTexEnvf(GL_TEXTURE_ENV
,
802 glTexEnvi(GL_TEXTURE_ENV
,
804 getEnvSource0RGB ());
806 glTexEnvi(GL_TEXTURE_ENV
,
808 getEnvSource1RGB ());
810 glTexEnvi(GL_TEXTURE_ENV
,
812 getEnvSource2RGB ());
814 glTexEnvi(GL_TEXTURE_ENV
,
816 getEnvOperand0RGB());
818 glTexEnvi(GL_TEXTURE_ENV
,
820 getEnvOperand1RGB());
822 glTexEnvi(GL_TEXTURE_ENV
,
824 getEnvOperand2RGB());
828 glTexEnvi(GL_TEXTURE_ENV
,
829 GL_COMBINE_ALPHA_EXT
,
830 getEnvCombineAlpha ());
832 glTexEnvf(GL_TEXTURE_ENV
,
834 getEnvScaleAlpha ());
836 glTexEnvi(GL_TEXTURE_ENV
,
837 GL_SOURCE0_ALPHA_EXT
,
838 getEnvSource0Alpha ());
840 glTexEnvi(GL_TEXTURE_ENV
,
841 GL_SOURCE1_ALPHA_EXT
,
842 getEnvSource1Alpha ());
844 glTexEnvi(GL_TEXTURE_ENV
,
845 GL_SOURCE2_ALPHA_EXT
,
846 getEnvSource2Alpha ());
848 glTexEnvi(GL_TEXTURE_ENV
,
849 GL_OPERAND0_ALPHA_EXT
,
850 getEnvOperand0Alpha());
852 glTexEnvi(GL_TEXTURE_ENV
,
853 GL_OPERAND1_ALPHA_EXT
,
854 getEnvOperand1Alpha());
856 glTexEnvi(GL_TEXTURE_ENV
,
857 GL_OPERAND2_ALPHA_EXT
,
858 getEnvOperand2Alpha());
861 if(win
->hasExtension(_extTextureShader
))
863 if( getShaderOperation() != GL_NONE
&&
864 oldp
->getShaderOperation() == GL_NONE
)
866 handleTextureShader(win
,
867 pEnv
->getActiveTexTarget(idx
));
870 glEnable(GL_TEXTURE_SHADER_NV
);
872 else if( getShaderOperation() == GL_NONE
&&
873 oldp
->getShaderOperation() != GL_NONE
)
875 glTexEnvi(GL_TEXTURE_SHADER_NV
,
876 GL_SHADER_OPERATION_NV
,
881 glDisable(GL_TEXTURE_SHADER_NV
);
890 glErr("TextureEnvChunk::changeFrom");
894 void TextureEnvChunk::deactivate(DrawEnv
*pEnv
, UInt32 idx
)
896 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
897 Window
*win
= pEnv
->getWindow();
899 Real32 nteximages
, ntexcoords
;
901 if((nteximages
= win
->getConstantValue(GL_MAX_TEXTURE_IMAGE_UNITS_ARB
)) ==
902 Window::unknownConstant
)
904 nteximages
= win
->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB
);
906 // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
907 if(nteximages
== Window::unknownConstant
)
911 if((ntexcoords
= win
->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB
)) ==
912 Window::unknownConstant
)
914 ntexcoords
= win
->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB
);
916 // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
917 if(ntexcoords
== Window::unknownConstant
)
921 if(idx
>= static_cast<UInt32
>(nteximages
))
924 FWARNING(("CubeTextureEnvChunk::deactivate: Trying to bind image unit "
925 "%d, but Window %p only supports %lf!\n",
927 static_cast<void *>(win
),
933 bool isActive
= false;
935 #ifdef GL_ARB_point_sprite
936 if(getPointSprite() &&
937 win
->hasExtOrVersion(_extPointSprite
, 0x0200) &&
938 idx
< static_cast<UInt32
>(ntexcoords
) )
942 TextureBaseChunk::activateTexture(win
, idx
);
946 glTexEnvi(GL_POINT_SPRITE_ARB
, GL_COORD_REPLACE_ARB
, GL_FALSE
);
950 if(getLodBias() != 0.0f
&& win
->hasExtOrVersion(_extTextureLodBias
, 0x0104))
954 TextureBaseChunk::activateTexture(win
, idx
);
958 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
959 GL_TEXTURE_LOD_BIAS_EXT
,
964 Real32 ntexunits
= win
->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB
);
966 if(ntexunits
== Window::unknownConstant
)
969 if(idx
>= static_cast<UInt32
>(ntexunits
))
971 return; // tetxures >= MTU are not enabled and don't have an env
975 TextureBaseChunk::activateTexture(win
, idx
);
978 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
980 glTexEnvfv(GL_TEXTURE_ENV
,
981 GL_TEXTURE_ENV_COLOR
,
982 Vec4f::Null
.getValues());
984 if(getShaderOperation() != GL_NONE
&&
985 win
->hasExtension(_extTextureShader
))
987 glTexEnvi(GL_TEXTURE_SHADER_NV
, GL_SHADER_OPERATION_NV
, GL_NONE
);
990 glDisable(GL_TEXTURE_SHADER_NV
);
996 glErr("TextureEnvChunk::deactivate");
999 /*-------------------------- Comparison -----------------------------------*/
1001 Real32
TextureEnvChunk::switchCost(StateChunk
*OSG_CHECK_ARG(chunk
))
1006 bool TextureEnvChunk::operator < (const StateChunk
&other
) const
1008 return this < &other
;
1011 bool TextureEnvChunk::operator == (const StateChunk
&other
) const
1013 TextureEnvChunk
const *tother
=
1014 dynamic_cast<TextureEnvChunk
const*>(&other
);
1023 getEnvMode () == tother
->getEnvMode ();
1025 if(returnValue
== true && getEnvMode() == GL_COMBINE_EXT
)
1028 getEnvCombineRGB () == tother
->getEnvCombineRGB () &&
1030 getEnvSource0RGB () == tother
->getEnvSource0RGB () &&
1031 getEnvSource1RGB () == tother
->getEnvSource1RGB () &&
1032 getEnvSource2RGB () == tother
->getEnvSource2RGB () &&
1034 getEnvOperand0RGB() == tother
->getEnvOperand0RGB () &&
1035 getEnvOperand1RGB() == tother
->getEnvOperand1RGB () &&
1036 getEnvOperand2RGB() == tother
->getEnvOperand2RGB () &&
1038 getEnvCombineAlpha () == tother
->getEnvCombineAlpha () &&
1040 getEnvSource0Alpha () == tother
->getEnvSource0Alpha () &&
1041 getEnvSource1Alpha () == tother
->getEnvSource1Alpha () &&
1042 getEnvSource2Alpha () == tother
->getEnvSource2Alpha () &&
1044 getEnvOperand0Alpha() == tother
->getEnvOperand0Alpha() &&
1045 getEnvOperand1Alpha() == tother
->getEnvOperand1Alpha() &&
1046 getEnvOperand2Alpha() == tother
->getEnvOperand2Alpha();
1050 (( getEnvScaleRGB () - tother
->getEnvScaleRGB ()) <
1051 TypeTraits
<Real32
>::getDefaultEps() ) &&
1052 ((tother
->getEnvScaleRGB () - getEnvScaleRGB ()) <
1053 TypeTraits
<Real32
>::getDefaultEps() ) &&
1054 (( getEnvScaleAlpha() - tother
->getEnvScaleAlpha()) <
1055 TypeTraits
<Real32
>::getDefaultEps() ) &&
1056 ((tother
->getEnvScaleAlpha() - getEnvScaleAlpha()) <
1057 TypeTraits
<Real32
>::getDefaultEps() );
1063 bool TextureEnvChunk::operator != (const StateChunk
&other
) const
1065 return ! (*this == other
);