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-2012 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,
    00078         TEX_TYPE_2D_ARRAY = 5
    00079     };
    00080
    00083     enum TextureMipmap
    00084     {
    00086         MIP_UNLIMITED = 0x7FFFFFFF,
    00088         MIP_DEFAULT = -1
    00089     };
    00090
    00091     // Forward declaration
    00092     class TexturePtr;
    00093
    00103     class _OgreExport Texture : public Resource
    00104     {
    00105     public:
    00106         Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
    00107             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00108
    00111         virtual void setTextureType(TextureType ttype ) { mTextureType = ttype; }
    00112
    00115         virtual TextureType getTextureType(void) const { return mTextureType; }
    00116
    00119         virtual size_t getNumMipmaps(void) const {return mNumMipmaps;}
    00120
    00125         virtual void setNumMipmaps(size_t num) {mNumRequestedMipmaps = mNumMipmaps = num;}
    00126
    00131         virtual bool getMipmapsHardwareGenerated(void) const { return mMipmapsHardwareGenerated; }
    00132
    00135         virtual float getGamma(void) const { return mGamma; }
    00136
    00145         virtual void setGamma(float g) { mGamma = g; }
    00146
    00165         virtual void setHardwareGammaEnabled(bool enabled) { mHwGamma = enabled; }
    00166
    00170         virtual bool isHardwareGammaEnabled() const { return mHwGamma; }
    00171
    00179         virtual void setFSAA(uint fsaa, const String& fsaaHint) { mFSAA = fsaa; mFSAAHint = fsaaHint; }
    00180
    00184         virtual uint getFSAA() const { return mFSAA; }
    00185
    00188         virtual const String& getFSAAHint() const { return mFSAAHint; }
    00189
    00192         virtual size_t getHeight(void) const { return mHeight; }
    00193
    00196         virtual size_t getWidth(void) const { return mWidth; }
    00197
    00200         virtual size_t getDepth(void) const { return mDepth; }
    00201
    00204         virtual size_t getSrcHeight(void) const { return mSrcHeight; }
    00205
    00208         virtual size_t getSrcWidth(void) const { return mSrcWidth; }
    00209
    00212         virtual size_t getSrcDepth(void) const { return mSrcDepth; }
    00213
    00216         virtual void setHeight(size_t h) { mHeight = mSrcHeight = h; }
    00217
    00220         virtual void setWidth(size_t w) { mWidth = mSrcWidth = w; }
    00221
    00225         virtual void setDepth(size_t d)  { mDepth = mSrcDepth = d; }
    00226
    00229         virtual int getUsage() const
    00230         {
    00231             return mUsage;
    00232         }
    00233
    00241         virtual void setUsage(int u) { mUsage = u; }
    00242
    00254         virtual void createInternalResources(void);
    00255
    00258         virtual void freeInternalResources(void);
    00259
    00262         virtual void copyToTexture( TexturePtr& target );
    00263
    00270         virtual void loadImage( const Image &img );
    00271
    00282         virtual void loadRawData( DataStreamPtr& stream,
    00283             ushort uWidth, ushort uHeight, PixelFormat eFormat);
    00284
    00290         virtual void _loadImages( const ConstImagePtrList& images );
    00291
    00293         virtual PixelFormat getFormat() const
    00294         {
    00295             return mFormat;
    00296         }
    00297
    00299         virtual PixelFormat getDesiredFormat(void) const
    00300         {
    00301             return mDesiredFormat;
    00302         }
    00303
    00307         virtual PixelFormat getSrcFormat(void) const
    00308         {
    00309             return mSrcFormat;
    00310         }
    00311
    00313         virtual void setFormat(PixelFormat pf);
    00314
    00316         virtual bool hasAlpha(void) const;
    00317
    00323         virtual void setDesiredIntegerBitDepth(ushort bits);
    00324
    00327         virtual ushort getDesiredIntegerBitDepth(void) const;
    00328
    00334         virtual void setDesiredFloatBitDepth(ushort bits);
    00335
    00338         virtual ushort getDesiredFloatBitDepth(void) const;
    00339
    00342         virtual void setDesiredBitDepths(ushort integerBits, ushort floatBits);
    00343
    00346         virtual void setTreatLuminanceAsAlpha(bool asAlpha);
    00347
    00350         virtual bool getTreatLuminanceAsAlpha(void) const;
    00351
    00355         virtual size_t getNumFaces() const;
    00356
    00369         virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) = 0;
    00370
    00371
    00376         virtual void convertToImage(Image& destImage, bool includeMipMaps = false);
    00377
    00383         virtual void getCustomAttribute(const String& name, void* pData) {}
    00384
    00385
    00386
    00387     protected:
    00388         size_t mHeight;
    00389         size_t mWidth;
    00390         size_t mDepth;
    00391
    00392         size_t mNumRequestedMipmaps;
    00393         size_t mNumMipmaps;
    00394         bool mMipmapsHardwareGenerated;
    00395         float mGamma;
    00396         bool mHwGamma;
    00397         uint mFSAA;
    00398         String mFSAAHint;
    00399
    00400         TextureType mTextureType;
    00401         PixelFormat mFormat;
    00402         int mUsage; // Bit field, so this can't be TextureUsage
    00403
    00404         PixelFormat mSrcFormat;
    00405         size_t mSrcWidth, mSrcHeight, mSrcDepth;
    00406
    00407         PixelFormat mDesiredFormat;
    00408         unsigned short mDesiredIntegerBitDepth;
    00409         unsigned short mDesiredFloatBitDepth;
    00410         bool mTreatLuminanceAsAlpha;
    00411
    00412         bool mInternalResourcesCreated;
    00413
    00415         size_t calculateSize(void) const;
    00416
    00417
    00420         virtual void createInternalResourcesImpl(void) = 0;
    00421
    00424         virtual void freeInternalResourcesImpl(void) = 0;
    00425
    00427         void unloadImpl(void);
    00428
    00432         String getSourceFileType() const;
    00433
    00434     };
    00435
    00442     class _OgreExport TexturePtr : public SharedPtr<Texture>
    00443     {
    00444     public:
    00445         TexturePtr() : SharedPtr<Texture>() {}
    00446         explicit TexturePtr(Texture* rep) : SharedPtr<Texture>(rep) {}
    00447         TexturePtr(const TexturePtr& r) : SharedPtr<Texture>(r) {}
    00448         TexturePtr(const ResourcePtr& r) : SharedPtr<Texture>()
    00449         {
    00450             // lock & copy other mutex pointer
    00451             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00452             {
    00453                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00454                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00455                 pRep = static_cast<Texture*>(r.getPointer());
    00456                 pUseCount = r.useCountPointer();
    00457                 if (pUseCount)
    00458                 {
    00459                     ++(*pUseCount);
    00460                 }
    00461             }
    00462         }
    00463
    00465         TexturePtr& operator=(const ResourcePtr& r)
    00466         {
    00467             if (pRep == static_cast<Texture*>(r.getPointer()))
    00468                 return *this;
    00469             release();
    00470             // lock & copy other mutex pointer
    00471             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00472             {
    00473                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00474                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00475                 pRep = static_cast<Texture*>(r.getPointer());
    00476                 pUseCount = r.useCountPointer();
    00477                 if (pUseCount)
    00478                 {
    00479                     ++(*pUseCount);
    00480                 }
    00481             }
    00482             else
    00483             {
    00484                 // RHS must be a null pointer
    00485                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    00486                 setNull();
    00487             }
    00488             return *this;
    00489         }
    00490     };
    00494 }
    00495
    00496 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:24