Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | 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-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         void setTextureType(TextureType ttype ) { mTextureType = ttype; }
00099 
00102         TextureType getTextureType(void) const { return mTextureType; }
00103 
00106         size_t getNumMipmaps(void) const {return mNumMipmaps;}
00107 
00112         void setNumMipmaps(size_t num) {mNumMipmaps = num;}
00113 
00116         float getGamma(void) const { return mGamma; }
00117 
00122         void setGamma(float g) { mGamma = g; }
00123 
00126         unsigned int getHeight(void) const { return mHeight; }
00127 
00130         unsigned int getWidth(void) const { return mWidth; }
00131 
00134         unsigned int getDepth(void) const { return mDepth; }
00135 
00138         void setHeight(unsigned int h) { mHeight = mSrcHeight = h; }
00139 
00142         void setWidth(unsigned int w) { mWidth = mSrcWidth = w; }
00143 
00147         void setDepth(unsigned int d)  { mDepth = d; }
00148 
00151         int getUsage() const
00152         {
00153             return mUsage;
00154         }
00155 
00163         void setUsage(int u) { mUsage = u; }
00164 
00176         virtual void createInternalResources(void) = 0;
00177 
00180         virtual void copyToTexture( TexturePtr& target ) {}
00181 
00184         virtual void loadImage( const Image &img ) = 0;
00185             
00188         virtual void loadRawData( DataStreamPtr& stream, 
00189             ushort uWidth, ushort uHeight, PixelFormat eFormat);
00190 
00191         void enable32Bit( bool setting = true ) 
00192         {
00193             setting ? mFinalBpp = 32 : mFinalBpp = 16;
00194         }
00195 
00197         virtual PixelFormat getFormat() const
00198         {
00199             return mFormat;
00200         }
00201 
00203         virtual void setFormat(PixelFormat pf);
00204 
00206         virtual bool hasAlpha(void) const
00207         {
00208             return mHasAlpha;
00209         }
00210         
00214         virtual size_t getNumFaces() const;
00215 
00226         virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) = 0;
00227 
00228     protected:
00229         unsigned long mHeight;
00230         unsigned long mWidth;
00231         unsigned long mDepth;
00232 
00233         size_t mNumMipmaps;
00234         float mGamma;
00235 
00236         TextureType mTextureType;
00237         PixelFormat mFormat;
00238         int mUsage; // Bit field, so this can't be TextureUsage
00239 
00240         unsigned short mSrcBpp;
00241         unsigned long mSrcWidth, mSrcHeight;
00242         unsigned short mFinalBpp;
00243         bool mHasAlpha;
00245         size_t calculateSize(void) const;
00246         
00255         void _loadImages( const std::vector<const Image*>& images );
00256     };
00257 
00264     class _OgreExport TexturePtr : public SharedPtr<Texture> 
00265     {
00266     public:
00267         TexturePtr() : SharedPtr<Texture>() {}
00268         explicit TexturePtr(Texture* rep) : SharedPtr<Texture>(rep) {}
00269         TexturePtr(const TexturePtr& r) : SharedPtr<Texture>(r) {} 
00270         TexturePtr(const ResourcePtr& r) : SharedPtr<Texture>()
00271         {
00272             // lock & copy other mutex pointer
00273             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00274             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00275             pRep = static_cast<Texture*>(r.getPointer());
00276             pUseCount = r.useCountPointer();
00277             if (pUseCount)
00278             {
00279                 ++(*pUseCount);
00280             }
00281         }
00282 
00284         TexturePtr& operator=(const ResourcePtr& r)
00285         {
00286             if (pRep == static_cast<Texture*>(r.getPointer()))
00287                 return *this;
00288             release();
00289             // lock & copy other mutex pointer
00290             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00291             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00292             pRep = static_cast<Texture*>(r.getPointer());
00293             pUseCount = r.useCountPointer();
00294             if (pUseCount)
00295             {
00296                 ++(*pUseCount);
00297             }
00298             return *this;
00299         }
00300     };
00301 
00302 }
00303 
00304 #endif

Copyright © 2000-2005 by The OGRE Team
Last modified Wed Feb 23 00:19:15 2005