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 #include <OSGGLU.h>
00050
00051 #include "OSGLightChunk.h"
00052
00053 OSG_USING_NAMESPACE
00054
00055
00056
00057
00058
00059
00075
00076
00077
00078
00079 StateChunkClass LightChunk::_class("Light", 8);
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 void LightChunk::initMethod (void)
00090 {
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 LightChunk::LightChunk(void) :
00105 Inherited()
00106 {
00107 }
00108
00109 LightChunk::LightChunk(const LightChunk &source) :
00110 Inherited(source)
00111 {
00112 }
00113
00114 LightChunk::~LightChunk(void)
00115 {
00116 }
00117
00118
00119
00120 const StateChunkClass *LightChunk::getClass(void) const
00121 {
00122 return &_class;
00123 }
00124
00125
00126
00127 void LightChunk::changed(BitVector whichField, UInt32 origin)
00128 {
00129 Inherited::changed(whichField, origin);
00130 }
00131
00132
00133
00134 void LightChunk::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00135 const BitVector OSG_CHECK_ARG(bvFlags )) const
00136 {
00137 SLOG << "Dump LightChunk NI" << std::endl;
00138 }
00139
00140
00141
00142
00143 void LightChunk::activate(DrawActionBase *, UInt32 index)
00144 {
00145 glErr("light:activate:precheck");
00146
00147 glLightfv(GL_LIGHT0 + index, GL_DIFFUSE,
00148 _sfDiffuse.getValue().getValuesRGBA());
00149 glLightfv(GL_LIGHT0 + index, GL_AMBIENT,
00150 _sfAmbient.getValue().getValuesRGBA());
00151 glLightfv(GL_LIGHT0 + index, GL_SPECULAR,
00152 _sfSpecular.getValue().getValuesRGBA());
00153 glLightfv(GL_LIGHT0 + index, GL_POSITION,
00154 _sfPosition.getValue().getValues());
00155 glLightf (GL_LIGHT0 + index, GL_CONSTANT_ATTENUATION,
00156 _sfConstantAttenuation.getValue());
00157 glLightf (GL_LIGHT0 + index, GL_LINEAR_ATTENUATION,
00158 _sfLinearAttenuation.getValue());
00159 glLightf (GL_LIGHT0 + index, GL_QUADRATIC_ATTENUATION,
00160 _sfQuadraticAttenuation.getValue());
00161
00162 glLightf( GL_LIGHT0 + index, GL_SPOT_CUTOFF, _sfCutoff.getValue());
00163
00164 if(_sfCutoff.getValue() < 180)
00165 {
00166 glLightfv(GL_LIGHT0 + index, GL_SPOT_DIRECTION,
00167 _sfDirection.getValue().getValues());
00168 glLightf( GL_LIGHT0 + index, GL_SPOT_EXPONENT, _sfExponent.getValue());
00169 }
00170 glEnable(GL_LIGHT0 + index);
00171
00172 glErr("light:activate:postcheck");
00173 }
00174
00175 void LightChunk::changeFrom(DrawActionBase *, StateChunk * old_chunk, UInt32 index)
00176 {
00177 glErr("light:changed:precheck");
00178
00179 LightChunk const *old = dynamic_cast<LightChunk const*>(old_chunk);
00180
00181
00182
00183 if(old == this)
00184 return;
00185
00186
00187
00188 glLightfv(GL_LIGHT0 + index, GL_DIFFUSE,
00189 _sfDiffuse.getValue().getValuesRGBA());
00190 glLightfv(GL_LIGHT0 + index, GL_AMBIENT,
00191 _sfAmbient.getValue().getValuesRGBA());
00192 glLightfv(GL_LIGHT0 + index, GL_SPECULAR,
00193 _sfSpecular.getValue().getValuesRGBA());
00194 glLightfv(GL_LIGHT0 + index, GL_POSITION,
00195 _sfPosition.getValue().getValues());
00196 glLightf (GL_LIGHT0 + index, GL_CONSTANT_ATTENUATION,
00197 _sfConstantAttenuation.getValue());
00198 glLightf (GL_LIGHT0 + index, GL_LINEAR_ATTENUATION,
00199 _sfLinearAttenuation.getValue());
00200 glLightf (GL_LIGHT0 + index, GL_QUADRATIC_ATTENUATION,
00201 _sfQuadraticAttenuation.getValue());
00202
00203 glLightf( GL_LIGHT0 + index, GL_SPOT_CUTOFF, _sfCutoff.getValue());
00204 if(_sfCutoff.getValue() < 180)
00205 {
00206 glLightfv(GL_LIGHT0 + index, GL_SPOT_DIRECTION,
00207 _sfDirection.getValue().getValues());
00208 glLightf( GL_LIGHT0 + index, GL_SPOT_EXPONENT, _sfExponent.getValue());
00209 }
00210
00211 glErr("light:changed:postcheck");
00212 }
00213
00214 void LightChunk::deactivate(DrawActionBase *, UInt32 index)
00215 {
00216 glDisable(GL_LIGHT0 + index);
00217 }
00218
00219
00220
00221
00222 Real32 LightChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
00223 {
00224 return 0;
00225 }
00226
00227 bool LightChunk::operator < (const StateChunk &other) const
00228 {
00229 return this < &other;
00230 }
00231
00232 bool LightChunk::operator == (const StateChunk &other) const
00233 {
00234 LightChunk const *tother = dynamic_cast<LightChunk const*>(&other);
00235
00236 if(!tother)
00237 return false;
00238
00239 if(tother == this)
00240 return true;
00241
00242 if(!getAmbient ().equals(tother->getAmbient (), Eps) ||
00243 !getDiffuse ().equals(tother->getDiffuse (), Eps) ||
00244 !getSpecular ().equals(tother->getSpecular (), Eps) ||
00245 !getPosition ().equals(tother->getPosition (), Eps) ||
00246 !getDirection().equals(tother->getDirection(), Eps) ||
00247 getConstantAttenuation() != tother->getConstantAttenuation() ||
00248 getLinearAttenuation() != tother->getLinearAttenuation() ||
00249 getQuadraticAttenuation() != tother->getQuadraticAttenuation() ||
00250 getCutoff() != tother->getCutoff() ||
00251 getExponent() != tother->getExponent()
00252 )
00253 return false;
00254
00255 return true;
00256 }
00257
00258 bool LightChunk::operator != (const StateChunk &other) const
00259 {
00260 return ! (*this == other);
00261 }
00262
00263
00264
00265
00266 #ifdef OSG_SGI_CC
00267 #pragma set woff 1174
00268 #endif
00269
00270 #ifdef OSG_LINUX_ICC
00271 #pragma warning( disable : 177 )
00272 #endif
00273
00274 namespace
00275 {
00276 static Char8 cvsid_cpp [] = "@(#)$Id: FCTemplate_cpp.h,v 1.13 2002/06/01 10:37:25 vossg Exp $";
00277 static Char8 cvsid_hpp [] = OSGLIGHTCHUNK_HEADER_CVSID;
00278 static Char8 cvsid_inl [] = OSGLIGHTCHUNK_INLINE_CVSID;
00279
00280 static Char8 cvsid_fields_hpp[] = OSGLIGHTCHUNKFIELDS_HEADER_CVSID;
00281 }
00282
00283 #ifdef __sgi
00284 #pragma reset woff 1174
00285 #endif
00286
00287