OSGTwoSidedLightingChunk.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *               Copyright (C) 2000-2002 by the OpenSG Forum                 *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #include <cstdlib>
00040 #include <cstdio>
00041 
00042 #include <OSGConfig.h>
00043 
00044 #include <OSGGL.h>
00045 
00046 #include "OSGTwoSidedLightingChunk.h"
00047 #include <OSGWindow.h>
00048 #include <OSGDrawActionBase.h>
00049 #include <OSGCamera.h>
00050 
00051 OSG_USING_NAMESPACE
00052 
00053 // Documentation for this class is emited in the
00054 // OSGTwoSidedLightingChunkBase.cpp file.
00055 // To modify it, please change the .fcd file (OSGTwoSidedLightingChunk.fcd) and
00056 // regenerate the base file.
00057 
00058 /***************************************************************************\
00059  *                           Class variables                               *
00060 \***************************************************************************/
00061 
00062 StateChunkClass TwoSidedLightingChunk::_class("TwoSidedLighting");
00063 
00064 /***************************************************************************\
00065  *                           Class methods                                 *
00066 \***************************************************************************/
00067 
00068 void TwoSidedLightingChunk::initMethod(InitPhase ePhase)
00069 {
00070     Inherited::initMethod(ePhase);
00071 }
00072 
00073 /***************************************************************************\
00074  *                           Instance methods                              *
00075 \***************************************************************************/
00076 
00077 /*-------------------------------------------------------------------------*\
00078  -  private                                                                 -
00079 \*-------------------------------------------------------------------------*/
00080 
00081 TwoSidedLightingChunk::TwoSidedLightingChunk(void) :
00082      Inherited(        ),
00083     _state    (GL_FALSE)
00084 {
00085 }
00086 
00087 TwoSidedLightingChunk::TwoSidedLightingChunk(
00088     const TwoSidedLightingChunk &source) :
00089 
00090     Inherited(source),
00091     _state(source._state)
00092 {
00093 }
00094 
00095 TwoSidedLightingChunk::~TwoSidedLightingChunk(void)
00096 {
00097 }
00098 
00099 /*------------------------- Chunk Class Access ---------------------------*/
00100 
00101 const StateChunkClass *TwoSidedLightingChunk::getClass(void) const
00102 {
00103     return &_class;
00104 }
00105 
00106 /*------------------------------- Sync -----------------------------------*/
00107 
00108 void TwoSidedLightingChunk::changed(ConstFieldMaskArg whichField, 
00109                                     UInt32            origin,
00110                                     BitVector         details)
00111 {
00112     Inherited::changed(whichField, origin, details);
00113 }
00114 
00115 /*------------------------------ Output ----------------------------------*/
00116 
00117 void TwoSidedLightingChunk::dump(      UInt32    , 
00118                          const BitVector ) const
00119 {
00120     SLOG << "Dump TwoSidedLightingChunk NI" << std::endl;
00121 }
00122 
00123 /*------------------------------ State ------------------------------------*/
00124 
00125 void TwoSidedLightingChunk::activate (DrawEnv *pEnv, UInt32 idx)
00126 {
00127     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00128 }
00129 
00130 void TwoSidedLightingChunk::changeFrom(DrawEnv    *pEnv, 
00131                                        StateChunk *old_chunk, 
00132                                        UInt32      idx      )
00133 {
00134     TwoSidedLightingChunk *old = 
00135         dynamic_cast<TwoSidedLightingChunk *>(old_chunk);
00136 
00137     if(old == NULL)
00138     {
00139         FWARNING(( "TwoSidedLightingChunk::changeFrom: "
00140                    "caught non-TwoSidedLightingChunk!\n"));
00141         return;
00142     }
00143 
00144     // TwoSidedLightingChunk didn't change so do nothing.
00145     if(old == this)
00146         return;
00147 
00148     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00149 }
00150 
00151 void TwoSidedLightingChunk::deactivate(DrawEnv *pEnv, UInt32 idx)
00152 {
00153     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
00154 }
00155 
00156 
00157 /*-------------------------- Comparison -----------------------------------*/
00158 
00159 Real32 TwoSidedLightingChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
00160 {
00161     return 0;
00162 }
00163 
00164 bool TwoSidedLightingChunk::operator <(const StateChunk &other) const
00165 {
00166     return this < &other;
00167 }
00168 
00169 bool TwoSidedLightingChunk::operator ==(const StateChunk &other) const
00170 {
00171     TwoSidedLightingChunk const *tother = 
00172                 dynamic_cast<TwoSidedLightingChunk const*>(&other);
00173 
00174     if(!tother)
00175         return false;
00176 
00177     if(tother == this)
00178         return true;
00179 
00180     return true;
00181 }
00182 
00183 bool TwoSidedLightingChunk::operator !=(const StateChunk &other) const
00184 {
00185     return !(*this == other);
00186 }