# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

instance_material_user.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "std3d.h"
00027 
00028 #include "3d/instance_material_user.h"
00029 #include "3d/async_texture_block.h"
00030 #include "3d/mesh_base_instance.h"
00031 
00032 
00033 namespace NL3D
00034 {
00035 
00036 
00037 // ***************************************************************************
00038 bool                            CInstanceMaterialUser::isTextureFile(uint stage) const
00039 {
00040         NL3D_MEM_MATERIAL_INSTANCE
00041         if (stage >= IDRV_MAT_MAXTEXTURES)
00042         {
00043                 nlwarning("UInstanceMaterialUser::isTextureFile : invalid stage");
00044                 return false;
00045         }
00046         return dynamic_cast<CTextureFile *>(_Material->getTexture(stage)) != NULL;
00047 }
00048 
00049 // ***************************************************************************
00050 std::string                     CInstanceMaterialUser::getTextureFileName(uint stage) const
00051 {               
00052         NL3D_MEM_MATERIAL_INSTANCE
00053         if (stage >= IDRV_MAT_MAXTEXTURES)
00054         {
00055                 nlwarning("UInstanceMaterialUser::getTextureFileName : invalid stage");
00056                 return "";
00057         }
00058 
00059         // If Async mode
00060         if(_MBI->getAsyncTextureMode())
00061         {
00062                 nlassert(_AsyncTextureBlock->isTextureFile(stage));
00063                 // return name of the async one.
00064                 return _AsyncTextureBlock->TextureNames[stage];
00065         }
00066         else
00067         {
00068                 // return the name in the material
00069                 return NLMISC::safe_cast<CTextureFile *>(_Material->getTexture(stage))->getFileName();
00070         }
00071 }
00072 
00073 // ***************************************************************************
00074 void                            CInstanceMaterialUser::setTextureFileName(const std::string &fileName, uint stage)
00075 {
00076         NL3D_MEM_MATERIAL_INSTANCE
00077         if (stage >= IDRV_MAT_MAXTEXTURES)
00078         {
00079                 nlwarning("UInstanceMaterialUser::setTextureFileName : invalid stage");
00080                 return;
00081         }
00082 
00083         // If Async mode
00084         if(_MBI->getAsyncTextureMode())
00085         {
00086                 if(!_AsyncTextureBlock->isTextureFile(stage))
00087                 {
00088                         nlwarning("UInstanceMaterialUser::setTextureFileName : the texture is not a texture file");
00089                         return;
00090                 }
00091                 // replace the fileName
00092                 _AsyncTextureBlock->TextureNames[stage]= fileName;
00093                 // Flag the instance.
00094                 _MBI->setAsyncTextureDirty(true);
00095         }
00096         else
00097         {
00098                 CTextureFile *otherTex = dynamic_cast<CTextureFile *>(_Material->getTexture(stage));
00099                 if (!otherTex)
00100                 {
00101                         nlwarning("UInstanceMaterialUser::setTextureFileName : the texture is not a texture file");
00102                         return;
00103                 }
00104                 CTextureFile *tf = new CTextureFile(*otherTex);
00105                 tf->setFileName(fileName);
00106                 NLMISC::CSmartPtr<ITexture> old = _Material->getTexture(stage);
00107                 _Material->setTexture(stage, tf);
00108         }
00109 }
00110 
00111 // ***************************************************************************
00112 void CInstanceMaterialUser::emptyTexture(uint stage /*=0*/)
00113 {
00114         NL3D_MEM_MATERIAL_INSTANCE
00115         if (stage >= IDRV_MAT_MAXTEXTURES)
00116         {
00117                 nlwarning("UInstanceMaterialUser::emptyTexture : invalid stage");
00118                 return;
00119         }
00120         _Material->setTexture(stage, NULL);
00121 }
00122 
00123 
00124 
00125 } // NL3D