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

OgreD3D7Texture.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 _D3DTexture_H__
00026 #define _D3DTexture_H__
00027 
00028 #include "OgreD3D7Prerequisites.h"
00029 #include "OgreTexture.h"
00030 #include "OgreRenderTarget.h"
00031 #include "OgreRenderTexture.h"
00032 #include "OgreRenderTargetListener.h"
00033 #include "OgreD3D7HardwarePixelBuffer.h"
00034 
00035 namespace Ogre {
00036 
00039     class D3DTexture : public Texture
00040     {
00041     public:
00042         // Constructor, called from D3DTextureManager
00043         D3DTexture(ResourceManager* creator, const String& name, ResourceHandle handle,
00044             const String& group, bool isManual, ManualResourceLoader* loader, 
00045             IDirect3DDevice7 * lpDirect3dDevice);
00046         virtual ~D3DTexture();
00047 
00048         virtual void loadImage( const Image &img );
00049         virtual void loadImage3D( const Image imgs[]);
00050         virtual void copyToTexture(TexturePtr& target );
00051 
00053         LPDIRECTDRAWSURFACE7 getDDSurface(void);
00054 
00056         HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
00057 
00059         static D3DX_SURFACEFORMAT OgreFormat_to_D3DXFormat( PixelFormat format );
00060         static PixelFormat closestD3DXFormat( PixelFormat format );
00061         static bool OgreFormat_to_DDPixelFormat( PixelFormat format, DDPIXELFORMAT & out );
00062 
00064         void restoreFromLostDevice(void);
00065 
00066     protected:
00067         IDirect3DDevice7 * mD3DDevice;       
00068         IDirectDrawSurface7 * mSurface;      
00069 
00070         String mCubeFaceNames[6];
00072         typedef std::vector<HardwarePixelBufferSharedPtr> SurfaceList;
00073         SurfaceList mSurfaceList;
00075         bool mRestoring;
00076 
00077     
00078 
00080         void loadImpl(void);
00082         void createInternalResourcesImpl(void);
00084         void freeInternalResourcesImpl(void);
00085         
00086         void createSurface2D(void);
00087         void createSurface3D(void);
00088 
00090         void _chooseD3DFormat(DDPIXELFORMAT &ddpf);
00091 
00093         void _constructCubeFaceNames(const String name);
00094 
00096         String _getCubeFaceName(unsigned char face) const
00097         { assert(face < 6); return mCubeFaceNames[face]; }
00098 
00099         // Create the list of surfaces
00100         void _createSurfaceList();
00101     };
00102 
00109     class D3DTexturePtr : public SharedPtr<D3DTexture> 
00110     {
00111     public:
00112         D3DTexturePtr() : SharedPtr<D3DTexture>() {}
00113         explicit D3DTexturePtr(D3DTexture* rep) : SharedPtr<D3DTexture>(rep) {}
00114         D3DTexturePtr(const D3DTexturePtr& r) : SharedPtr<D3DTexture>(r) {} 
00115         D3DTexturePtr(const ResourcePtr& r) : SharedPtr<D3DTexture>()
00116         {
00117             // lock & copy other mutex pointer
00118             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00119             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00120             pRep = static_cast<D3DTexture*>(r.getPointer());
00121             pUseCount = r.useCountPointer();
00122             if (pUseCount)
00123             {
00124                 ++(*pUseCount);
00125             }
00126         }
00127 
00129         D3DTexturePtr& operator=(const ResourcePtr& r)
00130         {
00131             if (pRep == static_cast<D3DTexture*>(r.getPointer()))
00132                 return *this;
00133             release();
00134             // lock & copy other mutex pointer
00135             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00136             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00137             pRep = static_cast<D3DTexture*>(r.getPointer());
00138             pUseCount = r.useCountPointer();
00139             if (pUseCount)
00140             {
00141                 ++(*pUseCount);
00142             }
00143             return *this;
00144         }
00146         D3DTexturePtr& operator=(const TexturePtr& r)
00147         {
00148             if (pRep == static_cast<D3DTexture*>(r.getPointer()))
00149                 return *this;
00150             release();
00151             pRep = static_cast<D3DTexture*>(r.getPointer());
00152             pUseCount = r.useCountPointer();
00153             if (pUseCount)
00154             {
00155                 ++(*pUseCount);
00156             }
00157             return *this;
00158         }
00159     };
00160 
00161 
00163     class D3D7RenderTexture : public RenderTexture
00164     {
00165     public:
00166         D3D7RenderTexture( const String & name, 
00167             unsigned int width, unsigned int height,
00168             TextureType texType, PixelFormat internalFormat, 
00169             const NameValuePairList *misc )
00170             : RenderTexture( name, width, height, texType, internalFormat )
00171         {
00172             mPrivateTex = TextureManager::getSingleton().createManual(mName + 
00173                 "_PRIVATE##", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
00174                 texType, mWidth, mHeight, 0, internalFormat, TU_RENDERTARGET);
00175             mPrivateTex->createInternalResources();
00176         }
00177 
00178         virtual ~D3D7RenderTexture()
00179         {
00180             mPrivateTex->unload();
00181             TextureManager::getSingleton().remove(mPrivateTex->getName());
00182         }
00183 
00184         bool requiresTextureFlipping() const { return false; }
00185 
00186         virtual void getCustomAttribute( const String& name, void* pData )
00187         {
00188             if( name == "DDBACKBUFFER" )
00189             {
00190                 LPDIRECTDRAWSURFACE7 *pSurf = (LPDIRECTDRAWSURFACE7*)pData;
00191 
00192                 *pSurf = mPrivateTex->getDDSurface();
00193                 return;
00194             }
00195             else if( name == "DDFRONTBUFFER" )
00196             {
00197                 LPDIRECTDRAWSURFACE7 *pSurf = (LPDIRECTDRAWSURFACE7*)pData;
00198 
00199                 *pSurf = mPrivateTex->getDDSurface();
00200                 return;
00201             }
00202             else if( name == "HWND" )
00203             {
00204                 HWND *pHwnd = (HWND*)pData;
00205 
00206                 *pHwnd = NULL;
00207                 return;
00208             }
00209             else if( name == "isTexture" )
00210             {
00211                 bool *b = reinterpret_cast< bool * >( pData );
00212                 *b = true;
00213 
00214                 return;
00215             }
00216         }
00217         virtual void writeContentsToFile( const String & filename ) {}
00218 
00219     protected:
00221         D3DTexturePtr mPrivateTex;
00222 
00223     protected:
00224         virtual void _copyToTexture()
00225         {
00226             // Copy the newly-rendered data to the public texture surface.
00227             mPrivateTex->copyToTexture( mTexture );
00228         }
00229     };
00230 }
00231 
00232 #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 Feb 12 12:59:43 2006