Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGSimpleTexturedMaterial.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 //---------------------------------------------------------------------------
00040 //  Includes
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 /*----------------------- constructors & destructors ----------------------*/
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 /*----------------------------- class specific ----------------------------*/
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     // these two are very expensive, as they need to regenerate the
00116     // texture object, do only if really needed
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     // this is not as expensive, but why do it more often then needed?
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     return state;
00183 }
00184 
00185 void SimpleTexturedMaterial::rebuildState(void)
00186 {
00187     Inherited::rebuildState();
00188 
00189     prepareLocalChunks();
00190 
00191     _pState->addChunk(_textureChunk);
00192     _pState->addChunk(_texGenChunk);
00193 }
00194 
00195 bool SimpleTexturedMaterial::isTransparent(void) const
00196 {
00197     return Inherited::isTransparent() ||
00198            (getImage()!=NullFC &&
00199              (getImage()->hasAlphaChannel() && getEnvMode() != GL_DECAL)
00200           );
00201 }
00202 
00203 void SimpleTexturedMaterial::dump(     UInt32    OSG_CHECK_ARG(uiIndent),
00204                                   const BitVector OSG_CHECK_ARG(bvFlags)) const
00205 {
00206     SLOG << "Dump SimpleTexturedMaterial NI" << std::endl;
00207 }
00208 
00209 
00210 /* Create the chunks needed by this Material, one for the material properties,
00211    one for the optional transparency blending.
00212 */
00213 
00214 void SimpleTexturedMaterial::prepareLocalChunks(void)
00215 {
00216     if(_textureChunk == NullFC)
00217     {
00218         _textureChunk = TextureChunk::create();
00219 
00220          addRefCP(_textureChunk);
00221     }
00222 
00223     if(_texGenChunk == NullFC)
00224     {
00225         _texGenChunk  = TexGenChunk::create();
00226 
00227         addRefCP(_texGenChunk);
00228     }
00229 }
00230 
00231 
00232 /*-------------------------------------------------------------------------*/
00233 /*                              cvs id's                                   */
00234 
00235 #ifdef OSG_SGI_CC
00236 #pragma set woff 1174
00237 #endif
00238 
00239 #ifdef OSG_LINUX_ICC
00240 #pragma warning(disable : 177)
00241 #endif
00242 
00243 namespace
00244 {
00245     static Char8 cvsid_cpp[] = "@(#)$Id: $";
00246     static Char8 cvsid_hpp[] = OSGSIMPLETEXTUREDMATERIAL_HEADER_CVSID;
00247     static Char8 cvsid_inl[] = OSGSIMPLETEXTUREDMATERIAL_INLINE_CVSID;
00248 
00249     static Char8 cvsid_fields_hpp[] = OSGSIMPLETEXTUREDMATERIALFIELDS_HEADER_CVSID;
00250 }
00251 
00252 #ifdef __sgi
00253 #pragma reset woff 1174
00254 #endif
00255 
00256 

Generated on Thu Aug 25 04:10:14 2005 for OpenSG by  doxygen 1.4.3