Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | 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-2005 The OGRE Team
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 */
00025 #ifndef _Texture_H__
00026 #define _Texture_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 #include "OgreHardwareBuffer.h"
00030 #include "OgreResource.h"
00031 #include "OgreImage.h"
00032 
00033 namespace Ogre {
00034 
00037     enum TextureUsage
00038     {
00040         TU_STATIC = HardwareBuffer::HBU_STATIC,
00041         TU_DYNAMIC = HardwareBuffer::HBU_DYNAMIC,
00042         TU_WRITE_ONLY = HardwareBuffer::HBU_WRITE_ONLY,
00043         TU_STATIC_WRITE_ONLY = HardwareBuffer::HBU_STATIC_WRITE_ONLY, 
00044         TU_DYNAMIC_WRITE_ONLY = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY,
00045         TU_DYNAMIC_WRITE_ONLY_DISCARDABLE = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE,
00047         TU_AUTOMIPMAP = 0x100,
00050         TU_RENDERTARGET = 0x200,
00052         TU_DEFAULT = TU_AUTOMIPMAP | TU_STATIC_WRITE_ONLY
00053         
00054     };
00055 
00058     enum TextureType
00059     {
00061         TEX_TYPE_1D = 1,
00063         TEX_TYPE_2D = 2,
00065         TEX_TYPE_3D = 3,
00067         TEX_TYPE_CUBE_MAP = 4
00068     };
00069 
00072     enum TextureMipmap
00073     {
00075         MIP_UNLIMITED = 0x7FFFFFFF
00076     };
00077 
00078     // Forward declaration
00079     class TexturePtr;
00080 
00090     class _OgreExport Texture : public Resource
00091     {
00092     public:
00093         Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
00094             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
00095 
00098         virtual void setTextureType(TextureType ttype ) { mTextureType = ttype; }
00099 
00102         virtual TextureType getTextureType(void) const { return mTextureType; }
00103 
00106         virtual size_t getNumMipmaps(void) const {return mNumMipmaps;}
00107 
00112         virtual void setNumMipmaps(size_t num) {mNumRequestedMipmaps = mNumMipmaps = num;}
00113 
00118         virtual bool getMipmapsHardwareGenerated(void) const { return mMipmapsHardwareGenerated; }
00119 
00122         virtual float getGamma(void) const { return mGamma; }
00123 
00128         virtual void setGamma(float g) { mGamma = g; }
00129 
00132         virtual unsigned int getHeight(void) const { return mHeight; }
00133 
00136         virtual unsigned int getWidth(void) const { return mWidth; }
00137 
00140         virtual unsigned int getDepth(void) const { return mDepth; }
00141 
00144         virtual void setHeight(unsigned int h) { mHeight = mSrcHeight = h; }
00145 
00148         virtual void setWidth(unsigned int w) { mWidth = mSrcWidth = w; }
00149 
00153         virtual void setDepth(unsigned int d)  { mDepth = d; }
00154 
00157         virtual int getUsage() const
00158         {
00159             return mUsage;
00160         }
00161 
00169         virtual void setUsage(int u) { mUsage = u; }
00170 
00182         virtual void createInternalResources(void);
00183 
00186         virtual void freeInternalResources(void);
00189         virtual void copyToTexture( TexturePtr& target ) {}
00190 
00193         virtual void loadImage( const Image &img ) = 0;
00194             
00197         virtual void loadRawData( DataStreamPtr& stream, 
00198             ushort uWidth, ushort uHeight, PixelFormat eFormat);
00199 
00200         virtual void enable32Bit( bool setting = true ) 
00201         {
00202             setting ? mFinalBpp = 32 : mFinalBpp = 16;
00203         }
00204 
00206         virtual PixelFormat getFormat() const
00207         {
00208             return mFormat;
00209         }
00210 
00212         virtual void setFormat(PixelFormat pf);
00213 
00215         virtual bool hasAlpha(void) const
00216         {
00217             return mHasAlpha;
00218         }
00219         
00223         virtual size_t getNumFaces() const;
00224 
00235         virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) = 0;
00236 
00237     protected:
00238         unsigned long mHeight;
00239         unsigned long mWidth;
00240         unsigned long mDepth;
00241 
00242         size_t mNumRequestedMipmaps;
00243         size_t mNumMipmaps;
00244         bool mMipmapsHardwareGenerated;
00245         float mGamma;
00246 
00247         TextureType mTextureType;
00248         PixelFormat mFormat;
00249         int mUsage; // Bit field, so this can't be TextureUsage
00250 
00251         unsigned short mSrcBpp;
00252         unsigned long mSrcWidth, mSrcHeight;
00253         unsigned short mFinalBpp;
00254         bool mHasAlpha;
00255 
00256         bool mInternalResourcesCreated;
00257 
00259         size_t calculateSize(void) const;
00260         
00269         virtual void _loadImages( const std::vector<const Image*>& images );
00270 
00271 
00274         virtual void createInternalResourcesImpl(void) = 0;
00275 
00278         virtual void freeInternalResourcesImpl(void) = 0;
00279 
00281         void unloadImpl(void);
00282 
00283     };
00284 
00291     class _OgreExport TexturePtr : public SharedPtr<Texture> 
00292     {
00293     public:
00294         TexturePtr() : SharedPtr<Texture>() {}
00295         explicit TexturePtr(Texture* rep) : SharedPtr<Texture>(rep) {}
00296         TexturePtr(const TexturePtr& r) : SharedPtr<Texture>(r) {} 
00297         TexturePtr(const ResourcePtr& r) : SharedPtr<Texture>()
00298         {
00299             // lock & copy other mutex pointer
00300             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00301             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00302             pRep = static_cast<Texture*>(r.getPointer());
00303             pUseCount = r.useCountPointer();
00304             if (pUseCount)
00305             {
00306                 ++(*pUseCount);
00307             }
00308         }
00309 
00311         TexturePtr& operator=(const ResourcePtr& r)
00312         {
00313             if (pRep == static_cast<Texture*>(r.getPointer()))
00314                 return *this;
00315             release();
00316             // lock & copy other mutex pointer
00317             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00318             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00319             pRep = static_cast<Texture*>(r.getPointer());
00320             pUseCount = r.useCountPointer();
00321             if (pUseCount)
00322             {
00323                 ++(*pUseCount);
00324             }
00325             return *this;
00326         }
00327     };
00328 
00329 }
00330 
00331 #endif

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Sep 25 17:36:02 2005