PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Material.h * 00003 * 00004 * Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLRENDERER_MATERIAL_MATERIAL_H__ 00024 #define __PLRENDERER_MATERIAL_MATERIAL_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Base/Event/Event.h> 00032 #include <PLCore/Container/Resource.h> 00033 #include <PLMath/Vector3.h> 00034 #include "PLRenderer/PLRenderer.h" 00035 00036 00037 //[-------------------------------------------------------] 00038 //[ Namespace ] 00039 //[-------------------------------------------------------] 00040 namespace PLRenderer { 00041 00042 00043 //[-------------------------------------------------------] 00044 //[ Forward declarations ] 00045 //[-------------------------------------------------------] 00046 class Effect; 00047 class Parameter; 00048 class TextureBuffer; 00049 class EffectHandler; 00050 class MaterialHandler; 00051 class MaterialManager; 00052 class ParameterManager; 00053 00054 00055 //[-------------------------------------------------------] 00056 //[ Classes ] 00057 //[-------------------------------------------------------] 00058 /** 00059 * @brief 00060 * Material resource class 00061 * 00062 * @remarks 00063 * A material is an abstract surface rendering description. Because a material is quite universal, this 00064 * resource has a special load implementation if a filename is given: 00065 * - If the given filename is a 'real' loadable material, (for instance 'Data/Materials/MyMaterial.mat') a 'Material' loader is used 00066 * - Else, if the given filename is a loadable effect, an 'Effect' loader is used 00067 * - Else, if the given filename is an texture animation 'tani', a texture animation is loaded 00068 * - Else, if the given filename is a loadable image, an 'Image' loader is used to load in a texture 00069 * - If there's a 'Create' in front of the given filename, an automatic texture is created 00070 * - Else, ERROR! :) 00071 * - The public static strings of this class are not any fixed function stuff, their only purpose is to 00072 * offer some 'standardized' attribute names you should use where ever possible instead of inventing new 00073 * ones that may lead to confusion! 00074 */ 00075 class Material : public PLCore::Resource<Material> { 00076 00077 00078 //[-------------------------------------------------------] 00079 //[ Friends ] 00080 //[-------------------------------------------------------] 00081 friend class MaterialManager; 00082 00083 00084 //[-------------------------------------------------------] 00085 //[ Public static data ] 00086 //[-------------------------------------------------------] 00087 public: 00088 static PLRENDERER_API const PLCore::String DiffuseMap; /**< 'DiffuseMap' string (other usual name: 'decal map') */ 00089 static PLRENDERER_API const PLCore::String LightMap; /**< 'LightMap' string (global ambient lighting) */ 00090 static PLRENDERER_API const PLCore::String AmbientOcclusionMap; /**< 'AmbientOcclusionMap' string (global ambient occlusion) */ 00091 static PLRENDERER_API const PLCore::String EmissiveMap; /**< 'EmissiveMap' string (other usual name: 'self illumination map') */ 00092 static PLRENDERER_API const PLCore::String ReflectionMap; /**< 'ReflectionMap' string (other usual name: 'environment map') */ 00093 static PLRENDERER_API const PLCore::String ReflectivityMap; /**< 'ReflectivityMap' string */ 00094 static PLRENDERER_API const PLCore::String NormalMap; /**< 'NormalMap' string */ 00095 static PLRENDERER_API const PLCore::String SpecularMap; /**< 'SpecularMap' string */ 00096 static PLRENDERER_API const PLCore::String HeightMap; /**< 'HeightMap' string (other usual name: 'bump map') */ 00097 00098 00099 //[-------------------------------------------------------] 00100 //[ Events ] 00101 //[-------------------------------------------------------] 00102 public: 00103 PLCore::Event<Parameter&> EventParameterChanged; /**< Parameter changed (created, destroyed, value changed) event, changed parameter as parameter */ 00104 00105 00106 //[-------------------------------------------------------] 00107 //[ Public functions ] 00108 //[-------------------------------------------------------] 00109 public: 00110 /** 00111 * @brief 00112 * Destructor 00113 */ 00114 PLRENDERER_API virtual ~Material(); 00115 00116 /** 00117 * @brief 00118 * Returns the material manager this material is in 00119 * 00120 * @return 00121 * The material manager this material is in 00122 */ 00123 inline MaterialManager &GetMaterialManager() const; 00124 00125 /** 00126 * @brief 00127 * Copy operator 00128 * 00129 * @param[in] cSource 00130 * Source to copy from 00131 * 00132 * @return 00133 * This instance 00134 */ 00135 PLRENDERER_API Material &operator =(const Material &cSource); 00136 00137 /** 00138 * @brief 00139 * Gets a material/effect parameter 00140 * 00141 * @param[in] sName 00142 * Parameter name 00143 * 00144 * @return 00145 * The requested parameter, a null pointer on error 00146 * 00147 * @remarks 00148 * While ParameterManager::GetParameter(<Name>) ONLY returns parameters within the 00149 * manager, this function will first look for a parameter with the given name within 00150 * this material. If there's no such parameter within the material, the function will 00151 * look for this parameter within it's own material list (sharing material parameters) 00152 * and finally within the used effect. Because an effect may be used by multiple 00153 * materials, try to add whenever possible an overwriting parameter to the material instead 00154 * manipulating the effect parameter by hand. 00155 */ 00156 PLRENDERER_API Parameter *GetParameter(const PLCore::String &sName) const; 00157 00158 /** 00159 * @brief 00160 * Gets a texture buffer 00161 * 00162 * @param[in] sName 00163 * Parameter name 00164 * 00165 * @return 00166 * The requested texture buffer, a null pointer on error 00167 * 00168 * @see 00169 * - GetParameter() 00170 */ 00171 PLRENDERER_API TextureBuffer *GetParameterTextureBuffer(const PLCore::String &sName) const; 00172 00173 /** 00174 * @brief 00175 * Returns the parameter manager of the material 00176 * 00177 * @return 00178 * The parameter manager of the material 00179 */ 00180 inline ParameterManager &GetParameterManager() const; 00181 00182 /** 00183 * @brief 00184 * Reloads all textures used direct or indirect by the material 00185 * 00186 * @return 00187 * 'true' if all went fine, else 'false' 00188 */ 00189 PLRENDERER_API bool ReloadTextures(); 00190 00191 //[-------------------------------------------------------] 00192 //[ Materials ] 00193 //[-------------------------------------------------------] 00194 /** 00195 * @brief 00196 * Returns the number of materials 00197 * 00198 * @return 00199 * The number of materials 00200 */ 00201 inline PLCore::uint32 GetNumOfMaterials() const; 00202 00203 /** 00204 * @brief 00205 * Adds a material 00206 * 00207 * @param[in] cMaterial 00208 * Material to add 00209 * 00210 * @return 00211 * 'true' if all went fine, else 'false' 00212 */ 00213 PLRENDERER_API bool AddMaterial(Material &cMaterial); 00214 00215 /** 00216 * @brief 00217 * Returns a material 00218 * 00219 * @param[in] nIndex 00220 * Index of the material to return 00221 * 00222 * @return 00223 * Pointer to the requested material, a null pointer on error 00224 */ 00225 PLRENDERER_API Material *GetMaterial(PLCore::uint32 nIndex) const; 00226 00227 /** 00228 * @brief 00229 * Removes a material 00230 * 00231 * @param[in] nIndex 00232 * Index of the material to remove 00233 * 00234 * @return 00235 * 'true' if all went fine, else 'false' 00236 */ 00237 PLRENDERER_API bool RemoveMaterial(PLCore::uint32 nIndex); 00238 00239 /** 00240 * @brief 00241 * Removes all materials 00242 * 00243 * @return 00244 * 'true' if all went fine, else 'false' 00245 */ 00246 PLRENDERER_API bool RemoveAllMaterials(); 00247 00248 //[-------------------------------------------------------] 00249 //[ Effect ] 00250 //[-------------------------------------------------------] 00251 /** 00252 * @brief 00253 * Returns the effect of the material 00254 * 00255 * @return 00256 * The effect of the material, a null pointer if there's no effect 00257 */ 00258 PLRENDERER_API Effect *GetEffect() const; 00259 00260 /** 00261 * @brief 00262 * Sets the effect of the material 00263 * 00264 * @param[in] pFX 00265 * The effect of the material, a null pointer if there's no effect 00266 */ 00267 PLRENDERER_API void SetEffect(Effect *pFX = nullptr); 00268 00269 /** 00270 * @brief 00271 * Returns whether the material should be blend or not 00272 * 00273 * @return 00274 * 'true' if the pass should be blend, else 'false' 00275 * 00276 * @remarks 00277 * This only a general setting whether the material is blend or not. 00278 * Because transparent objects should be rendered after all solid objects this 00279 * setting indicates when the object should be rendered. 00280 */ 00281 PLRENDERER_API bool GetBlend() const; 00282 00283 /** 00284 * @brief 00285 * Gets the number of render passes the current technique is using 00286 * 00287 * @return 00288 * Number of passes 00289 */ 00290 PLRENDERER_API PLCore::uint32 GetNumOfPasses() const; 00291 00292 /** 00293 * @brief 00294 * Setup the given path 00295 * 00296 * @param[in] nIndex 00297 * Index of the path to setup 00298 * 00299 * @return 00300 * 'true' if all went fine, else 'false' 00301 */ 00302 PLRENDERER_API bool SetupPass(PLCore::uint32 nIndex = 0) const; 00303 00304 00305 //[-------------------------------------------------------] 00306 //[ Private functions ] 00307 //[-------------------------------------------------------] 00308 private: 00309 /** 00310 * @brief 00311 * Constructor 00312 * 00313 * @param[in] cManager 00314 * Material manager using this resource 00315 * @param[in] sName 00316 * Resource name to set 00317 */ 00318 Material(MaterialManager &cManager, const PLCore::String &sName); 00319 00320 /** 00321 * @brief 00322 * Called when a parameter has been changed (created, destroyed, value changed) 00323 * 00324 * @param[in] cParameter 00325 * The changed parameter 00326 */ 00327 void OnParameterChanged(Parameter &cParameter); 00328 00329 00330 //[-------------------------------------------------------] 00331 //[ Private event handlers ] 00332 //[-------------------------------------------------------] 00333 private: 00334 PLCore::EventHandler<Parameter&> EventHandlerParameterChanged; 00335 00336 00337 //[-------------------------------------------------------] 00338 //[ Private data ] 00339 //[-------------------------------------------------------] 00340 private: 00341 ParameterManager *m_pParameterManager; /**< Parameter manager (NEVER a null pointer!) */ 00342 PLCore::Array<MaterialHandler*> m_lstMaterials; /**< List of materials */ 00343 EffectHandler *m_pFXHandler; /**< Effect handler, can be a null pointer */ 00344 00345 00346 //[-------------------------------------------------------] 00347 //[ Public virtual PLCore::Loadable functions ] 00348 //[-------------------------------------------------------] 00349 public: 00350 PLRENDERER_API virtual bool LoadByFilename(const PLCore::String &sFilename, const PLCore::String &sParams = "", const PLCore::String &sMethod = "") override; 00351 PLRENDERER_API virtual bool Reload() override; 00352 PLRENDERER_API virtual bool Unload() override; 00353 PLRENDERER_API virtual PLCore::String GetLoadableTypeName() const override; 00354 00355 00356 }; 00357 00358 00359 //[-------------------------------------------------------] 00360 //[ Namespace ] 00361 //[-------------------------------------------------------] 00362 } // PLRenderer 00363 00364 00365 //[-------------------------------------------------------] 00366 //[ Implementation ] 00367 //[-------------------------------------------------------] 00368 #include "PLRenderer/Material/Material.inl" 00369 00370 00371 #endif // __PLRENDERER_MATERIAL_MATERIAL_H__
|