Index: OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/include/OgreD3D9Texture.h
===================================================================
--- OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/include/OgreD3D9Texture.h	(revision 193)
+++ OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/include/OgreD3D9Texture.h	(revision 657)
@@ -68,6 +68,4 @@
 		/// device capabilities pointer
 		D3DCAPS9						mDevCaps;
-        // Auto-generated mipmaps?
-        bool                            mAutoGenMipmaps;
 		// Dynamic textures?
 		bool                            mDynamicTextures;
@@ -95,6 +93,8 @@
 		D3DFORMAT _chooseD3DFormat();
 
-		/// internal method, free D3D9 resources
-		void _freeResources();
+		/// @copydoc Texture::createInternalResourcesImpl
+		void createInternalResourcesImpl(void);
+		/// free internal resources
+		void freeInternalResourcesImpl(void);
 		/// internal method, set Texture class source image protected attributes
 		void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
@@ -116,10 +116,8 @@
 		/// internal method, create D3D9HardwarePixelBuffers for every face and
 		/// mipmap level. This method must be called after the D3D texture object was created
-		void _createSurfaceList(bool updateOldList=false);
+		void _createSurfaceList(void);
 
         /// overriden from Resource
         void loadImpl();
-        /// overriden from Resource
-        void unloadImpl();
 	public:
 		/// constructor 
@@ -135,6 +133,4 @@
 		void loadImage( const Image &img );
 
-        /// @copydoc Texture::createInternalResources
-        void createInternalResources(void);
 
 		/// @copydoc Texture::getBuffer
Index: OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/include/OgreD3D9HardwareOcclusionQuery.h
===================================================================
--- OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/include/OgreD3D9HardwareOcclusionQuery.h	(revision 115)
+++ OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/include/OgreD3D9HardwareOcclusionQuery.h	(revision 657)
@@ -34,7 +34,7 @@
 
 // If you use multiple rendering passes you can test only the first pass and all other passes don't have to be rendered 
-	// if the first pass resultet has too few pixels visible.
+	// if the first pass results has too few pixels visible.
 
-// Be sure to render all occlluder first and whats out so the RenderQue don't switch places on 
+	// Be sure to render all occluder first and whats out so the RenderQue don't switch places on 
 // the occluding objects and the tested objects because it thinks it's more effective..
 
@@ -46,4 +46,5 @@
 	*
 	* Updated on 12/7/2004 by Chris McGuirk
+	* Updated on 4/8/2005 by Tuan Kuranes email: tuan.kuranes@free.fr
   */
 class D3D9HardwareOcclusionQuery : public HardwareOcclusionQuery
@@ -73,4 +74,5 @@
 		bool pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag = HWOCCLUSIONQUERY_FLUSH);
 		unsigned int getLastQuerysPixelcount() { return mPixelCount; }
+        bool isStillOutstanding(void);
 
 		// These functions are optional, it's a simple filter that simply skips some hardware occlusion tests on visible objects only
@@ -82,11 +84,11 @@
 	  *   
 		* Remarks This function allows you to set how often the hardware occlusion query is sent to the driver
-	  * if you set it to 0 every hw occlusion test is acctually made. If you set it to 1 only the half of your queries are sent 
-		* 2 will result in 25% of all queries to acctualy be sent. 
+		* if you set it to 0 every hardware occlusion test is actually made. If you set it to 1 only the half of your queries are sent 
+		* 2 will result in 25% of all queries to factually be sent. 
 		* This functionality is here because this class can keep track on visible and none visible objects for you.
 	  * Once you you set the SkipRate for any hardware occlusion instance it effects all others.
 	  */
 
-		void setSkipRate( int skip ) { mSkipInterval = skip; }			// Using 2 only 50 % of the tests are actully made and 3 results in only 33% of the tests. So on.
+		void setSkipRate( int skip ) { mSkipInterval = skip; }			// Using 2 only 50 % of the tests are actually made and 3 results in only 33% of the tests. So on.
 		int	 getSkipRate() { return mSkipInterval; } 
 
@@ -105,4 +107,5 @@
 		int					mSkipInterval;
 		bool				mHasOcclusionSupport;
+		bool				mIsQueryResultStillOutstanding;
 };
 
Index: OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9HardwareOcclusionQuery.cpp
===================================================================
--- OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9HardwareOcclusionQuery.cpp	(revision 193)
+++ OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9HardwareOcclusionQuery.cpp	(revision 657)
@@ -113,5 +113,5 @@
 	// This version of pullOcclusionQuery causes the DX9 API/Driver to not flush all commands to the 3D card
 // to allow a fast result from the query, but the batching of API calls to the card will be normal. 
-	// But the query wont be processed until the card recives the query in the next batch.
+	// But the query wont be processed until the card receives the query in the next batch.
 // Note: OpenGL dosn't use this flag at all so the application running OpenGL won't display any different behaviour.
 //--
Index: OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9RenderWindow.cpp
===================================================================
--- OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9RenderWindow.cpp	(revision 193)
+++ OGRE/trunk/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9RenderWindow.cpp	(revision 657)
@@ -110,11 +110,5 @@
 	D3D9RenderWindow::~D3D9RenderWindow()
 	{
-		// access and update device through driver, realse only primary
-		if (!mIsSwapChain) 
-		{
-			LPDIRECT3DDEVICE9 mpD3DDevice = mDriver->getD3DDevice();
-			SAFE_RELEASE( mpD3DDevice );
-			mDriver->setD3DDevice( NULL );
-		}
+		destroyD3DResources();
 	}
 
@@ -342,7 +336,4 @@
 		md3dpp.BackBufferHeight			= mHeight;
 
-#ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	//md3dpp.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
-#endif
 		if (mVSync)
 			md3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
@@ -493,7 +484,4 @@
 			// ignore depth buffer, access device through driver
 			mpRenderZBuffer = 0;
-			LPDIRECT3DDEVICE9 mpD3DDevice = mDriver->getD3DDevice();
-			SAFE_RELEASE(mpD3DDevice);
-			mDriver->setD3DDevice(NULL);
 		}
 	}
@@ -727,7 +715,15 @@
 		}
 
-		if (!mIsFullScreen)
-		{
-			POINT pt={0, 0};
+		D3DLOCKED_RECT lockedRect;
+		if(mIsFullScreen)
+		{
+			if (FAILED(hr = pTempSurf->LockRect(&lockedRect, NULL, 
+			D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK)))
+			{
+				OGRE_EXCEPT(hr, "can't lock rect!", "D3D9RenderWindow::writeContentsToFile");
+			} 
+		}
+		else
+		{
 			RECT srcRect;
 			GetWindowRect(mHWnd, &srcRect);
@@ -735,40 +731,12 @@
 			desc.Width = srcRect.right - srcRect.left;
 			desc.Height = srcRect.bottom - srcRect.top;
-			desc.Format = D3DFMT_A8R8G8B8;         // this is what we get from the screen, so stick with it
-
-			// NB we can't lock the back buffer direct because it's no created that way
-			// and to do so hits performance, so copy to another surface
-			// Must be the same format as the source surface
-			if (FAILED(hr = mpD3DDevice->CreateOffscreenPlainSurface(
-							desc.Width, 
-							desc.Height, 
-							desc.Format, 
-							D3DPOOL_DEFAULT, 
-							&pSurf,
-							NULL)))
-			{
-				SAFE_RELEASE(pSurf);
-				OGRE_EXCEPT(hr, "Cannot create offscreen buffer 2!", "D3D9RenderWindow::writeContentsToFile");
-			}
-
-			// Copy
-			if (FAILED(hr = mpD3DDevice->UpdateSurface(pTempSurf, &srcRect, pSurf, &pt)))
-			{
-				SAFE_RELEASE(pTempSurf);
-				SAFE_RELEASE(pSurf);
-				OGRE_EXCEPT(hr, "Cannot update surface!", "D3D9RenderWindow::writeContentsToFile");
-			}
-
-			SAFE_RELEASE(pTempSurf);
-			pTempSurf = pSurf;
-			pSurf = NULL;
-		}
-
-		D3DLOCKED_RECT lockedRect;
-		if (FAILED(hr = pTempSurf->LockRect(&lockedRect, NULL, 
+
+			if (FAILED(hr = pTempSurf->LockRect(&lockedRect, &srcRect, 
+
 			D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK)))
 		{
 			OGRE_EXCEPT(hr, "can't lock rect!", "D3D9RenderWindow::writeContentsToFile");
 		} 
+		}
 
         ImageCodec::ImageData *imgData = new ImageCodec::ImageData();
