PixelLightAPI  .
TextureManager.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: TextureManager.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_TEXTUREMANAGER_H__
00024 #define __PLRENDERER_TEXTUREMANAGER_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLCore/Container/ResourceManager.h>
00032 #include "PLRenderer/Texture/Texture.h"
00033 #include "PLRenderer/Texture/TextureHandler.h"
00034 
00035 
00036 //[-------------------------------------------------------]
00037 //[ Namespace                                             ]
00038 //[-------------------------------------------------------]
00039 namespace PLRenderer {
00040 
00041 
00042 //[-------------------------------------------------------]
00043 //[ Forward declarations                                  ]
00044 //[-------------------------------------------------------]
00045 class RendererContext;
00046 
00047 
00048 //[-------------------------------------------------------]
00049 //[ Classes                                               ]
00050 //[-------------------------------------------------------]
00051 /**
00052 *  @brief
00053 *    This is a manager for the texture resource
00054 *
00055 *  @note
00056 *    - Unloads unused resources automatically by default
00057 */
00058 class TextureManager : public PLCore::ResourceManager<Texture> {
00059 
00060 
00061     //[-------------------------------------------------------]
00062     //[ Friends                                               ]
00063     //[-------------------------------------------------------]
00064     friend class TextureHandler;
00065     friend class RendererContext;
00066 
00067 
00068     //[-------------------------------------------------------]
00069     //[ Public static data                                    ]
00070     //[-------------------------------------------------------]
00071     public:
00072         static PLRENDERER_API const PLCore::String Default; /**< Default texture */
00073 
00074 
00075     //[-------------------------------------------------------]
00076     //[ Public functions                                      ]
00077     //[-------------------------------------------------------]
00078     public:
00079         /**
00080         *  @brief
00081         *    Returns the owner renderer context of this manager
00082         *
00083         *  @return
00084         *    Reference to the owner renderer context of this manager
00085         */
00086         inline RendererContext &GetRendererContext() const;
00087 
00088         /**
00089         *  @brief
00090         *    Returns the texture quality
00091         *
00092         *  @return
00093         *    Texture quality, 1 best, 0 worst
00094         *
00095         *  @see
00096         *    - SetTextureQuality()
00097         */
00098         inline float GetTextureQuality() const;
00099 
00100         /**
00101         *  @brief
00102         *    Sets the texture quality
00103         *
00104         *  @param[in] fQuality
00105         *    Texture quality, 1.0 best, 0.0 worst, default is 1.0
00106         *
00107         *  @note
00108         *    - Only has an influence on newly loaded textures, not already loaded ones
00109         *    - If the given texture quality is outside the specified range, it's clamped automatically to the nearest borders
00110         */
00111         PLRENDERER_API void SetTextureQuality(float fQuality);
00112 
00113         /**
00114         *  @brief
00115         *    Returns whether the next lower valid texture size should be taken or
00116         *    the higher one
00117         *
00118         *  @return
00119         *    If 'true' the next lower valid texture size will be taken, if 'false'
00120         *    the next higher one is chosen
00121         *
00122         *  @remarks
00123         *    Normally the texture manager will automatically correct invalid texture sizes.
00124         *    With the texture fit setting you can setup whether the next lower or higher valid texture
00125         *    size is selected automatically.
00126         */
00127         inline bool GetTextureFit() const;
00128 
00129         /**
00130         *  @brief
00131         *    Sets whether the next lower valid texture size should be taken or
00132         *    the higher one
00133         *
00134         *  @param[in] bLower
00135         *    Should the next lower valid texture size be chosen? If
00136         *    'false' the next higher will be taken
00137         *
00138         *  @see
00139         *    - GetTextureFit()
00140         *
00141         *  @note
00142         *    - Only has an influence on newly loaded textures, not already loaded ones
00143         */
00144         inline void SetTextureFit(bool bLower = true);
00145 
00146         /**
00147         *  @brief
00148         *    Returns whether or not the usage of texture mipmaps is allowed
00149         *
00150         *  @return
00151         *    'true' if the usage of texture mipmaps is allowed, else 'false'
00152         *
00153         *  @see
00154         *    - SetTextureMipmapsAllowed()
00155         */
00156         inline bool AreTextureMipmapsAllowed() const;
00157 
00158         /**
00159         *  @brief
00160         *    Sets whether or not the usage of texture mipmaps is allowed
00161         *
00162         *  @param[in] bAllowed
00163         *    'true' if the usage of texture mipmaps is allowed, else 'false', default is 'true'
00164         *
00165         *  @note
00166         *    - Only has an influence on newly loaded textures, not already loaded ones
00167         */
00168         inline void SetTextureMipmapsAllowed(bool bAllowed);
00169 
00170         /**
00171         *  @brief
00172         *    Returns whether or not the usage of texture compression is allowed
00173         *
00174         *  @return
00175         *    'true' if the usage of texture compression is allowed, else 'false'
00176         *
00177         *  @see
00178         *    - SetTextureCompressionAllowed()
00179         */
00180         inline bool IsTextureCompressionAllowed() const;
00181 
00182         /**
00183         *  @brief
00184         *    Sets whether or not the usage of texture compression is allowed
00185         *
00186         *  @param[in] bAllowed
00187         *    'true' if the usage of texture compression is allowed, else 'false', default is 'true'
00188         *
00189         *  @note
00190         *    - Only has an influence on newly loaded textures, not already loaded ones
00191         */
00192         inline void SetTextureCompressionAllowed(bool bAllowed);
00193 
00194         /**
00195         *  @brief
00196         *    Reloads all textures
00197         *
00198         *  @return
00199         *    'true' if all went fine, else 'false'
00200         */
00201         PLRENDERER_API bool ReloadTextures();
00202 
00203         /**
00204         *  @brief
00205         *    Creates a new texture
00206         *
00207         *  @param[in] sName
00208         *    Texture name
00209         *  @param[in] cTextureBuffer
00210         *    Texture buffer to use
00211         *
00212         *  @return
00213         *    Pointer to the new texture, a null pointer on error
00214         *
00215         *  @remarks
00216         *    A texture wraps up a texture buffer for more comfortable usage within high-level components. In rare situations
00217         *    one texture buffer needs to be referenced by multiple textures - this is what this method is used for. When creating
00218         *    a texture with this method, the given texture buffer is just shared and therefore not automatically destroyed
00219         *    when the texture gets destroyed. If possible, try to avoid using this method because it's somewhat ugly!
00220         */
00221         PLRENDERER_API Texture *CreateTexture(const PLCore::String &sName, TextureBuffer &cTextureBuffer);
00222 
00223         /**
00224         *  @brief
00225         *    Creates a texture resource using a texture creator
00226         *
00227         *  @param[in] sName
00228         *    Texture creator class name (for instance "PLRenderer::TextureCreatorTurbulence3D")
00229         *  @param[in] sParameters
00230         *    Texture creator parameters. (for instance "XSize='64' YSize='32'")
00231         *    This parameters depend on the used texture creator.
00232         *
00233         *  @return
00234         *    Pointer to the created resource, a null pointer if there was an error
00235         *    (maybe unknown class or the class is not derived from 'PLRenderer::TextureCreator')
00236         */
00237         PLRENDERER_API Texture *CreateTexture(const PLCore::String &sName, const PLCore::String &sParameters);
00238 
00239 
00240     //[-------------------------------------------------------]
00241     //[ Private functions                                     ]
00242     //[-------------------------------------------------------]
00243     private:
00244         /**
00245         *  @brief
00246         *    Constructor
00247         *
00248         *  @param[in] cRendererContext
00249         *    Owner renderer context
00250         */
00251         TextureManager(RendererContext &cRendererContext);
00252 
00253         /**
00254         *  @brief
00255         *    Destructor
00256         */
00257         virtual ~TextureManager();
00258 
00259 
00260     //[-------------------------------------------------------]
00261     //[ Private data                                          ]
00262     //[-------------------------------------------------------]
00263     private:
00264         RendererContext *m_pRendererContext;            /**< Owner renderer context of this manager, always valid! */
00265         float            m_fTextureQuality;             /**< Texture quality, 1.0 best, 0.0 worst, default is 1.0 */
00266         bool             m_bTextureFitLower;            /**< Take the next lower valid texture size? */
00267         bool             m_bTextureMipmapsAllowed;      /**< Are texture mipmaps allowed? Default is 'true'. */
00268         bool             m_bTextureCompressionAllowed;  /**< Is texture compression allowed? Default is 'true'. */
00269 
00270 
00271     //[-------------------------------------------------------]
00272     //[ Private virtual PLCore::ResourceManager functions     ]
00273     //[-------------------------------------------------------]
00274     private:
00275         virtual Texture *CreateResource(const PLCore::String &sName) override;
00276 
00277 
00278 };
00279 
00280 
00281 //[-------------------------------------------------------]
00282 //[ Namespace                                             ]
00283 //[-------------------------------------------------------]
00284 } // PLRenderer
00285 
00286 
00287 //[-------------------------------------------------------]
00288 //[ Implementation                                        ]
00289 //[-------------------------------------------------------]
00290 #include "PLRenderer/Texture/TextureManager.inl"
00291 
00292 
00293 #endif // __PLRENDERER_TEXTUREMANAGER_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:04
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported