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 <OSGGLEXT.h>
00049
00050 #include "OSGLightModelChunk.h"
00051
00052 OSG_USING_NAMESPACE
00053
00054
00055
00056
00057
00062
00063
00064
00065
00066 StateChunkClass LightModelChunk::_class("LightModel");
00067
00068
00069
00070
00071
00072 void LightModelChunk::initMethod (void)
00073 {
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 LightModelChunk::LightModelChunk(void) :
00088 Inherited()
00089 {
00090 }
00091
00092 LightModelChunk::LightModelChunk(const LightModelChunk &source) :
00093 Inherited(source)
00094 {
00095 }
00096
00097 LightModelChunk::~LightModelChunk(void)
00098 {
00099 }
00100
00101
00102
00103 const StateChunkClass *LightModelChunk::getClass(void) const
00104 {
00105 return &_class;
00106 }
00107
00108 void LightModelChunk::changed(BitVector whichField, UInt32 origin)
00109 {
00110 Inherited::changed(whichField, origin);
00111 }
00112
00113 void LightModelChunk::dump( UInt32 ,
00114 const BitVector ) const
00115 {
00116 SLOG << "Dump LightModelChunk NI" << std::endl;
00117 }
00118
00119
00120
00121 void LightModelChunk::activate ( DrawActionBase * action, UInt32 idx )
00122 {
00123 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, _sfAmbient.getValue().getValuesRGBA());
00124
00125 const GLenum color_control = _sfColorControl.getValue();
00126 if(color_control == GL_SINGLE_COLOR ||
00127 color_control == GL_SEPARATE_SPECULAR_COLOR)
00128 {
00129 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, color_control);
00130 }
00131
00132 if(_sfLocalViewer.getValue())
00133 {
00134 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
00135 }
00136 else
00137 {
00138 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
00139 }
00140 }
00141
00142 void LightModelChunk::changeFrom( DrawActionBase *action, StateChunk *old_chunk, UInt32 idx )
00143 {
00144 LightModelChunk *old = dynamic_cast<LightModelChunk *>(old_chunk);
00145
00146 if(old == NULL)
00147 {
00148 FWARNING(( "LightModelChunk::changeFrom: caught non-LightModelChunk!\n"));
00149 return;
00150 }
00151
00152
00153 if(old == this)
00154 return;
00155
00156 if(old->_sfAmbient.getValue() != _sfAmbient.getValue())
00157 {
00158 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, _sfAmbient.getValue().getValuesRGBA());
00159 }
00160
00161 const GLenum color_control = _sfColorControl.getValue();
00162 if(color_control == GL_SINGLE_COLOR ||
00163 color_control == GL_SEPARATE_SPECULAR_COLOR &&
00164 color_control != old->_sfColorControl.getValue())
00165 {
00166 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, color_control);
00167 }
00168
00169 if(_sfLocalViewer.getValue() != old->_sfLocalViewer.getValue())
00170 {
00171 if(_sfLocalViewer.getValue())
00172 {
00173 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
00174 }
00175 else
00176 {
00177 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
00178 }
00179 }
00180 }
00181
00182 void LightModelChunk::deactivate ( DrawActionBase * action, UInt32 idx )
00183 {
00184 GLfloat ambient[] = {0.2f, 0.2f, 0.2f, 1.0f};
00185 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
00186
00187 if(_sfColorControl.getValue() != GL_SINGLE_COLOR)
00188 {
00189 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
00190 }
00191
00192 if(_sfLocalViewer.getValue())
00193 {
00194 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
00195 }
00196 }
00197
00198
00199
00200 Real32 LightModelChunk::switchCost(StateChunk *)
00201 {
00202 return 0;
00203 }
00204
00205 bool LightModelChunk::operator < (const StateChunk &other) const
00206 {
00207 return this < &other;
00208 }
00209
00210 bool LightModelChunk::operator == (const StateChunk &other) const
00211 {
00212 LightModelChunk const *tother = dynamic_cast<LightModelChunk const*>(&other);
00213
00214 if(!tother)
00215 return false;
00216
00217 if(tother == this)
00218 return true;
00219
00220 if(getAmbient() != tother->getAmbient() ||
00221 getColorControl() != tother->getColorControl() ||
00222 getLocalViewer() != tother->getLocalViewer() )
00223 return false;
00224
00225 return true;
00226 }
00227
00228 bool LightModelChunk::operator != (const StateChunk &other) const
00229 {
00230 return ! (*this == other);
00231 }
00232
00233
00234
00235
00236
00237 #ifdef OSG_SGI_CC
00238 #pragma set woff 1174
00239 #endif
00240
00241 #ifdef OSG_LINUX_ICC
00242 #pragma warning( disable : 177 )
00243 #endif
00244
00245 namespace
00246 {
00247 static Char8 cvsid_cpp [] = "@(#)$Id: OSGLightModelChunk.cpp,v 1.2 2005/12/16 11:05:45 a-m-z Exp $";
00248 static Char8 cvsid_hpp [] = OSGLIGHTMODELCHUNKBASE_HEADER_CVSID;
00249 static Char8 cvsid_inl [] = OSGLIGHTMODELCHUNKBASE_INLINE_CVSID;
00250
00251 static Char8 cvsid_fields_hpp[] = OSGLIGHTMODELCHUNKFIELDS_HEADER_CVSID;
00252 }
00253
00254 #ifdef __sgi
00255 #pragma reset woff 1174
00256 #endif
00257