00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_INSTANCE_MATERIAL_USER_H
00027 #define NL_INSTANCE_MATERIAL_USER_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/3d/u_instance_material.h"
00031 #include "3d/material.h"
00032 #include "3d/texture_file.h"
00033 #include "3d/texture_multi_file.h"
00034
00035 #define NL3D_MEM_MATERIAL_INSTANCE NL_ALLOC_CONTEXT( 3dMatI )
00036
00037 namespace NL3D
00038 {
00039
00040
00041 class CMeshBaseInstance;
00042 class CInstanceUser;
00043 class CAsyncTextureBlock;
00044
00045
00046
00053 class CInstanceMaterialUser : public UInstanceMaterial
00054 {
00055 public:
00057 CInstanceMaterialUser(CMeshBaseInstance *mbi, CMaterial *mat, CAsyncTextureBlock *asyncTextBlock)
00058 {
00059 NL3D_MEM_MATERIAL_INSTANCE
00060 nlassert(mat && mbi && asyncTextBlock);
00061 _MBI= mbi;
00062 _Material= mat;
00063 _AsyncTextureBlock= asyncTextBlock;
00064 }
00066 virtual ~CInstanceMaterialUser()
00067 {
00068 NL3D_MEM_MATERIAL_INSTANCE
00069 }
00070
00071
00072
00074
00075 virtual bool isLighted() const
00076 {
00077 NL3D_MEM_MATERIAL_INSTANCE
00078 return _Material->isLighted();
00079 }
00080 virtual bool isUserColor() const
00081 {
00082 NL3D_MEM_MATERIAL_INSTANCE
00083 return _Material->getShader()==CMaterial::UserColor;
00084 }
00085
00086
00087
00089
00090
00091 virtual void setEmissive( CRGBA emissive=CRGBA(0,0,0) )
00092 {
00093 NL3D_MEM_MATERIAL_INSTANCE
00094 _Material->setEmissive(emissive);
00095 }
00096 virtual void setAmbient( CRGBA ambient=CRGBA(0,0,0) )
00097 {
00098 NL3D_MEM_MATERIAL_INSTANCE
00099 _Material->setAmbient( ambient);
00100 }
00101 virtual void setDiffuse( CRGBA diffuse=CRGBA(0,0,0) )
00102 {
00103 NL3D_MEM_MATERIAL_INSTANCE
00104 _Material->setDiffuse( diffuse);
00105 }
00106 virtual void setOpacity( uint8 opa )
00107 {
00108 NL3D_MEM_MATERIAL_INSTANCE
00109 _Material->setOpacity( opa );
00110 }
00111 virtual void setSpecular( CRGBA specular=CRGBA(0,0,0) )
00112 {
00113 NL3D_MEM_MATERIAL_INSTANCE
00114 _Material->setSpecular( specular);
00115 }
00116 virtual void setShininess( float shininess )
00117 {
00118 NL3D_MEM_MATERIAL_INSTANCE
00119 _Material->setShininess( shininess );
00120 }
00121
00122 virtual CRGBA getEmissive() const
00123 {
00124 NL3D_MEM_MATERIAL_INSTANCE
00125 return _Material->getEmissive();
00126 }
00127 virtual CRGBA getAmbient() const
00128 {
00129 NL3D_MEM_MATERIAL_INSTANCE
00130 return _Material->getAmbient();
00131 }
00132 virtual CRGBA getDiffuse() const
00133 {
00134 NL3D_MEM_MATERIAL_INSTANCE
00135 return _Material->getDiffuse();
00136 }
00137 virtual uint8 getOpacity() const
00138 {
00139 NL3D_MEM_MATERIAL_INSTANCE
00140 return _Material->getOpacity();
00141 }
00142 virtual CRGBA getSpecular() const
00143 {
00144 NL3D_MEM_MATERIAL_INSTANCE
00145 return _Material->getSpecular();
00146 }
00147 virtual float getShininess() const
00148 {
00149 NL3D_MEM_MATERIAL_INSTANCE
00150 return _Material->getShininess();
00151 }
00152
00153
00154
00155
00157
00158 virtual void setColor(CRGBA rgba)
00159 {
00160 NL3D_MEM_MATERIAL_INSTANCE
00161 _Material->setColor(rgba) ;
00162 }
00163 virtual CRGBA getColor(void) const
00164 {
00165 NL3D_MEM_MATERIAL_INSTANCE
00166 return _Material->getColor();
00167 }
00168
00169
00170
00172
00173 virtual void setUserColor(CRGBA userColor)
00174 {
00175 NL3D_MEM_MATERIAL_INSTANCE
00176 if(isUserColor())
00177 _Material->setUserColor(userColor);
00178 }
00179 virtual CRGBA getUserColor() const
00180 {
00181 NL3D_MEM_MATERIAL_INSTANCE
00182 if(isUserColor())
00183 return _Material->getUserColor();
00184 else
00185 return CRGBA(0,0,0,0);
00186 }
00187
00188
00190
00191 virtual void setConstantColor(uint stage, NLMISC::CRGBA color)
00192 {
00193 NL3D_MEM_MATERIAL_INSTANCE
00194 if (stage >= IDRV_MAT_MAXTEXTURES)
00195 {
00196 nlwarning("UInstanceMaterialUser::setConstantColor : invalid stage");
00197 return;
00198 }
00199 _Material->texConstantColor(stage, color);
00200 }
00201 virtual NLMISC::CRGBA getConstantColor(uint stage) const
00202 {
00203 NL3D_MEM_MATERIAL_INSTANCE
00204 if (stage >= IDRV_MAT_MAXTEXTURES)
00205 {
00206 nlwarning("UInstanceMaterialUser::getConstantColor : invalid stage");
00207 return NLMISC::CRGBA::Black;
00208 }
00209 return _Material->getTexConstantColor(stage);
00210
00211 }
00212
00213
00215
00216 virtual bool isTextureFile(uint stage = 0) const;
00217 virtual std::string getTextureFileName(uint stage = 0) const;
00218 virtual void setTextureFileName(const std::string &fileName, uint stage = 0);
00219
00220
00221 virtual void emptyTexture(uint stage = 0);
00222
00223
00224 virtual sint getLastTextureStage() const
00225 {
00226 NL3D_MEM_MATERIAL_INSTANCE
00227 sint lastStage = -1;
00228 for(uint k = 0; k < IDRV_MAT_MAXTEXTURES; ++k)
00229 {
00230 if (_Material->getTexture(k) != NULL)
00231 {
00232 lastStage = k;
00233 }
00234 }
00235 return lastStage;
00236 }
00237
00239
00240 virtual void setBlend(bool active)
00241 {
00242 NL3D_MEM_MATERIAL_INSTANCE
00243 _Material->setBlend(active);
00244 }
00245 virtual void setBlendFunc(TBlend src, TBlend dst)
00246 {
00247 NL3D_MEM_MATERIAL_INSTANCE
00248 _Material->setBlendFunc((CMaterial::TBlend)(uint32)src, (CMaterial::TBlend)(uint32)dst);
00249 }
00250 virtual void setSrcBlend(TBlend val)
00251 {
00252 NL3D_MEM_MATERIAL_INSTANCE
00253 _Material->setSrcBlend((CMaterial::TBlend)(uint32)val);
00254 }
00255 virtual void setDstBlend(TBlend val)
00256 {
00257 NL3D_MEM_MATERIAL_INSTANCE
00258 _Material->setDstBlend((CMaterial::TBlend)(uint32)val);
00259 }
00260
00261 virtual bool getBlend() const
00262 {
00263 NL3D_MEM_MATERIAL_INSTANCE
00264 return _Material->getBlend();
00265 }
00266 virtual TBlend getSrcBlend(void) const
00267 {
00268 NL3D_MEM_MATERIAL_INSTANCE
00269 return (UInstanceMaterial::TBlend)(uint32)_Material->getSrcBlend();
00270 }
00271 virtual TBlend getDstBlend(void) const
00272 {
00273 NL3D_MEM_MATERIAL_INSTANCE
00274 return (UInstanceMaterial::TBlend)(uint32)_Material->getDstBlend();
00275 }
00276
00277
00278
00279
00281
00282 virtual void enableUserTexMat(uint stage, bool enabled = true)
00283 {
00284 NL3D_MEM_MATERIAL_INSTANCE
00285 if (stage >= IDRV_MAT_MAXTEXTURES)
00286 {
00287 nlwarning("UInstanceMaterial::enableUserTexMat : stage %d is invalid", stage);
00288 return;
00289 }
00290 _Material->enableUserTexMat(stage, enabled);
00291 }
00292 virtual bool isUserTexMatEnabled(uint stage) const
00293 {
00294 NL3D_MEM_MATERIAL_INSTANCE
00295 if (stage >= IDRV_MAT_MAXTEXTURES)
00296 {
00297 nlwarning("UInstanceMaterial::enableUserTexMat : stage %d is invalid", stage);
00298 return false;
00299 }
00300 return _Material->isUserTexMatEnabled(stage);
00301 }
00302 virtual void setUserTexMat(uint stage, const NLMISC::CMatrix &m)
00303 {
00304 NL3D_MEM_MATERIAL_INSTANCE
00305 if (stage >= IDRV_MAT_MAXTEXTURES)
00306 {
00307 nlwarning("UInstanceMaterial::enableUserTexMat : stage %d is invalid", stage);
00308 return;
00309 }
00310 if (!_Material->isUserTexMatEnabled(stage))
00311 {
00312 nlwarning("UInstanceMaterial::setUserTexMat : texture stage %d has no user matrix.", stage);
00313 }
00314 _Material->setUserTexMat(stage, m);
00315 }
00316 virtual const NLMISC::CMatrix &getUserTexMat(uint stage) const
00317 {
00318 NL3D_MEM_MATERIAL_INSTANCE
00319 if (stage >= IDRV_MAT_MAXTEXTURES)
00320 {
00321 nlwarning("UInstanceMaterial::enableUserTexMat : stage %d is invalid", stage);
00322 return CMatrix::Identity;
00323 }
00324 if (!_Material->isUserTexMatEnabled(stage))
00325 {
00326 nlwarning("UInstanceMaterial::setUserTexMat : texture stage %d has no user matrix.", stage);
00327 return CMatrix::Identity;
00328 }
00329 return _Material->getUserTexMat(stage);
00330 }
00331
00332
00333 private:
00334 CMeshBaseInstance *_MBI;
00335 CMaterial *_Material;
00336 CAsyncTextureBlock *_AsyncTextureBlock;
00337
00338 public:
00339
00340
00341 CMaterial *getMaterial() const
00342 {
00343 NL3D_MEM_MATERIAL_INSTANCE
00344 return _Material;
00345 }
00346
00347 };
00348
00349
00350 }
00351
00352
00353 #endif // NL_INSTANCE_MATERIAL_USER_H
00354
00355