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-2011 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         
00381         virtual void getCustomAttribute(const String& name, void* pData) {}
00382         
00383 
00384 
00385     protected:
00386         size_t mHeight;
00387         size_t mWidth;
00388         size_t mDepth;
00389 
00390         size_t mNumRequestedMipmaps;
00391         size_t mNumMipmaps;
00392         bool mMipmapsHardwareGenerated;
00393         float mGamma;
00394         bool mHwGamma;
00395         uint mFSAA;
00396         String mFSAAHint;
00397 
00398         TextureType mTextureType;
00399         PixelFormat mFormat;
00400         int mUsage; // Bit field, so this can't be TextureUsage
00401 
00402         PixelFormat mSrcFormat;
00403         size_t mSrcWidth, mSrcHeight, mSrcDepth;
00404 
00405         PixelFormat mDesiredFormat;
00406         unsigned short mDesiredIntegerBitDepth;
00407         unsigned short mDesiredFloatBitDepth;
00408         bool mTreatLuminanceAsAlpha;
00409 
00410         bool mInternalResourcesCreated;
00411 
00413         size_t calculateSize(void) const;
00414         
00415 
00418         virtual void createInternalResourcesImpl(void) = 0;
00419 
00422         virtual void freeInternalResourcesImpl(void) = 0;
00423 
00425         void unloadImpl(void);
00426 
00430         String getSourceFileType() const;
00431 
00432     };
00433 
00440     class _OgreExport TexturePtr : public SharedPtr<Texture> 
00441     {
00442     public:
00443         TexturePtr() : SharedPtr<Texture>() {}
00444         explicit TexturePtr(Texture* rep) : SharedPtr<Texture>(rep) {}
00445         TexturePtr(const TexturePtr& r) : SharedPtr<Texture>(r) {} 
00446         TexturePtr(const ResourcePtr& r) : SharedPtr<Texture>()
00447         {
00448             // lock & copy other mutex pointer
00449             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
00450             {
00451                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00452                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00453                 pRep = static_cast<Texture*>(r.getPointer());
00454                 pUseCount = r.useCountPointer();
00455                 if (pUseCount)
00456                 {
00457                     ++(*pUseCount);
00458                 }
00459             }
00460         }
00461 
00463         TexturePtr& operator=(const ResourcePtr& r)
00464         {
00465             if (pRep == static_cast<Texture*>(r.getPointer()))
00466                 return *this;
00467             release();
00468             // lock & copy other mutex pointer
00469             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
00470             {
00471                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00472                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00473                 pRep = static_cast<Texture*>(r.getPointer());
00474                 pUseCount = r.useCountPointer();
00475                 if (pUseCount)
00476                 {
00477                     ++(*pUseCount);
00478                 }
00479             }
00480             else
00481             {
00482                 // RHS must be a null pointer
00483                 assert(r.isNull() && "RHS must be null if it has no mutex!");
00484                 setNull();
00485             }
00486             return *this;
00487         }
00488     };
00492 }
00493 
00494 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sat Jan 14 2012 18:40:44