# 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-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);
    00201         virtual void copyToTexture( TexturePtr& target ) {}
    00202
    00205         virtual void loadImage( const Image &img ) = 0;
    00206
    00209         virtual void loadRawData( DataStreamPtr& stream,
    00210             ushort uWidth, ushort uHeight, PixelFormat eFormat);
    00211
    00212         virtual void enable32Bit( bool setting = true )
    00213         {
    00214             setting ? mFinalBpp = 32 : mFinalBpp = 16;
    00215         }
    00216
    00218         virtual PixelFormat getFormat() const
    00219         {
    00220             return mFormat;
    00221         }
    00222
    00224         virtual void setFormat(PixelFormat pf);
    00225
    00227         virtual bool hasAlpha(void) const
    00228         {
    00229             return mHasAlpha;
    00230         }
    00231
    00235         virtual size_t getNumFaces() const;
    00236
    00247         virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) = 0;
    00248
    00249     protected:
    00250         unsigned long mHeight;
    00251         unsigned long mWidth;
    00252         unsigned long mDepth;
    00253
    00254         size_t mNumRequestedMipmaps;
    00255         size_t mNumMipmaps;
    00256         bool mMipmapsHardwareGenerated;
    00257         float mGamma;
    00258
    00259         TextureType mTextureType;
    00260         PixelFormat mFormat;
    00261         int mUsage; // Bit field, so this can't be TextureUsage
    00262
    00263         unsigned short mSrcBpp;
    00264         unsigned long mSrcWidth, mSrcHeight, mSrcDepth;
    00265         unsigned short mFinalBpp;
    00266         bool mHasAlpha;
    00267
    00268         bool mInternalResourcesCreated;
    00269
    00271         size_t calculateSize(void) const;
    00272
    00281         virtual void _loadImages( const std::vector<const Image*>& images );
    00282
    00283
    00286         virtual void createInternalResourcesImpl(void) = 0;
    00287
    00290         virtual void freeInternalResourcesImpl(void) = 0;
    00291
    00293         void unloadImpl(void);
    00294
    00295     };
    00296
    00303     class _OgreExport TexturePtr : public SharedPtr<Texture>
    00304     {
    00305     public:
    00306         TexturePtr() : SharedPtr<Texture>() {}
    00307         explicit TexturePtr(Texture* rep) : SharedPtr<Texture>(rep) {}
    00308         TexturePtr(const TexturePtr& r) : SharedPtr<Texture>(r) {}
    00309         TexturePtr(const ResourcePtr& r) : SharedPtr<Texture>()
    00310         {
    00311             // lock & copy other mutex pointer
    00312             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00313             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00314             pRep = static_cast<Texture*>(r.getPointer());
    00315             pUseCount = r.useCountPointer();
    00316             if (pUseCount)
    00317             {
    00318                 ++(*pUseCount);
    00319             }
    00320         }
    00321
    00323         TexturePtr& operator=(const ResourcePtr& r)
    00324         {
    00325             if (pRep == static_cast<Texture*>(r.getPointer()))
    00326                 return *this;
    00327             release();
    00328             // lock & copy other mutex pointer
    00329             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00330             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00331             pRep = static_cast<Texture*>(r.getPointer());
    00332             pUseCount = r.useCountPointer();
    00333             if (pUseCount)
    00334             {
    00335                 ++(*pUseCount);
    00336             }
    00337             return *this;
    00338         }
    00339     };
    00340
    00341 }
    00342
    00343 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:54 2006