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 unsigned int getSrcHeight(void) const { return mSrcHeight; } 00145 00148 virtual unsigned int getSrcWidth(void) const { return mSrcWidth; } 00149 00152 virtual unsigned int getSrcDepth(void) const { return mSrcDepth; } 00153 00156 virtual void setHeight(unsigned int h) { mHeight = mSrcHeight = h; } 00157 00160 virtual void setWidth(unsigned int w) { mWidth = mSrcWidth = w; } 00161 00165 virtual void setDepth(unsigned int d) { mDepth = mSrcDepth = d; } 00166 00169 virtual int getUsage() const 00170 { 00171 return mUsage; 00172 } 00173 00181 virtual void setUsage(int u) { mUsage = u; } 00182 00194 virtual void createInternalResources(void); 00195 00198 virtual void freeInternalResources(void); 00199 00202 virtual void copyToTexture( TexturePtr& target ); 00203 00206 virtual void loadImage( const Image &img ) = 0; 00207 00210 virtual void loadRawData( DataStreamPtr& stream, 00211 ushort uWidth, ushort uHeight, PixelFormat eFormat); 00212 00213 virtual void enable32Bit( bool setting = true ) 00214 { 00215 setting ? mFinalBpp = 32 : mFinalBpp = 16; 00216 } 00217 00219 virtual PixelFormat getFormat() const 00220 { 00221 return mFormat; 00222 } 00223 00225 virtual void setFormat(PixelFormat pf); 00226 00228 virtual bool hasAlpha(void) const 00229 { 00230 return mHasAlpha; 00231 } 00232 00236 virtual size_t getNumFaces() const; 00237 00250 virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) = 0; 00251 00252 protected: 00253 unsigned long mHeight; 00254 unsigned long mWidth; 00255 unsigned long mDepth; 00256 00257 size_t mNumRequestedMipmaps; 00258 size_t mNumMipmaps; 00259 bool mMipmapsHardwareGenerated; 00260 float mGamma; 00261 00262 TextureType mTextureType; 00263 PixelFormat mFormat; 00264 int mUsage; // Bit field, so this can't be TextureUsage 00265 00266 unsigned short mSrcBpp; 00267 unsigned long mSrcWidth, mSrcHeight, mSrcDepth; 00268 unsigned short mFinalBpp; 00269 bool mHasAlpha; 00270 00271 bool mInternalResourcesCreated; 00272 00274 size_t calculateSize(void) const; 00275 00284 virtual void _loadImages( const std::vector<const Image*>& images ); 00285 00286 00289 virtual void createInternalResourcesImpl(void) = 0; 00290 00293 virtual void freeInternalResourcesImpl(void) = 0; 00294 00296 void unloadImpl(void); 00297 00298 }; 00299 00306 class _OgreExport TexturePtr : public SharedPtr<Texture> 00307 { 00308 public: 00309 TexturePtr() : SharedPtr<Texture>() {} 00310 explicit TexturePtr(Texture* rep) : SharedPtr<Texture>(rep) {} 00311 TexturePtr(const TexturePtr& r) : SharedPtr<Texture>(r) {} 00312 TexturePtr(const ResourcePtr& r) : SharedPtr<Texture>() 00313 { 00314 // lock & copy other mutex pointer 00315 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00316 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00317 pRep = static_cast<Texture*>(r.getPointer()); 00318 pUseCount = r.useCountPointer(); 00319 if (pUseCount) 00320 { 00321 ++(*pUseCount); 00322 } 00323 } 00324 00326 TexturePtr& operator=(const ResourcePtr& r) 00327 { 00328 if (pRep == static_cast<Texture*>(r.getPointer())) 00329 return *this; 00330 release(); 00331 // lock & copy other mutex pointer 00332 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00333 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00334 pRep = static_cast<Texture*>(r.getPointer()); 00335 pUseCount = r.useCountPointer(); 00336 if (pUseCount) 00337 { 00338 ++(*pUseCount); 00339 } 00340 return *this; 00341 } 00342 }; 00343 00344 } 00345 00346 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:51 2006