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

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Sep 25 17:35:52 2005