PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: TextureHandler.h * 00003 * 00004 * Copyright (C) 2002-2012 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_TEXTUREHANDLER_H__ 00024 #define __PLRENDERER_TEXTUREHANDLER_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Base/Event/EventHandler.h> 00032 #include <PLCore/Container/ResourceHandler.h> 00033 #include <PLMath/Matrix4x4.h> 00034 #include <PLGraphics/Color/Color4.h> 00035 #include "PLRenderer/PLRenderer.h" 00036 #include "PLRenderer/Texture/Texture.h" 00037 00038 00039 //[-------------------------------------------------------] 00040 //[ Namespace ] 00041 //[-------------------------------------------------------] 00042 namespace PLRenderer { 00043 00044 00045 //[-------------------------------------------------------] 00046 //[ Forward declarations ] 00047 //[-------------------------------------------------------] 00048 class Animation; 00049 00050 00051 //[-------------------------------------------------------] 00052 //[ Classes ] 00053 //[-------------------------------------------------------] 00054 /** 00055 * @brief 00056 * Texture handler class 00057 */ 00058 class TextureHandler : public PLCore::ResourceHandler<Texture> { 00059 00060 00061 //[-------------------------------------------------------] 00062 //[ Public classes ] 00063 //[-------------------------------------------------------] 00064 public: 00065 /** 00066 * @brief 00067 * Texture animation state 00068 */ 00069 class AnimationState { 00070 00071 00072 //[-------------------------------------------------------] 00073 //[ Friends ] 00074 //[-------------------------------------------------------] 00075 friend class TextureHandler; 00076 00077 00078 //[-------------------------------------------------------] 00079 //[ Public functions ] 00080 //[-------------------------------------------------------] 00081 public: 00082 /** 00083 * @brief 00084 * Returns the texture handlers texture 00085 * 00086 * @return 00087 * Pointer to the texture handlers texture, can be a null pointer 00088 */ 00089 PLRENDERER_API Texture *GetTexture() const; 00090 00091 /** 00092 * @brief 00093 * Returns the texture handler from a texture animation frame 00094 * 00095 * @param[in] nIndex 00096 * Index of the texture animation frame the handler should be returned. 00097 * < 0 if the texture handler from the current texture animation frame 00098 * should be returned 00099 * 00100 * @return 00101 * Pointer to the requested texture animation frame texture handlers, 00102 * a null pointer if there was an error or if nIndex = < 0 and the animation 00103 * is disabled 00104 */ 00105 PLRENDERER_API TextureHandler *GetFrameTextureHandler(int nIndex = -1) const; 00106 00107 /** 00108 * @brief 00109 * Returns the matrix from a matrix animation frame 00110 * 00111 * @param[in] nIndex 00112 * Index of the matrix animation frame the matrix should be returned. 00113 * < 0 if the matrix from the current matrix animation frame 00114 * should be returned 00115 * 00116 * @return 00117 * The requested matrix animation frame matrix, identity matrix if there 00118 * was an error or if nIndex = < 0 and the animation is disabled 00119 */ 00120 PLRENDERER_API PLMath::Matrix4x4 GetFrameMatrix(int nIndex = -1) const; 00121 00122 /** 00123 * @brief 00124 * Returns the texture animation 00125 * 00126 * @return 00127 * The texture handlers texture animation 00128 */ 00129 inline Animation &GetTextureAnimation(); 00130 00131 /** 00132 * @brief 00133 * Returns the matrix animation 00134 * 00135 * @return 00136 * The texture handlers matrix animation 00137 */ 00138 inline Animation &GetMatrixAnimation(); 00139 00140 /** 00141 * @brief 00142 * Returns the current texture transformation matrix 00143 * 00144 * @return 00145 * Current texture transformation matrix 00146 */ 00147 inline PLMath::Matrix4x4 &GetMatrix(); 00148 00149 /** 00150 * @brief 00151 * Returns the color animation 00152 * 00153 * @return 00154 * The texture handlers color animation 00155 */ 00156 inline Animation &GetColorAnimation(); 00157 00158 /** 00159 * @brief 00160 * Returns the current texture color 00161 * 00162 * @return 00163 * Current texture color 00164 */ 00165 inline const PLGraphics::Color4 &GetColor() const; 00166 00167 /** 00168 * @brief 00169 * Copy operator 00170 * 00171 * @param[in] cSource 00172 * Source to copy from 00173 * 00174 * @return 00175 * This instance 00176 */ 00177 PLRENDERER_API AnimationState &operator =(const AnimationState &cSource); 00178 00179 00180 //[-------------------------------------------------------] 00181 //[ Private functions ] 00182 //[-------------------------------------------------------] 00183 private: 00184 /** 00185 * @brief 00186 * Constructor 00187 * 00188 * @param[in] cTextureHandler 00189 * Owner texture handler 00190 */ 00191 AnimationState(TextureHandler &cTextureHandler); 00192 00193 /** 00194 * @brief 00195 * Destructor 00196 */ 00197 ~AnimationState(); 00198 00199 /** 00200 * @brief 00201 * Called on update 00202 */ 00203 void OnUpdate(); 00204 00205 00206 //[-------------------------------------------------------] 00207 //[ Private event handlers ] 00208 //[-------------------------------------------------------] 00209 private: 00210 PLCore::EventHandler<> EventHandlerUpdate; 00211 00212 00213 //[-------------------------------------------------------] 00214 //[ Private data ] 00215 //[-------------------------------------------------------] 00216 private: 00217 TextureHandler *m_pTextureHandler; /**< Owner texture handler (NEVER a null pointer!) */ 00218 Animation *m_pTextureAnimation; /**< Texture animation (NEVER a null pointer!) */ 00219 PLMath::Matrix4x4 m_mTrans; /**< Current texture transformation matrix */ 00220 Animation *m_pMatrixAnimation; /**< Matrix animation (NEVER a null pointer!) */ 00221 PLGraphics::Color4 m_cColor; /**< Current color */ 00222 Animation *m_pColorAnimation; /**< Color animation (NEVER a null pointer!) */ 00223 00224 00225 }; 00226 00227 00228 //[-------------------------------------------------------] 00229 //[ Public functions ] 00230 //[-------------------------------------------------------] 00231 public: 00232 /** 00233 * @brief 00234 * Constructor 00235 */ 00236 PLRENDERER_API TextureHandler(); 00237 00238 /** 00239 * @brief 00240 * Destructor 00241 */ 00242 PLRENDERER_API virtual ~TextureHandler(); 00243 00244 /** 00245 * @brief 00246 * Load texture 00247 * 00248 * @param[in] cTextureManager 00249 * Texture manager to use 00250 * @param[in] sFilename 00251 * Texture filename. It's also possible to create textures dynamically. 00252 * "Create PLRenderer::TextureCreatorASCII3D Name=\"ASCII3D\" ASCIIFilename=\"Data/Textures/PostProcess/Font.dds\"" 00253 * For instance will use the texture creator class 'PLRenderer::TextureCreatorASCII3D' 00254 * to create a texture with the name 'ASCII3D' and some parameters. 00255 * @param[in] bReloadTexture 00256 * Force texture itself to be reloaded? 00257 * 00258 * @return 00259 * 'true' if all went fine, else 'false' 00260 */ 00261 PLRENDERER_API bool Load(TextureManager &cTextureManager, const PLCore::String &sFilename, bool bReloadTexture = false); 00262 00263 /** 00264 * @brief 00265 * Unload texture 00266 * 00267 * @return 00268 * 'true' if all went fine, else 'false' 00269 */ 00270 PLRENDERER_API bool Unload(); 00271 00272 /** 00273 * @brief 00274 * Makes the texture handlers texture to the current renderer texture 00275 * 00276 * @param[in] nStage 00277 * Which texture stage? 00278 * 00279 * @return 00280 * 'true' if all went fine, else 'false' 00281 * 00282 * @note 00283 * - The texture handlers texture transformation matrix is also set! 00284 */ 00285 PLRENDERER_API bool Bind(PLCore::uint32 nStage = 0) const; 00286 00287 /** 00288 * @brief 00289 * Returns the texture handlers texture 00290 * 00291 * @return 00292 * Pointer to the texture handlers texture, can be a null pointer 00293 */ 00294 PLRENDERER_API Texture *GetTexture() const; 00295 00296 /** 00297 * @brief 00298 * Copy operator 00299 * 00300 * @param[in] cSource 00301 * Source to copy from 00302 * 00303 * @return 00304 * This instance 00305 */ 00306 PLRENDERER_API TextureHandler &operator =(const TextureHandler &cSource); 00307 00308 /** 00309 * @brief 00310 * Returns the texture animation state object (if there's one :) 00311 * 00312 * @return 00313 * The texture animation state object, a null pointer if there's no such object 00314 */ 00315 inline AnimationState *GetAnimationState() const; 00316 00317 00318 //[-------------------------------------------------------] 00319 //[ Private data ] 00320 //[-------------------------------------------------------] 00321 private: 00322 AnimationState *m_pAnimationState; /**< Texture animation state, can be a null pointer */ 00323 00324 00325 }; 00326 00327 00328 //[-------------------------------------------------------] 00329 //[ Namespace ] 00330 //[-------------------------------------------------------] 00331 } // PLRenderer 00332 00333 00334 //[-------------------------------------------------------] 00335 //[ Implementation ] 00336 //[-------------------------------------------------------] 00337 #include "PLRenderer/Texture/TextureHandler.inl" 00338 00339 00340 #endif // __PLRENDERER_TEXTUREHANDLER_H__
|