2
0
Эх сурвалжийг харах

More refactoring of DX9 and some refactoring of fullscreen switching

Marko Pintera 11 жил өмнө
parent
commit
17a8f4d6f9

+ 15 - 0
CamelotCore/Include/CmCoreThreadAccessor.h

@@ -141,6 +141,21 @@ namespace BansheeEngine
 		 */
 		void showWindow(RenderWindowPtr& renderWindow);
 
+		/**
+		 * @copydoc RenderWindow::setFullscreen(UINT32, UINT32, float, UINT32)
+		 */
+		void setFullscreen(RenderWindowPtr& renderWindow, UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
+
+		/**
+		 * @copydoc RenderWindow::setFullscreen(const VideoMode&, UINT32)
+		 */
+		void setFullscreen(RenderWindowPtr& renderWindow, const VideoMode& mode, UINT32 refreshRateIdx = 0);
+
+		/**
+		 * @copydoc RenderWindow::setWindowed
+		 */
+		void setWindowed(RenderWindowPtr& renderWindow);
+
 		/**
 		* @brief	Queues a new generic command that will be added to the command queue.
 		*/

+ 1 - 1
CamelotCore/Include/CmPixelBuffer.h

@@ -75,7 +75,7 @@ namespace BansheeEngine
 		/**
 		 * @brief	Internal implementation of the "lock" method.
 		 */
-		virtual PixelData lockImpl(const PixelVolume lockBox, GpuLockOptions options) = 0;
+		virtual PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options) = 0;
 
 		/**
 		 * @copydoc	HardwareBuffer::lockImpl

+ 1 - 1
CamelotCore/Include/CmTexture.h

@@ -246,7 +246,7 @@ namespace BansheeEngine
 		 * @note	This is only false for some rare special cases. (e.g. AA render texture in DX9)
 		 *			Internal method.
 		 */
-		virtual bool _isBindableAsShaderResource() const { return true; }
+		virtual bool isBindableAsShaderResource() const { return true; }
 
 		/************************************************************************/
 		/* 								TEXTURE VIEW                      		*/

+ 11 - 0
CamelotCore/Include/CmVideoModeInfo.h

@@ -13,6 +13,9 @@ namespace BansheeEngine
 		VideoMode(UINT32 width, UINT32 height, VideoOutputInfo* parentOutputInfo);
 		virtual ~VideoMode();
 
+		VideoMode(const VideoMode&) = delete; // Make non-copyable
+		VideoMode& operator=(const VideoMode&) = delete; // Make non-copyable
+
 		/**
 		 * @brief	Width of the front/back buffer in pixels.
 		 */
@@ -52,8 +55,12 @@ namespace BansheeEngine
 	class CM_EXPORT VideoOutputInfo
 	{
 	public:
+		VideoOutputInfo() { }
 		virtual ~VideoOutputInfo();
 
+		VideoOutputInfo(const VideoOutputInfo&) = delete; // Make non-copyable
+		VideoOutputInfo& operator=(const VideoOutputInfo&) = delete; // Make non-copyable
+
 		/**
 		 * @brief	Name of the output device.
 		 */
@@ -87,8 +94,12 @@ namespace BansheeEngine
 	class CM_EXPORT VideoModeInfo
 	{
 	public:
+		VideoModeInfo() { }
 		virtual ~VideoModeInfo();
 
+		VideoModeInfo(const VideoModeInfo&) = delete; // Make non-copyable
+		VideoModeInfo& operator=(const VideoModeInfo&) = delete; // Make non-copyable
+
 		/**
 		 * @brief	Returns the number of available output devices.
 		 */

+ 22 - 0
CamelotCore/Source/CmCoreThreadAccessor.cpp

@@ -5,6 +5,7 @@
 #include "CmRasterizerState.h"
 #include "CmDepthStencilState.h"
 #include "CmGpuResourceData.h"
+#include "CmVideoModeInfo.h"
 #include "CmGpuParams.h"
 #include "CmPass.h"
 #include "CmMaterial.h"
@@ -255,6 +256,27 @@ namespace BansheeEngine
 		mCommandQueue->queue(std::bind(&RenderWindow::setHidden, renderWindow.get(), false));
 	}
 
+	void CoreThreadAccessorBase::setFullscreen(RenderWindowPtr& renderWindow, UINT32 width, UINT32 height, 
+		float refreshRate, UINT32 monitorIdx)
+	{
+		void(RenderWindow::*funcPtr)(UINT32, UINT32, float, UINT32) = &RenderWindow::setFullscreen;
+
+		mCommandQueue->queue(std::bind(funcPtr, renderWindow.get(), width, height, refreshRate, monitorIdx));
+	}
+
+	void CoreThreadAccessorBase::setFullscreen(RenderWindowPtr& renderWindow, const VideoMode& mode, 
+		UINT32 refreshRateIdx)
+	{
+		void(RenderWindow::*funcPtr)(const VideoMode&, UINT32) = &RenderWindow::setFullscreen;
+
+		mCommandQueue->queue(std::bind(funcPtr, renderWindow.get(), std::cref(mode), refreshRateIdx));
+	}
+
+	void CoreThreadAccessorBase::setWindowed(RenderWindowPtr& renderWindow)
+	{
+		mCommandQueue->queue(std::bind(&RenderWindow::setWindowed, renderWindow.get()));
+	}
+
 	AsyncOp CoreThreadAccessorBase::queueReturnCommand(std::function<void(AsyncOp&)> commandCallback)
 	{
 		return mCommandQueue->queueReturn(commandCallback);

+ 4 - 4
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -31,13 +31,13 @@ namespace BansheeEngine
 		void setActive(bool state);
 
 		/**
-		* @copydoc RenderWindow::setFullscreen
-		*/
+		 * @copydoc RenderWindow::setFullscreen(UINT32, UINT32, float, UINT32)
+		 */
 		void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
 
 		/**
-		* @copydoc RenderWindow::setFullscreen
-		*/
+		 * @copydoc RenderWindow::setFullscreen(const VideoMode&, UINT32)
+		 */
 		void setFullscreen(const VideoMode& mode, UINT32 refreshRateIdx = 0);
 
 		/**

+ 17 - 21
CamelotD3D9Renderer/Include/CmD3D9IndexBuffer.h

@@ -8,13 +8,23 @@ namespace BansheeEngine
 { 
     class CM_D3D9_EXPORT D3D9IndexBuffer : public IndexBuffer, public D3D9Resource
     {
-  
+	protected:
+		struct BufferResources
+		{
+			IDirect3DIndexBuffer9* mBuffer;
+			bool mOutOfDate;
+			UINT32 mLockOffset;
+			UINT32 mLockLength;
+			GpuLockOptions mLockOptions;
+		};
+
     public:
         ~D3D9IndexBuffer();
+
         /** See HardwareBuffer. */
-        void readData(UINT32 offset, UINT32 length, void* pDest);
+        void readData(UINT32 offset, UINT32 length, void* dest);
         /** See HardwareBuffer. */
-		void writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal);
+		void writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags = BufferWriteType::Normal);
 
 		// Called immediately after the Direct3D device has been created.
 		virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
@@ -34,17 +44,6 @@ namespace BansheeEngine
 		/// Get the D3D-specific index buffer
         IDirect3DIndexBuffer9* getD3DIndexBuffer();		
 
-	protected:
-		struct BufferResources
-		{
-			IDirect3DIndexBuffer9*		mBuffer;
-			bool						mOutOfDate;
-			UINT32						mLockOffset;
-			UINT32						mLockLength;
-			GpuLockOptions					mLockOptions;
-			UINT32						mLastUsedFrame;
-		};
-
 	protected:
 		friend class D3D9HardwareBufferManager;
 
@@ -55,7 +54,7 @@ namespace BansheeEngine
 		/** See HardwareBuffer. */
 		void unlockImpl();
 		// updates buffer resources from system memory buffer.
-		bool updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources);
+		bool updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources);
 
 		/**
 		 * @copydoc IndexBuffer::initialize_internal()
@@ -68,11 +67,8 @@ namespace BansheeEngine
 		void destroy_internal();
 
 	protected:		
-		typedef Map<IDirect3DDevice9*, BufferResources*>	DeviceToBufferResourcesMap;
-		typedef DeviceToBufferResourcesMap::iterator			DeviceToBufferResourcesIterator;
-
-		DeviceToBufferResourcesMap	mMapDeviceToBufferResources;	// Map between device to buffer resources.	
-		D3DINDEXBUFFER_DESC			mBufferDesc;					// Buffer description.		
-		char*						mSystemMemoryBuffer;			// Consistent system memory buffer for multiple devices support.
+		Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;	// Map between device to buffer resources.	
+		D3DINDEXBUFFER_DESC	mBufferDesc;					// Buffer description.		
+		UINT8* mSystemMemoryBuffer;			// Consistent system memory buffer for multiple devices support.
     };
 }

+ 46 - 82
CamelotD3D9Renderer/Include/CmD3D9PixelBuffer.h

@@ -1,57 +1,40 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-    (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __D3D9PIXELBUFFER_H__
-#define __D3D9PIXELBUFFER_H__
+#pragma once
 
 #include "CmD3D9Prerequisites.h"
 #include "CmPixelBuffer.h"
 
-namespace BansheeEngine {
-
-	class D3D9Texture;
-	class D3D9RenderTexture;
-
+namespace BansheeEngine 
+{
 	class CM_D3D9_EXPORT D3D9PixelBuffer : public PixelBuffer
 	{
+	protected:
+		struct BufferResources
+		{
+			/// Surface abstracted by this buffer
+			IDirect3DSurface9* surface;
+			/// Volume abstracted by this buffer
+			IDirect3DVolume9* volume;
+			/// Temporary surface in main memory if direct locking of mSurface is not possible
+			IDirect3DSurface9* tempSurface;
+			/// Temporary volume in main memory if direct locking of mVolume is not possible
+			IDirect3DVolume9* tempVolume;
+			/// Mip map texture.
+			IDirect3DBaseTexture9 *mipTex;
+		};
+
 	public:
-		D3D9PixelBuffer(GpuBufferUsage usage, 
-			D3D9Texture* ownerTexture);
+		D3D9PixelBuffer(GpuBufferUsage usage, D3D9Texture* ownerTexture);
 		~D3D9PixelBuffer();
 
 		/// Call this to associate a D3D surface or volume with this pixel buffer
-		void bind(IDirect3DDevice9 *dev, IDirect3DSurface9 *mSurface,
-			bool writeGamma, UINT32 fsaa, const String& srcName, IDirect3DBaseTexture9 *mipTex);
-		void bind(IDirect3DDevice9 *dev, IDirect3DVolume9 *mVolume, IDirect3DBaseTexture9 *mipTex);
+		void bind(IDirect3DDevice9* dev, IDirect3DSurface9* mSurface,
+			bool writeGamma, UINT32 fsaa, const String& srcName, IDirect3DBaseTexture9* mipTex);
+		void bind(IDirect3DDevice9* dev, IDirect3DVolume9* mVolume, IDirect3DBaseTexture9* mipTex);
 		/// Internal function to update mipmaps on update of level 0
-		void _genMipmaps(IDirect3DBaseTexture9* mipTex);
+		void genMipmaps(IDirect3DBaseTexture9* mipTex);
 
 		/// Function to set mipmap generation
-		void _setMipmapping(bool doMipmapGen, bool HWMipmaps);
+		void setMipmapping(bool doMipmapGen, bool HWMipmaps);
 
 		/// Accessor for surface
 		IDirect3DSurface9 *getSurface(IDirect3DDevice9* d3d9Device);
@@ -69,56 +52,37 @@ namespace BansheeEngine {
 		// Called when device state change completed. Access to any device is allowed.
 		// Relevant for multi thread application.
 		static void unlockDeviceAccess();
-	protected:		
-		struct BufferResources
-		{			
-			/// Surface abstracted by this buffer
-			IDirect3DSurface9* surface;
-			/// Volume abstracted by this buffer
-			IDirect3DVolume9* volume;
-			/// Temporary surface in main memory if direct locking of mSurface is not possible
-			IDirect3DSurface9* tempSurface;
-			/// Temporary volume in main memory if direct locking of mVolume is not possible
-			IDirect3DVolume9* tempVolume;
-			/// Mip map texture.
-			IDirect3DBaseTexture9 *mipTex;			
-		};
-
-		typedef Map<IDirect3DDevice9*, BufferResources*>	DeviceToBufferResourcesMap;
-		typedef DeviceToBufferResourcesMap::iterator			DeviceToBufferResourcesIterator;
-
-		/// Map between device to buffer resources.
-		DeviceToBufferResourcesMap	mMapDeviceToBufferResources;
-				
-		/// Mipmapping
-		bool mDoMipmapGen;
-		bool mHWMipmaps;
-		
-		// The owner texture if exists.
-		D3D9Texture* mOwnerTexture;
-		
-		// The current lock flags of this surface.
-		DWORD mLockFlags;
 
 	protected:
 		/// Lock a box
-		PixelData lockImpl(const PixelVolume lockBox,  GpuLockOptions options);
-		PixelData lockBuffer(BufferResources* bufferResources, const PixelVolume &lockBox, DWORD flags);
+		PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options);
+		PixelData lockBuffer(BufferResources* bufferResources, const PixelVolume& lockBox, DWORD flags);
 
 		/// Unlock a box
-		void unlockImpl(void);
+		void unlockImpl();
 		void unlockBuffer(BufferResources* bufferResources);
 
 		BufferResources* getBufferResources(IDirect3DDevice9* d3d9Device);
 		BufferResources* createBufferResources();
 
-		void blit(IDirect3DDevice9* d3d9Device, const PixelBufferPtr &src,
-				const PixelVolume &srcBox, const PixelVolume &dstBox, 
-				BufferResources* srcBufferResources, 
-				BufferResources* dstBufferResources);
-		void blitFromMemory(const PixelData &src, const PixelVolume &dstBox, BufferResources* dstBufferResources);
+		void blit(IDirect3DDevice9* d3d9Device, const PixelBufferPtr& src, const PixelVolume& srcBox, const PixelVolume& dstBox, 
+				BufferResources* srcBufferResources, BufferResources* dstBufferResources);
+
+		void blitFromMemory(const PixelData& src, const PixelVolume& dstBox, BufferResources* dstBufferResources);
+		void blitToMemory(const PixelVolume& srcBox, const PixelData& dst, BufferResources* srcBufferResources, IDirect3DDevice9* d3d9Device);
 
-		void blitToMemory(const PixelVolume &srcBox, const PixelData &dst, BufferResources* srcBufferResources, IDirect3DDevice9* d3d9Device);
+	protected:
+		/// Map between device to buffer resources.
+		Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
+
+		/// Mipmapping
+		bool mDoMipmapGen;
+		bool mHWMipmaps;
+
+		// The owner texture if exists.
+		D3D9Texture* mOwnerTexture;
+
+		// The current lock flags of this surface.
+		DWORD mLockFlags;
 	};
-};
-#endif
+};

+ 5 - 5
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -12,14 +12,14 @@ namespace BansheeEngine
 		~D3D9RenderWindow();
 		
 		/**
-		* @copydoc RenderWindow::setFullscreen
-		*/
+		 * @copydoc RenderWindow::setFullscreen(UINT32, UINT32, float, UINT32)
+		 */
 		void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
 
 		/**
-		* @copydoc RenderWindow::setFullscreen
-		*/
-		void setFullscreen(const VideoMode& mode, UINT32 refreshRateIdx);
+		 * @copydoc RenderWindow::setFullscreen(const VideoMode&, UINT32)
+		 */
+		void setFullscreen(const VideoMode& mode, UINT32 refreshRateIdx = 0);
 
 		/**
 		* @copydoc RenderWindow::setWindowed

+ 54 - 85
CamelotD3D9Renderer/Include/CmD3D9Texture.h

@@ -1,32 +1,4 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-    (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __D3D9TEXTURE_H__
-#define __D3D9TEXTURE_H__
+#pragma once
 
 #include "CmD3D9Prerequisites.h"
 #include "CmTexture.h"
@@ -35,16 +7,34 @@ THE SOFTWARE.
 #include "CmD3D9PixelBuffer.h"
 #include "CmD3D9Resource.h"
 
-namespace BansheeEngine {
+namespace BansheeEngine 
+{
 	class CM_D3D9_EXPORT D3D9Texture : public Texture, public D3D9Resource
 	{
+	protected:
+		struct TextureResources
+		{
+			/// 1D/2D normal texture pointer
+			IDirect3DTexture9* pNormTex;
+			/// cubic texture pointer
+			IDirect3DCubeTexture9* pCubeTex;
+			/// Volume texture
+			IDirect3DVolumeTexture9* pVolumeTex;
+			/// actual texture pointer
+			IDirect3DBaseTexture9* pBaseTex;
+			/// Optional FSAA surface
+			IDirect3DSurface9* pFSAASurface;
+			/// Optional depth stencil surface
+			IDirect3DSurface9* pDepthStencilSurface;
+		};
+
 	public:
 		~D3D9Texture();
 
 		/**
 		 * @copydoc Texture::isBindableAsShaderResource
 		 */
-		bool _isBindableAsShaderResource() const { return mIsBindableAsShaderResource; }
+		bool isBindableAsShaderResource() const { return mIsBindableAsShaderResource; }
 
 		/// retrieves a pointer to the actual texture
 		IDirect3DBaseTexture9 *getTexture_internal();		
@@ -95,46 +85,6 @@ namespace BansheeEngine {
 		friend class D3D9TextureManager;
 		friend class D3D9PixelBuffer;
 
-		struct TextureResources
-		{
-			/// 1D/2D normal texture pointer
-			IDirect3DTexture9* pNormTex;	
-			/// cubic texture pointer
-			IDirect3DCubeTexture9* pCubeTex;	
-			/// Volume texture
-			IDirect3DVolumeTexture9* pVolumeTex;
-			/// actual texture pointer
-			IDirect3DBaseTexture9* pBaseTex;
-			/// Optional FSAA surface
-			IDirect3DSurface9* pFSAASurface;	
-			/// Optional depth stencil surface
-			IDirect3DSurface9* pDepthStencilSurface;	
-		};
-		
-		typedef Map<IDirect3DDevice9*, TextureResources*>	DeviceToTextureResourcesMap;
-		typedef DeviceToTextureResourcesMap::iterator			DeviceToTextureResourcesIterator;
-
-		/// Map between device to texture resources.
-		DeviceToTextureResourcesMap	mMapDeviceToTextureResources;
-
-		/// Vector of pointers to subsurfaces
-		typedef Vector<PixelBufferPtr> SurfaceList;
-		SurfaceList	mSurfaceList;
-		/// The memory pool being used
-		D3DPOOL	mD3DPool;
-		// Dynamic textures?
-		bool mDynamicTextures;
-		bool mIsBindableAsShaderResource;
-
-		PixelBufferPtr	mLockedBuffer;
-
-		/// Is hardware gamma supported (read)?
-		bool mHwGammaReadSupported;
-		/// Is hardware gamma supported (write)?
-		bool mHwGammaWriteSupported;
-		D3DMULTISAMPLE_TYPE mFSAAType;
-		DWORD mFSAAQuality;
-
 		D3D9Texture();
 
 		/**
@@ -173,34 +123,34 @@ namespace BansheeEngine {
 		void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false);
 
 		/// internal method, create a blank normal 1D/2D texture		
-		void _createNormTex(IDirect3DDevice9* d3d9Device);
+		void createNormTex(IDirect3DDevice9* d3d9Device);
 		/// internal method, create a blank cube texture		
-		void _createCubeTex(IDirect3DDevice9* d3d9Device);
+		void createCubeTex(IDirect3DDevice9* d3d9Device);
 		/// internal method, create a blank cube texture		
-		void _createVolumeTex(IDirect3DDevice9* d3d9Device);
+		void createVolumeTex(IDirect3DDevice9* d3d9Device);
 
 		/// internal method, return a D3D pixel format for texture creation
-		D3DFORMAT _chooseD3DFormat(IDirect3DDevice9* d3d9Device);
+		D3DFORMAT chooseD3DFormat(IDirect3DDevice9* d3d9Device);
 
 		/// @copydoc Resource::calculateSize
-		UINT32 calculateSize(void) const;
+		UINT32 calculateSize() const;
 		/// Creates this texture resources on the specified device.
 		void createInternalResources(IDirect3DDevice9* d3d9Device);
 		/// internal method, set Texture class final texture protected attributes
-		void _setFinalAttributes(IDirect3DDevice9* d3d9Device, TextureResources* textureResources, 
+		void setFinalAttributes(IDirect3DDevice9* d3d9Device, TextureResources* textureResources, 
 			UINT32 width, UINT32 height, UINT32 depth, PixelFormat format);
 		/// internal method, return the best by hardware supported filter method
-		D3DTEXTUREFILTERTYPE _getBestFilterMethod(IDirect3DDevice9* d3d9Device);
+		D3DTEXTUREFILTERTYPE getBestFilterMethod(IDirect3DDevice9* d3d9Device);
 		/// internal method, return true if the device/texture combination can use dynamic textures
-		bool _canUseDynamicTextures(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
+		bool canUseDynamicTextures(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
 		/// internal method, return true if the device/texture combination can auto gen. mip maps
-		bool _canAutoGenMipmaps(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
+		bool canAutoGenMipmaps(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
 		/// internal method, return true if the device/texture combination can use hardware gamma
-		bool _canUseHardwareGammaCorrection(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat, bool forwriting);
+		bool canUseHardwareGammaCorrection(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat, bool forwriting);
 
 		/// internal method, create D3D9HardwarePixelBuffers for every face and
 		/// mipmap level. This method must be called after the D3D texture object was created
-		void _createSurfaceList(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
+		void createSurfaceList(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
 	 
 		/// gets the texture resources attached to the given device.
 		TextureResources* getTextureResources(IDirect3DDevice9* d3d9Device);
@@ -212,7 +162,26 @@ namespace BansheeEngine {
 		void freeTextureResources(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
 
 		void determinePool();
-    };
-}
 
-#endif
+	protected:
+		/// Map between device to texture resources.
+		Map<IDirect3DDevice9*, TextureResources*> mMapDeviceToTextureResources;
+
+		/// Vector of pointers to subsurfaces
+		Vector<PixelBufferPtr>	mSurfaceList;
+		/// The memory pool being used
+		D3DPOOL	mD3DPool;
+		// Dynamic textures?
+		bool mDynamicTextures;
+		bool mIsBindableAsShaderResource;
+
+		PixelBufferPtr mLockedBuffer;
+
+		/// Is hardware gamma supported (read)?
+		bool mHwGammaReadSupported;
+		/// Is hardware gamma supported (write)?
+		bool mHwGammaWriteSupported;
+		D3DMULTISAMPLE_TYPE mFSAAType;
+		DWORD mFSAAQuality;
+    };
+}

+ 25 - 59
CamelotD3D9Renderer/Include/CmD3D9VertexBuffer.h

@@ -1,49 +1,30 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-    (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __D3D9HARDWAREVERTEXBUFFER_H__
-#define __D3D9HARDWAREVERTEXBUFFER_H__
+#pragma once
 
 #include "CmD3D9Prerequisites.h"
 #include "CmVertexBuffer.h"
 #include "CmD3D9Resource.h"
 
-namespace BansheeEngine {
-
+namespace BansheeEngine 
+{
     /// Specialisation of HardwareVertexBuffer for D3D9
     class CM_D3D9_EXPORT D3D9VertexBuffer : public VertexBuffer, public D3D9Resource
     {   
+	protected:
+		struct BufferResources
+		{
+			IDirect3DVertexBuffer9*	mBuffer;
+			bool mOutOfDate;
+			UINT32 mLockOffset;
+			UINT32 mLockLength;
+			GpuLockOptions mLockOptions;
+		};
 
     public:
         ~D3D9VertexBuffer();
         /** See HardwareBuffer. */
-        void readData(UINT32 offset, UINT32 length, void* pDest);
+        void readData(UINT32 offset, UINT32 length, void* dest);
         /** See HardwareBuffer. */
-        void writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal);
+        void writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags = BufferWriteType::Normal);
 	
 		// Called immediately after the Direct3D device has been created.
 		virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
@@ -58,34 +39,24 @@ namespace BansheeEngine {
 		virtual void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
 
 		// Create the actual vertex buffer.
-		void createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool);
+		void createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL pool);
 		
         /// Get D3D9-specific vertex buffer
-        IDirect3DVertexBuffer9* getD3D9VertexBuffer(void);
+        IDirect3DVertexBuffer9* getD3D9VertexBuffer();
 
 		virtual bool vertexColorReqRGBFlip() { return true; }
-	protected:	
-		struct BufferResources
-		{
-			IDirect3DVertexBuffer9*		mBuffer;
-			bool						mOutOfDate;
-			UINT32						mLockOffset;
-			UINT32						mLockLength;
-			GpuLockOptions					mLockOptions;
-			UINT32						mLastUsedFrame;
-		};
 
+	protected:	
 		friend class D3D9HardwareBufferManager;
 
-		D3D9VertexBuffer(UINT32 vertexSize, 
-			UINT32 numVertices, GpuBufferUsage usage, bool useSystemMem);
+		D3D9VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMem);
 	
 		/** See HardwareBuffer. */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);		
 		/** See HardwareBuffer. */
-		void unlockImpl(void);			
+		void unlockImpl();			
 		// updates buffer resources from system memory buffer.
-		bool updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources);		
+		bool updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources);		
 
 		/**
 		 * @copydoc VertexBuffer::initialize_internal()
@@ -97,14 +68,9 @@ namespace BansheeEngine {
 		 */
 		void destroy_internal();
 
-		typedef Map<IDirect3DDevice9*, BufferResources*>	DeviceToBufferResourcesMap;
-		typedef DeviceToBufferResourcesMap::iterator			DeviceToBufferResourcesIterator;
-
-		DeviceToBufferResourcesMap	mMapDeviceToBufferResources;	// Map between device to buffer resources.
-		D3DVERTEXBUFFER_DESC		mBufferDesc;					// Buffer description.		
-		char*						mSystemMemoryBuffer;			// Consistent system memory buffer for multiple devices support.
+	protected:
+		Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources; // Map between device to buffer resources.
+		D3DVERTEXBUFFER_DESC mBufferDesc; // Buffer description.		
+		UINT8* mSystemMemoryBuffer; // Consistent system memory buffer for multiple devices support.
     };
-
-}
-#endif
-
+}

+ 51 - 86
CamelotD3D9Renderer/Source/CmD3D9IndexBuffer.cpp

@@ -19,15 +19,13 @@ namespace BansheeEngine
 
 	void D3D9IndexBuffer::initialize_internal()
 	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		D3DPOOL eResourcePool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_MANAGED;
+		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
 
 		// Set the desired memory pool.
-		mBufferDesc.Pool = eResourcePool;
+		mBufferDesc.Pool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;
 
 		// Allocate the system memory buffer.
-		mSystemMemoryBuffer = (char*) cm_alloc<ScratchAlloc>(getSizeInBytes());
+		mSystemMemoryBuffer = (UINT8*) cm_alloc(getSizeInBytes());
 		memset(mSystemMemoryBuffer, 0, getSizeInBytes());
 
 		// Case we have to create this buffer resource on loading.
@@ -46,23 +44,22 @@ namespace BansheeEngine
 
 	void D3D9IndexBuffer::destroy_internal()
 	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
+		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
 
-		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
-
-		while (it != mMapDeviceToBufferResources.end())
+		for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
 		{
-			SAFE_RELEASE(it->second->mBuffer);
+			BufferResources* bufferResources = bufferResourcesPair.second;
 
-			if(it->second != nullptr)
-				cm_delete<PoolAlloc>(it->second);
+			SAFE_RELEASE(bufferResources->mBuffer);
+
+			if (bufferResources != nullptr)
+				cm_delete(bufferResources);
+		}
 
-			++it;
-		}	
 		mMapDeviceToBufferResources.clear();   
 
 		if(mSystemMemoryBuffer != nullptr)
-			cm_free<ScratchAlloc>(mSystemMemoryBuffer);
+			cm_free(mSystemMemoryBuffer);
 
 		IndexBuffer::destroy_internal();
 	}
@@ -73,19 +70,16 @@ namespace BansheeEngine
 
 		if (options != GBL_READ_ONLY)
 		{
-			DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
-
-			while (it != mMapDeviceToBufferResources.end())
+			for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
 			{
-				BufferResources* bufferResources = it->second;
-
+				BufferResources* bufferResources = bufferResourcesPair.second;
 				bufferResources->mOutOfDate = true;
 
 				if(bufferResources->mLockLength > 0)
 				{
-					UINT32 highPoint = std::max( offset + length, 
-						bufferResources->mLockOffset + bufferResources->mLockLength );
-					bufferResources->mLockOffset = std::min( bufferResources->mLockOffset, offset );
+					UINT32 highPoint = std::max(offset + length, 
+						bufferResources->mLockOffset + bufferResources->mLockLength);
+					bufferResources->mLockOffset = std::min(bufferResources->mLockOffset, offset);
 					bufferResources->mLockLength = highPoint - bufferResources->mLockOffset;
 				}
 				else
@@ -98,48 +92,33 @@ namespace BansheeEngine
 			
 				if (bufferResources->mLockOptions != GBL_WRITE_ONLY_DISCARD)
 					bufferResources->mLockOptions = options;
-
-				++it;
 			}
 		}
 
 		return mSystemMemoryBuffer + offset;		
     }
 
-	void D3D9IndexBuffer::unlockImpl(void)
+	void D3D9IndexBuffer::unlockImpl()
     {	
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
-		// TODO PORT - nextFrameNumber will always be 0 for now. This has potential for errors, so make sure to add a frame counting method before port is done
-		//UINT32 nextFrameNumber = Root::getSingleton().getNextFrameNumber();
-		UINT32 nextFrameNumber = 0;
-
-		while (it != mMapDeviceToBufferResources.end())
+		for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
 		{
-			BufferResources* bufferResources = it->second;
+			BufferResources* bufferResources = bufferResourcesPair.second;
 
-			if (bufferResources->mOutOfDate && 
-				bufferResources->mBuffer != NULL &&
-				nextFrameNumber - bufferResources->mLastUsedFrame <= 1)
+			if (bufferResources->mOutOfDate && bufferResources->mBuffer != nullptr)
 				updateBufferResources(mSystemMemoryBuffer, bufferResources);
-
-			++it;
 		}			
     }
 
-    void D3D9IndexBuffer::readData(UINT32 offset, UINT32 length, 
-        void* pDest)
+    void D3D9IndexBuffer::readData(UINT32 offset, UINT32 length, void* dest)
     {
-       // There is no functional interface in D3D, just do via manual 
-        // lock, copy & unlock
         void* pSrc = this->lock(offset, length, GBL_READ_ONLY);
-        memcpy(pDest, pSrc, length);
+        memcpy(dest, pSrc, length);
         this->unlock();
-
     }
 
-    void D3D9IndexBuffer::writeData(UINT32 offset, UINT32 length,  const void* pSource, BufferWriteType writeFlags)
+    void D3D9IndexBuffer::writeData(UINT32 offset, UINT32 length,  const void* source, BufferWriteType writeFlags)
     {
 		GpuLockOptions lockOption = GBL_WRITE_ONLY;
 		if(writeFlags == BufferWriteType::Discard)
@@ -147,10 +126,8 @@ namespace BansheeEngine
 		else if(writeFlags == BufferWriteType::NoOverwrite)
 			lockOption = GBL_WRITE_ONLY_NO_OVERWRITE;
 
-        // There is no functional interface in D3D, just do via manual 
-        // lock, copy & unlock
         void* pDst = this->lock(offset, length, lockOption);
-        memcpy(pDst, pSource, length);
+        memcpy(pDst, source, length);
         this->unlock();    
 	}
 
@@ -167,16 +144,15 @@ namespace BansheeEngine
 	{		
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.find(d3d9Device);
-
-		if (it != mMapDeviceToBufferResources.end())	
+		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
+		if (iterFind != mMapDeviceToBufferResources.end())	
 		{									
-			SAFE_RELEASE(it->second->mBuffer);
+			SAFE_RELEASE(iterFind->second->mBuffer);
 
-			if(it->second != nullptr)
-				cm_delete<PoolAlloc>(it->second);
+			if(iterFind->second != nullptr)
+				cm_delete(iterFind->second);
 
-			mMapDeviceToBufferResources.erase(it);
+			mMapDeviceToBufferResources.erase(iterFind);
 		}
 	}
 
@@ -186,11 +162,10 @@ namespace BansheeEngine
 
 		if (mBufferDesc.Pool == D3DPOOL_DEFAULT)
 		{
-			DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.find(d3d9Device);
-
-			if (it != mMapDeviceToBufferResources.end())
+			auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
+			if (iterFind != mMapDeviceToBufferResources.end())
 			{			
-				SAFE_RELEASE(it->second->mBuffer);	
+				SAFE_RELEASE(iterFind->second->mBuffer);	
 			}					
 		}
 	}
@@ -206,45 +181,40 @@ namespace BansheeEngine
 		}
 	}
 
-	void D3D9IndexBuffer::createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool)
+	void D3D9IndexBuffer::createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL pool)
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
 		BufferResources* bufferResources;		
 		HRESULT hr;
 
-		DeviceToBufferResourcesIterator it;
-
 		// Find the vertex buffer of this device.
-		it = mMapDeviceToBufferResources.find(d3d9Device);
-		if (it != mMapDeviceToBufferResources.end())
+		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
+		if (iterFind != mMapDeviceToBufferResources.end())
 		{
-			bufferResources = it->second;
+			bufferResources = iterFind->second;
 			SAFE_RELEASE(bufferResources->mBuffer);
 		}
 		else
 		{
-			bufferResources = cm_new<BufferResources, PoolAlloc>();			
+			bufferResources = cm_new<BufferResources>();			
 			mMapDeviceToBufferResources[d3d9Device] = bufferResources;
 		}
 
-		bufferResources->mBuffer = NULL;
+		bufferResources->mBuffer = nullptr;
 		bufferResources->mOutOfDate = true;
 		bufferResources->mLockOffset = 0;
 		bufferResources->mLockLength = getSizeInBytes();
 		bufferResources->mLockOptions = GBL_READ_WRITE;
-		// TODO PORT - I don't know current frame number. Once I add a method for counting frames call it here
-		//bufferResources->mLastUsedFrame = Root::getSingleton().getNextFrameNumber();
-		bufferResources->mLastUsedFrame = 0;
 
 		// Create the Index buffer				
 		hr = d3d9Device->CreateIndexBuffer(
 			static_cast<UINT>(mSizeInBytes),
 			D3D9Mappings::get(mUsage),
 			D3D9Mappings::get(mIndexType),
-			ePool,
+			pool,
 			&bufferResources->mBuffer,
-			NULL
+			nullptr
 			);
 
 		if (FAILED(hr))
@@ -264,32 +234,27 @@ namespace BansheeEngine
 	IDirect3DIndexBuffer9* D3D9IndexBuffer::getD3DIndexBuffer()
 	{		
 		IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getActiveD3D9Device();
-		DeviceToBufferResourcesIterator it;
 
 		// Find the index buffer of this device.
-		it = mMapDeviceToBufferResources.find(d3d9Device);
+		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
 
 		// Case index buffer was not found for the current device -> create it.		
-		if (it == mMapDeviceToBufferResources.end() || it->second->mBuffer == NULL)		
+		if (iterFind == mMapDeviceToBufferResources.end() || iterFind->second->mBuffer == nullptr)
 		{						
 			createBuffer(d3d9Device, mBufferDesc.Pool);
-			it = mMapDeviceToBufferResources.find(d3d9Device);						
+			iterFind = mMapDeviceToBufferResources.find(d3d9Device);						
 		}
 
-		if (it->second->mOutOfDate)
-			updateBufferResources(mSystemMemoryBuffer, it->second);
-
-		// TODO PORT - I don't know current frame number. Once I add a method for counting frames call it here
-		//it->second->mLastUsedFrame = Root::getSingleton().getNextFrameNumber();
-		it->second->mLastUsedFrame = 0;
+		if (iterFind->second->mOutOfDate)
+			updateBufferResources(mSystemMemoryBuffer, iterFind->second);
 
-		return it->second->mBuffer;
+		return iterFind->second->mBuffer;
 	}
 
-	bool D3D9IndexBuffer::updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources)
+	bool D3D9IndexBuffer::updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources)
 	{
-		assert(bufferResources != NULL);
-		assert(bufferResources->mBuffer != NULL);
+		assert(bufferResources != nullptr);
+		assert(bufferResources->mBuffer != nullptr);
 		assert(bufferResources->mOutOfDate);
 			
 		void* dstBytes;

+ 129 - 205
CamelotD3D9Renderer/Source/CmD3D9PixelBuffer.cpp

@@ -1,30 +1,3 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-    (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
 #include "CmD3D9PixelBuffer.h"
 #include "CmD3D9Texture.h"
 #include "CmD3D9Mappings.h"
@@ -34,6 +7,77 @@ THE SOFTWARE.
 
 namespace BansheeEngine 
 {
+	void fromD3DLock(PixelData& rval, const D3DLOCKED_RECT& lrect)
+	{
+		UINT32 bpp = PixelUtil::getNumElemBytes(rval.getFormat());
+		if (bpp != 0)
+		{
+			rval.setRowPitch(lrect.Pitch / bpp);
+			rval.setSlicePitch(rval.getRowPitch() * rval.getHeight());
+			assert((lrect.Pitch % bpp) == 0);
+		}
+		else if (PixelUtil::isCompressed(rval.getFormat()))
+		{
+			rval.setRowPitch(rval.getWidth());
+			rval.setSlicePitch(rval.getWidth() * rval.getHeight());
+		}
+		else
+		{
+			CM_EXCEPT(InvalidParametersException, "Invalid pixel format.");
+		}
+
+		rval.setExternalBuffer((UINT8*)lrect.pBits);
+	}
+
+	void fromD3DLock(PixelData& rval, const D3DLOCKED_BOX& lbox)
+	{
+		UINT32 bpp = PixelUtil::getNumElemBytes(rval.getFormat());
+		if (bpp != 0)
+		{
+			rval.setRowPitch(lbox.RowPitch / bpp);
+			rval.setSlicePitch(lbox.SlicePitch / bpp);
+			assert((lbox.RowPitch % bpp) == 0);
+			assert((lbox.SlicePitch % bpp) == 0);
+		}
+		else if (PixelUtil::isCompressed(rval.getFormat()))
+		{
+			rval.setRowPitch(rval.getWidth());
+			rval.setSlicePitch(rval.getWidth() * rval.getHeight());
+		}
+		else
+		{
+			CM_EXCEPT(InvalidParametersException, "Invalid pixel format.");
+		}
+
+		rval.setExternalBuffer((UINT8*)lbox.pBits);
+	}
+
+	RECT toD3DRECT(const PixelVolume &lockBox)
+	{
+		RECT prect;
+		assert(lockBox.getDepth() == 1);
+		prect.left = (LONG)lockBox.left;
+		prect.right = (LONG)lockBox.right;
+		prect.top = (LONG)lockBox.top;
+		prect.bottom = (LONG)lockBox.bottom;
+
+		return prect;
+	}
+
+	D3DBOX toD3DBOX(const PixelVolume &lockBox)
+	{
+		D3DBOX pbox;
+
+		pbox.Left = (UINT)lockBox.left;
+		pbox.Right = (UINT)lockBox.right;
+		pbox.Top = (UINT)lockBox.top;
+		pbox.Bottom = (UINT)lockBox.bottom;
+		pbox.Front = (UINT)lockBox.front;
+		pbox.Back = (UINT)lockBox.back;
+
+		return pbox;
+	}
+
 	D3D9PixelBuffer::D3D9PixelBuffer(GpuBufferUsage usage, D3D9Texture* ownerTexture)
 		:PixelBuffer(0, 0, 0, PF_UNKNOWN, usage, false),
 		 mDoMipmapGen(0), mHWMipmaps(0), mOwnerTexture(ownerTexture)
@@ -41,26 +85,25 @@ namespace BansheeEngine
 
 	D3D9PixelBuffer::~D3D9PixelBuffer()
 	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
+		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
 
-		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
+		auto iter = mMapDeviceToBufferResources.begin();
 
-		while (it != mMapDeviceToBufferResources.end())
+		while (iter != mMapDeviceToBufferResources.end())
 		{
-			SAFE_RELEASE(it->second->surface);
-			SAFE_RELEASE(it->second->volume);
+			SAFE_RELEASE(iter->second->surface);
+			SAFE_RELEASE(iter->second->volume);
 
-			if(it->second != nullptr)
-				cm_delete<PoolAlloc>(it->second);
+			if(iter->second != nullptr)
+				cm_delete(iter->second);
 
-			DeviceToBufferResourcesIterator deadi = it++;
-			mMapDeviceToBufferResources.erase(deadi);
+			auto toRemove = iter++;
+			mMapDeviceToBufferResources.erase(toRemove);
 		}
 	}
-	//-----------------------------------------------------------------------------  
-	void D3D9PixelBuffer::bind(IDirect3DDevice9 *dev, IDirect3DSurface9 *surface, 
-									   bool writeGamma, UINT32 fsaa, const String& srcName,
-									   IDirect3DBaseTexture9 *mipTex)
+
+	void D3D9PixelBuffer::bind(IDirect3DDevice9* dev, IDirect3DSurface9* surface, bool writeGamma, 
+		UINT32 fsaa, const String& srcName, IDirect3DBaseTexture9* mipTex)
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -86,13 +129,13 @@ namespace BansheeEngine
 		mHeight = desc.Height;
 		mDepth = 1;
 		mFormat = D3D9Mappings::_getPF(desc.Format);
-		// Default
+
 		mRowPitch = mWidth;
 		mSlicePitch = mHeight*mWidth;
 		mSizeInBytes = PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);	
 	}
-	//-----------------------------------------------------------------------------
-	void D3D9PixelBuffer::bind(IDirect3DDevice9 *dev, IDirect3DVolume9 *volume, IDirect3DBaseTexture9 *mipTex)
+
+	void D3D9PixelBuffer::bind(IDirect3DDevice9* dev, IDirect3DVolume9* volume, IDirect3DBaseTexture9* mipTex)
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -113,171 +156,71 @@ namespace BansheeEngine
 		D3DVOLUME_DESC desc;
 		if(volume->GetDesc(&desc) != D3D_OK)
 			CM_EXCEPT(RenderingAPIException, "Could not get volume information");
+
 		mWidth = desc.Width;
 		mHeight = desc.Height;
 		mDepth = desc.Depth;
 		mFormat = D3D9Mappings::_getPF(desc.Format);
-		// Default
+
 		mRowPitch = mWidth;
 		mSlicePitch = mHeight*mWidth;
 		mSizeInBytes = PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);
 	}
 
-	//-----------------------------------------------------------------------------  
 	D3D9PixelBuffer::BufferResources* D3D9PixelBuffer::getBufferResources(IDirect3DDevice9* d3d9Device)
 	{
-		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.find(d3d9Device);
+		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
 
-		if (it != mMapDeviceToBufferResources.end())	
-			return it->second;
+		if (iterFind != mMapDeviceToBufferResources.end())	
+			return iterFind->second;
 	
-		return NULL;
+		return nullptr;
 	}
 
-	//-----------------------------------------------------------------------------  
 	D3D9PixelBuffer::BufferResources* D3D9PixelBuffer::createBufferResources()
 	{
-		BufferResources* newResources = cm_new<BufferResources, PoolAlloc>();
-
+		BufferResources* newResources = cm_new<BufferResources>();
 		memset(newResources, 0, sizeof(BufferResources));
 
 		return newResources;
 	}
 
-	//-----------------------------------------------------------------------------  
 	void D3D9PixelBuffer::destroyBufferResources(IDirect3DDevice9* d3d9Device)
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.find(d3d9Device);
+		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
 
-		if (it != mMapDeviceToBufferResources.end())
+		if (iterFind != mMapDeviceToBufferResources.end())
 		{
-			SAFE_RELEASE(it->second->surface);
-			SAFE_RELEASE(it->second->volume);	
+			SAFE_RELEASE(iterFind->second->surface);
+			SAFE_RELEASE(iterFind->second->volume);	
 
-			if(it->second != nullptr)
-				cm_delete<PoolAlloc>(it->second);
+			if(iterFind->second != nullptr)
+				cm_delete(iterFind->second);
 
-			mMapDeviceToBufferResources.erase(it);
+			mMapDeviceToBufferResources.erase(iterFind);
 		}
 	}
 
-	//-----------------------------------------------------------------------------  
 	void D3D9PixelBuffer::lockDeviceAccess()
 	{
 		D3D9_DEVICE_ACCESS_LOCK;			
 	}
 
-	//-----------------------------------------------------------------------------  
 	void D3D9PixelBuffer::unlockDeviceAccess()
 	{
 		D3D9_DEVICE_ACCESS_UNLOCK;								
 	}
 
-	//-----------------------------------------------------------------------------  
-	// Util functions to convert a D3D locked box to a pixel box
-	void fromD3DLock(PixelData &rval, const D3DLOCKED_RECT &lrect)
-	{
-		UINT32 bpp = PixelUtil::getNumElemBytes(rval.getFormat());
-		if (bpp != 0)
-		{
-			rval.setRowPitch(lrect.Pitch / bpp);
-			rval.setSlicePitch(rval.getRowPitch() * rval.getHeight());
-			assert((lrect.Pitch % bpp)==0);
-		}
-		else if (PixelUtil::isCompressed(rval.getFormat()))
-		{
-			rval.setRowPitch(rval.getWidth());
-			rval.setSlicePitch(rval.getWidth() * rval.getHeight());
-		}
-		else
-		{
-			CM_EXCEPT(InvalidParametersException, "Invalid pixel format");
-		}
-
-		rval.setExternalBuffer((UINT8*)lrect.pBits);
-	}
-	void fromD3DLock(PixelData &rval, const D3DLOCKED_BOX &lbox)
-	{
-		UINT32 bpp = PixelUtil::getNumElemBytes(rval.getFormat());
-		if (bpp != 0)
-		{
-			rval.setRowPitch(lbox.RowPitch / bpp);
-			rval.setSlicePitch(lbox.SlicePitch / bpp);
-			assert((lbox.RowPitch % bpp)==0);
-			assert((lbox.SlicePitch % bpp)==0);
-		}
-		else if (PixelUtil::isCompressed(rval.getFormat()))
-		{
-			rval.setRowPitch(rval.getWidth());
-			rval.setSlicePitch(rval.getWidth() * rval.getHeight());
-		}
-		else
-		{
-			CM_EXCEPT(InvalidParametersException, "Invalid pixel format");
-		}
-		rval.setExternalBuffer((UINT8*)lbox.pBits);
-	}
-	// Convert Ogre integer Box to D3D rectangle
-	RECT toD3DRECT(const PixelVolume &lockBox)
-	{
-		RECT prect;
-		assert(lockBox.getDepth() == 1);
-		prect.left = static_cast<LONG>(lockBox.left);
-		prect.right = static_cast<LONG>(lockBox.right);
-		prect.top = static_cast<LONG>(lockBox.top);
-		prect.bottom = static_cast<LONG>(lockBox.bottom);
-		return prect;
-	}
-	// Convert Ogre integer Box to D3D box
-	D3DBOX toD3DBOX(const PixelVolume &lockBox)
-	{
-		D3DBOX pbox;
-	
-		pbox.Left = static_cast<UINT>(lockBox.left);
-		pbox.Right = static_cast<UINT>(lockBox.right);
-		pbox.Top = static_cast<UINT>(lockBox.top);
-		pbox.Bottom = static_cast<UINT>(lockBox.bottom);
-		pbox.Front = static_cast<UINT>(lockBox.front);
-		pbox.Back = static_cast<UINT>(lockBox.back);
-		return pbox;
-	}
-	// Convert Ogre pixelbox extent to D3D rectangle
-	RECT toD3DRECTExtent(const PixelData &lockBox)
-	{
-		RECT prect;
-		assert(lockBox.getDepth() == 1);
-		prect.left = 0;
-		prect.right = static_cast<LONG>(lockBox.getWidth());
-		prect.top = 0;
-		prect.bottom = static_cast<LONG>(lockBox.getHeight());
-		return prect;
-	}
-	// Convert Ogre pixelbox extent to D3D box
-	D3DBOX toD3DBOXExtent(const PixelData &lockBox)
-	{
-		D3DBOX pbox;
-		pbox.Left = 0;
-		pbox.Right = static_cast<UINT>(lockBox.getWidth());
-		pbox.Top = 0;
-		pbox.Bottom = static_cast<UINT>(lockBox.getHeight());
-		pbox.Front = 0;
-		pbox.Back = static_cast<UINT>(lockBox.getDepth());
-		return pbox;
-	}
-	//-----------------------------------------------------------------------------  
-	PixelData D3D9PixelBuffer::lockImpl(const PixelVolume lockBox,  GpuLockOptions options)
+	PixelData D3D9PixelBuffer::lockImpl(PixelVolume lockBox, GpuLockOptions options)
 	{	
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-		// Set locking flags according to options
 		DWORD flags = 0;
 		switch(options)
 		{
 		case GBL_WRITE_ONLY_DISCARD:
-			// D3D only likes D3DLOCK_DISCARD if you created the texture with D3DUSAGE_DYNAMIC
-			// debug runtime flags this up, could cause problems on some drivers
 			if (mUsage & GBU_DYNAMIC)
 				flags |= D3DLOCK_DISCARD;
 			break;
@@ -298,131 +241,112 @@ namespace BansheeEngine
 
 		BufferResources* bufferResources = mMapDeviceToBufferResources.begin()->second;
 	
-		// Lock the source buffer.
 		return lockBuffer(bufferResources, lockBox, flags);
 	}
 
-	//-----------------------------------------------------------------------------  
-	PixelData D3D9PixelBuffer::lockBuffer(BufferResources* bufferResources, 
-													   const PixelVolume &lockBox, 
-													   DWORD flags)
+	PixelData D3D9PixelBuffer::lockBuffer(BufferResources* bufferResources, const PixelVolume& lockBox, DWORD flags)
 	{
-		// Set extents and format
-		// Note that we do not carry over the left/top/front here, since the returned
-		// PixelBox will be re-based from the locking point onwards
 		PixelData rval(lockBox.getWidth(), lockBox.getHeight(), lockBox.getDepth(), mFormat);
 
-		if (bufferResources->surface != NULL) 
+		if (bufferResources->surface != nullptr)
 		{
-			// Surface
-			D3DLOCKED_RECT lrect; // Filled in by D3D
+			D3DLOCKED_RECT lrect;
 			HRESULT hr;
 
-			if (lockBox.left == 0 && lockBox.top == 0 
-				&& lockBox.right == mWidth && lockBox.bottom == mHeight)
+			if (lockBox.left == 0 && lockBox.top == 0 && lockBox.right == mWidth && lockBox.bottom == mHeight)
 			{
-				// Lock whole surface
-				hr = bufferResources->surface->LockRect(&lrect, NULL, flags);
+				hr = bufferResources->surface->LockRect(&lrect, nullptr, flags);
 			}
 			else
 			{
-				RECT prect = toD3DRECT(lockBox); // specify range to lock
+				RECT prect = toD3DRECT(lockBox);
 				hr = bufferResources->surface->LockRect(&lrect, &prect, flags);
 			}
+
 			if (FAILED(hr))		
 				CM_EXCEPT(RenderingAPIException, "Surface locking failed");
+
 			fromD3DLock(rval, lrect);
 		} 
 		else if(bufferResources->volume) 
 		{
-			// Volume
-			D3DBOX pbox = toD3DBOX(lockBox); // specify range to lock
-			D3DLOCKED_BOX lbox; // Filled in by D3D
+			D3DBOX pbox = toD3DBOX(lockBox);
+			D3DLOCKED_BOX lbox;
 
 			if(bufferResources->volume->LockBox(&lbox, &pbox, flags) != D3D_OK)
 				CM_EXCEPT(RenderingAPIException, "Volume locking failed");
+
 			fromD3DLock(rval, lbox);
 		}
 
-
 		return rval;
 	}
 
-	//-----------------------------------------------------------------------------  
-	void D3D9PixelBuffer::unlockImpl(void)
+	void D3D9PixelBuffer::unlockImpl()
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
 		if (mMapDeviceToBufferResources.size() == 0)
-		{
-			CM_EXCEPT(RenderingAPIException, "There are no resources attached to this pixel buffer !!");	
-		}
+			CM_EXCEPT(RenderingAPIException, "There are no resources attached to this pixel buffer.");	
+
+		auto it = mMapDeviceToBufferResources.begin();							
+		unlockBuffer(it->second);	
 
-		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();							
-		unlockBuffer( it->second);		
 		if(mDoMipmapGen)
-			_genMipmaps(it->second->mipTex);	
+			genMipmaps(it->second->mipTex);	
 	}
 
-	//-----------------------------------------------------------------------------  
 	void D3D9PixelBuffer::unlockBuffer(BufferResources* bufferResources)
 	{
 		if(bufferResources->surface) 
 		{
-			// Surface
 			bufferResources->surface->UnlockRect();
 		} 
 		else if(bufferResources->volume) 
 		{
-			// Volume
 			bufferResources->volume->UnlockBox();
 		}
 	}
-	//-----------------------------------------------------------------------------  
-	void D3D9PixelBuffer::_genMipmaps(IDirect3DBaseTexture9* mipTex)
+
+	void D3D9PixelBuffer::genMipmaps(IDirect3DBaseTexture9* mipTex)
 	{
-		assert(mipTex);
+		assert(mipTex != nullptr);
 
-		// Mipmapping
 		if (mHWMipmaps)
 		{
-			// Hardware mipmaps
 			mipTex->GenerateMipSubLevels();
 		}
 		else
 		{
-			// Software mipmaps
-			if( D3DXFilterTexture( mipTex, NULL, D3DX_DEFAULT, D3DX_DEFAULT ) != D3D_OK )
+			if(D3DXFilterTexture(mipTex, nullptr, D3DX_DEFAULT, D3DX_DEFAULT) != D3D_OK)
 			{
-				CM_EXCEPT(RenderingAPIException, "Failed to filter texture (generate mipmaps)");
+				CM_EXCEPT(RenderingAPIException, "Failed to generate mipmaps.");
 			}
 		}
-
 	}
-	//----------------------------------------------------------------------------- 
-	void D3D9PixelBuffer::_setMipmapping(bool doMipmapGen, 
-												 bool HWMipmaps)
+
+	void D3D9PixelBuffer::setMipmapping(bool doMipmapGen, bool HWMipmaps)
 	{	
 		mDoMipmapGen = doMipmapGen;
 		mHWMipmaps = HWMipmaps;	
 	}
-	//-----------------------------------------------------------------------------  
+
 	void D3D9PixelBuffer::releaseSurfaces(IDirect3DDevice9* d3d9Device)
 	{
 		BufferResources* bufferResources = getBufferResources(d3d9Device);
 
-		if (bufferResources != NULL)
+		if (bufferResources != nullptr)
 		{
 			SAFE_RELEASE(bufferResources->surface);
 			SAFE_RELEASE(bufferResources->volume);
 		}
 	}
-	//-----------------------------------------------------------------------------   
+
 	IDirect3DSurface9* D3D9PixelBuffer::getSurface(IDirect3DDevice9* d3d9Device)
 	{
 		BufferResources* bufferResources = getBufferResources(d3d9Device);
 
-		if (bufferResources	== NULL)
+		if (bufferResources	== nullptr)
 		{
 			mOwnerTexture->createInternalResources(d3d9Device);
 			bufferResources = getBufferResources(d3d9Device);

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -460,7 +460,7 @@ namespace BansheeEngine
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		if(!tex->_isBindableAsShaderResource())
+		if(!tex->isBindableAsShaderResource())
 			CM_EXCEPT(InvalidParametersException, "Texture you have specified cannot be bound to a shader.");
 
 		if(gptype != GPT_FRAGMENT_PROGRAM && gptype != GPT_VERTEX_PROGRAM)

+ 2 - 0
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -305,6 +305,8 @@ namespace BansheeEngine
 
 	void D3D9RenderWindow::setFullscreen(const VideoMode& mode, UINT32 refreshRateIdx)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		const VideoOutputInfo& outputInfo = mode.getParentOutput();
 		UINT32 monitorIdx = 0;
 		for (UINT32 i = 0; i < outputInfo.getNumVideoModes(); i++)

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 208 - 373
CamelotD3D9Renderer/Source/CmD3D9Texture.cpp


+ 101 - 169
CamelotD3D9Renderer/Source/CmD3D9VertexBuffer.cpp

@@ -1,30 +1,3 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-    (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
 #include "CmD3D9VertexBuffer.h"
 #include "CmD3D9Mappings.h"
 #include "CmException.h"
@@ -33,31 +6,71 @@ THE SOFTWARE.
 #include "CmD3D9Device.h"
 #include "CmD3D9ResourceManager.h"
 
-namespace BansheeEngine {
-
-	//---------------------------------------------------------------------
-    D3D9VertexBuffer::D3D9VertexBuffer(UINT32 vertexSize, 
-        UINT32 numVertices, GpuBufferUsage usage, 
-        bool useSystemMemory)
+namespace BansheeEngine 
+{
+    D3D9VertexBuffer::D3D9VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMemory)
 		: VertexBuffer(vertexSize, numVertices, usage, useSystemMemory)
-    {    }
-	//---------------------------------------------------------------------
+    { }
+
     D3D9VertexBuffer::~D3D9VertexBuffer()
-    {	    }
-	//---------------------------------------------------------------------
-    void* D3D9VertexBuffer::lockImpl(UINT32 offset, 
-        UINT32 length, GpuLockOptions options)
+    { }
+
+	void D3D9VertexBuffer::initialize_internal()
+	{
+		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
+
+		// Set the desired memory pool
+		mBufferDesc.Pool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;
+
+		// Allocate the system memory buffer.
+		mSystemMemoryBuffer = (UINT8*)cm_alloc(getSizeInBytes());
+		memset(mSystemMemoryBuffer, 0, getSizeInBytes());
+
+		// Case we have to create this buffer resource on loading.
+		if (D3D9RenderSystem::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
+		{
+			for (UINT32 i = 0; i < D3D9RenderSystem::getResourceCreationDeviceCount(); ++i)
+			{
+				IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getResourceCreationDevice(i);
+
+				createBuffer(d3d9Device, mBufferDesc.Pool);
+			}
+		}
+
+		VertexBuffer::initialize_internal();
+	}
+
+	void D3D9VertexBuffer::destroy_internal()
+	{
+		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
+
+		for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
+		{
+			BufferResources* bufferResources = bufferResourcesPair.second;
+
+			SAFE_RELEASE(bufferResources->mBuffer);
+
+			if (bufferResources != nullptr)
+				cm_delete(bufferResources);
+		}
+
+		mMapDeviceToBufferResources.clear();
+
+		if (mSystemMemoryBuffer != nullptr)
+			cm_free(mSystemMemoryBuffer);
+
+		VertexBuffer::destroy_internal();
+	}
+
+    void* D3D9VertexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
     {		
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
 		if (options != GBL_READ_ONLY)
 		{
-			DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
-
-			while (it != mMapDeviceToBufferResources.end())
+			for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
 			{
-				BufferResources* bufferResources = it->second;
-
+				BufferResources* bufferResources = bufferResourcesPair.second;
 				bufferResources->mOutOfDate = true;
 
 				if(bufferResources->mLockLength > 0)
@@ -77,49 +90,35 @@ namespace BansheeEngine {
 				
 				if (bufferResources->mLockOptions != GBL_WRITE_ONLY_DISCARD)
 					bufferResources->mLockOptions = options;					
-
-				++it;
 			}
 		}
 
 		return mSystemMemoryBuffer + offset;		
     }
-	//---------------------------------------------------------------------
-	void D3D9VertexBuffer::unlockImpl(void)
+
+	void D3D9VertexBuffer::unlockImpl()
     {
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
-		// TODO PORT - Don't know what the next frame number is. Add a method for that
-		//UINT32 nextFrameNumber = Root::getSingleton().getNextFrameNumber();
-		UINT32 nextFrameNumber = 0;
-
-		while (it != mMapDeviceToBufferResources.end())
+		for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
 		{
-			BufferResources* bufferResources = it->second;
+			BufferResources* bufferResources = bufferResourcesPair.second;
 
-			if (bufferResources->mOutOfDate && 
-				bufferResources->mBuffer != NULL&&
-				nextFrameNumber - bufferResources->mLastUsedFrame <= 1)
+			if (bufferResources->mOutOfDate && bufferResources->mBuffer != nullptr)
 				updateBufferResources(mSystemMemoryBuffer, bufferResources);
-
-			++it;
-		}			
+		}
     }
-	//---------------------------------------------------------------------
-    void D3D9VertexBuffer::readData(UINT32 offset, UINT32 length, 
-        void* pDest)
+
+    void D3D9VertexBuffer::readData(UINT32 offset, UINT32 length, void* dest)
     {
-        // There is no functional interface in D3D, just do via manual 
-        // lock, copy & unlock
         void* pSrc = this->lock(offset, length, GBL_READ_ONLY);
-        memcpy(pDest, pSrc, length);
+        memcpy(dest, pSrc, length);
         this->unlock();
 
     }
-	//---------------------------------------------------------------------
-	void D3D9VertexBuffer::writeData(UINT32 offset, UINT32 length, 
-		const void* pSource, BufferWriteType writeFlags)
+
+	void D3D9VertexBuffer::writeData(UINT32 offset, UINT32 length, const void* source, 
+		BufferWriteType writeFlags)
 	{
 		GpuLockOptions lockOption = GBL_WRITE_ONLY;
 		if(writeFlags == BufferWriteType::Discard)
@@ -127,13 +126,11 @@ namespace BansheeEngine {
 		else if(writeFlags == BufferWriteType::NoOverwrite)
 			lockOption = GBL_WRITE_ONLY_NO_OVERWRITE;
 
-		// There is no functional interface in D3D, just do via manual 
-		// lock, copy & unlock
 		void* pDst = this->lock(offset, length, lockOption);
-		memcpy(pDst, pSource, length);
+		memcpy(pDst, source, length);
 		this->unlock();
 	}
-	//---------------------------------------------------------------------
+
 	void D3D9VertexBuffer::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
 	{			
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
@@ -141,39 +138,39 @@ namespace BansheeEngine {
 		if (D3D9RenderSystem::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
 			createBuffer(d3d9Device, mBufferDesc.Pool);
 	}
-	//---------------------------------------------------------------------
+
 	void D3D9VertexBuffer::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
 	{	
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.find(d3d9Device);
+		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
 
-		if (it != mMapDeviceToBufferResources.end())	
+		if (iterFind != mMapDeviceToBufferResources.end())	
 		{								
-			SAFE_RELEASE(it->second->mBuffer);
+			SAFE_RELEASE(iterFind->second->mBuffer);
 
-			if(it->second != nullptr)
-				cm_delete<PoolAlloc>(it->second);
+			if(iterFind->second != nullptr)
+				cm_delete(iterFind->second);
 
-			mMapDeviceToBufferResources.erase(it);
+			mMapDeviceToBufferResources.erase(iterFind);
 		}	
 	}
-	//---------------------------------------------------------------------
+
 	void D3D9VertexBuffer::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
 	{	
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
 		if (mBufferDesc.Pool == D3DPOOL_DEFAULT)
 		{
-			DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.find(d3d9Device);
+			auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
 
-			if (it != mMapDeviceToBufferResources.end())
+			if (iterFind != mMapDeviceToBufferResources.end())
 			{				
-				SAFE_RELEASE(it->second->mBuffer);	
+				SAFE_RELEASE(iterFind->second->mBuffer);	
 			}					
 		}
 	}
-	//---------------------------------------------------------------------
+
 	void D3D9VertexBuffer::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
 	{		
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
@@ -181,7 +178,7 @@ namespace BansheeEngine {
 		if (D3D9RenderSystem::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
 			createBuffer(d3d9Device, mBufferDesc.Pool);
 	}
-	//---------------------------------------------------------------------
+
 	void D3D9VertexBuffer::createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool)
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
@@ -189,18 +186,16 @@ namespace BansheeEngine {
 		BufferResources* bufferResources;		
 		HRESULT hr;
 
-		DeviceToBufferResourcesIterator it;
-
 		// Find the vertex buffer of this device.
-		it = mMapDeviceToBufferResources.find(d3d9Device);
-		if (it != mMapDeviceToBufferResources.end())
+		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
+		if (iterFind != mMapDeviceToBufferResources.end())
 		{
-			bufferResources = it->second;
+			bufferResources = iterFind->second;
 			SAFE_RELEASE(bufferResources->mBuffer);
 		}
 		else
 		{
-			bufferResources = cm_new<BufferResources, PoolAlloc>();			
+			bufferResources = cm_new<BufferResources>();			
 			mMapDeviceToBufferResources[d3d9Device] = bufferResources;
 		}
 
@@ -209,16 +204,12 @@ namespace BansheeEngine {
 		bufferResources->mLockOffset = 0;
 		bufferResources->mLockLength = getSizeInBytes();
 		bufferResources->mLockOptions = GBL_READ_WRITE;
-
-		// TODO PORT - Don't know what the next frame number is. Add a method for that
-		//bufferResources->mLastUsedFrame = Root::getSingleton().getNextFrameNumber();
-		bufferResources->mLastUsedFrame = 0;
 		
 		// Create the vertex buffer
 		hr = d3d9Device->CreateVertexBuffer(
 			static_cast<UINT>(mSizeInBytes), 
 			D3D9Mappings::get(mUsage), 
-			0, // No FVF here, thank you.
+			0,
 			ePool,
 			&bufferResources->mBuffer,
 			NULL);
@@ -236,43 +227,34 @@ namespace BansheeEngine {
 			CM_EXCEPT(RenderingAPIException, "Cannot get D3D9 Vertex buffer desc: " + msg);
 		}		
 	}
-	//---------------------------------------------------------------------
-	IDirect3DVertexBuffer9* D3D9VertexBuffer::getD3D9VertexBuffer(void)
+
+	IDirect3DVertexBuffer9* D3D9VertexBuffer::getD3D9VertexBuffer()
 	{
 		IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getActiveD3D9Device();
-		DeviceToBufferResourcesIterator it;
-
-		// Find the vertex buffer of this device.
-		it = mMapDeviceToBufferResources.find(d3d9Device);
+		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
 
 		// Case vertex buffer was not found for the current device -> create it.		
-		if (it == mMapDeviceToBufferResources.end() || it->second->mBuffer == NULL)		
+		if (iterFind == mMapDeviceToBufferResources.end() || iterFind->second->mBuffer == nullptr)
 		{						
 			createBuffer(d3d9Device, mBufferDesc.Pool);
-			it = mMapDeviceToBufferResources.find(d3d9Device);			
+			iterFind = mMapDeviceToBufferResources.find(d3d9Device);
 		}
 
-		if (it->second->mOutOfDate)
-			updateBufferResources(mSystemMemoryBuffer, it->second);
+		if (iterFind->second->mOutOfDate)
+			updateBufferResources(mSystemMemoryBuffer, iterFind->second);
 		
-		// TODO PORT - Don't know what the next frame number is. Add a method for that
-		//it->second->mLastUsedFrame = Root::getSingleton().getNextFrameNumber();
-		it->second->mLastUsedFrame = 0;
-
-		return it->second->mBuffer;
+		return iterFind->second->mBuffer;
 	}	
-	//---------------------------------------------------------------------
-	bool D3D9VertexBuffer::updateBufferResources(const char* systemMemoryBuffer,
-		BufferResources* bufferResources)
+
+	bool D3D9VertexBuffer::updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources)
 	{		
-		assert(bufferResources != NULL);
-		assert(bufferResources->mBuffer != NULL);
+		assert(bufferResources != nullptr);
+		assert(bufferResources->mBuffer != nullptr);
 		assert(bufferResources->mOutOfDate);
 				
 		void* dstBytes;
 		HRESULT hr;
 		
-
 		// Lock the buffer.
 		hr = bufferResources->mBuffer->Lock(
 			static_cast<UINT>(bufferResources->mLockOffset), 
@@ -303,54 +285,4 @@ namespace BansheeEngine {
 
 		return true;		
 	}
-	//--------------------------------------------------------------------
-	void D3D9VertexBuffer::initialize_internal()
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		D3DPOOL eResourcePool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_MANAGED;    		
-
-		// Set the desired memory pool.
-		mBufferDesc.Pool = eResourcePool;
-
-		// Allocate the system memory buffer.
-		mSystemMemoryBuffer = (char*)cm_alloc<ScratchAlloc>(getSizeInBytes());
-		memset(mSystemMemoryBuffer, 0, getSizeInBytes());	
-
-		// Case we have to create this buffer resource on loading.
-		if (D3D9RenderSystem::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
-		{
-			for (UINT32 i = 0; i < D3D9RenderSystem::getResourceCreationDeviceCount(); ++i)
-			{
-				IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getResourceCreationDevice(i);
-
-				createBuffer(d3d9Device, mBufferDesc.Pool);
-			}
-		}
-
-		VertexBuffer::initialize_internal();
-	}
-	//---------------------------------------------------------------------
-	void D3D9VertexBuffer::destroy_internal()
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-			DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
-
-		while (it != mMapDeviceToBufferResources.end())
-		{
-			SAFE_RELEASE(it->second->mBuffer);
-
-			if(it->second != nullptr)
-				cm_delete<PoolAlloc>(it->second);
-
-			++it;
-		}	
-		mMapDeviceToBufferResources.clear();   
-
-		if(mSystemMemoryBuffer != nullptr)
-			cm_free<ScratchAlloc>(mSystemMemoryBuffer);
-
-		VertexBuffer::destroy_internal();
-	}
 }

+ 1 - 1
CamelotGLRenderer/Include/CmGLPixelBuffer.h

@@ -48,7 +48,7 @@ namespace BansheeEngine
 
 	protected:  
 		/// Lock a box
-		PixelData lockImpl(const PixelVolume lockBox,  GpuLockOptions options);
+		PixelData lockImpl(PixelVolume lockBox,  GpuLockOptions options);
 
 		/// Unlock a box
 		void unlockImpl(void);

+ 21 - 10
CamelotGLRenderer/Include/CmWin32Window.h

@@ -11,9 +11,19 @@ namespace BansheeEngine
         ~Win32Window();
 
 		/**
-		 * @copydoc RenderWindow::setFullscreen
+		 * @copydoc RenderWindow::setFullscreen(UINT32, UINT32, float, UINT32)
 		 */
-		void setFullscreen(bool fullScreen, UINT32 width, UINT32 height);
+		void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
+
+		/**
+		 * @copydoc RenderWindow::setFullscreen(const VideoMode&, UINT32)
+		 */
+		void setFullscreen(const VideoMode& mode, UINT32 refreshRateIdx = 0);
+
+		/**
+		 * @copydoc RenderWindow::setWindowed
+		 */
+		void setWindowed();
 
 		/**
 		 * @copydoc RenderWindow::setHidden
@@ -109,14 +119,15 @@ namespace BansheeEngine
 
 		protected:
 			Win32GLSupport &mGLSupport;
-			HWND	mHWnd;					// Win32 Window handle
-			HDC		mHDC;
-			bool    mIsExternal;
-			char*   mDeviceName;
-			bool    mIsExternalGLControl;
-			bool    mSizing;
-			bool	mClosed;
-			int     mDisplayFrequency;      // fullscreen only, to restore display
+			HWND mHWnd;					// Win32 Window handle
+			HDC	mHDC;
+			bool mIsExternal;
+			bool mIsChild;
+			char* mDeviceName;
+			bool mIsExternalGLControl;
+			bool mSizing;
+			bool mClosed;
+			int mDisplayFrequency;      // fullscreen only, to restore display
 			Win32Context *mContext;
     };
 }

+ 1 - 1
CamelotGLRenderer/Source/CmGLPixelBuffer.cpp

@@ -70,7 +70,7 @@ namespace BansheeEngine
 		}
 	}
 
-	PixelData GLPixelBuffer::lockImpl(const PixelVolume lockBox,  GpuLockOptions options)
+	PixelData GLPixelBuffer::lockImpl(PixelVolume lockBox,  GpuLockOptions options)
 	{
 		allocateBuffer();
 		if(options != GBL_WRITE_ONLY_DISCARD) 

+ 87 - 90
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -10,6 +10,7 @@
 #include "CmWin32GLSupport.h"
 #include "CmWin32Context.h"
 #include "Win32/CmPlatformWndProc.h"
+#include "CmWin32VideoModeInfo.h"
 #include "CmGLPixelFormat.h"
 
 GLenum GLEWAPIENTRY wglewContextInit(BansheeEngine::GLSupport *glSupport);
@@ -68,6 +69,7 @@ namespace BansheeEngine
 			if (mHWnd)
 			{
 				mIsExternal = true;
+				mIsChild = true;
 				mIsFullScreen = false;
 			}
 
@@ -352,120 +354,115 @@ namespace BansheeEngine
 		RenderWindow::destroy_internal();
 	}
 
-	void Win32Window::setFullscreen(bool fullScreen, UINT32 width, UINT32 height)
+	void Win32Window::setFullscreen(UINT32 width, UINT32 height, float refreshRate, UINT32 monitorIdx)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		if (mIsFullScreen != fullScreen || width != mWidth || height != mHeight)
-		{
-			mIsFullScreen = fullScreen;
-			DWORD dwStyle = WS_VISIBLE | WS_CLIPCHILDREN;
+		if (mIsChild)
+			return;
 
-			if (mIsFullScreen)
-			{
-				dwStyle |= WS_POPUP;
+		const Win32VideoModeInfo& videoModeInfo = static_cast<const Win32VideoModeInfo&>(RenderSystem::instance().getVideoModeInfo());
+		UINT32 numOutputs = videoModeInfo.getNumOutputs();
+		if (numOutputs == 0)
+			return;
 
-				DEVMODE displayDeviceMode;
+		UINT32 actualMonitorIdx = std::min(monitorIdx, numOutputs - 1);
+		const Win32VideoOutputInfo& outputInfo = static_cast<const Win32VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
 
-				memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
-				displayDeviceMode.dmSize = sizeof(DEVMODE);
-				displayDeviceMode.dmBitsPerPel = mColorDepth;
-				displayDeviceMode.dmPelsWidth = width;
-				displayDeviceMode.dmPelsHeight = height;
-				displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
-				if (mDisplayFrequency)
-				{
-					displayDeviceMode.dmDisplayFrequency = mDisplayFrequency;
-					displayDeviceMode.dmFields |= DM_DISPLAYFREQUENCY;
+		bool oldFullscreen = mIsFullScreen;
 
-					if (ChangeDisplaySettingsEx(mDeviceName, &displayDeviceMode, NULL, 
-						CDS_FULLSCREEN | CDS_TEST, NULL) != DISP_CHANGE_SUCCESSFUL)					
-					{
-						// TODO LOG PORT - Log this somewhere
-						//LogManager::getSingleton().logMessage(LML_NORMAL, "ChangeDisplaySettings with user display frequency failed");
-						displayDeviceMode.dmFields ^= DM_DISPLAYFREQUENCY;
-					}
-				}
-				else
-				{
-					// try a few
-					displayDeviceMode.dmDisplayFrequency = 100;
-					displayDeviceMode.dmFields |= DM_DISPLAYFREQUENCY;
-					if (ChangeDisplaySettingsEx(mDeviceName, &displayDeviceMode, NULL, 
-						CDS_FULLSCREEN | CDS_TEST, NULL) != DISP_CHANGE_SUCCESSFUL)		
-					{
-						displayDeviceMode.dmDisplayFrequency = 75;
-						if (ChangeDisplaySettingsEx(mDeviceName, &displayDeviceMode, NULL, 
-							CDS_FULLSCREEN | CDS_TEST, NULL) != DISP_CHANGE_SUCCESSFUL)		
-						{
-							displayDeviceMode.dmFields ^= DM_DISPLAYFREQUENCY;
-						}
-					}
+		DWORD style = WS_VISIBLE | WS_CLIPCHILDREN | WS_POPUP;
+		mDisplayFrequency = Math::roundToInt(refreshRate);
+		mIsFullScreen = true;
 
-				}
-				// move window to 0,0 before display switch
-				SetWindowPos(mHWnd, HWND_TOPMOST, 0, 0, mWidth, mHeight, SWP_NOACTIVATE);
+		DEVMODE displayDeviceMode;
 
-				if (ChangeDisplaySettingsEx(mDeviceName, &displayDeviceMode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL)				
-				{
-					// TODO LOG PORT - Log this somewhere
-					//LogManager::getSingleton().logMessage(LML_CRITICAL, "ChangeDisplaySettings failed");
-				}
+		memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
+		displayDeviceMode.dmSize = sizeof(DEVMODE);
+		displayDeviceMode.dmBitsPerPel = mColorDepth;
+		displayDeviceMode.dmPelsWidth = width;
+		displayDeviceMode.dmPelsHeight = height;
+		displayDeviceMode.dmDisplayFrequency = mDisplayFrequency;
+		displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
 
-				// Get the nearest monitor to this window.
-				HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
+		// Move window to 0,0 before display switch
+		SetWindowPos(mHWnd, HWND_TOPMOST, 0, 0, mWidth, mHeight, SWP_NOACTIVATE);
 
-				// Get monitor info	
-				MONITORINFO monitorInfo;
+		if (ChangeDisplaySettingsEx(mDeviceName, &displayDeviceMode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL)
+		{
+			CM_EXCEPT(RenderingAPIException, "ChangeDisplaySettings failed");
+		}
 
-				memset(&monitorInfo, 0, sizeof(MONITORINFO));
-				monitorInfo.cbSize = sizeof(MONITORINFO);
-				GetMonitorInfo(hMonitor, &monitorInfo);
+		HMONITOR hMonitor = outputInfo.getMonitorHandle();
+		MONITORINFO monitorInfo;
 
-				mTop = monitorInfo.rcMonitor.top;
-				mLeft = monitorInfo.rcMonitor.left;
+		memset(&monitorInfo, 0, sizeof(MONITORINFO));
+		monitorInfo.cbSize = sizeof(MONITORINFO);
+		GetMonitorInfo(hMonitor, &monitorInfo);
 
-				SetWindowLong(mHWnd, GWL_STYLE, dwStyle);
-				SetWindowPos(mHWnd, HWND_TOPMOST, mLeft, mTop, width, height,
-					SWP_NOACTIVATE);
-				mWidth = width;
-				mHeight = height;
-			}
-			else
+		mTop = monitorInfo.rcMonitor.top;
+		mLeft = monitorInfo.rcMonitor.left;
+		mWidth = width;
+		mHeight = height;
+
+		SetWindowLong(mHWnd, GWL_STYLE, style);
+		SetWindowPos(mHWnd, HWND_TOPMOST, mLeft, mTop, width, height, SWP_NOACTIVATE);
+	}
+
+	void Win32Window::setFullscreen(const VideoMode& mode, UINT32 refreshRateIdx)
+	{
+		THROW_IF_NOT_CORE_THREAD;
+
+		const VideoOutputInfo& outputInfo = mode.getParentOutput();
+		UINT32 monitorIdx = 0;
+		for (UINT32 i = 0; i < outputInfo.getNumVideoModes(); i++)
+		{
+			if (&outputInfo.getVideoMode(i) == &mode)
 			{
-				dwStyle |= WS_OVERLAPPEDWINDOW;
+				monitorIdx = i;
+				break;
+			}
+		}
 
-				// drop out of fullscreen
-				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
+		setFullscreen(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(refreshRateIdx), monitorIdx);
+	}
 
-				// calculate overall dimensions for requested client area
-				unsigned int winWidth, winHeight;
-				_adjustWindow(width, height, &winWidth, &winHeight);
+	void Win32Window::setWindowed()
+	{
+		THROW_IF_NOT_CORE_THREAD;
+
+		if (!mIsFullScreen)
+			return;
+
+		mIsFullScreen = false;
 
-				// deal with centreing when switching down to smaller resolution
+		DWORD style = WS_VISIBLE | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
 
-				HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
-				MONITORINFO monitorInfo;
-				memset(&monitorInfo, 0, sizeof(MONITORINFO));
-				monitorInfo.cbSize = sizeof(MONITORINFO);
-				GetMonitorInfo(hMonitor, &monitorInfo);
+		// Drop out of fullscreen
+		ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
 
-				LONG screenw = monitorInfo.rcWork.right  - monitorInfo.rcWork.left;
-				LONG screenh = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
+		// Calculate overall dimensions for requested client area
+		unsigned int winWidth, winHeight;
+		_adjustWindow(mWidth, mHeight, &winWidth, &winHeight);
 
+		// Deal with centering when switching down to smaller resolution
+		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
+		MONITORINFO monitorInfo;
+		memset(&monitorInfo, 0, sizeof(MONITORINFO));
+		monitorInfo.cbSize = sizeof(MONITORINFO);
+		GetMonitorInfo(hMonitor, &monitorInfo);
 
-				int left = screenw > int(winWidth) ? ((screenw - int(winWidth)) / 2) : 0;
-				int top = screenh > int(winHeight) ? ((screenh - int(winHeight)) / 2) : 0;
+		LONG screenw = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
+		LONG screenh = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
 
-				SetWindowLong(mHWnd, GWL_STYLE, dwStyle);
-				SetWindowPos(mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight,
-					SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);
-				mWidth = width;
-				mHeight = height;
+		int left = screenw > int(winWidth) ? ((screenw - int(winWidth)) / 2) : 0;
+		int top = screenh > int(winHeight) ? ((screenh - int(winHeight)) / 2) : 0;
 
-				_windowMovedOrResized();
-			}
-		}
+		SetWindowLong(mHWnd, GWL_STYLE, style);
+		SetWindowPos(mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight,
+			SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);
+
+		_windowMovedOrResized();
 	}
 
 	bool Win32Window::isActive(void) const

+ 13 - 3
ExampleProject/Main/Main.cpp

@@ -1,4 +1,3 @@
-#include "stdafx.h"
 #include <windows.h>
 
 #include "CmApplication.h"
@@ -25,6 +24,7 @@
 #include "CmHString.h"
 #include "CmRenderWindow.h"
 #include "CmSceneObject.h"
+#include "CmCoreThread.h"
 
 using namespace BansheeEngine;
 
@@ -36,6 +36,8 @@ Path exampleVertexShaderPath = "..\\..\\..\\..\\Data\\Examples\\example_vs.gpupr
 GUIButton* toggleFullscreenButton = nullptr;
 UINT32 resolutionWidth = 1280;
 UINT32 resolutionHeight = 720;
+bool fullscreen = false;
+const VideoMode* videoMode = nullptr;
 
 HMesh exampleModel;
 HTexture exampleTexture;
@@ -72,9 +74,17 @@ void toggleFullscreen()
 {
 	RenderWindowPtr window = gApplication().getPrimaryWindow();
 
+	if (fullscreen)
+	{
+		gCoreAccessor().setWindowed(window);
+	}
+	else
+	{
+		//gCoreAccessor().setFullscreen(window, *videoMode);
+		gCoreAccessor().setFullscreen(window, 1920, 1200);
+	}
 
-
-	//window->setFullscreen(!window->isFullScreen(), resolutionWidth, resolutionHeight);
+	fullscreen = !fullscreen;
 }
 
 void setUpExample()

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно