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,
00081         MIP_DEFAULT = -1
00082     };
00083 
00084     // Forward declaration
00085     class TexturePtr;
00086 
00096     class _OgreExport Texture : public Resource
00097     {
00098     public:
00099         Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
00100             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
00101 
00104         virtual void setTextureType(TextureType ttype ) { mTextureType = ttype; }
00105 
00108         virtual TextureType getTextureType(void) const { return mTextureType; }
00109 
00112         virtual size_t getNumMipmaps(void) const {return mNumMipmaps;}
00113 
00118         virtual void setNumMipmaps(size_t num) {mNumRequestedMipmaps = mNumMipmaps = num;}
00119 
00124         virtual bool getMipmapsHardwareGenerated(void) const { return mMipmapsHardwareGenerated; }
00125 
00128         virtual float getGamma(void) const { return mGamma; }
00129 
00138         virtual void setGamma(float g) { mGamma = g; }
00139 
00158         virtual void setHardwareGammaEnabled(bool enabled) { mHwGamma = enabled; }
00159 
00163         virtual bool isHardwareGammaEnabled() const { return mHwGamma; }
00164 
00170         virtual void setFSAA(uint fsaa) { mFSAA = fsaa; }
00171 
00175         virtual uint getFSAA() const { return mFSAA; }
00176 
00179         virtual size_t getHeight(void) const { return mHeight; }
00180 
00183         virtual size_t getWidth(void) const { return mWidth; }
00184 
00187         virtual size_t getDepth(void) const { return mDepth; }
00188 
00191         virtual size_t getSrcHeight(void) const { return mSrcHeight; }
00192 
00195         virtual size_t getSrcWidth(void) const { return mSrcWidth; }
00196 
00199         virtual size_t getSrcDepth(void) const { return mSrcDepth; }
00200 
00203         virtual void setHeight(size_t h) { mHeight = mSrcHeight = h; }
00204 
00207         virtual void setWidth(size_t w) { mWidth = mSrcWidth = w; }
00208 
00212         virtual void setDepth(size_t d)  { mDepth = mSrcDepth = d; }
00213 
00216         virtual int getUsage() const
00217         {
00218             return mUsage;
00219         }
00220 
00228         virtual void setUsage(int u) { mUsage = u; }
00229 
00241         virtual void createInternalResources(void);
00242 
00245         virtual void freeInternalResources(void);
00246         
00249         virtual void copyToTexture( TexturePtr& target );
00250 
00257         virtual void loadImage( const Image &img );
00258             
00269         virtual void loadRawData( DataStreamPtr& stream, 
00270             ushort uWidth, ushort uHeight, PixelFormat eFormat);
00271 
00277         virtual void _loadImages( const ConstImagePtrList& images );
00278 
00280         virtual PixelFormat getFormat() const
00281         {
00282             return mFormat;
00283         }
00284 
00286         virtual PixelFormat getDesiredFormat(void) const
00287         {
00288             return mDesiredFormat;
00289         }
00290 
00294         virtual PixelFormat getSrcFormat(void) const
00295         {
00296             return mSrcFormat;
00297         }
00298 
00300         virtual void setFormat(PixelFormat pf);
00301 
00303         virtual bool hasAlpha(void) const;
00304 
00310         virtual void setDesiredIntegerBitDepth(ushort bits);
00311 
00314         virtual ushort getDesiredIntegerBitDepth(void) const;
00315 
00321         virtual void setDesiredFloatBitDepth(ushort bits);
00322 
00325         virtual ushort getDesiredFloatBitDepth(void) const;
00326 
00329         virtual void setDesiredBitDepths(ushort integerBits, ushort floatBits);
00330 
00333         virtual void setTreatLuminanceAsAlpha(bool asAlpha);
00334 
00337         virtual bool getTreatLuminanceAsAlpha(void) const;
00338 
00342         virtual size_t getNumFaces() const;
00343 
00356         virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) = 0;
00357 
00358     protected:
00359         size_t mHeight;
00360         size_t mWidth;
00361         size_t mDepth;
00362 
00363         size_t mNumRequestedMipmaps;
00364         size_t mNumMipmaps;
00365         bool mMipmapsHardwareGenerated;
00366         float mGamma;
00367         bool mHwGamma;
00368         uint mFSAA;
00369 
00370         TextureType mTextureType;
00371         PixelFormat mFormat;
00372         int mUsage; // Bit field, so this can't be TextureUsage
00373 
00374         PixelFormat mSrcFormat;
00375         size_t mSrcWidth, mSrcHeight, mSrcDepth;
00376 
00377         PixelFormat mDesiredFormat;
00378         unsigned short mDesiredIntegerBitDepth;
00379         unsigned short mDesiredFloatBitDepth;
00380         bool mTreatLuminanceAsAlpha;
00381 
00382         bool mInternalResourcesCreated;
00383 
00385         size_t calculateSize(void) const;
00386         
00387 
00390         virtual void createInternalResourcesImpl(void) = 0;
00391 
00394         virtual void freeInternalResourcesImpl(void) = 0;
00395 
00397         void unloadImpl(void);
00398 
00402         String getSourceFileType() const;
00403 
00404     };
00405 
00412     class _OgreExport TexturePtr : public SharedPtr<Texture> 
00413     {
00414     public:
00415         TexturePtr() : SharedPtr<Texture>() {}
00416         explicit TexturePtr(Texture* rep) : SharedPtr<Texture>(rep) {}
00417         TexturePtr(const TexturePtr& r) : SharedPtr<Texture>(r) {} 
00418         TexturePtr(const ResourcePtr& r) : SharedPtr<Texture>()
00419         {
00420             // lock & copy other mutex pointer
00421             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
00422             {
00423                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00424                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00425                 pRep = static_cast<Texture*>(r.getPointer());
00426                 pUseCount = r.useCountPointer();
00427                 if (pUseCount)
00428                 {
00429                     ++(*pUseCount);
00430                 }
00431             }
00432         }
00433 
00435         TexturePtr& operator=(const ResourcePtr& r)
00436         {
00437             if (pRep == static_cast<Texture*>(r.getPointer()))
00438                 return *this;
00439             release();
00440             // lock & copy other mutex pointer
00441             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
00442             {
00443                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00444                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00445                 pRep = static_cast<Texture*>(r.getPointer());
00446                 pUseCount = r.useCountPointer();
00447                 if (pUseCount)
00448                 {
00449                     ++(*pUseCount);
00450                 }
00451             }
00452             else
00453             {
00454                 // RHS must be a null pointer
00455                 assert(r.isNull() && "RHS must be null if it has no mutex!");
00456                 setNull();
00457             }
00458             return *this;
00459         }
00460     };
00461 
00462 }
00463 
00464 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 27 22:02:26 2009