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         void createInternalResources(void);
00057 
00059         HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
00060 
00062         static D3DX_SURFACEFORMAT OgreFormat_to_D3DXFormat( PixelFormat format );
00063         static PixelFormat closestD3DXFormat( PixelFormat format );
00064         static bool OgreFormat_to_DDPixelFormat( PixelFormat format, DDPIXELFORMAT & out );
00065     protected:
00066         IDirect3DDevice7 * mD3DDevice;       
00067         IDirectDrawSurface7 * mSurface;      
00068 
00069         String mCubeFaceNames[6];
00071         typedef std::vector<HardwarePixelBufferSharedPtr> SurfaceList;
00072         SurfaceList                     mSurfaceList;
00073     
00074 
00076         void loadImpl(void);
00078         void unloadImpl(void);
00079         
00080         void createSurface2D(void);
00081         void createSurface3D(void);
00082 
00084         void _chooseD3DFormat(DDPIXELFORMAT &ddpf);
00085 
00087         void _constructCubeFaceNames(const String name);
00088 
00090         String _getCubeFaceName(unsigned char face) const
00091         { assert(face < 6); return mCubeFaceNames[face]; }
00092 
00093         // Create the list of surfaces
00094         void _createSurfaceList();
00095     };
00096 
00103     class D3DTexturePtr : public SharedPtr<D3DTexture> 
00104     {
00105     public:
00106         D3DTexturePtr() : SharedPtr<D3DTexture>() {}
00107         explicit D3DTexturePtr(D3DTexture* rep) : SharedPtr<D3DTexture>(rep) {}
00108         D3DTexturePtr(const D3DTexturePtr& r) : SharedPtr<D3DTexture>(r) {} 
00109         D3DTexturePtr(const ResourcePtr& r) : SharedPtr<D3DTexture>()
00110         {
00111             // lock & copy other mutex pointer
00112             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00113             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00114             pRep = static_cast<D3DTexture*>(r.getPointer());
00115             pUseCount = r.useCountPointer();
00116             if (pUseCount)
00117             {
00118                 ++(*pUseCount);
00119             }
00120         }
00121 
00123         D3DTexturePtr& operator=(const ResourcePtr& r)
00124         {
00125             if (pRep == static_cast<D3DTexture*>(r.getPointer()))
00126                 return *this;
00127             release();
00128             // lock & copy other mutex pointer
00129             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00130             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00131             pRep = static_cast<D3DTexture*>(r.getPointer());
00132             pUseCount = r.useCountPointer();
00133             if (pUseCount)
00134             {
00135                 ++(*pUseCount);
00136             }
00137             return *this;
00138         }
00140         D3DTexturePtr& operator=(const TexturePtr& r)
00141         {
00142             if (pRep == static_cast<D3DTexture*>(r.getPointer()))
00143                 return *this;
00144             release();
00145             pRep = static_cast<D3DTexture*>(r.getPointer());
00146             pUseCount = r.useCountPointer();
00147             if (pUseCount)
00148             {
00149                 ++(*pUseCount);
00150             }
00151             return *this;
00152         }
00153     };
00154 
00155 
00157     class D3D7RenderTexture : public RenderTexture
00158     {
00159     public:
00160         D3D7RenderTexture( const String & name, 
00161             unsigned int width, unsigned int height,
00162             TextureType texType, PixelFormat internalFormat, 
00163             const NameValuePairList *misc )
00164             : RenderTexture( name, width, height, texType, internalFormat )
00165         {
00166             mPrivateTex = TextureManager::getSingleton().createManual(mName + 
00167                 "_PRIVATE##", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
00168                 texType, mWidth, mHeight, 0, internalFormat, TU_RENDERTARGET);
00169             mPrivateTex->createInternalResources();
00170         }
00171 
00172         virtual ~D3D7RenderTexture()
00173         {
00174             mPrivateTex->unload();
00175             TextureManager::getSingleton().remove(mPrivateTex->getName());
00176         }
00177 
00178         bool requiresTextureFlipping() const { return false; }
00179 
00180         virtual void getCustomAttribute( const String& name, void* pData )
00181         {
00182             if( name == "DDBACKBUFFER" )
00183             {
00184                 LPDIRECTDRAWSURFACE7 *pSurf = (LPDIRECTDRAWSURFACE7*)pData;
00185 
00186                 *pSurf = mPrivateTex->getDDSurface();
00187                 return;
00188             }
00189             else if( name == "DDFRONTBUFFER" )
00190             {
00191                 LPDIRECTDRAWSURFACE7 *pSurf = (LPDIRECTDRAWSURFACE7*)pData;
00192 
00193                 *pSurf = mPrivateTex->getDDSurface();
00194                 return;
00195             }
00196             else if( name == "HWND" )
00197             {
00198                 HWND *pHwnd = (HWND*)pData;
00199 
00200                 *pHwnd = NULL;
00201                 return;
00202             }
00203             else if( name == "isTexture" )
00204             {
00205                 bool *b = reinterpret_cast< bool * >( pData );
00206                 *b = true;
00207 
00208                 return;
00209             }
00210         }
00211         virtual void writeContentsToFile( const String & filename ) {}
00212 
00213     protected:
00215         D3DTexturePtr mPrivateTex;
00216 
00217     protected:
00218         virtual void _copyToTexture()
00219         {
00220             // Copy the newly-rendered data to the public texture surface.
00221             mPrivateTex->copyToTexture( mTexture );
00222         }
00223     };
00224 }
00225 
00226 #endif

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Apr 10 23:21:13 2005