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 <OSGAction.h>
00051 #include <OSGDrawAction.h>
00052 #include <OSGGeometry.h>
00053
00054 #include <OSGStateChunk.h>
00055 #include <OSGState.h>
00056 #include <OSGMaterialChunk.h>
00057 #include <OSGImage.h>
00058
00059 #include "OSGSimpleTexturedMaterial.h"
00060
00061 OSG_USING_NAMESPACE
00062
00081
00082
00083 SimpleTexturedMaterial::SimpleTexturedMaterial(void) :
00084 Inherited()
00085 {
00086 }
00087
00088 SimpleTexturedMaterial::SimpleTexturedMaterial(
00089 const SimpleTexturedMaterial &source) :
00090
00091 Inherited(source)
00092 {
00093 }
00094
00095 SimpleTexturedMaterial::~SimpleTexturedMaterial(void)
00096 {
00097 subRefCP(_textureChunk);
00098 subRefCP(_texGenChunk);
00099 }
00100
00101
00102
00103 void SimpleTexturedMaterial::initMethod(void)
00104 {
00105 }
00106
00107 #if defined(OSG_WIN32_ICL) && !defined(OSG_CHECK_FIELDSETARG)
00108 #pragma warning (disable : 383)
00109 #endif
00110
00111 void SimpleTexturedMaterial::changed(BitVector whichField, UInt32 origin)
00112 {
00113 prepareLocalChunks();
00114
00115
00116
00117
00118 if(whichField & ImageFieldMask)
00119 {
00120 beginEditCP(_textureChunk, TextureChunk::ImageFieldMask);
00121
00122 _textureChunk->setImage(getImage());
00123
00124 endEditCP(_textureChunk, TextureChunk::ImageFieldMask);
00125 }
00126 if(whichField & MinFilterFieldMask || whichField & MagFilterFieldMask)
00127 {
00128 beginEditCP(_textureChunk, TextureChunk::MinFilterFieldMask |
00129 TextureChunk::MagFilterFieldMask);
00130
00131 _textureChunk->setMinFilter(getMinFilter());
00132 _textureChunk->setMagFilter(getMagFilter());
00133
00134 endEditCP(_textureChunk, TextureChunk::MinFilterFieldMask |
00135 TextureChunk::MagFilterFieldMask);
00136 }
00137
00138 if(whichField & EnvModeFieldMask)
00139 {
00140 beginEditCP(_textureChunk, TextureChunk::EnvModeFieldMask);
00141
00142 _textureChunk->setEnvMode(getEnvMode());
00143
00144 endEditCP(_textureChunk, TextureChunk::EnvModeFieldMask);
00145 }
00146 if(whichField & EnvMapFieldMask)
00147 {
00148 beginEditCP(_texGenChunk, TexGenChunk::GenFuncSFieldMask |
00149 TexGenChunk::GenFuncTFieldMask);
00150
00151 if (getEnvMap())
00152 {
00153 _texGenChunk->setGenFuncS(GL_SPHERE_MAP);
00154 _texGenChunk->setGenFuncT(GL_SPHERE_MAP);
00155 }
00156 else
00157 {
00158 _texGenChunk->setGenFuncS(GL_NONE);
00159 _texGenChunk->setGenFuncT(GL_NONE);
00160 }
00161
00162 endEditCP(_texGenChunk, TexGenChunk::GenFuncSFieldMask |
00163 TexGenChunk::GenFuncTFieldMask);
00164 }
00165
00166 Inherited::changed(whichField, origin);
00167 }
00168
00169 #if defined(OSG_WIN32_ICL) && !defined(OSG_CHECK_FIELDSETARG)
00170 #pragma warning (default : 383)
00171 #endif
00172
00173 StatePtr SimpleTexturedMaterial::makeState(void)
00174 {
00175 StatePtr state = Inherited::makeState();
00176
00177 prepareLocalChunks();
00178
00179 state->addChunk(_textureChunk);
00180 state->addChunk(_texGenChunk);
00181
00182 if(getImage() != NullFC &&
00183 getImage()->hasAlphaChannel() &&
00184 getEnvMode() != GL_DECAL)
00185 {
00186 if(getImage()->isAlphaBinary())
00187 {
00188 if(_blendChunk->getSrcFactor() == GL_SRC_ALPHA)
00189 {
00190 beginEditCP(_blendChunk);
00191 _blendChunk->setSrcFactor(GL_ONE);
00192 _blendChunk->setDestFactor(GL_ZERO);
00193 _blendChunk->setAlphaFunc(GL_NOTEQUAL);
00194 _blendChunk->setAlphaValue(0);
00195 endEditCP(_blendChunk);
00196 }
00197 }
00198 else
00199 {
00200 if(_blendChunk->getSrcFactor() != GL_SRC_ALPHA)
00201 {
00202 beginEditCP(_blendChunk);
00203 _blendChunk->setSrcFactor(GL_SRC_ALPHA);
00204 _blendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
00205 _blendChunk->setAlphaFunc(GL_NONE);
00206 _blendChunk->setAlphaValue(0);
00207 endEditCP(_blendChunk);
00208 }
00209 }
00210 }
00211
00212 return state;
00213 }
00214
00215 void SimpleTexturedMaterial::rebuildState(void)
00216 {
00217 Inherited::rebuildState();
00218
00219 prepareLocalChunks();
00220
00221 _pState->addChunk(_textureChunk);
00222 _pState->addChunk(_texGenChunk);
00223
00224 if(getImage() != NullFC &&
00225 getImage()->hasAlphaChannel() &&
00226 getEnvMode() != GL_DECAL)
00227 {
00228 if(getImage()->isAlphaBinary())
00229 {
00230 if(_blendChunk->getSrcFactor() == GL_SRC_ALPHA)
00231 {
00232 beginEditCP(_blendChunk);
00233 _blendChunk->setSrcFactor(GL_ONE);
00234 _blendChunk->setDestFactor(GL_ZERO);
00235 _blendChunk->setAlphaFunc(GL_NOTEQUAL);
00236 _blendChunk->setAlphaValue(0);
00237 endEditCP(_blendChunk);
00238 }
00239 }
00240 else
00241 {
00242 if(_blendChunk->getSrcFactor() != GL_SRC_ALPHA)
00243 {
00244 beginEditCP(_blendChunk);
00245 _blendChunk->setSrcFactor(GL_SRC_ALPHA);
00246 _blendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
00247 _blendChunk->setAlphaFunc(GL_NONE);
00248 _blendChunk->setAlphaValue(0);
00249 endEditCP(_blendChunk);
00250 }
00251 }
00252 }
00253 }
00254
00255 bool SimpleTexturedMaterial::isTransparent(void) const
00256 {
00257 return Inherited::isTransparent() ||
00258 (getImage()!=NullFC &&
00259 ( getImage()->hasAlphaChannel() &&
00260 getEnvMode() != GL_DECAL
00261 )
00262 );
00263 }
00264
00265 void SimpleTexturedMaterial::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00266 const BitVector OSG_CHECK_ARG(bvFlags)) const
00267 {
00268 SLOG << "Dump SimpleTexturedMaterial NI" << std::endl;
00269 }
00270
00271
00272
00273
00274
00275
00276 void SimpleTexturedMaterial::prepareLocalChunks(void)
00277 {
00278 if(_textureChunk == NullFC)
00279 {
00280 _textureChunk = TextureChunk::create();
00281
00282 addRefCP(_textureChunk);
00283 }
00284
00285 if(_texGenChunk == NullFC)
00286 {
00287 _texGenChunk = TexGenChunk::create();
00288
00289 addRefCP(_texGenChunk);
00290 }
00291 }
00292
00293
00294
00295
00296
00297 #ifdef OSG_SGI_CC
00298 #pragma set woff 1174
00299 #endif
00300
00301 #ifdef OSG_LINUX_ICC
00302 #pragma warning(disable : 177)
00303 #endif
00304
00305 namespace
00306 {
00307 static Char8 cvsid_cpp[] = "@(#)$Id: $";
00308 static Char8 cvsid_hpp[] = OSGSIMPLETEXTUREDMATERIAL_HEADER_CVSID;
00309 static Char8 cvsid_inl[] = OSGSIMPLETEXTUREDMATERIAL_INLINE_CVSID;
00310
00311 static Char8 cvsid_fields_hpp[] = OSGSIMPLETEXTUREDMATERIALFIELDS_HEADER_CVSID;
00312 }
00313
00314 #ifdef __sgi
00315 #pragma reset woff 1174
00316 #endif
00317
00318