OGRE: OgreTexture.h Source File - OGRE Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | 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-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef _Texture_H__
    00030 #define _Texture_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreHardwareBuffer.h"
    00034 #include "OgreResource.h"
    00035 #include "OgreImage.h"
    00036
    00037 namespace Ogre {
    00038
    00041     enum TextureUsage
    00042     {
    00044         TU_STATIC = HardwareBuffer::HBU_STATIC,
    00045         TU_DYNAMIC = HardwareBuffer::HBU_DYNAMIC,
    00046         TU_WRITE_ONLY = HardwareBuffer::HBU_WRITE_ONLY,
    00047         TU_STATIC_WRITE_ONLY = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
    00048         TU_DYNAMIC_WRITE_ONLY = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY,
    00049         TU_DYNAMIC_WRITE_ONLY_DISCARDABLE = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE,
    00051         TU_AUTOMIPMAP = 0x100,
    00054         TU_RENDERTARGET = 0x200,
    00056         TU_DEFAULT = TU_AUTOMIPMAP | TU_STATIC_WRITE_ONLY
    00057
    00058     };
    00059
    00062     enum TextureType
    00063     {
    00065         TEX_TYPE_1D = 1,
    00067         TEX_TYPE_2D = 2,
    00069         TEX_TYPE_3D = 3,
    00071         TEX_TYPE_CUBE_MAP = 4
    00072     };
    00073
    00076     enum TextureMipmap
    00077     {
    00079         MIP_UNLIMITED = 0x7FFFFFFF,
    00081         MIP_DEFAULT = -1
    00082     };
    00083
    00084     // Forward declaration
    00085     class TexturePtr;
    00086
    00096     class _OgreExport Texture : public Resource
    00097     {
    00098     public:
    00099         Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
    00100             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00101
    00104         virtual void setTextureType(TextureType ttype ) { mTextureType = ttype; }
    00105
    00108         virtual TextureType getTextureType(void) const { return mTextureType; }
    00109
    00112         virtual size_t getNumMipmaps(void) const {return mNumMipmaps;}
    00113
    00118         virtual void setNumMipmaps(size_t num) {mNumRequestedMipmaps = mNumMipmaps = num;}
    00119
    00124         virtual bool getMipmapsHardwareGenerated(void) const { return mMipmapsHardwareGenerated; }
    00125
    00128         virtual float getGamma(void) const { return mGamma; }
    00129
    00134         virtual void setGamma(float g) { mGamma = g; }
    00135
    00138         virtual size_t getHeight(void) const { return mHeight; }
    00139
    00142         virtual size_t getWidth(void) const { return mWidth; }
    00143
    00146         virtual size_t getDepth(void) const { return mDepth; }
    00147
    00150         virtual size_t getSrcHeight(void) const { return mSrcHeight; }
    00151
    00154         virtual size_t getSrcWidth(void) const { return mSrcWidth; }
    00155
    00158         virtual size_t getSrcDepth(void) const { return mSrcDepth; }
    00159
    00162         virtual void setHeight(size_t h) { mHeight = mSrcHeight = h; }
    00163
    00166         virtual void setWidth(size_t w) { mWidth = mSrcWidth = w; }
    00167
    00171         virtual void setDepth(size_t d)  { mDepth = mSrcDepth = d; }
    00172
    00175         virtual int getUsage() const
    00176         {
    00177             return mUsage;
    00178         }
    00179
    00187         virtual void setUsage(int u) { mUsage = u; }
    00188
    00200         virtual void createInternalResources(void);
    00201
    00204         virtual void freeInternalResources(void);
    00205
    00208         virtual void copyToTexture( TexturePtr& target );
    00209
    00216         virtual void loadImage( const Image &img );
    00217
    00228         virtual void loadRawData( DataStreamPtr& stream,
    00229             ushort uWidth, ushort uHeight, PixelFormat eFormat);
    00230
    00236         virtual void _loadImages( const ConstImagePtrList& images );
    00237
    00239         virtual PixelFormat getFormat() const
    00240         {
    00241             return mFormat;
    00242         }
    00243
    00245         virtual PixelFormat getDesiredFormat(void) const
    00246         {
    00247             return mDesiredFormat;
    00248         }
    00249
    00253         virtual PixelFormat getSrcFormat(void) const
    00254         {
    00255             return mSrcFormat;
    00256         }
    00257
    00259         virtual void setFormat(PixelFormat pf);
    00260
    00262         virtual bool hasAlpha(void) const;
    00263
    00269         virtual void setDesiredIntegerBitDepth(ushort bits);
    00270
    00273         virtual ushort getDesiredIntegerBitDepth(void) const;
    00274
    00280         virtual void setDesiredFloatBitDepth(ushort bits);
    00281
    00284         virtual ushort getDesiredFloatBitDepth(void) const;
    00285
    00288         virtual void setDesiredBitDepths(ushort integerBits, ushort floatBits);
    00289
    00292         virtual void setTreatLuminanceAsAlpha(bool asAlpha);
    00293
    00296         virtual bool getTreatLuminanceAsAlpha(void) const;
    00297
    00301         virtual size_t getNumFaces() const;
    00302
    00315         virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) = 0;
    00316
    00317     protected:
    00318         size_t mHeight;
    00319         size_t mWidth;
    00320         size_t mDepth;
    00321
    00322         size_t mNumRequestedMipmaps;
    00323         size_t mNumMipmaps;
    00324         bool mMipmapsHardwareGenerated;
    00325         float mGamma;
    00326
    00327         TextureType mTextureType;
    00328         PixelFormat mFormat;
    00329         int mUsage; // Bit field, so this can't be TextureUsage
    00330
    00331         PixelFormat mSrcFormat;
    00332         size_t mSrcWidth, mSrcHeight, mSrcDepth;
    00333
    00334         PixelFormat mDesiredFormat;
    00335         unsigned short mDesiredIntegerBitDepth;
    00336         unsigned short mDesiredFloatBitDepth;
    00337         bool mTreatLuminanceAsAlpha;
    00338
    00339         bool mInternalResourcesCreated;
    00340
    00342         size_t calculateSize(void) const;
    00343
    00344
    00347         virtual void createInternalResourcesImpl(void) = 0;
    00348
    00351         virtual void freeInternalResourcesImpl(void) = 0;
    00352
    00354         void unloadImpl(void);
    00355
    00356     };
    00357
    00364     class _OgreExport TexturePtr : public SharedPtr<Texture>
    00365     {
    00366     public:
    00367         TexturePtr() : SharedPtr<Texture>() {}
    00368         explicit TexturePtr(Texture* rep) : SharedPtr<Texture>(rep) {}
    00369         TexturePtr(const TexturePtr& r) : SharedPtr<Texture>(r) {}
    00370         TexturePtr(const ResourcePtr& r) : SharedPtr<Texture>()
    00371         {
    00372             // lock & copy other mutex pointer
    00373             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00374             {
    00375                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00376                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00377                 pRep = static_cast<Texture*>(r.getPointer());
    00378                 pUseCount = r.useCountPointer();
    00379                 if (pUseCount)
    00380                 {
    00381                     ++(*pUseCount);
    00382                 }
    00383             }
    00384         }
    00385
    00387         TexturePtr& operator=(const ResourcePtr& r)
    00388         {
    00389             if (pRep == static_cast<Texture*>(r.getPointer()))
    00390                 return *this;
    00391             release();
    00392             // lock & copy other mutex pointer
    00393             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00394             {
    00395                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00396                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00397                 pRep = static_cast<Texture*>(r.getPointer());
    00398                 pUseCount = r.useCountPointer();
    00399                 if (pUseCount)
    00400                 {
    00401                     ++(*pUseCount);
    00402                 }
    00403             }
    00404             else
    00405             {
    00406                 // RHS must be a null pointer
    00407                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    00408                 setNull();
    00409             }
    00410             return *this;
    00411         }
    00412     };
    00413
    00414 }
    00415
    00416 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Mar 6 09:46:26 2008