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-2009 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef _Texture_H__ 00029 #define _Texture_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 #include "OgreHardwareBuffer.h" 00033 #include "OgreResource.h" 00034 #include "OgreImage.h" 00035 00036 namespace Ogre { 00037 00046 enum TextureUsage 00047 { 00049 TU_STATIC = HardwareBuffer::HBU_STATIC, 00050 TU_DYNAMIC = HardwareBuffer::HBU_DYNAMIC, 00051 TU_WRITE_ONLY = HardwareBuffer::HBU_WRITE_ONLY, 00052 TU_STATIC_WRITE_ONLY = HardwareBuffer::HBU_STATIC_WRITE_ONLY, 00053 TU_DYNAMIC_WRITE_ONLY = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, 00054 TU_DYNAMIC_WRITE_ONLY_DISCARDABLE = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE, 00056 TU_AUTOMIPMAP = 0x100, 00059 TU_RENDERTARGET = 0x200, 00061 TU_DEFAULT = TU_AUTOMIPMAP | TU_STATIC_WRITE_ONLY 00062 00063 }; 00064 00067 enum TextureType 00068 { 00070 TEX_TYPE_1D = 1, 00072 TEX_TYPE_2D = 2, 00074 TEX_TYPE_3D = 3, 00076 TEX_TYPE_CUBE_MAP = 4 00077 }; 00078 00081 enum TextureMipmap 00082 { 00084 MIP_UNLIMITED = 0x7FFFFFFF, 00086 MIP_DEFAULT = -1 00087 }; 00088 00089 // Forward declaration 00090 class TexturePtr; 00091 00101 class _OgreExport Texture : public Resource 00102 { 00103 public: 00104 Texture(ResourceManager* creator, const String& name, ResourceHandle handle, 00105 const String& group, bool isManual = false, ManualResourceLoader* loader = 0); 00106 00109 virtual void setTextureType(TextureType ttype ) { mTextureType = ttype; } 00110 00113 virtual TextureType getTextureType(void) const { return mTextureType; } 00114 00117 virtual size_t getNumMipmaps(void) const {return mNumMipmaps;} 00118 00123 virtual void setNumMipmaps(size_t num) {mNumRequestedMipmaps = mNumMipmaps = num;} 00124 00129 virtual bool getMipmapsHardwareGenerated(void) const { return mMipmapsHardwareGenerated; } 00130 00133 virtual float getGamma(void) const { return mGamma; } 00134 00143 virtual void setGamma(float g) { mGamma = g; } 00144 00163 virtual void setHardwareGammaEnabled(bool enabled) { mHwGamma = enabled; } 00164 00168 virtual bool isHardwareGammaEnabled() const { return mHwGamma; } 00169 00177 virtual void setFSAA(uint fsaa, const String& fsaaHint) { mFSAA = fsaa; mFSAAHint = fsaaHint; } 00178 00182 virtual uint getFSAA() const { return mFSAA; } 00183 00186 virtual const String& getFSAAHint() const { return mFSAAHint; } 00187 00190 virtual size_t getHeight(void) const { return mHeight; } 00191 00194 virtual size_t getWidth(void) const { return mWidth; } 00195 00198 virtual size_t getDepth(void) const { return mDepth; } 00199 00202 virtual size_t getSrcHeight(void) const { return mSrcHeight; } 00203 00206 virtual size_t getSrcWidth(void) const { return mSrcWidth; } 00207 00210 virtual size_t getSrcDepth(void) const { return mSrcDepth; } 00211 00214 virtual void setHeight(size_t h) { mHeight = mSrcHeight = h; } 00215 00218 virtual void setWidth(size_t w) { mWidth = mSrcWidth = w; } 00219 00223 virtual void setDepth(size_t d) { mDepth = mSrcDepth = d; } 00224 00227 virtual int getUsage() const 00228 { 00229 return mUsage; 00230 } 00231 00239 virtual void setUsage(int u) { mUsage = u; } 00240 00252 virtual void createInternalResources(void); 00253 00256 virtual void freeInternalResources(void); 00257 00260 virtual void copyToTexture( TexturePtr& target ); 00261 00268 virtual void loadImage( const Image &img ); 00269 00280 virtual void loadRawData( DataStreamPtr& stream, 00281 ushort uWidth, ushort uHeight, PixelFormat eFormat); 00282 00288 virtual void _loadImages( const ConstImagePtrList& images ); 00289 00291 virtual PixelFormat getFormat() const 00292 { 00293 return mFormat; 00294 } 00295 00297 virtual PixelFormat getDesiredFormat(void) const 00298 { 00299 return mDesiredFormat; 00300 } 00301 00305 virtual PixelFormat getSrcFormat(void) const 00306 { 00307 return mSrcFormat; 00308 } 00309 00311 virtual void setFormat(PixelFormat pf); 00312 00314 virtual bool hasAlpha(void) const; 00315 00321 virtual void setDesiredIntegerBitDepth(ushort bits); 00322 00325 virtual ushort getDesiredIntegerBitDepth(void) const; 00326 00332 virtual void setDesiredFloatBitDepth(ushort bits); 00333 00336 virtual ushort getDesiredFloatBitDepth(void) const; 00337 00340 virtual void setDesiredBitDepths(ushort integerBits, ushort floatBits); 00341 00344 virtual void setTreatLuminanceAsAlpha(bool asAlpha); 00345 00348 virtual bool getTreatLuminanceAsAlpha(void) const; 00349 00353 virtual size_t getNumFaces() const; 00354 00367 virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) = 0; 00368 00369 00374 virtual void convertToImage(Image& destImage, bool includeMipMaps = false); 00375 00376 00377 protected: 00378 size_t mHeight; 00379 size_t mWidth; 00380 size_t mDepth; 00381 00382 size_t mNumRequestedMipmaps; 00383 size_t mNumMipmaps; 00384 bool mMipmapsHardwareGenerated; 00385 float mGamma; 00386 bool mHwGamma; 00387 uint mFSAA; 00388 String mFSAAHint; 00389 00390 TextureType mTextureType; 00391 PixelFormat mFormat; 00392 int mUsage; // Bit field, so this can't be TextureUsage 00393 00394 PixelFormat mSrcFormat; 00395 size_t mSrcWidth, mSrcHeight, mSrcDepth; 00396 00397 PixelFormat mDesiredFormat; 00398 unsigned short mDesiredIntegerBitDepth; 00399 unsigned short mDesiredFloatBitDepth; 00400 bool mTreatLuminanceAsAlpha; 00401 00402 bool mInternalResourcesCreated; 00403 00405 size_t calculateSize(void) const; 00406 00407 00410 virtual void createInternalResourcesImpl(void) = 0; 00411 00414 virtual void freeInternalResourcesImpl(void) = 0; 00415 00417 void unloadImpl(void); 00418 00422 String getSourceFileType() const; 00423 00424 }; 00425 00432 class _OgreExport TexturePtr : public SharedPtr<Texture> 00433 { 00434 public: 00435 TexturePtr() : SharedPtr<Texture>() {} 00436 explicit TexturePtr(Texture* rep) : SharedPtr<Texture>(rep) {} 00437 TexturePtr(const TexturePtr& r) : SharedPtr<Texture>(r) {} 00438 TexturePtr(const ResourcePtr& r) : SharedPtr<Texture>() 00439 { 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 } 00453 00455 TexturePtr& operator=(const ResourcePtr& r) 00456 { 00457 if (pRep == static_cast<Texture*>(r.getPointer())) 00458 return *this; 00459 release(); 00460 // lock & copy other mutex pointer 00461 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00462 { 00463 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00464 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00465 pRep = static_cast<Texture*>(r.getPointer()); 00466 pUseCount = r.useCountPointer(); 00467 if (pUseCount) 00468 { 00469 ++(*pUseCount); 00470 } 00471 } 00472 else 00473 { 00474 // RHS must be a null pointer 00475 assert(r.isNull() && "RHS must be null if it has no mutex!"); 00476 setNull(); 00477 } 00478 return *this; 00479 } 00480 }; 00484 } 00485 00486 #endif
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52