00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00060 if(_MBI->getAsyncTextureMode())
00061 {
00062 nlassert(_AsyncTextureBlock->isTextureFile(stage));
00063
00064 return _AsyncTextureBlock->TextureNames[stage];
00065 }
00066 else
00067 {
00068
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
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
00092 _AsyncTextureBlock->TextureNames[stage]= fileName;
00093
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 )
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 }