Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OgreTexture.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 
00024 You may alternatively use this source under the terms of a specific version of
00025 the OGRE Unrestricted License provided you have obtained such a license from
00026 Torus Knot Software Ltd.
00027 -----------------------------------------------------------------------------
00028 */
00029 #ifndef _Texture_H__
00030 #define _Texture_H__
00031 
00032 #include "OgrePrerequisites.h"
00033 #include "OgreHardwareBuffer.h"
00034 #include "OgreResource.h"
00035 #include "OgreImage.h"
00036 
00037 namespace Ogre {
00038 
00041     enum TextureUsage
00042     {
00044         TU_STATIC = HardwareBuffer::HBU_STATIC,
00045         TU_DYNAMIC = HardwareBuffer::HBU_DYNAMIC,
00046         TU_WRITE_ONLY = HardwareBuffer::HBU_WRITE_ONLY,
00047         TU_STATIC_WRITE_ONLY = HardwareBuffer::HBU_STATIC_WRITE_ONLY, 
00048         TU_DYNAMIC_WRITE_ONLY = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY,
00049         TU_DYNAMIC_WRITE_ONLY_DISCARDABLE = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE,
00051         TU_AUTOMIPMAP = 0x100,
00054         TU_RENDERTARGET = 0x200,
00056         TU_DEFAULT = TU_AUTOMIPMAP | TU_STATIC_WRITE_ONLY
00057         
00058     };
00059 
00062     enum TextureType
00063     {
00065         TEX_TYPE_1D = 1,
00067         TEX_TYPE_2D = 2,
00069         TEX_TYPE_3D = 3,
00071         TEX_TYPE_CUBE_MAP = 4
00072     };
00073 
00076     enum TextureMipmap
00077     {
00079         MIP_UNLIMITED = 0x7FFFFFFF
00080     };
00081 
00082     // Forward declaration
00083     class TexturePtr;
00084 
00094     class _OgreExport Texture : public Resource
00095     {
00096     public:
00097         Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
00098             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
00099 
00102         virtual void setTextureType(TextureType ttype ) { mTextureType = ttype; }
00103 
00106         virtual TextureType getTextureType(void) const { return mTextureType; }
00107 
00110         virtual size_t getNumMipmaps(void) const {return mNumMipmaps;}
00111 
00116         virtual void setNumMipmaps(size_t num) {mNumRequestedMipmaps = mNumMipmaps = num;}
00117 
00122         virtual bool getMipmapsHardwareGenerated(void) const { return mMipmapsHardwareGenerated; }
00123 
00126         virtual float getGamma(void) const { return mGamma; }
00127 
00132         virtual void setGamma(float g) { mGamma = g; }
00133 
00136         virtual size_t getHeight(void) const { return mHeight; }
00137 
00140         virtual size_t getWidth(void) const { return mWidth; }
00141 
00144         virtual size_t getDepth(void) const { return mDepth; }
00145 
00148         virtual size_t getSrcHeight(void) const { return mSrcHeight; }
00149 
00152         virtual size_t getSrcWidth(void) const { return mSrcWidth; }
00153 
00156         virtual size_t getSrcDepth(void) const { return mSrcDepth; }
00157 
00160         virtual void setHeight(size_t h) { mHeight = mSrcHeight = h; }
00161 
00164         virtual void setWidth(size_t w) { mWidth = mSrcWidth = w; }
00165 
00169         virtual void setDepth(size_t d)  { mDepth = mSrcDepth = d; }
00170 
00173         virtual int getUsage() const
00174         {
00175             return mUsage;
00176         }
00177 
00185         virtual void setUsage(int u) { mUsage = u; }
00186 
00198         virtual void createInternalResources(void);
00199 
00202         virtual void freeInternalResources(void);
00203         
00206         virtual void copyToTexture( TexturePtr& target );
00207 
00214         virtual void loadImage( const Image &img );
00215             
00226         virtual void loadRawData( DataStreamPtr& stream, 
00227             ushort uWidth, ushort uHeight, PixelFormat eFormat);
00228 
00234         virtual void _loadImages( const ConstImagePtrList& images );
00235 
00237         virtual PixelFormat getFormat() const
00238         {
00239             return mFormat;
00240         }
00241 
00243         virtual PixelFormat getDesiredFormat(void) const
00244         {
00245             return mDesiredFormat;
00246         }
00247 
00251         virtual PixelFormat getSrcFormat(void) const
00252         {
00253             return mSrcFormat;
00254         }
00255 
00257         virtual void setFormat(PixelFormat pf);
00258 
00260         virtual bool hasAlpha(void) const;
00261 
00267         virtual void setDesiredIntegerBitDepth(ushort bits);
00268 
00271         virtual ushort getDesiredIntegerBitDepth(void) const;
00272 
00278         virtual void setDesiredFloatBitDepth(ushort bits);
00279 
00282         virtual ushort getDesiredFloatBitDepth(void) const;
00283 
00286         virtual void setDesiredBitDepths(ushort integerBits, ushort floatBits);
00287 
00290         virtual void setTreatLuminanceAsAlpha(bool asAlpha);
00291 
00294         virtual bool getTreatLuminanceAsAlpha(void) const;
00295 
00299         virtual size_t getNumFaces() const;
00300 
00313         virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) = 0;
00314 
00315     protected:
00316         size_t mHeight;
00317         size_t mWidth;
00318         size_t mDepth;
00319 
00320         size_t mNumRequestedMipmaps;
00321         size_t mNumMipmaps;
00322         bool mMipmapsHardwareGenerated;
00323         float mGamma;
00324 
00325         TextureType mTextureType;
00326         PixelFormat mFormat;
00327         int mUsage; // Bit field, so this can't be TextureUsage
00328 
00329         PixelFormat mSrcFormat;
00330         size_t mSrcWidth, mSrcHeight, mSrcDepth;
00331 
00332         PixelFormat mDesiredFormat;
00333         unsigned short mDesiredIntegerBitDepth;
00334         unsigned short mDesiredFloatBitDepth;
00335         bool mTreatLuminanceAsAlpha;
00336 
00337         bool mInternalResourcesCreated;
00338 
00340         size_t calculateSize(void) const;
00341         
00342 
00345         virtual void createInternalResourcesImpl(void) = 0;
00346 
00349         virtual void freeInternalResourcesImpl(void) = 0;
00350 
00352         void unloadImpl(void);
00353 
00354     };
00355 
00362     class _OgreExport TexturePtr : public SharedPtr<Texture> 
00363     {
00364     public:
00365         TexturePtr() : SharedPtr<Texture>() {}
00366         explicit TexturePtr(Texture* rep) : SharedPtr<Texture>(rep) {}
00367         TexturePtr(const TexturePtr& r) : SharedPtr<Texture>(r) {} 
00368         TexturePtr(const ResourcePtr& r) : SharedPtr<Texture>()
00369         {
00370             // lock & copy other mutex pointer
00371             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
00372             {
00373                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00374                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00375                 pRep = static_cast<Texture*>(r.getPointer());
00376                 pUseCount = r.useCountPointer();
00377                 if (pUseCount)
00378                 {
00379                     ++(*pUseCount);
00380                 }
00381             }
00382         }
00383 
00385         TexturePtr& operator=(const ResourcePtr& r)
00386         {
00387             if (pRep == static_cast<Texture*>(r.getPointer()))
00388                 return *this;
00389             release();
00390             // lock & copy other mutex pointer
00391             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
00392             {
00393                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00394                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00395                 pRep = static_cast<Texture*>(r.getPointer());
00396                 pUseCount = r.useCountPointer();
00397                 if (pUseCount)
00398                 {
00399                     ++(*pUseCount);
00400                 }
00401             }
00402             else
00403             {
00404                 // RHS must be a null pointer
00405                 assert(r.isNull() && "RHS must be null if it has no mutex!");
00406                 setNull();
00407             }
00408             return *this;
00409         }
00410     };
00411 
00412 }
00413 
00414 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 25 13:03:17 2007