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-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __D3D9TEXTURE_H__ 00029 #define __D3D9TEXTURE_H__ 00030 00031 #include "OgreD3D9Prerequisites.h" 00032 #include "OgreTexture.h" 00033 #include "OgreRenderTexture.h" 00034 #include "OgreImage.h" 00035 #include "OgreException.h" 00036 #include "OgreD3D9HardwarePixelBuffer.h" 00037 #include "OgreD3D9Resource.h" 00038 00039 namespace Ogre { 00040 class _OgreD3D9Export D3D9Texture : public Texture, public D3D9Resource 00041 { 00042 protected: 00043 00044 struct TextureResources 00045 { 00047 IDirect3DTexture9* pNormTex; 00049 IDirect3DCubeTexture9* pCubeTex; 00051 IDirect3DVolumeTexture9* pVolumeTex; 00053 IDirect3DBaseTexture9* pBaseTex; 00055 IDirect3DSurface9* pFSAASurface; 00056 }; 00057 00058 typedef map<IDirect3DDevice9*, TextureResources*>::type DeviceToTextureResourcesMap; 00059 typedef DeviceToTextureResourcesMap::iterator DeviceToTextureResourcesIterator; 00060 00062 DeviceToTextureResourcesMap mMapDeviceToTextureResources; 00063 00064 00066 typedef vector<HardwarePixelBufferSharedPtr>::type SurfaceList; 00067 SurfaceList mSurfaceList; 00069 String mCubeFaceNames[6]; 00071 D3DPOOL mD3DPool; 00072 // Dynamic textures? 00073 bool mDynamicTextures; 00074 00076 bool mHwGammaReadSupported; 00078 bool mHwGammaWriteSupported; 00079 D3DMULTISAMPLE_TYPE mFSAAType; 00080 DWORD mFSAAQuality; 00081 00082 // needed to store data between prepareImpl and loadImpl 00083 typedef SharedPtr<vector<MemoryDataStreamPtr>::type > LoadedStreams; 00084 00086 void _loadCubeTex(IDirect3DDevice9* d3d9Device, const LoadedStreams &loadedStreams); 00088 void _loadNormTex(IDirect3DDevice9* d3d9Device, const LoadedStreams &loadedStreams); 00090 void _loadVolumeTex(IDirect3DDevice9* d3d9Device, const LoadedStreams &loadedStreams); 00091 00093 LoadedStreams _prepareCubeTex(); 00095 LoadedStreams _prepareNormTex(); 00097 LoadedStreams _prepareVolumeTex(); 00098 00100 void _createNormTex(IDirect3DDevice9* d3d9Device); 00102 void _createCubeTex(IDirect3DDevice9* d3d9Device); 00104 void _createVolumeTex(IDirect3DDevice9* d3d9Device); 00105 00107 D3DFORMAT _chooseD3DFormat(IDirect3DDevice9* d3d9Device); 00108 00110 size_t calculateSize(void) const; 00112 void createInternalResources(void); 00114 void freeInternalResources(void); 00116 void createInternalResourcesImpl(void); 00118 void createInternalResourcesImpl(IDirect3DDevice9* d3d9Device); 00120 void freeInternalResourcesImpl(void); 00122 void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format); 00124 void _setFinalAttributes(IDirect3DDevice9* d3d9Device, TextureResources* textureResources, 00125 unsigned long width, unsigned long height, unsigned long depth, PixelFormat format); 00127 D3DTEXTUREFILTERTYPE _getBestFilterMethod(IDirect3DDevice9* d3d9Device); 00129 bool _canUseDynamicTextures(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat); 00131 bool _canAutoGenMipmaps(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat); 00133 bool _canUseHardwareGammaCorrection(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat, bool forwriting); 00134 00136 String _getCubeFaceName(unsigned char face) const 00137 { assert(face < 6); return mCubeFaceNames[face]; } 00138 00141 void _createSurfaceList(IDirect3DDevice9* d3d9Device, TextureResources* textureResources); 00142 00144 void loadImpl(); 00146 void loadImpl(IDirect3DDevice9* d3d9Device); 00148 void prepareImpl(); 00150 void unprepareImpl(); 00152 void postLoadImpl(); 00153 00155 TextureResources* getTextureResources(IDirect3DDevice9* d3d9Device); 00156 00158 TextureResources* allocateTextureResources(IDirect3DDevice9* d3d9Device); 00159 00161 void createTextureResources(IDirect3DDevice9* d3d9Device); 00162 00164 void freeTextureResources(IDirect3DDevice9* d3d9Device, TextureResources* textureResources); 00165 00166 void determinePool(); 00167 00172 LoadedStreams mLoadedStreams; 00173 00174 friend class D3D9HardwarePixelBuffer; 00175 public: 00177 D3D9Texture(ResourceManager* creator, const String& name, ResourceHandle handle, 00178 const String& group, bool isManual, ManualResourceLoader* loader); 00180 ~D3D9Texture(); 00181 00183 void copyToTexture( TexturePtr& target ); 00184 00185 00187 HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap); 00188 00190 IDirect3DBaseTexture9 *getTexture(); 00192 IDirect3DTexture9 *getNormTexture(); 00194 IDirect3DCubeTexture9 *getCubeTexture(); 00195 00203 bool isHardwareGammaReadToBeUsed() const { return mHwGamma && mHwGammaReadSupported; } 00204 00206 bool useDefaultPool(); 00207 00208 // Called immediately after the Direct3D device has been created. 00209 virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device); 00210 00211 // Called before the Direct3D device is going to be destroyed. 00212 virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device); 00213 00214 // Called immediately after the Direct3D device has entered a lost state. 00215 virtual void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device); 00216 00217 // Called immediately after the Direct3D device has been reset 00218 virtual void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device); 00219 }; 00220 00227 class _OgreD3D9Export D3D9TexturePtr : public SharedPtr<D3D9Texture> 00228 { 00229 public: 00230 D3D9TexturePtr() : SharedPtr<D3D9Texture>() {} 00231 explicit D3D9TexturePtr(D3D9Texture* rep) : SharedPtr<D3D9Texture>(rep) {} 00232 D3D9TexturePtr(const D3D9TexturePtr& r) : SharedPtr<D3D9Texture>(r) {} 00233 D3D9TexturePtr(const ResourcePtr& r) : SharedPtr<D3D9Texture>() 00234 { 00235 // lock & copy other mutex pointer 00236 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00237 { 00238 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00239 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00240 pRep = static_cast<D3D9Texture*>(r.getPointer()); 00241 pUseCount = r.useCountPointer(); 00242 if (pUseCount) 00243 { 00244 ++(*pUseCount); 00245 } 00246 } 00247 } 00248 D3D9TexturePtr(const TexturePtr& r) : SharedPtr<D3D9Texture>() 00249 { 00250 *this = r; 00251 } 00252 00254 D3D9TexturePtr& operator=(const ResourcePtr& r) 00255 { 00256 if (pRep == static_cast<D3D9Texture*>(r.getPointer())) 00257 return *this; 00258 release(); 00259 // lock & copy other mutex pointer 00260 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00261 { 00262 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00263 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00264 pRep = static_cast<D3D9Texture*>(r.getPointer()); 00265 pUseCount = r.useCountPointer(); 00266 if (pUseCount) 00267 { 00268 ++(*pUseCount); 00269 } 00270 } 00271 else 00272 { 00273 // RHS must be a null pointer 00274 assert(r.isNull() && "RHS must be null if it has no mutex!"); 00275 setNull(); 00276 } 00277 return *this; 00278 } 00280 D3D9TexturePtr& operator=(const TexturePtr& r) 00281 { 00282 if (pRep == static_cast<D3D9Texture*>(r.getPointer())) 00283 return *this; 00284 release(); 00285 // lock & copy other mutex pointer 00286 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00287 { 00288 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00289 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00290 pRep = static_cast<D3D9Texture*>(r.getPointer()); 00291 pUseCount = r.useCountPointer(); 00292 if (pUseCount) 00293 { 00294 ++(*pUseCount); 00295 } 00296 } 00297 else 00298 { 00299 // RHS must be a null pointer 00300 assert(r.isNull() && "RHS must be null if it has no mutex!"); 00301 setNull(); 00302 } 00303 return *this; 00304 } 00305 }; 00306 00308 class _OgreD3D9Export D3D9RenderTexture : public RenderTexture 00309 { 00310 public: 00311 D3D9RenderTexture(const String &name, D3D9HardwarePixelBuffer *buffer, bool writeGamma, uint fsaa); 00312 ~D3D9RenderTexture() {} 00313 00314 virtual void update(bool swap); 00315 00316 virtual void getCustomAttribute( const String& name, void *pData ); 00317 00318 bool requiresTextureFlipping() const { return false; } 00319 00321 void swapBuffers(bool waitForVSync = true); 00322 00323 }; 00324 00325 } 00326 00327 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:21