Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

OgreD3D9Texture.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 __D3D8TEXTURE_H__
00026 #define __D3D8TEXTURE_H__
00027 
00028 #include "OgreD3D9Prerequisites.h"
00029 #include "OgreTexture.h"
00030 #include "OgreRenderTexture.h"
00031 #include "OgreImage.h"
00032 #include "OgreException.h"
00033 #include "OgreD3D9HardwarePixelBuffer.h"
00034 
00035 #include "OgreNoMemoryMacros.h"
00036 #include <d3d9.h>
00037 #include <d3dx9.h>
00038 #include <dxerr9.h>
00039 #include "OgreMemoryMacros.h"
00040 
00041 namespace Ogre {
00042     class D3D9Texture : public Texture
00043     {
00044     protected:
00046         IDirect3DDevice9        *mpDev;     
00048         IDirect3D9              *mpD3D;
00050         IDirect3DTexture9       *mpNormTex; 
00052         IDirect3DCubeTexture9   *mpCubeTex; 
00054         IDirect3DVolumeTexture9 *mpVolumeTex;
00056         IDirect3DBaseTexture9   *mpTex;     
00057 
00059         String                          mCubeFaceNames[6];
00061         D3DDEVICE_CREATION_PARAMETERS   mDevCreParams;
00063         D3DFORMAT                       mBBPixelFormat;
00065         D3DPOOL                         mD3DPool;
00067         D3DCAPS9                        mDevCaps;
00068         // Dynamic textures?
00069         bool                            mDynamicTextures;
00071         typedef std::vector<HardwarePixelBufferSharedPtr> SurfaceList;
00072         SurfaceList                     mSurfaceList;
00073     
00075         void _initDevice(void);
00077         void _loadCubeTex();
00079         void _loadNormTex();
00081         void _loadVolumeTex();
00082 
00084         void _createNormTex();
00086         void _createCubeTex();
00088         void _createVolumeTex();
00089 
00091         D3DFORMAT _chooseD3DFormat();
00092 
00094         void createInternalResourcesImpl(void);
00096         void freeInternalResourcesImpl(void);
00098         void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
00100         void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
00102         D3DTEXTUREFILTERTYPE _getBestFilterMethod();
00104         bool _canUseDynamicTextures(DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
00106         bool _canAutoGenMipmaps(DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
00107         
00109         String _getCubeFaceName(unsigned char face) const
00110         { assert(face < 6); return mCubeFaceNames[face]; }
00111         
00114         void _createSurfaceList(void);
00115 
00117         void loadImpl();
00118     public:
00120         D3D9Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
00121             const String& group, bool isManual, ManualResourceLoader* loader, 
00122             IDirect3DDevice9 *pD3DDevice);
00124         ~D3D9Texture();
00125 
00127         void copyToTexture( TexturePtr& target );
00129         void loadImage( const Image &img );
00130 
00131 
00133         HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
00134         
00136         IDirect3DBaseTexture9 *getTexture() 
00137         { assert(mpTex); return mpTex; }
00139         IDirect3DTexture9 *getNormTexture()
00140         { assert(mpNormTex); return mpNormTex; }
00142         IDirect3DCubeTexture9 *getCubeTexture()
00143         { assert(mpCubeTex); return mpCubeTex; }
00144         
00145         
00146 
00148         bool releaseIfDefaultPool(void);
00150         bool recreateIfDefaultPool(LPDIRECT3DDEVICE9 pDev);
00151 
00152     };
00153 
00160     class D3D9TexturePtr : public SharedPtr<D3D9Texture> 
00161     {
00162     public:
00163         D3D9TexturePtr() : SharedPtr<D3D9Texture>() {}
00164         explicit D3D9TexturePtr(D3D9Texture* rep) : SharedPtr<D3D9Texture>(rep) {}
00165         D3D9TexturePtr(const D3D9TexturePtr& r) : SharedPtr<D3D9Texture>(r) {} 
00166         D3D9TexturePtr(const ResourcePtr& r) : SharedPtr<D3D9Texture>()
00167         {
00168             // lock & copy other mutex pointer
00169             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00170             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00171             pRep = static_cast<D3D9Texture*>(r.getPointer());
00172             pUseCount = r.useCountPointer();
00173             if (pUseCount)
00174             {
00175                 ++(*pUseCount);
00176             }
00177         }
00178 
00180         D3D9TexturePtr& operator=(const ResourcePtr& r)
00181         {
00182             if (pRep == static_cast<D3D9Texture*>(r.getPointer()))
00183                 return *this;
00184             release();
00185             // lock & copy other mutex pointer
00186             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00187             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00188             pRep = static_cast<D3D9Texture*>(r.getPointer());
00189             pUseCount = r.useCountPointer();
00190             if (pUseCount)
00191             {
00192                 ++(*pUseCount);
00193             }
00194             return *this;
00195         }
00197         D3D9TexturePtr& operator=(const TexturePtr& r)
00198         {
00199             if (pRep == static_cast<D3D9Texture*>(r.getPointer()))
00200                 return *this;
00201             release();
00202             // lock & copy other mutex pointer
00203             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00204             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00205             pRep = static_cast<D3D9Texture*>(r.getPointer());
00206             pUseCount = r.useCountPointer();
00207             if (pUseCount)
00208             {
00209                 ++(*pUseCount);
00210             }
00211             return *this;
00212         }
00213     };
00214 
00216     class D3D9RenderTexture : public RenderTexture
00217     {
00218     public:
00219         D3D9RenderTexture(const String &name, D3D9HardwarePixelBuffer *buffer):
00220             RenderTexture(buffer, 0)
00221         { 
00222             mName = name;
00223         }
00224         ~D3D9RenderTexture() {}
00225 
00226         void rebind(D3D9HardwarePixelBuffer *buffer)
00227         {
00228             mBuffer = buffer;
00229             mWidth = mBuffer->getWidth();
00230             mHeight = mBuffer->getHeight();
00231             mColourDepth = Ogre::PixelUtil::getNumElemBits(mBuffer->getFormat());
00232         }
00233 
00234         virtual void getCustomAttribute( const String& name, void *pData )
00235         {
00236             if(name == "DDBACKBUFFER")
00237             {
00238                 IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
00239                 *pSurf = static_cast<D3D9HardwarePixelBuffer*>(mBuffer)->getSurface();
00240                 return;
00241             }
00242             else if(name == "HWND")
00243             {
00244                 HWND *pHwnd = (HWND*)pData;
00245                 *pHwnd = NULL;
00246                 return;
00247             }
00248             else if(name == "BUFFER")
00249             {
00250                 *static_cast<HardwarePixelBuffer**>(pData) = mBuffer;
00251                 return;
00252             }
00253         }
00254 
00255         bool requiresTextureFlipping() const { return false; }
00256     };
00257 
00258 }
00259 
00260 #endif

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