Browse Source

RenderTarget refactor to comply with new CoreObject synchronization

Marko Pintera 11 years ago
parent
commit
87946cf44b
37 changed files with 867 additions and 653 deletions
  1. 0 2
      BansheeCore/BansheeCore.vcxproj
  2. 0 6
      BansheeCore/BansheeCore.vcxproj.filters
  3. 42 0
      BansheeCore/Include/BsCommonTypes.h
  4. 3 1
      BansheeCore/Include/BsCoreObject.h
  5. 1 32
      BansheeCore/Include/BsCoreObjectCore.h
  6. 4 0
      BansheeCore/Include/BsCoreObjectManager.h
  7. 28 12
      BansheeCore/Include/BsMultiRenderTexture.h
  8. 25 40
      BansheeCore/Include/BsRenderTarget.h
  9. 0 59
      BansheeCore/Include/BsRenderTargetManager.h
  10. 28 17
      BansheeCore/Include/BsRenderTexture.h
  11. 15 16
      BansheeCore/Include/BsRenderWindow.h
  12. 0 5
      BansheeCore/Source/BsCoreApplication.cpp
  13. 8 1
      BansheeCore/Source/BsCoreObjectManager.cpp
  14. 37 22
      BansheeCore/Source/BsMultiRenderTexture.cpp
  15. 51 30
      BansheeCore/Source/BsRenderTarget.cpp
  16. 0 74
      BansheeCore/Source/BsRenderTargetManager.cpp
  17. 33 24
      BansheeCore/Source/BsRenderTexture.cpp
  18. 12 14
      BansheeCore/Source/BsRenderWindow.cpp
  19. 2 2
      BansheeD3D11RenderSystem/Include/BsD3D11MultiRenderTexture.h
  20. 1 2
      BansheeD3D11RenderSystem/Include/BsD3D11RenderTexture.h
  21. 36 9
      BansheeD3D11RenderSystem/Include/BsD3D11RenderWindow.h
  22. 8 2
      BansheeD3D11RenderSystem/Source/BsD3D11MultiRenderTexture.cpp
  23. 8 3
      BansheeD3D11RenderSystem/Source/BsD3D11RenderTexture.cpp
  24. 123 82
      BansheeD3D11RenderSystem/Source/BsD3D11RenderWindow.cpp
  25. 7 2
      BansheeD3D9RenderSystem/Include/BsD3D9MultiRenderTexture.h
  26. 6 2
      BansheeD3D9RenderSystem/Include/BsD3D9RenderTexture.h
  27. 36 9
      BansheeD3D9RenderSystem/Include/BsD3D9RenderWindow.h
  28. 16 7
      BansheeD3D9RenderSystem/Source/BsD3D9MultiRenderTexture.cpp
  29. 14 6
      BansheeD3D9RenderSystem/Source/BsD3D9RenderTexture.cpp
  30. 112 72
      BansheeD3D9RenderSystem/Source/BsD3D9RenderWindow.cpp
  31. 1 1
      BansheeEditorExec/BsEditorExec.cpp
  32. 12 2
      BansheeGLRenderSystem/Include/BsGLMultiRenderTexture.h
  33. 11 2
      BansheeGLRenderSystem/Include/BsGLRenderTexture.h
  34. 35 8
      BansheeGLRenderSystem/Include/BsWin32Window.h
  35. 22 4
      BansheeGLRenderSystem/Source/BsGLMultiRenderTexture.cpp
  36. 21 6
      BansheeGLRenderSystem/Source/BsGLRenderTexture.cpp
  37. 109 77
      BansheeGLRenderSystem/Source/BsWin32Window.cpp

+ 0 - 2
BansheeCore/BansheeCore.vcxproj

@@ -309,7 +309,6 @@
     <ClInclude Include="Include\BsPlatform.h" />
     <ClInclude Include="Include\BsPlatform.h" />
     <ClInclude Include="Include\BsProfilingManager.h" />
     <ClInclude Include="Include\BsProfilingManager.h" />
     <ClInclude Include="Include\BsQueryManager.h" />
     <ClInclude Include="Include\BsQueryManager.h" />
-    <ClInclude Include="Include\BsRenderTargetManager.h" />
     <ClInclude Include="Include\BsResourceManifest.h" />
     <ClInclude Include="Include\BsResourceManifest.h" />
     <ClInclude Include="Include\BsResourceManifestRTTI.h" />
     <ClInclude Include="Include\BsResourceManifestRTTI.h" />
     <ClInclude Include="Include\BsResourceMetaData.h" />
     <ClInclude Include="Include\BsResourceMetaData.h" />
@@ -478,7 +477,6 @@
     <ClCompile Include="Source\BsProfilingManager.cpp" />
     <ClCompile Include="Source\BsProfilingManager.cpp" />
     <ClCompile Include="Source\BsQueryManager.cpp" />
     <ClCompile Include="Source\BsQueryManager.cpp" />
     <ClCompile Include="Source\BsRenderer.cpp" />
     <ClCompile Include="Source\BsRenderer.cpp" />
-    <ClCompile Include="Source\BsRenderTargetManager.cpp" />
     <ClCompile Include="Source\BsResourceManifest.cpp" />
     <ClCompile Include="Source\BsResourceManifest.cpp" />
     <ClCompile Include="Source\BsResourceMetaData.cpp" />
     <ClCompile Include="Source\BsResourceMetaData.cpp" />
     <ClCompile Include="Source\BsTextureImportOptions.cpp" />
     <ClCompile Include="Source\BsTextureImportOptions.cpp" />

+ 0 - 6
BansheeCore/BansheeCore.vcxproj.filters

@@ -528,9 +528,6 @@
     <ClInclude Include="Include\BsResourceMetaDataRTTI.h">
     <ClInclude Include="Include\BsResourceMetaDataRTTI.h">
       <Filter>Header Files\RTTI</Filter>
       <Filter>Header Files\RTTI</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="Include\BsRenderTargetManager.h">
-      <Filter>Header Files\RenderSystem</Filter>
-    </ClInclude>
     <ClInclude Include="Include\BsViewportRTTI.h">
     <ClInclude Include="Include\BsViewportRTTI.h">
       <Filter>Header Files\RTTI</Filter>
       <Filter>Header Files\RTTI</Filter>
     </ClInclude>
     </ClInclude>
@@ -839,9 +836,6 @@
     <ClCompile Include="Source\BsResourceMetaData.cpp">
     <ClCompile Include="Source\BsResourceMetaData.cpp">
       <Filter>Source Files\Resources</Filter>
       <Filter>Source Files\Resources</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Source\BsRenderTargetManager.cpp">
-      <Filter>Source Files\RenderSystem</Filter>
-    </ClCompile>
     <ClCompile Include="Source\BsMaterialProxy.cpp">
     <ClCompile Include="Source\BsMaterialProxy.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>

+ 42 - 0
BansheeCore/Include/BsCommonTypes.h

@@ -355,5 +355,47 @@ namespace BansheeEngine
 		UINT32 numArraySlices;
 		UINT32 numArraySlices;
 	};
 	};
 
 
+	/**
+	 * @brief	Helper class for syncing dirty data from sim CoreObject to
+	 *			core CoreObject and other way around.
+	 */
+	class CoreSyncData
+	{
+	public:
+		CoreSyncData()
+			:data(nullptr), size(0)
+		{ }
+
+		CoreSyncData(UINT8* data, UINT32 size)
+			:data(data), size(size)
+		{ }
+
+		/**
+		 * @brief	Gets the internal data and checks the data is of
+		 *			valid size.
+		 */
+		template<class T>
+		const T& getData()
+		{
+			assert(sizeof(T) == size);
+
+			return *(T*)data;
+		}
+
+		/**
+		 * @brief	Returns a pointer to internal data buffer.
+		 */
+		UINT8* getBuffer() const { return data; }
+
+		/**
+		 * @brief	Returns the size of the internal data buffer.
+		 */
+		UINT32 getBufferSize() const { return size; }
+
+	private:
+		UINT8* data;
+		UINT32 size;
+	};
+
 	typedef Map<String, String> NameValuePairList;
 	typedef Map<String, String> NameValuePairList;
 }
 }

+ 3 - 1
BansheeCore/Include/BsCoreObject.h

@@ -178,7 +178,6 @@ namespace BansheeEngine
 		friend class CoreObjectManager;
 		friend class CoreObjectManager;
 
 
 		volatile UINT8 mFlags;
 		volatile UINT8 mFlags;
-		CoreObjectCore* mCoreSpecific;
 		UINT32 mCoreDirtyFlags;
 		UINT32 mCoreDirtyFlags;
 		UINT64 mInternalID; // ID == 0 is not a valid ID
 		UINT64 mInternalID; // ID == 0 is not a valid ID
 		std::weak_ptr<CoreObject> mThis;
 		std::weak_ptr<CoreObject> mThis;
@@ -254,6 +253,9 @@ namespace BansheeEngine
 		 *			was populated with data from the core thread.
 		 *			was populated with data from the core thread.
 		 */
 		 */
 		virtual void syncFromCore(const CoreSyncData& data) { }
 		virtual void syncFromCore(const CoreSyncData& data) { }
+
+	protected:
+		CoreObjectCore* mCoreSpecific;
 	};
 	};
 
 
 	/**
 	/**

+ 1 - 32
BansheeCore/Include/BsCoreObjectCore.h

@@ -5,38 +5,6 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	/**
-	 * @brief	Helper class for syncing dirty data from sim CoreObject to
-	 *			core CoreObject and other way around.
-	 */
-	class CoreSyncData
-	{
-	public:
-		CoreSyncData()
-			:data(nullptr), size(0)
-		{ }
-
-		CoreSyncData(UINT8* data, UINT32 size)
-			:data(data), size(size)
-		{ }
-
-		/**
-		 * @brief	Gets the internal data and checks the data is of
-		 *			valid size.
-		 */
-		template<class T>
-		const T& getData()
-		{
-			assert(sizeof(T) == size);
-
-			return *(T*)data;
-		}
-
-	private:
-		UINT8* data;
-		UINT32 size;
-	};
-
 	/**
 	/**
 	 * @brief	Represents part of a CoreObject that is meant to be used specifically
 	 * @brief	Represents part of a CoreObject that is meant to be used specifically
 	 *			on the core thread. 
 	 *			on the core thread. 
@@ -50,6 +18,7 @@ namespace BansheeEngine
 	{
 	{
 	public:
 	public:
 		CoreObjectCore();
 		CoreObjectCore();
+		virtual ~CoreObjectCore() {}
 
 
 	protected:
 	protected:
 		friend class CoreObjectManager;
 		friend class CoreObjectManager;

+ 4 - 0
BansheeCore/Include/BsCoreObjectManager.h

@@ -114,7 +114,11 @@ namespace BansheeEngine
 	private:
 	private:
 		UINT64 mNextAvailableID;
 		UINT64 mNextAvailableID;
 		Map<UINT64, CoreObject*> mObjects;
 		Map<UINT64, CoreObject*> mObjects;
+
+		FrameAlloc* mSimSyncDataAlloc;
 		Map<UINT64, SimStoredSyncData> mSimSyncData;
 		Map<UINT64, SimStoredSyncData> mSimSyncData;
+
+		FrameAlloc* mCoreSyncDataAlloc;
 		Map<UINT64, CoreStoredSyncData> mCoreSyncData;
 		Map<UINT64, CoreStoredSyncData> mCoreSyncData;
 		BS_MUTEX(mObjectsMutex);
 		BS_MUTEX(mObjectsMutex);
 	};
 	};

+ 28 - 12
BansheeCore/Include/BsMultiRenderTexture.h

@@ -24,9 +24,24 @@ namespace BansheeEngine
 	public:
 	public:
 		virtual ~MultiRenderTextureProperties() { }
 		virtual ~MultiRenderTextureProperties() { }
 
 
-	private:
+	protected:
 		friend class MultiRenderTextureCore;
 		friend class MultiRenderTextureCore;
 		friend class MultiRenderTexture;
 		friend class MultiRenderTexture;
+
+		/**
+		 * @copydoc	RenderTargetProperties::copyToBuffer
+		 */
+		virtual void copyToBuffer(UINT8* buffer) const;
+
+		/**
+		 * @copydoc	RenderTargetProperties::copyFromBuffer
+		 */
+		virtual void copyFromBuffer(UINT8* buffer);
+
+		/**
+		 * @copydoc	RenderTargetProperties::getSize
+		 */
+		virtual UINT32 getSize() const;
 	};
 	};
 
 
 	/**
 	/**
@@ -48,6 +63,16 @@ namespace BansheeEngine
 		 */
 		 */
 		MultiRenderTexture* getNonCore() const;
 		MultiRenderTexture* getNonCore() const;
 
 
+		/**
+		 * @copydoc	CoreObjectCore::initialize
+		 */
+		virtual void initialize();
+
+		/**
+		 * @copydoc	CoreObjectCore::destroy
+		 */
+		virtual void destroy();
+
 	private:
 	private:
 		/**
 		/**
 		 * @brief	Checks that all render surfaces and depth/stencil surface match. If they do not match
 		 * @brief	Checks that all render surfaces and depth/stencil surface match. If they do not match
@@ -61,6 +86,8 @@ namespace BansheeEngine
 	protected:
 	protected:
 		Vector<TextureViewPtr> mColorSurfaces;
 		Vector<TextureViewPtr> mColorSurfaces;
 		TextureViewPtr mDepthStencilSurface;
 		TextureViewPtr mDepthStencilSurface;
+
+		MULTI_RENDER_TEXTURE_DESC mDesc;
 	};
 	};
 
 
 	/**
 	/**
@@ -105,17 +132,6 @@ namespace BansheeEngine
 	protected:
 	protected:
 		MultiRenderTexture() { }
 		MultiRenderTexture() { }
 
 
-		/**
-		 * @copydoc	RenderTexture::createCore
-		 */
-		virtual RenderTargetCore* createCore();
-
-		/**
-		 * @brief	Creates a core implementation of a render texture. This implementation
-		 *			is to be used on the core thread only.
-		 */
-		virtual MultiRenderTextureCore* createCore(MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc) = 0;
-
 		MULTI_RENDER_TEXTURE_DESC mDesc;
 		MULTI_RENDER_TEXTURE_DESC mDesc;
 	};
 	};
 }
 }

+ 25 - 40
BansheeCore/Include/BsRenderTarget.h

@@ -27,11 +27,6 @@ namespace BansheeEngine
 	public:
 	public:
 		virtual ~RenderTargetProperties() { }
 		virtual ~RenderTargetProperties() { }
 
 
-		/**
-		 * @brief	Returns a name of the render target, used for easier identification.
-		 */
-        const String& getName() const { return mName; }
-
 		/**
 		/**
 		 * @brief	Returns width of the render target, in pixels.
 		 * @brief	Returns width of the render target, in pixels.
 		 * 
 		 * 
@@ -97,16 +92,24 @@ namespace BansheeEngine
 		 */
 		 */
 		bool requiresTextureFlipping() const { return mRequiresTextureFlipping; }
 		bool requiresTextureFlipping() const { return mRequiresTextureFlipping; }
 
 
-		/**
-		 * @brief	Copies all data from the provided object to this object.
-		 */
-		virtual void copyFrom(const RenderTargetProperties& other);
-
 	protected:
 	protected:
 		friend class RenderTargetCore;
 		friend class RenderTargetCore;
 		friend class RenderTarget;
 		friend class RenderTarget;
 
 
-		String mName;
+		/**
+		 * @brief	Copies all internal data to the specified buffer.
+		 */
+		virtual void copyToBuffer(UINT8* buffer) const;
+
+		/**
+		 * @brief	Initializes all internal data from the specified buffer.
+		 */
+		virtual void copyFromBuffer(UINT8* buffer);
+
+		/**
+		 * @brief	Returns the size of the buffer needed to hold all internal data.
+		 */
+		virtual UINT32 getSize() const;
 
 
 		UINT32 mWidth = 0;
 		UINT32 mWidth = 0;
 		UINT32 mHeight = 0;
 		UINT32 mHeight = 0;
@@ -129,7 +132,7 @@ namespace BansheeEngine
 	 *
 	 *
 	 * @note	Core thread only.
 	 * @note	Core thread only.
 	 */
 	 */
-	class BS_CORE_EXPORT RenderTargetCore
+	class BS_CORE_EXPORT RenderTargetCore : public CoreObjectCore
 	{
 	{
 	public:
 	public:
 		/**
 		/**
@@ -184,30 +187,21 @@ namespace BansheeEngine
 		 */
 		 */
 		RenderTarget* getNonCore() const { return mParent; }
 		RenderTarget* getNonCore() const { return mParent; }
 
 
-		/**
-		 * @brief	Returns true if this object was modified and the sim thread version requires an update.
-		 */
-		bool _isCoreDirty() const { return mCoreDirty; }
+	protected:
+		friend class RenderTarget;
 
 
 		/**
 		/**
-		 * @brief	Marks the object as clean. Usually called after the sim thread version was updated.
+		 * @copydoc	CoreObjectCore::syncFromCore
 		 */
 		 */
-		void _markCoreClean() { mCoreDirty = false; }
-
-	protected:
-		friend class RenderTarget;
+		virtual CoreSyncData syncFromCore(FrameAlloc* allocator);
 
 
 		/**
 		/**
-		 * @brief	Marks this object as modified. Signals the system that the sim thread verison
-		 *			of the object needs an update.
+		 * @copydoc	CoreObjectCore::syncToCore
 		 */
 		 */
-		void markCoreDirty() { mCoreDirty = true; }
+		virtual void syncToCore(const CoreSyncData& data);
 
 
 		RenderTargetProperties* mProperties;
 		RenderTargetProperties* mProperties;
 		RenderTarget* mParent;
 		RenderTarget* mParent;
-
-	private:
-		bool mCoreDirty = true;
 	};
 	};
 
 
 	/**
 	/**
@@ -255,8 +249,6 @@ namespace BansheeEngine
 		mutable Event<void()> onResized;
 		mutable Event<void()> onResized;
 
 
     protected:
     protected:
-		friend class RenderTargetManager;
-
 		RenderTarget();
 		RenderTarget();
 
 
 		/**
 		/**
@@ -266,22 +258,15 @@ namespace BansheeEngine
 		virtual RenderTargetProperties* createProperties() const = 0;
 		virtual RenderTargetProperties* createProperties() const = 0;
 
 
 		/**
 		/**
-		 * @brief	Creates a core implementation of a render target. This implementation
-		 *			is to be used on the core thread only.
-		 */
-		virtual RenderTargetCore* createCore() = 0;
-
-		/**
-		 * @copydoc	CoreObject::initialize_internal
+		 * @copydoc	CoreObject::syncToCore
 		 */
 		 */
-		virtual void initialize_internal();
+		virtual CoreSyncData syncToCore(FrameAlloc* allocator);
 
 
 		/**
 		/**
-		 * @copydoc	CoreObject::destroy_internal
+		 * @copydoc	CoreObject::syncFromCore
 		 */
 		 */
-		virtual void destroy_internal();
+		virtual void syncFromCore(const CoreSyncData& data);
 
 
-		RenderTargetCore* mCore;
 		RenderTargetProperties* mProperties;
 		RenderTargetProperties* mProperties;
     };
     };
 }
 }

+ 0 - 59
BansheeCore/Include/BsRenderTargetManager.h

@@ -1,59 +0,0 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsModule.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Handles render target updates, usually cross-thread updates triggered
-	 *			by render targets getting modified on the core thread.
-	 *
-	 * @note	Internal class.
-	 */
-	class BS_CORE_EXPORT RenderTargetManager : public Module<RenderTargetManager>
-	{
-		struct RenderTargetData
-		{
-			RenderTargetProperties* properties;
-			bool dirty;
-		};
-
-	public:
-		~RenderTargetManager();
-
-		/**
-		 * @brief	Registers a new render target with the manager.
-		 *			Should be called when RT is initialized on the core thread.
-		 *
-		 * @note	Core thread only.
-		 */
-		void registerRenderTarget(RenderTarget* rt);
-
-		/**
-		 * @brief	Unregisters a render target from the manager.
-		 *			Should be called when RT is getting destroyed on the core thread.
-		 *
-		 * @note	Core thread only.
-		 */
-		void unregisterRenderTarget(RenderTarget* rt);
-
-		/**
-		 * @brief	Called once per frame on the core thread. Should be called at the end of
-		 *			the frame once all render target related methods have completed.
-		 *
-		 * @note	Core thread only.
-		 */
-		void updateCore();
-
-		/**
-		 * @brief	Called once per frame on the sim thread. Should be called at the beginning
-		 *			of the frame before the code can access render targets.
-		 */
-		void update();
-
-	private:
-		UnorderedMap<RenderTarget*, RenderTargetData> mRenderTargets;
-		BS_MUTEX(mMutex);
-	};
-}

+ 28 - 17
BansheeCore/Include/BsRenderTexture.h

@@ -23,14 +23,24 @@ namespace BansheeEngine
 	public:
 	public:
 		virtual ~RenderTextureProperties() { }
 		virtual ~RenderTextureProperties() { }
 
 
-		/**
-		 * @copydoc	RenderTargetProperties::copyFrom
-		 */
-		virtual void copyFrom(const RenderTargetProperties& other);
-
 	private:
 	private:
 		friend class RenderTextureCore;
 		friend class RenderTextureCore;
 		friend class RenderTexture;
 		friend class RenderTexture;
+
+		/**
+		 * @copydoc	RenderTargetProperties::copyToBuffer
+		 */
+		virtual void copyToBuffer(UINT8* buffer) const;
+
+		/**
+		 * @copydoc	RenderTargetProperties::copyFromBuffer
+		 */
+		virtual void copyFromBuffer(UINT8* buffer);
+
+		/**
+		 * @copydoc	RenderTargetProperties::getSize
+		 */
+		virtual UINT32 getSize() const;
 	};
 	};
 
 
 	/**
 	/**
@@ -64,8 +74,21 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class RenderTexture;
 		friend class RenderTexture;
 
 
+		/**
+		 * @copydoc	CoreObjectCore::initialize
+		 */
+		virtual void initialize();
+
+		/**
+		 * @copydoc	CoreObjectCore::destroy
+		 */
+		virtual void destroy();
+
 		TextureViewPtr mColorSurface;
 		TextureViewPtr mColorSurface;
 		TextureViewPtr mDepthStencilSurface;
 		TextureViewPtr mDepthStencilSurface;
+
+		RENDER_SURFACE_DESC mColorSurfaceDesc;
+		RENDER_SURFACE_DESC mDepthStencilSurfaceDesc;
 	};
 	};
 
 
 	/**
 	/**
@@ -143,18 +166,6 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual void initialize(const RENDER_TEXTURE_DESC& desc);
 		virtual void initialize(const RENDER_TEXTURE_DESC& desc);
 
 
-		/**
-		 * @copydoc	RenderTexture::createCore
-		 */
-		virtual RenderTargetCore* createCore();
-
-		/**
-		 * @brief	Creates a core implementation of a render texture. This implementation
-		 *			is to be used on the core thread only.
-		 */
-		virtual RenderTextureCore* createCore(RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-			const RENDER_SURFACE_DESC& depthStencilSurfaceDesc) = 0;
-
 	protected:
 	protected:
 		HTexture mBindableColorTex;
 		HTexture mBindableColorTex;
 		HTexture mBindableDepthStencilTex;
 		HTexture mBindableDepthStencilTex;

+ 15 - 16
BansheeCore/Include/BsRenderWindow.h

@@ -90,15 +90,25 @@ namespace BansheeEngine
 		 */
 		 */
 		bool isHidden() const { return mHidden; }
 		bool isHidden() const { return mHidden; }
 
 
-		/**
-		 * @copydoc	RenderTargetProperties::copyFrom
-		 */
-		virtual void copyFrom(const RenderTargetProperties& other);
-
 	protected:
 	protected:
 		friend class RenderWindowCore;
 		friend class RenderWindowCore;
 		friend class RenderWindow;
 		friend class RenderWindow;
 
 
+		/**
+		 * @copydoc	RenderTargetProperties::copyToBuffer
+		 */
+		virtual void copyToBuffer(UINT8* buffer) const;
+
+		/**
+		 * @copydoc	RenderTargetProperties::copyFromBuffer
+		 */
+		virtual void copyFromBuffer(UINT8* buffer);
+
+		/**
+		 * @copydoc	RenderTargetProperties::getSize
+		 */
+		virtual UINT32 getSize() const;
+
 		bool mIsFullScreen = false;
 		bool mIsFullScreen = false;
 		INT32 mLeft = 0;
 		INT32 mLeft = 0;
 		INT32 mTop = 0;
 		INT32 mTop = 0;
@@ -263,17 +273,6 @@ namespace BansheeEngine
 
 
 		RenderWindow() { }
 		RenderWindow() { }
 
 
-		/**
-		 * @copydoc	RenderWindow::createCore
-		 */
-		virtual RenderTargetCore* createCore();
-
-		/**
-		 * @brief	Creates a core implementation of a render window. This implementation
-		 *			is to be used on the core thread only.
-		 */
-		virtual RenderWindowCore* createCore(RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc) = 0;
-        
 	protected:
 	protected:
 		RENDER_WINDOW_DESC mDesc;
 		RENDER_WINDOW_DESC mDesc;
     };
     };

+ 0 - 5
BansheeCore/Source/BsCoreApplication.cpp

@@ -26,7 +26,6 @@
 #include "BsMaterialManager.h"
 #include "BsMaterialManager.h"
 #include "BsFontManager.h"
 #include "BsFontManager.h"
 #include "BsRenderWindowManager.h"
 #include "BsRenderWindowManager.h"
-#include "BsRenderTargetManager.h"
 #include "BsRenderer.h"
 #include "BsRenderer.h"
 #include "BsDeferredCallManager.h"
 #include "BsDeferredCallManager.h"
 #include "BsCoreThread.h"
 #include "BsCoreThread.h"
@@ -69,7 +68,6 @@ namespace BansheeEngine
 		MemStack::beginThread();
 		MemStack::beginThread();
 
 
 		MessageHandler::startUp();
 		MessageHandler::startUp();
-		RenderTargetManager::startUp();
 		UUIDGenerator::startUp();
 		UUIDGenerator::startUp();
 		ProfilerCPU::startUp();
 		ProfilerCPU::startUp();
 		ProfilingManager::startUp();
 		ProfilingManager::startUp();
@@ -155,7 +153,6 @@ namespace BansheeEngine
 		ProfilingManager::shutDown();
 		ProfilingManager::shutDown();
 		ProfilerCPU::shutDown();
 		ProfilerCPU::shutDown();
 		UUIDGenerator::shutDown();
 		UUIDGenerator::shutDown();
-		RenderTargetManager::shutDown();
 		MessageHandler::shutDown();
 		MessageHandler::shutDown();
 
 
 		MemStack::endThread();
 		MemStack::endThread();
@@ -171,7 +168,6 @@ namespace BansheeEngine
 			gProfilerCPU().beginThread("Sim");
 			gProfilerCPU().beginThread("Sim");
 
 
 			gCoreThread().update();
 			gCoreThread().update();
-			RenderTargetManager::instance().update();
 			Platform::_update();
 			Platform::_update();
 			DeferredCallManager::instance()._update();
 			DeferredCallManager::instance()._update();
 			RenderWindowManager::instance()._update();
 			RenderWindowManager::instance()._update();
@@ -222,7 +218,6 @@ namespace BansheeEngine
 
 
 			// This should be called after accessors are submitted to ensure we don't sync CoreObjects that are about to be destroyed (They're only ever destroyed from accessors)
 			// This should be called after accessors are submitted to ensure we don't sync CoreObjects that are about to be destroyed (They're only ever destroyed from accessors)
 			gCoreThread().queueCommand(std::bind(&CoreObjectManager::syncDownload, CoreObjectManager::instancePtr(), CoreObjectSync::Core, gCoreThread().getFrameAlloc()));
 			gCoreThread().queueCommand(std::bind(&CoreObjectManager::syncDownload, CoreObjectManager::instancePtr(), CoreObjectSync::Core, gCoreThread().getFrameAlloc()));
-			gCoreThread().queueCommand(std::bind(&RenderTargetManager::updateCore, RenderTargetManager::instancePtr()));
 			gCoreThread().queueCommand(std::bind(&CoreApplication::endCoreProfiling, this));
 			gCoreThread().queueCommand(std::bind(&CoreApplication::endCoreProfiling, this));
 			gCoreThread().queueCommand(std::bind(&CoreApplication::frameRenderingFinishedCallback, this));
 			gCoreThread().queueCommand(std::bind(&CoreApplication::frameRenderingFinishedCallback, this));
 
 

+ 8 - 1
BansheeCore/Source/BsCoreObjectManager.cpp

@@ -2,11 +2,12 @@
 #include "BsCoreObject.h"
 #include "BsCoreObject.h"
 #include "BsCoreObjectCore.h"
 #include "BsCoreObjectCore.h"
 #include "BsException.h"
 #include "BsException.h"
+#include "BsFrameAlloc.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	CoreObjectManager::CoreObjectManager()
 	CoreObjectManager::CoreObjectManager()
-		:mNextAvailableID(1)
+		:mNextAvailableID(1), mSimSyncDataAlloc(nullptr), mCoreSyncDataAlloc(nullptr)
 	{
 	{
 
 
 	} 
 	} 
@@ -57,6 +58,7 @@ namespace BansheeEngine
 
 
 		if (type == CoreObjectSync::Sim)
 		if (type == CoreObjectSync::Sim)
 		{
 		{
+			mCoreSyncDataAlloc = allocator;
 			for (auto& objectData : mObjects)
 			for (auto& objectData : mObjects)
 			{
 			{
 				CoreObject* object = objectData.second;
 				CoreObject* object = objectData.second;
@@ -72,6 +74,7 @@ namespace BansheeEngine
 		}
 		}
 		else
 		else
 		{
 		{
+			mSimSyncDataAlloc = allocator;
 			for (auto& objectData : mObjects)
 			for (auto& objectData : mObjects)
 			{
 			{
 				CoreObject* object = objectData.second;
 				CoreObject* object = objectData.second;
@@ -97,6 +100,8 @@ namespace BansheeEngine
 			{
 			{
 				const CoreStoredSyncData& syncData = objectData.second;
 				const CoreStoredSyncData& syncData = objectData.second;
 				syncData.destinationObj->syncToCore(syncData.syncData);
 				syncData.destinationObj->syncToCore(syncData.syncData);
+
+				mCoreSyncDataAlloc->dealloc(syncData.syncData.getBuffer());
 			}
 			}
 
 
 			mCoreSyncData.clear();
 			mCoreSyncData.clear();
@@ -107,6 +112,8 @@ namespace BansheeEngine
 			{
 			{
 				const SimStoredSyncData& syncData = objectData.second;
 				const SimStoredSyncData& syncData = objectData.second;
 				syncData.destinationObj->syncFromCore(syncData.syncData);
 				syncData.destinationObj->syncFromCore(syncData.syncData);
+
+				mSimSyncDataAlloc->dealloc(syncData.syncData.getBuffer());
 			}
 			}
 
 
 			mSimSyncData.clear();
 			mSimSyncData.clear();

+ 37 - 22
BansheeCore/Source/BsMultiRenderTexture.cpp

@@ -7,14 +7,37 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	void MultiRenderTextureProperties::copyToBuffer(UINT8* buffer) const
+	{
+		*(MultiRenderTextureProperties*)buffer = *this;
+	}
+
+	void MultiRenderTextureProperties::copyFromBuffer(UINT8* buffer)
+	{
+		*this = *(MultiRenderTextureProperties*)buffer;
+	}
+
+	UINT32 MultiRenderTextureProperties::getSize() const
+	{
+		return sizeof(MultiRenderTextureProperties);
+	}
+
 	MultiRenderTextureCore::MultiRenderTextureCore(MultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
 	MultiRenderTextureCore::MultiRenderTextureCore(MultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
-		:RenderTargetCore(parent, properties)
+		:RenderTargetCore(parent, properties), mDesc(desc)
+	{ }
+
+	MultiRenderTextureCore::~MultiRenderTextureCore()
+	{ }
+
+	void MultiRenderTextureCore::initialize()
 	{
 	{
+		RenderTargetCore::initialize();
+
 		mColorSurfaces.resize(BS_MAX_MULTIPLE_RENDER_TARGETS);
 		mColorSurfaces.resize(BS_MAX_MULTIPLE_RENDER_TARGETS);
 
 
-		for (size_t i = 0; i < desc.colorSurfaces.size(); i++)
+		for (size_t i = 0; i < mDesc.colorSurfaces.size(); i++)
 		{
 		{
-			if (desc.colorSurfaces[i].texture != nullptr)
+			if (mDesc.colorSurfaces[i].texture != nullptr)
 			{
 			{
 				if (i >= BS_MAX_MULTIPLE_RENDER_TARGETS)
 				if (i >= BS_MAX_MULTIPLE_RENDER_TARGETS)
 				{
 				{
@@ -24,31 +47,31 @@ namespace BansheeEngine
 					continue;
 					continue;
 				}
 				}
 
 
-				TexturePtr texture = desc.colorSurfaces[i].texture;
+				TexturePtr texture = mDesc.colorSurfaces[i].texture;
 
 
 				if (texture->getUsage() != TU_RENDERTARGET)
 				if (texture->getUsage() != TU_RENDERTARGET)
 					BS_EXCEPT(InvalidParametersException, "Provided texture is not created with render target usage.");
 					BS_EXCEPT(InvalidParametersException, "Provided texture is not created with render target usage.");
 
 
-				mColorSurfaces[i] = Texture::requestView(texture, desc.colorSurfaces[i].mipLevel, 1,
-					desc.colorSurfaces[i].face, 1, GVU_RENDERTARGET);
+				mColorSurfaces[i] = Texture::requestView(texture, mDesc.colorSurfaces[i].mipLevel, 1,
+					mDesc.colorSurfaces[i].face, 1, GVU_RENDERTARGET);
 			}
 			}
 		}
 		}
 
 
-		if (desc.depthStencilSurface.texture != nullptr)
+		if (mDesc.depthStencilSurface.texture != nullptr)
 		{
 		{
-			TexturePtr texture = desc.depthStencilSurface.texture;
+			TexturePtr texture = mDesc.depthStencilSurface.texture;
 
 
 			if (texture->getUsage() != TU_DEPTHSTENCIL)
 			if (texture->getUsage() != TU_DEPTHSTENCIL)
 				BS_EXCEPT(InvalidParametersException, "Provided texture is not created with depth stencil usage.");
 				BS_EXCEPT(InvalidParametersException, "Provided texture is not created with depth stencil usage.");
 
 
-			mDepthStencilSurface = Texture::requestView(texture, desc.depthStencilSurface.mipLevel, 1,
-				desc.depthStencilSurface.face, 1, GVU_DEPTHSTENCIL);
+			mDepthStencilSurface = Texture::requestView(texture, mDesc.depthStencilSurface.mipLevel, 1,
+				mDesc.depthStencilSurface.face, 1, GVU_DEPTHSTENCIL);
 		}
 		}
 
 
 		throwIfBuffersDontMatch();
 		throwIfBuffersDontMatch();
 	}
 	}
 
 
-	MultiRenderTextureCore::~MultiRenderTextureCore()
+	void MultiRenderTextureCore::destroy()
 	{
 	{
 		for (auto iter = mColorSurfaces.begin(); iter != mColorSurfaces.end(); ++iter)
 		for (auto iter = mColorSurfaces.begin(); iter != mColorSurfaces.end(); ++iter)
 		{
 		{
@@ -58,6 +81,8 @@ namespace BansheeEngine
 
 
 		if (mDepthStencilSurface != nullptr)
 		if (mDepthStencilSurface != nullptr)
 			Texture::releaseView(mDepthStencilSurface);
 			Texture::releaseView(mDepthStencilSurface);
+
+		RenderTargetCore::destroy();
 	}
 	}
 
 
 	void MultiRenderTextureCore::throwIfBuffersDontMatch() const
 	void MultiRenderTextureCore::throwIfBuffersDontMatch() const
@@ -166,17 +191,7 @@ namespace BansheeEngine
 
 
 	MultiRenderTextureCore* MultiRenderTexture::getCore() const
 	MultiRenderTextureCore* MultiRenderTexture::getCore() const
 	{
 	{
-		return static_cast<MultiRenderTextureCore*>(mCore);
-	}
-
-	RenderTargetCore* MultiRenderTexture::createCore()
-	{
-		MultiRenderTextureProperties* coreProperties = bs_new<MultiRenderTextureProperties>();
-		MultiRenderTextureProperties* myProperties = static_cast<MultiRenderTextureProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
-
-		return createCore(coreProperties, mDesc);
+		return static_cast<MultiRenderTextureCore*>(mCoreSpecific);
 	}
 	}
 
 
 	MultiRenderTexturePtr MultiRenderTexture::create(const MULTI_RENDER_TEXTURE_DESC& desc)
 	MultiRenderTexturePtr MultiRenderTexture::create(const MULTI_RENDER_TEXTURE_DESC& desc)

+ 51 - 30
BansheeCore/Source/BsRenderTarget.cpp

@@ -3,13 +3,23 @@
 #include "BsException.h"
 #include "BsException.h"
 #include "BsRenderSystem.h"
 #include "BsRenderSystem.h"
 #include "BsCoreThread.h"
 #include "BsCoreThread.h"
-#include "BsRenderTargetManager.h"
+#include "BsFrameAlloc.h"
 
 
-namespace BansheeEngine 
+namespace BansheeEngine
 {
 {
-	void RenderTargetProperties::copyFrom(const RenderTargetProperties& other)
+	void RenderTargetProperties::copyToBuffer(UINT8* buffer) const
 	{
 	{
-		*this = other;
+		*(RenderTargetProperties*)buffer = *this;
+	}
+
+	void RenderTargetProperties::copyFromBuffer(UINT8* buffer)
+	{
+		*this = *(RenderTargetProperties*)buffer;
+	}
+
+	UINT32 RenderTargetProperties::getSize() const
+	{
+		return sizeof(RenderTargetProperties);
 	}
 	}
 
 
 	RenderTargetCore::RenderTargetCore(RenderTarget* parent, RenderTargetProperties* properties)
 	RenderTargetCore::RenderTargetCore(RenderTarget* parent, RenderTargetProperties* properties)
@@ -23,27 +33,47 @@ namespace BansheeEngine
 		bs_delete(mProperties);
 		bs_delete(mProperties);
 	}
 	}
 
 
+	CoreSyncData RenderTargetCore::syncFromCore(FrameAlloc* allocator)
+	{
+		UINT8* buffer = allocator->alloc(mProperties->getSize());
+		mProperties->copyToBuffer(buffer);
+
+		return CoreSyncData(buffer, mProperties->getSize());
+	}
+
+	void RenderTargetCore::syncToCore(const CoreSyncData& data)
+	{
+		assert(data.getBufferSize() == mProperties->getSize());
+
+		mProperties->copyFromBuffer(data.getBuffer());
+	}
+
 	void RenderTargetCore::getCustomAttribute(const String& name, void* pData) const
 	void RenderTargetCore::getCustomAttribute(const String& name, void* pData) const
 	{
 	{
 		BS_EXCEPT(InvalidParametersException, "Attribute not found.");
 		BS_EXCEPT(InvalidParametersException, "Attribute not found.");
 	}
 	}
 
 
-	const RenderTargetProperties& RenderTargetCore::getProperties() const 
-	{ 
+	const RenderTargetProperties& RenderTargetCore::getProperties() const
+	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		return *mProperties; 
+		return *mProperties;
+	}
+
+	RenderTargetCore* RenderTarget::getCore() const
+	{
+		return static_cast<RenderTargetCore*>(mCoreSpecific);
 	}
 	}
 
 
-    RenderTarget::RenderTarget()
-		:mCore(nullptr), mProperties(nullptr)
-    {
-    }
+	RenderTarget::RenderTarget()
+		:mProperties(nullptr)
+	{
+	}
 
 
-    RenderTarget::~RenderTarget()
-    {
+	RenderTarget::~RenderTarget()
+	{
 		bs_delete(mProperties);
 		bs_delete(mProperties);
-    }
+	}
 
 
 	const RenderTargetProperties& RenderTarget::getProperties() const
 	const RenderTargetProperties& RenderTarget::getProperties() const
 	{
 	{
@@ -52,28 +82,19 @@ namespace BansheeEngine
 		return *mProperties;
 		return *mProperties;
 	}
 	}
 
 
-	RenderTargetCore* RenderTarget::getCore() const
+	CoreSyncData RenderTarget::syncToCore(FrameAlloc* allocator)
 	{
 	{
-		return mCore;
-	}
+		UINT8* buffer = allocator->alloc(mProperties->getSize());
+		mProperties->copyToBuffer(buffer);
 
 
-	void RenderTarget::initialize_internal()
-	{
-		CoreObject::initialize_internal();
-
-		mCore = createCore();
-
-		RenderTargetManager::instance().registerRenderTarget(this);
+		return CoreSyncData(buffer, mProperties->getSize());
 	}
 	}
 
 
-	void RenderTarget::destroy_internal()
+	void RenderTarget::syncFromCore(const CoreSyncData& data)
 	{
 	{
-		RenderTargetManager::instance().unregisterRenderTarget(this);
-
-		bs_delete(mCore);
-		mCore = nullptr;
+		assert(data.getBufferSize() == mProperties->getSize());
 
 
-		CoreObject::destroy_internal();
+		mProperties->copyFromBuffer(data.getBuffer());
 	}
 	}
 
 
 	void RenderTarget::getCustomAttribute(const String& name, void* pData) const
 	void RenderTarget::getCustomAttribute(const String& name, void* pData) const

+ 0 - 74
BansheeCore/Source/BsRenderTargetManager.cpp

@@ -1,74 +0,0 @@
-#include "BsRenderTargetManager.h"
-#include "BsRenderTarget.h"
-
-#include "BsRenderWindow.h"
-
-namespace BansheeEngine
-{
-	RenderTargetManager::~RenderTargetManager()
-	{
-		assert(mRenderTargets.size() == 0 && "All render targets must be released before render target manager can be shut down.");
-	}
-
-	void RenderTargetManager::registerRenderTarget(RenderTarget* rt)
-	{
-		BS_LOCK_MUTEX(mMutex);
-
-		RenderTargetData rtData;
-		rtData.properties = rt->createProperties();
-		rtData.dirty = true;
-
-		mRenderTargets.insert(std::make_pair(rt, rtData));
-	}
-
-	void RenderTargetManager::unregisterRenderTarget(RenderTarget* rt)
-	{
-		BS_LOCK_MUTEX(mMutex);
-
-		auto findIter = mRenderTargets.find(rt);
-		if (findIter == mRenderTargets.end())
-			return;
-
-		RenderTargetData& rtData = findIter->second;
-		bs_delete(rtData.properties);
-
-		mRenderTargets.erase(findIter);
-	}
-
-	void RenderTargetManager::updateCore()
-	{
-		BS_LOCK_MUTEX(mMutex);
-
-		for (auto& rtPair : mRenderTargets)
-		{
-			RenderTarget* rt = rtPair.first;
-			RenderTargetData& rtData = rtPair.second;
-
-			if (rt->getCore()->_isCoreDirty())
-			{
-				rtData.properties->copyFrom(rt->getCore()->getProperties());
-				rtData.dirty = true;
-
-				rt->getCore()->_markCoreClean();
-			}
-		}
-	}
-
-	void RenderTargetManager::update()
-	{
-		BS_LOCK_MUTEX(mMutex);
-
-		for (auto& rtPair : mRenderTargets)
-		{
-			RenderTarget* rt = rtPair.first;
-			RenderTargetData& rtData = rtPair.second;
-
-			if (rtData.dirty)
-			{
-				rt->mProperties->copyFrom(*rtData.properties);
-
-				rtData.dirty = false;
-			}
-		}
-	}
-}

+ 33 - 24
BansheeCore/Source/BsRenderTexture.cpp

@@ -8,37 +8,54 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	void RenderTextureProperties::copyFrom(const RenderTargetProperties& other)
+	void RenderTextureProperties::copyToBuffer(UINT8* buffer) const
 	{
 	{
-		const RenderTextureProperties& windowProps = static_cast<const RenderTextureProperties&>(other);
+		*(RenderTextureProperties*)buffer = *this;
+	}
+
+	void RenderTextureProperties::copyFromBuffer(UINT8* buffer)
+	{
+		*this = *(RenderTextureProperties*)buffer;
+	}
 
 
-		*this = windowProps;
+	UINT32 RenderTextureProperties::getSize() const
+	{
+		return sizeof(RenderTextureProperties);
 	}
 	}
 
 
 	RenderTextureCore::RenderTextureCore(RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
 	RenderTextureCore::RenderTextureCore(RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
 		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
 		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
-		:RenderTargetCore(parent, properties), mColorSurface(nullptr), mDepthStencilSurface(nullptr)
+		:RenderTargetCore(parent, properties), mColorSurface(nullptr), mDepthStencilSurface(nullptr), 
+		mColorSurfaceDesc(colorSurfaceDesc), mDepthStencilSurfaceDesc(depthStencilSurfaceDesc)
+	{ }
+
+	RenderTextureCore::~RenderTextureCore()
+	{ }
+
+	void RenderTextureCore::initialize()
 	{
 	{
-		if (colorSurfaceDesc.texture != nullptr)
+		RenderTargetCore::initialize();
+
+		if (mColorSurfaceDesc.texture != nullptr)
 		{
 		{
-			TexturePtr texture = colorSurfaceDesc.texture;
+			TexturePtr texture = mColorSurfaceDesc.texture;
 
 
 			if (texture->getUsage() != TU_RENDERTARGET)
 			if (texture->getUsage() != TU_RENDERTARGET)
 				BS_EXCEPT(InvalidParametersException, "Provided texture is not created with render target usage.");
 				BS_EXCEPT(InvalidParametersException, "Provided texture is not created with render target usage.");
 
 
-			mColorSurface = Texture::requestView(texture, colorSurfaceDesc.mipLevel, 1,
-				colorSurfaceDesc.face, 1, GVU_RENDERTARGET);
+			mColorSurface = Texture::requestView(texture, mColorSurfaceDesc.mipLevel, 1,
+				mColorSurfaceDesc.face, 1, GVU_RENDERTARGET);
 		}
 		}
 
 
-		if (depthStencilSurfaceDesc.texture != nullptr)
+		if (mDepthStencilSurfaceDesc.texture != nullptr)
 		{
 		{
-			TexturePtr texture = depthStencilSurfaceDesc.texture;
+			TexturePtr texture = mDepthStencilSurfaceDesc.texture;
 
 
 			if (texture->getUsage() != TU_DEPTHSTENCIL)
 			if (texture->getUsage() != TU_DEPTHSTENCIL)
 				BS_EXCEPT(InvalidParametersException, "Provided texture is not created with depth stencil usage.");
 				BS_EXCEPT(InvalidParametersException, "Provided texture is not created with depth stencil usage.");
 
 
-			mDepthStencilSurface = Texture::requestView(texture, depthStencilSurfaceDesc.mipLevel, 1,
-				depthStencilSurfaceDesc.face, 1, GVU_DEPTHSTENCIL);
+			mDepthStencilSurface = Texture::requestView(texture, mDepthStencilSurfaceDesc.mipLevel, 1,
+				mDepthStencilSurfaceDesc.face, 1, GVU_DEPTHSTENCIL);
 		}
 		}
 
 
 		throwIfBuffersDontMatch();
 		throwIfBuffersDontMatch();
@@ -63,13 +80,15 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	RenderTextureCore::~RenderTextureCore()
+	void RenderTextureCore::destroy()
 	{
 	{
 		if (mColorSurface != nullptr)
 		if (mColorSurface != nullptr)
 			Texture::releaseView(mColorSurface);
 			Texture::releaseView(mColorSurface);
 
 
 		if (mDepthStencilSurface != nullptr)
 		if (mDepthStencilSurface != nullptr)
 			Texture::releaseView(mDepthStencilSurface);
 			Texture::releaseView(mDepthStencilSurface);
+
+		RenderTargetCore::destroy();
 	}
 	}
 
 
 	void RenderTextureCore::throwIfBuffersDontMatch() const
 	void RenderTextureCore::throwIfBuffersDontMatch() const
@@ -116,7 +135,7 @@ namespace BansheeEngine
 
 
 	RenderTextureCore* RenderTexture::getCore() const 
 	RenderTextureCore* RenderTexture::getCore() const 
 	{ 
 	{ 
-		return static_cast<RenderTextureCore*>(mCore); 
+		return static_cast<RenderTextureCore*>(mCoreSpecific); 
 	}
 	}
 
 
 	void RenderTexture::initialize(const RENDER_TEXTURE_DESC& desc)
 	void RenderTexture::initialize(const RENDER_TEXTURE_DESC& desc)
@@ -151,14 +170,4 @@ namespace BansheeEngine
 
 
 		RenderTarget::initialize();
 		RenderTarget::initialize();
 	}
 	}
-
-	RenderTargetCore* RenderTexture::createCore()
-	{
-		RenderTextureProperties* coreProperties = bs_new<RenderTextureProperties>();
-		RenderTextureProperties* myProperties = static_cast<RenderTextureProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
-
-		return createCore(coreProperties, mColorSurfaceDesc, mDepthStencilSurfaceDesc);
-	}
 }
 }

+ 12 - 14
BansheeCore/Source/BsRenderWindow.cpp

@@ -6,11 +6,19 @@
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
-	void RenderWindowProperties::copyFrom(const RenderTargetProperties& other)
+	void RenderWindowProperties::copyToBuffer(UINT8* buffer) const
 	{
 	{
-		const RenderWindowProperties& windowProps = static_cast<const RenderWindowProperties&>(other);
+		*(RenderWindowProperties*)buffer = *this;
+	}
 
 
-		*this = windowProps;
+	void RenderWindowProperties::copyFromBuffer(UINT8* buffer)
+	{
+		*this = *(RenderWindowProperties*)buffer;
+	}
+
+	UINT32 RenderWindowProperties::getSize() const
+	{
+		return sizeof(RenderWindowProperties);
 	}
 	}
 
 
 	RenderWindowCore::RenderWindowCore(RenderWindow* parent, RenderWindowProperties* properties)
 	RenderWindowCore::RenderWindowCore(RenderWindow* parent, RenderWindowProperties* properties)
@@ -96,17 +104,7 @@ namespace BansheeEngine
 
 
 	RenderWindowCore* RenderWindow::getCore() const
 	RenderWindowCore* RenderWindow::getCore() const
 	{
 	{
-		return static_cast<RenderWindowCore*>(mCore);
-	}
-
-	RenderTargetCore* RenderWindow::createCore()
-	{
-		RenderWindowProperties* coreProperties = bs_new<RenderWindowProperties>();
-		RenderWindowProperties* myProperties = static_cast<RenderWindowProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
-
-		return createCore(coreProperties, mDesc);
+		return static_cast<RenderWindowCore*>(mCoreSpecific);
 	}
 	}
 
 
 	RenderWindowPtr RenderWindow::create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow)
 	RenderWindowPtr RenderWindow::create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow)

+ 2 - 2
BansheeD3D11RenderSystem/Include/BsD3D11MultiRenderTexture.h

@@ -47,8 +47,8 @@ namespace BansheeEngine
 		virtual RenderTargetProperties* createProperties() const;
 		virtual RenderTargetProperties* createProperties() const;
 
 
 		/**
 		/**
-		 * @copydoc	MultiRenderTexture::createCore
+		 * @copydoc	RenderTexture::createCore
 		 */
 		 */
-		virtual MultiRenderTextureCore* createCore(MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc);
+		virtual CoreObjectCore* createCore() const;
 	};
 	};
 }
 }

+ 1 - 2
BansheeD3D11RenderSystem/Include/BsD3D11RenderTexture.h

@@ -53,7 +53,6 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc	RenderTexture::createCore
 		 * @copydoc	RenderTexture::createCore
 		 */
 		 */
-		virtual RenderTextureCore* createCore(RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-			const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
+		virtual CoreObjectCore* createCore() const;
 	};
 	};
 }
 }

+ 36 - 9
BansheeD3D11RenderSystem/Include/BsD3D11RenderWindow.h

@@ -15,9 +15,31 @@ namespace BansheeEngine
 	public:
 	public:
 		virtual ~D3D11RenderWindowProperties() { }
 		virtual ~D3D11RenderWindowProperties() { }
 
 
+		/**
+		 * @brief	Retrieves the window handle.
+		 */
+		HWND getHWnd() const { return mHWnd; }
+
 	private:
 	private:
 		friend class D3D11RenderWindowCore;
 		friend class D3D11RenderWindowCore;
 		friend class D3D11RenderWindow;
 		friend class D3D11RenderWindow;
+
+		/**
+		 * @copydoc	RenderTargetProperties::copyToBuffer
+		 */
+		virtual void copyToBuffer(UINT8* buffer) const;
+
+		/**
+		 * @copydoc	RenderTargetProperties::copyFromBuffer
+		 */
+		virtual void copyFromBuffer(UINT8* buffer);
+
+		/**
+		 * @copydoc	RenderTargetProperties::getSize
+		 */
+		virtual UINT32 getSize() const;
+
+		HWND mHWnd = 0;
 	};
 	};
 
 
 	/**
 	/**
@@ -99,11 +121,21 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Returns internal window handle.
 		 * @brief	Returns internal window handle.
 		 */
 		 */
-		HWND _getWindowHandle() const { return mHWnd; }
+		HWND _getWindowHandle() const;
 
 
 	protected:
 	protected:
 		friend class D3D11RenderWindow;
 		friend class D3D11RenderWindow;
 
 
+		/**
+		 * @copydoc	CoreObjectCore::initialize
+		 */
+		virtual void initialize();
+
+		/**
+		 * @copydoc	CoreObjectCore::destroy
+		 */
+		virtual void destroy();
+
 		/**
 		/**
 		 * @brief	Creates internal resources dependent on window size.
 		 * @brief	Creates internal resources dependent on window size.
 		 */
 		 */
@@ -148,7 +180,7 @@ namespace BansheeEngine
 		IDXGISwapChain*	mSwapChain;
 		IDXGISwapChain*	mSwapChain;
 		DXGI_SWAP_CHAIN_DESC mSwapChainDesc;
 		DXGI_SWAP_CHAIN_DESC mSwapChainDesc;
 
 
-		HWND mHWnd;
+		RENDER_WINDOW_DESC mDesc;
 	};
 	};
 
 
 	/**
 	/**
@@ -183,14 +215,10 @@ namespace BansheeEngine
 
 
 	protected:
 	protected:
 		friend class D3D11RenderWindowManager;
 		friend class D3D11RenderWindowManager;
+		friend class D3D11RenderWindowCore;
 
 
 		D3D11RenderWindow(D3D11Device& device, IDXGIFactory* DXGIFactory);
 		D3D11RenderWindow(D3D11Device& device, IDXGIFactory* DXGIFactory);
 
 
-		/**
-		 * @copydoc	RenderWindow::initialize_internal
-		 */
-		virtual void initialize_internal();
-
 		/**
 		/**
 		 * @copydoc	RenderWindow::createProperties
 		 * @copydoc	RenderWindow::createProperties
 		 */
 		 */
@@ -199,11 +227,10 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc	RenderWindow::createCore
 		 * @copydoc	RenderWindow::createCore
 		 */
 		 */
-		virtual RenderWindowCore* createCore(RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc);
+		virtual CoreObjectCore* createCore() const;
 
 
 	private:
 	private:
 		D3D11Device& mDevice;
 		D3D11Device& mDevice;
 		IDXGIFactory* mDXGIFactory;
 		IDXGIFactory* mDXGIFactory;
-		HWND mHWnd;
 	};
 	};
 }
 }

+ 8 - 2
BansheeD3D11RenderSystem/Source/BsD3D11MultiRenderTexture.cpp

@@ -45,8 +45,14 @@ namespace BansheeEngine
 		return bs_new<MultiRenderTextureProperties>();
 		return bs_new<MultiRenderTextureProperties>();
 	}
 	}
 
 
-	MultiRenderTextureCore* D3D11MultiRenderTexture::createCore(MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
+	CoreObjectCore* D3D11MultiRenderTexture::createCore() const
 	{
 	{
-		return bs_new<D3D11MultiRenderTextureCore>(this, properties, desc);
+		MultiRenderTextureProperties* coreProperties = bs_new<MultiRenderTextureProperties>();
+		MultiRenderTextureProperties* myProperties = static_cast<MultiRenderTextureProperties*>(mProperties);
+
+		*coreProperties = *myProperties;
+
+		return bs_new<D3D11MultiRenderTextureCore>(const_cast<D3D11MultiRenderTexture*>(this),
+			coreProperties, mDesc);
 	}
 	}
 }
 }

+ 8 - 3
BansheeD3D11RenderSystem/Source/BsD3D11RenderTexture.cpp

@@ -38,9 +38,14 @@ namespace BansheeEngine
 		return bs_new<RenderTextureProperties>();
 		return bs_new<RenderTextureProperties>();
 	}
 	}
 
 
-	RenderTextureCore* D3D11RenderTexture::createCore(RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
+	CoreObjectCore* D3D11RenderTexture::createCore() const
 	{
 	{
-		return bs_new<D3D11RenderTextureCore>(this, properties, colorSurfaceDesc, depthStencilSurfaceDesc);
+		RenderTextureProperties* coreProperties = bs_new<RenderTextureProperties>();
+		RenderTextureProperties* myProperties = static_cast<RenderTextureProperties*>(mProperties);
+
+		*coreProperties = *myProperties;
+
+		return bs_new<D3D11RenderTextureCore>(const_cast<D3D11RenderTexture*>(this), 
+			coreProperties, mColorSurfaceDesc, mDepthStencilSurfaceDesc);
 	}
 	}
 }
 }

+ 123 - 82
BansheeD3D11RenderSystem/Source/BsD3D11RenderWindow.cpp

@@ -15,11 +15,34 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	void D3D11RenderWindowProperties::copyToBuffer(UINT8* buffer) const
+	{
+		*(D3D11RenderWindowProperties*)buffer = *this;
+	}
+
+	void D3D11RenderWindowProperties::copyFromBuffer(UINT8* buffer)
+	{
+		*this = *(D3D11RenderWindowProperties*)buffer;
+	}
+
+	UINT32 D3D11RenderWindowProperties::getSize() const
+	{
+		return sizeof(D3D11RenderWindowProperties);
+	}
+
 	D3D11RenderWindowCore::D3D11RenderWindowCore(D3D11RenderWindow* parent, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, D3D11Device& device, IDXGIFactory* DXGIFactory)
 	D3D11RenderWindowCore::D3D11RenderWindowCore(D3D11RenderWindow* parent, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, D3D11Device& device, IDXGIFactory* DXGIFactory)
 		: RenderWindowCore(parent, properties), mDevice(device), mDXGIFactory(DXGIFactory), mIsExternal(false), mSizing(false),
 		: RenderWindowCore(parent, properties), mDevice(device), mDXGIFactory(DXGIFactory), mIsExternal(false), mSizing(false),
-		 mRenderTargetView(nullptr), mBackBuffer(nullptr), mSwapChain(nullptr), mHWnd(0), 
-		mDepthStencilView(nullptr), mIsChild(false), mRefreshRateNumerator(0), mRefreshRateDenominator(0)
+		 mRenderTargetView(nullptr), mBackBuffer(nullptr), mSwapChain(nullptr), mDepthStencilView(nullptr), mIsChild(false), 
+		 mRefreshRateNumerator(0), mRefreshRateDenominator(0), mDesc(desc)
+	{ }
+
+	D3D11RenderWindowCore::~D3D11RenderWindowCore()
+	{ }
+
+	void D3D11RenderWindowCore::initialize()
 	{
 	{
+		RenderWindowCore::initialize();
+
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 
 
 		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
 		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
@@ -29,31 +52,29 @@ namespace BansheeEngine
 		HWND parentHWnd = 0;
 		HWND parentHWnd = 0;
 		HWND externalHandle = 0;
 		HWND externalHandle = 0;
 
 
-
 		NameValuePairList::const_iterator opt;
 		NameValuePairList::const_iterator opt;
-		opt = desc.platformSpecific.find("parentWindowHandle");
-		if (opt != desc.platformSpecific.end())
+		opt = mDesc.platformSpecific.find("parentWindowHandle");
+		if (opt != mDesc.platformSpecific.end())
 			parentHWnd = (HWND)parseUnsignedInt(opt->second);
 			parentHWnd = (HWND)parseUnsignedInt(opt->second);
 
 
-		opt = desc.platformSpecific.find("externalWindowHandle");
-		if (opt != desc.platformSpecific.end())
+		opt = mDesc.platformSpecific.find("externalWindowHandle");
+		if (opt != mDesc.platformSpecific.end())
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
 
 
-		props->mName = desc.title;
 		mIsChild = parentHWnd != 0;
 		mIsChild = parentHWnd != 0;
-		props->mIsFullScreen = desc.fullscreen && !mIsChild;
+		props->mIsFullScreen = mDesc.fullscreen && !mIsChild;
 		props->mColorDepth = 32;
 		props->mColorDepth = 32;
 
 
 		props->mActive = true;
 		props->mActive = true;
 
 
-		if (desc.videoMode.isCustom())
+		if (mDesc.videoMode.isCustom())
 		{
 		{
-			mRefreshRateNumerator = Math::roundToInt(desc.videoMode.getRefreshRate());
+			mRefreshRateNumerator = Math::roundToInt(mDesc.videoMode.getRefreshRate());
 			mRefreshRateDenominator = 1;
 			mRefreshRateDenominator = 1;
 		}
 		}
 		else
 		else
 		{
 		{
-			const D3D11VideoMode& d3d11videoMode = static_cast<const D3D11VideoMode&>(desc.videoMode);
+			const D3D11VideoMode& d3d11videoMode = static_cast<const D3D11VideoMode&>(mDesc.videoMode);
 			mRefreshRateNumerator = d3d11videoMode.getRefreshRateNumerator();
 			mRefreshRateNumerator = d3d11videoMode.getRefreshRateNumerator();
 			mRefreshRateDenominator = d3d11videoMode.getRefreshRateDenominator();
 			mRefreshRateDenominator = d3d11videoMode.getRefreshRateDenominator();
 		}
 		}
@@ -65,7 +86,7 @@ namespace BansheeEngine
 		UINT32 numOutputs = videoModeInfo.getNumOutputs();
 		UINT32 numOutputs = videoModeInfo.getNumOutputs();
 		if (numOutputs > 0)
 		if (numOutputs > 0)
 		{
 		{
-			UINT32 actualMonitorIdx = std::min(desc.videoMode.getOutputIdx(), numOutputs - 1);
+			UINT32 actualMonitorIdx = std::min(mDesc.videoMode.getOutputIdx(), numOutputs - 1);
 			outputInfo = static_cast<const D3D11VideoOutputInfo*>(&videoModeInfo.getOutputInfo(actualMonitorIdx));
 			outputInfo = static_cast<const D3D11VideoOutputInfo*>(&videoModeInfo.getOutputInfo(actualMonitorIdx));
 
 
 			DXGI_OUTPUT_DESC desc;
 			DXGI_OUTPUT_DESC desc;
@@ -87,8 +108,8 @@ namespace BansheeEngine
 				POINT windowAnchorPoint;
 				POINT windowAnchorPoint;
 
 
 				// Fill in anchor point.
 				// Fill in anchor point.
-				windowAnchorPoint.x = desc.left;
-				windowAnchorPoint.y = desc.top;
+				windowAnchorPoint.x = mDesc.left;
+				windowAnchorPoint.y = mDesc.top;
 
 
 				// Get the nearest monitor to this window.
 				// Get the nearest monitor to this window.
 				hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTOPRIMARY);
 				hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTOPRIMARY);
@@ -100,11 +121,11 @@ namespace BansheeEngine
 			GetMonitorInfo(hMonitor, &monitorInfo);
 			GetMonitorInfo(hMonitor, &monitorInfo);
 
 
 			unsigned int winWidth, winHeight;
 			unsigned int winWidth, winHeight;
-			winWidth = desc.videoMode.getWidth();
-			winHeight = desc.videoMode.getHeight();
+			winWidth = mDesc.videoMode.getWidth();
+			winHeight = mDesc.videoMode.getHeight();
 
 
-			UINT32 left = desc.left;
-			UINT32 top = desc.top;
+			UINT32 left = mDesc.left;
+			UINT32 top = mDesc.top;
 
 
 			// No specified top left -> Center the window in the middle of the monitor
 			// No specified top left -> Center the window in the middle of the monitor
 			if (left == -1 || top == -1)
 			if (left == -1 || top == -1)
@@ -132,33 +153,33 @@ namespace BansheeEngine
 				top += monitorInfo.rcWork.top;
 				top += monitorInfo.rcWork.top;
 			}
 			}
 
 
-			props->mWidth = desc.videoMode.getWidth();
-			props->mHeight = desc.videoMode.getHeight();
+			props->mWidth = mDesc.videoMode.getWidth();
+			props->mHeight = mDesc.videoMode.getHeight();
 			props->mTop = top;
 			props->mTop = top;
 			props->mLeft = left;
 			props->mLeft = left;
 
 
-			if (!desc.fullscreen)
+			if (!mDesc.fullscreen)
 			{
 			{
 				if (parentHWnd)
 				if (parentHWnd)
 				{
 				{
-					if (desc.toolWindow)
+					if (mDesc.toolWindow)
 						dwStyleEx = WS_EX_TOOLWINDOW;
 						dwStyleEx = WS_EX_TOOLWINDOW;
 					else
 					else
 						dwStyle |= WS_CHILD;
 						dwStyle |= WS_CHILD;
 				}
 				}
 
 
-				if (!parentHWnd || desc.toolWindow)
+				if (!parentHWnd || mDesc.toolWindow)
 				{
 				{
-					if (desc.border == WindowBorder::None)
+					if (mDesc.border == WindowBorder::None)
 						dwStyle |= WS_POPUP;
 						dwStyle |= WS_POPUP;
-					else if (desc.border == WindowBorder::Fixed)
+					else if (mDesc.border == WindowBorder::Fixed)
 						dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 						dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 						WS_SYSMENU | WS_MINIMIZEBOX;
 						WS_SYSMENU | WS_MINIMIZEBOX;
 					else
 					else
 						dwStyle |= WS_OVERLAPPEDWINDOW;
 						dwStyle |= WS_OVERLAPPEDWINDOW;
 				}
 				}
 
 
-				if (!desc.outerDimensions)
+				if (!mDesc.outerDimensions)
 				{
 				{
 					// Calculate window dimensions required
 					// Calculate window dimensions required
 					// to get the requested client area
 					// to get the requested client area
@@ -188,7 +209,7 @@ namespace BansheeEngine
 			}
 			}
 
 
 			UINT classStyle = 0;
 			UINT classStyle = 0;
-			if (desc.enableDoubleClick)
+			if (mDesc.enableDoubleClick)
 				classStyle |= CS_DBLCLKS;
 				classStyle |= CS_DBLCLKS;
 
 
 			HINSTANCE hInst = NULL;
 			HINSTANCE hInst = NULL;
@@ -204,21 +225,21 @@ namespace BansheeEngine
 			// Create our main window
 			// Create our main window
 			// Pass pointer to self
 			// Pass pointer to self
 			mIsExternal = false;
 			mIsExternal = false;
-			mHWnd = CreateWindowEx(dwStyleEx, "D3D11Wnd", desc.title.c_str(), dwStyle,
+			props->mHWnd = CreateWindowEx(dwStyleEx, "D3D11Wnd", mDesc.title.c_str(), dwStyle,
 				props->mLeft, props->mTop, props->mWidth, props->mHeight, parentHWnd, 0, hInst, this);
 				props->mLeft, props->mTop, props->mWidth, props->mHeight, parentHWnd, 0, hInst, this);
 		}
 		}
 		else
 		else
 		{
 		{
-			mHWnd = externalHandle;
+			props->mHWnd = externalHandle;
 			mIsExternal = true;
 			mIsExternal = true;
 		}
 		}
 
 
 		RECT rc;
 		RECT rc;
-		GetWindowRect(mHWnd, &rc);
+		GetWindowRect(props->mHWnd, &rc);
 		props->mTop = rc.top;
 		props->mTop = rc.top;
 		props->mLeft = rc.left;
 		props->mLeft = rc.left;
 
 
-		GetClientRect(mHWnd, &rc);
+		GetClientRect(props->mHWnd, &rc);
 		props->mWidth = rc.right;
 		props->mWidth = rc.right;
 		props->mHeight = rc.bottom;
 		props->mHeight = rc.bottom;
 
 
@@ -233,23 +254,28 @@ namespace BansheeEngine
 		}
 		}
 
 
 		createSizeDependedD3DResources();
 		createSizeDependedD3DResources();
-		mDXGIFactory->MakeWindowAssociation(mHWnd, NULL);
+		mDXGIFactory->MakeWindowAssociation(props->mHWnd, NULL);
 		setHidden(getProperties().isHidden());
 		setHidden(getProperties().isHidden());
+
+		// Sync HWnd to CoreObject immediately
+		D3D11RenderWindow* parent = static_cast<D3D11RenderWindow*>(mParent);
+		D3D11RenderWindowProperties* parentProps = static_cast<D3D11RenderWindowProperties*>(parent->mProperties);
+		parentProps->mHWnd = props->mHWnd;
 	}
 	}
 
 
-	D3D11RenderWindowCore::~D3D11RenderWindowCore()
+	void D3D11RenderWindowCore::destroy()
 	{
 	{
-		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
 
 
-		properties->mActive = false;
+		props->mActive = false;
 		markCoreDirty();
 		markCoreDirty();
 
 
 		SAFE_RELEASE(mSwapChain);
 		SAFE_RELEASE(mSwapChain);
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_SwapChain);
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_SwapChain);
 
 
-		if (mHWnd && !mIsExternal)
+		if (props->mHWnd && !mIsExternal)
 		{
 		{
-			DestroyWindow(mHWnd);
+			DestroyWindow(props->mHWnd);
 		}
 		}
 
 
 		if (mDepthStencilView != nullptr)
 		if (mDepthStencilView != nullptr)
@@ -258,9 +284,11 @@ namespace BansheeEngine
 			mDepthStencilView = nullptr;
 			mDepthStencilView = nullptr;
 		}
 		}
 
 
-		mHWnd = nullptr;
+		props->mHWnd = 0;
 
 
 		destroySizeDependedD3DResources();
 		destroySizeDependedD3DResources();
+
+		RenderWindowCore::destroy();
 	}
 	}
 
 
 	void D3D11RenderWindowCore::swapBuffers()
 	void D3D11RenderWindowCore::swapBuffers()
@@ -280,14 +308,14 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
 
 
-		if (mHWnd && !properties->mIsFullScreen)
+		if (props->mHWnd && !props->mIsFullScreen)
 		{
 		{
-			properties->mTop = top;
-			properties->mLeft = left;
+			props->mTop = top;
+			props->mLeft = left;
 
 
-			SetWindowPos(mHWnd, 0, top, left, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+			SetWindowPos(props->mHWnd, 0, top, left, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 			markCoreDirty();			
 			markCoreDirty();			
 		}
 		}
 	}
 	}
@@ -296,19 +324,19 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
 
 
-		if (mHWnd && !properties->mIsFullScreen)
+		if (props->mHWnd && !props->mIsFullScreen)
 		{
 		{
-			properties->mWidth = width;
-			properties->mHeight = height;
+			props->mWidth = width;
+			props->mHeight = height;
 
 
 			RECT rc = { 0, 0, width, height };
 			RECT rc = { 0, 0, width, height };
-			AdjustWindowRect(&rc, GetWindowLong(mHWnd, GWL_STYLE), false);
+			AdjustWindowRect(&rc, GetWindowLong(props->mHWnd, GWL_STYLE), false);
 			width = rc.right - rc.left;
 			width = rc.right - rc.left;
 			height = rc.bottom - rc.top;
 			height = rc.bottom - rc.top;
 
 
-			SetWindowPos(mHWnd, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
+			SetWindowPos(props->mHWnd, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 			markCoreDirty();
 			markCoreDirty();
 		}
 		}
 	}
 	}
@@ -317,18 +345,18 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
 
 
-		if (mHWnd && mSwapChain)
+		if (props->mHWnd && mSwapChain)
 		{
 		{
 			if (state)
 			if (state)
 			{
 			{
-				ShowWindow(mHWnd, SW_RESTORE);
-				mSwapChain->SetFullscreenState(properties->mIsFullScreen, nullptr);
+				ShowWindow(props->mHWnd, SW_RESTORE);
+				mSwapChain->SetFullscreenState(props->mIsFullScreen, nullptr);
 			}
 			}
 			else
 			else
 			{
 			{
-				ShowWindow(mHWnd, SW_SHOWMINIMIZED);
+				ShowWindow(props->mHWnd, SW_SHOWMINIMIZED);
 				mSwapChain->SetFullscreenState(FALSE, nullptr);
 				mSwapChain->SetFullscreenState(FALSE, nullptr);
 			}
 			}
 		}
 		}
@@ -340,15 +368,15 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
 
 
-		properties->mHidden = hidden;
+		props->mHidden = hidden;
 		if (!mIsExternal)
 		if (!mIsExternal)
 		{
 		{
 			if (hidden)
 			if (hidden)
-				ShowWindow(mHWnd, SW_HIDE);
+				ShowWindow(props->mHWnd, SW_HIDE);
 			else
 			else
-				ShowWindow(mHWnd, SW_SHOWNORMAL);
+				ShowWindow(props->mHWnd, SW_SHOWNORMAL);
 		}
 		}
 
 
 		markCoreDirty();
 		markCoreDirty();
@@ -460,12 +488,20 @@ namespace BansheeEngine
 		markCoreDirty();
 		markCoreDirty();
 	}
 	}
 
 
+	HWND D3D11RenderWindowCore::_getWindowHandle() const
+	{
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		return props->mHWnd;
+	}
+
 	void D3D11RenderWindowCore::getCustomAttribute(const String& name, void* pData) const
 	void D3D11RenderWindowCore::getCustomAttribute(const String& name, void* pData) const
 	{
 	{
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+
 		if(name == "WINDOW")
 		if(name == "WINDOW")
 		{
 		{
 			HWND *pWnd = (HWND*)pData;
 			HWND *pWnd = (HWND*)pData;
-			*pWnd = mHWnd;
+			*pWnd = props->mHWnd;
 			return;
 			return;
 		}
 		}
 
 
@@ -558,18 +594,20 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		if (!mHWnd || IsIconic(mHWnd))
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+
+		if (!props->mHWnd || IsIconic(props->mHWnd))
 			return;
 			return;
 
 
 		RECT rc;
 		RECT rc;
-		GetWindowRect(mHWnd, &rc);
+		GetWindowRect(props->mHWnd, &rc);
 
 
 		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
 		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
 		properties->mTop = rc.top;
 		properties->mTop = rc.top;
 		properties->mLeft = rc.left;
 		properties->mLeft = rc.left;
 		markCoreDirty();
 		markCoreDirty();
 
 
-		GetClientRect(mHWnd, &rc);
+		GetClientRect(props->mHWnd, &rc);
 		unsigned int width = rc.right - rc.left;
 		unsigned int width = rc.right - rc.left;
 		unsigned int height = rc.bottom - rc.top;
 		unsigned int height = rc.bottom - rc.top;
 
 
@@ -588,16 +626,17 @@ namespace BansheeEngine
 	{
 	{
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 
 
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
 		IDXGIDevice* pDXGIDevice = queryDxgiDevice();
 		IDXGIDevice* pDXGIDevice = queryDxgiDevice();
 
 
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 		DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
 		DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
-		mSwapChainDesc.OutputWindow	= mHWnd;
-		mSwapChainDesc.BufferDesc.Width = getProperties().getWidth();
-		mSwapChainDesc.BufferDesc.Height = getProperties().getHeight();
+		mSwapChainDesc.OutputWindow	= props->mHWnd;
+		mSwapChainDesc.BufferDesc.Width = props->mWidth;
+		mSwapChainDesc.BufferDesc.Height = props->mHeight;
 		mSwapChainDesc.BufferDesc.Format = format;
 		mSwapChainDesc.BufferDesc.Format = format;
 
 
-		if (getProperties().isFullScreen())
+		if (props->mIsFullScreen)
 		{
 		{
 			mSwapChainDesc.BufferDesc.RefreshRate.Numerator = mRefreshRateNumerator;
 			mSwapChainDesc.BufferDesc.RefreshRate.Numerator = mRefreshRateNumerator;
 			mSwapChainDesc.BufferDesc.RefreshRate.Denominator = mRefreshRateDenominator;
 			mSwapChainDesc.BufferDesc.RefreshRate.Denominator = mRefreshRateDenominator;
@@ -619,7 +658,7 @@ namespace BansheeEngine
 		mSwapChainDesc.Windowed	= true;
 		mSwapChainDesc.Windowed	= true;
 
 
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
-		rs->determineMultisampleSettings(getProperties().getMultisampleCount(), format, &mMultisampleType);
+		rs->determineMultisampleSettings(props->mMultisampleCount, format, &mMultisampleType);
 		mSwapChainDesc.SampleDesc.Count = mMultisampleType.Count;
 		mSwapChainDesc.SampleDesc.Count = mMultisampleType.Count;
 		mSwapChainDesc.SampleDesc.Quality = mMultisampleType.Quality;
 		mSwapChainDesc.SampleDesc.Quality = mMultisampleType.Quality;
 		
 		
@@ -730,7 +769,7 @@ namespace BansheeEngine
 	}
 	}
 
 
 	D3D11RenderWindow::D3D11RenderWindow(D3D11Device& device, IDXGIFactory* DXGIFactory)
 	D3D11RenderWindow::D3D11RenderWindow(D3D11Device& device, IDXGIFactory* DXGIFactory)
-		:mDevice(device), mDXGIFactory(DXGIFactory), mHWnd(0)
+		:mDevice(device), mDXGIFactory(DXGIFactory)
 	{
 	{
 
 
 	}
 	}
@@ -739,10 +778,12 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_CORE_THREAD;
 		THROW_IF_CORE_THREAD;
 
 
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+
 		if (name == "WINDOW")
 		if (name == "WINDOW")
 		{
 		{
 			HWND *pWnd = (HWND*)pData;
 			HWND *pWnd = (HWND*)pData;
-			*pWnd = mHWnd;
+			*pWnd = props->mHWnd;
 			return;
 			return;
 		}
 		}
 
 
@@ -755,7 +796,8 @@ namespace BansheeEngine
 		pos.x = screenPos.x;
 		pos.x = screenPos.x;
 		pos.y = screenPos.y;
 		pos.y = screenPos.y;
 
 
-		ScreenToClient(mHWnd, &pos);
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		ScreenToClient(props->mHWnd, &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
@@ -765,24 +807,23 @@ namespace BansheeEngine
 		pos.x = windowPos.x;
 		pos.x = windowPos.x;
 		pos.y = windowPos.y;
 		pos.y = windowPos.y;
 
 
-		ClientToScreen(mHWnd, &pos);
+		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		ClientToScreen(props->mHWnd, &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
-	void D3D11RenderWindow::initialize_internal()
-	{
-		RenderWindow::initialize_internal();
-
-		mCore->getCustomAttribute("WINDOW", (void*)&mHWnd);
-	}
-
 	RenderTargetProperties* D3D11RenderWindow::createProperties() const
 	RenderTargetProperties* D3D11RenderWindow::createProperties() const
 	{
 	{
-		return bs_new<RenderWindowProperties>();
+		return bs_new<D3D11RenderWindowProperties>();
 	}
 	}
 
 
-	RenderWindowCore* D3D11RenderWindow::createCore(RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc)
+	CoreObjectCore* D3D11RenderWindow::createCore() const
 	{
 	{
-		return bs_new<D3D11RenderWindowCore>(this, properties, desc, mDevice, mDXGIFactory);
+		D3D11RenderWindowProperties* coreProperties = bs_new<D3D11RenderWindowProperties>();
+		D3D11RenderWindowProperties* myProperties = static_cast<D3D11RenderWindowProperties*>(mProperties);
+
+		*coreProperties = *myProperties;
+
+		return bs_new<D3D11RenderWindowCore>(const_cast<D3D11RenderWindow*>(this), coreProperties, mDesc, mDevice, mDXGIFactory);
 	}
 	}
 }
 }

+ 7 - 2
BansheeD3D9RenderSystem/Include/BsD3D9MultiRenderTexture.h

@@ -26,6 +26,11 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class D3D9MultiRenderTexture;
 		friend class D3D9MultiRenderTexture;
 
 
+		/**
+		 * @copydoc	CoreObjectCore::initialize
+		 */
+		virtual void initialize();
+
 		Vector<IDirect3DSurface9*> mDX9ColorSurfaces;
 		Vector<IDirect3DSurface9*> mDX9ColorSurfaces;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
 	};
 	};
@@ -51,8 +56,8 @@ namespace BansheeEngine
 		virtual RenderTargetProperties* createProperties() const;
 		virtual RenderTargetProperties* createProperties() const;
 
 
 		/**
 		/**
-		 * @copydoc	MultiRenderTexture::createCore
+		 * @copydoc	RenderTexture::createCore
 		 */
 		 */
-		virtual MultiRenderTextureCore* createCore(MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc);
+		virtual CoreObjectCore* createCore() const;
 	};
 	};
 }
 }

+ 6 - 2
BansheeD3D9RenderSystem/Include/BsD3D9RenderTexture.h

@@ -49,6 +49,11 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class D3D9RenderTexture;
 		friend class D3D9RenderTexture;
 
 
+		/**
+		 * @copydoc	CoreObjectCore::initialize
+		 */
+		virtual void initialize();
+
 		/**
 		/**
 		 * @brief	Initializes the internal color and depth surfaces.
 		 * @brief	Initializes the internal color and depth surfaces.
 		 */
 		 */
@@ -88,7 +93,6 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc	RenderTexture::createCore
 		 * @copydoc	RenderTexture::createCore
 		 */
 		 */
-		virtual RenderTextureCore* createCore(RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-			const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
+		virtual CoreObjectCore* createCore() const;
 	};
 	};
 }
 }

+ 36 - 9
BansheeD3D9RenderSystem/Include/BsD3D9RenderWindow.h

@@ -16,9 +16,31 @@ namespace BansheeEngine
 	public:
 	public:
 		virtual ~D3D9RenderWindowProperties() { }
 		virtual ~D3D9RenderWindowProperties() { }
 
 
+		/**
+		 * @brief	Retrieves the window handle.
+		 */
+		HWND getHWnd() const { return mHWnd; }
+
 	private:
 	private:
 		friend class D3D9RenderWindowCore;
 		friend class D3D9RenderWindowCore;
 		friend class D3D9RenderWindow;
 		friend class D3D9RenderWindow;
+
+		/**
+		 * @copydoc	RenderTargetProperties::copyToBuffer
+		 */
+		virtual void copyToBuffer(UINT8* buffer) const;
+
+		/**
+		 * @copydoc	RenderTargetProperties::copyFromBuffer
+		 */
+		virtual void copyFromBuffer(UINT8* buffer);
+
+		/**
+		 * @copydoc	RenderTargetProperties::getSize
+		 */
+		virtual UINT32 getSize() const;
+
+		HWND mHWnd = 0;
 	};
 	};
 
 
 	/**
 	/**
@@ -85,7 +107,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Gets internal Win32 window handle.
 		 * @brief	Gets internal Win32 window handle.
 		 */
 		 */
-		HWND _getWindowHandle() const { return mHWnd; }
+		HWND _getWindowHandle() const;
 
 
 		/**
 		/**
 		 * @brief	Gets the DirectX 9 device object that manages this window.
 		 * @brief	Gets the DirectX 9 device object that manages this window.
@@ -125,6 +147,16 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class D3D9RenderWindow;
 		friend class D3D9RenderWindow;
 
 
+		/**
+		 * @copydoc	CoreObjectCore::initialize
+		 */
+		virtual void initialize();
+
+		/**
+		 * @copydoc	CoreObjectCore::destroy
+		 */
+		virtual void destroy();
+
 		/**
 		/**
 		 * @brief	Updates window coordinates and size from actual values provided by Windows.
 		 * @brief	Updates window coordinates and size from actual values provided by Windows.
 		 */
 		 */
@@ -140,7 +172,6 @@ namespace BansheeEngine
 		HINSTANCE mInstance;
 		HINSTANCE mInstance;
 		D3D9Device* mDevice;
 		D3D9Device* mDevice;
 		bool mDeviceValid;
 		bool mDeviceValid;
-		HWND mHWnd;
 		bool mIsExternal;		
 		bool mIsExternal;		
 		D3DMULTISAMPLE_TYPE	mMultisampleType;
 		D3DMULTISAMPLE_TYPE	mMultisampleType;
 		DWORD mMultisampleQuality;
 		DWORD mMultisampleQuality;
@@ -151,6 +182,7 @@ namespace BansheeEngine
 		DWORD mWindowedStyleEx;
 		DWORD mWindowedStyleEx;
 		bool mIsDepthBuffered;
 		bool mIsDepthBuffered;
 		bool mIsChild;
 		bool mIsChild;
+		RENDER_WINDOW_DESC mDesc;
 	};
 	};
 
 
 	/**
 	/**
@@ -190,14 +222,10 @@ namespace BansheeEngine
 
 
 	protected:
 	protected:
 		friend class D3D9RenderWindowManager;
 		friend class D3D9RenderWindowManager;
+		friend class D3D9RenderWindowCore;
 
 
 		D3D9RenderWindow(HINSTANCE instance);
 		D3D9RenderWindow(HINSTANCE instance);
 
 
-		/**
-		 * @copydoc	RenderWindow::initialize_internal
-		 */
-		virtual void initialize_internal();
-
 		/**
 		/**
 		 * @copydoc	RenderWindow::createProperties
 		 * @copydoc	RenderWindow::createProperties
 		 */
 		 */
@@ -206,10 +234,9 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc	RenderWindow::createCore
 		 * @copydoc	RenderWindow::createCore
 		 */
 		 */
-		virtual RenderWindowCore* createCore(RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc);
+		virtual CoreObjectCore* createCore() const;
 
 
 	private:
 	private:
 		HINSTANCE mInstance;
 		HINSTANCE mInstance;
-		HWND mHWnd;
 	};
 	};
 }
 }

+ 16 - 7
BansheeD3D9RenderSystem/Source/BsD3D9MultiRenderTexture.cpp

@@ -6,7 +6,15 @@ namespace BansheeEngine
 {
 {
 	D3D9MultiRenderTextureCore::D3D9MultiRenderTextureCore(D3D9MultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
 	D3D9MultiRenderTextureCore::D3D9MultiRenderTextureCore(D3D9MultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
 		:MultiRenderTextureCore(parent, properties, desc), mDX9DepthStencilSurface(nullptr)
 		:MultiRenderTextureCore(parent, properties, desc), mDX9DepthStencilSurface(nullptr)
+	{ }
+
+	D3D9MultiRenderTextureCore::~D3D9MultiRenderTextureCore()
+	{ }
+
+	void D3D9MultiRenderTextureCore::initialize()
 	{
 	{
+		MultiRenderTextureCore::initialize();
+
 		mDX9ColorSurfaces.resize(mColorSurfaces.size());
 		mDX9ColorSurfaces.resize(mColorSurfaces.size());
 
 
 		for (size_t i = 0; i < mColorSurfaces.size(); i++)
 		for (size_t i = 0; i < mColorSurfaces.size(); i++)
@@ -48,11 +56,6 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	D3D9MultiRenderTextureCore::~D3D9MultiRenderTextureCore()
-	{
-
-	}
-
 	void D3D9MultiRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
 	void D3D9MultiRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
 	{
 	{
 		if(name == "DDBACKBUFFER")
 		if(name == "DDBACKBUFFER")
@@ -83,8 +86,14 @@ namespace BansheeEngine
 		return bs_new<MultiRenderTextureProperties>();
 		return bs_new<MultiRenderTextureProperties>();
 	}
 	}
 
 
-	MultiRenderTextureCore* D3D9MultiRenderTexture::createCore(MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
+	CoreObjectCore* D3D9MultiRenderTexture::createCore() const
 	{
 	{
-		return bs_new<D3D9MultiRenderTextureCore>(this, properties, desc);
+		MultiRenderTextureProperties* coreProperties = bs_new<MultiRenderTextureProperties>();
+		MultiRenderTextureProperties* myProperties = static_cast<MultiRenderTextureProperties*>(mProperties);
+
+		*coreProperties = *myProperties;
+
+		return bs_new<D3D9MultiRenderTextureCore>(const_cast<D3D9MultiRenderTexture*>(this),
+			coreProperties, mDesc);
 	}
 	}
 }
 }

+ 14 - 6
BansheeD3D9RenderSystem/Source/BsD3D9RenderTexture.cpp

@@ -10,13 +10,16 @@ namespace BansheeEngine
 		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
 		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
 		:RenderTextureCore(parent, properties, colorSurfaceDesc, depthStencilSurfaceDesc), mDX9ColorSurface(nullptr), 
 		:RenderTextureCore(parent, properties, colorSurfaceDesc, depthStencilSurfaceDesc), mDX9ColorSurface(nullptr), 
 		mDX9DepthStencilSurface(nullptr), mIsBindableToShader(false)
 		mDX9DepthStencilSurface(nullptr), mIsBindableToShader(false)
-	{
-		initializeSurfaces();
-	}
+	{ }
 
 
 	D3D9RenderTextureCore::~D3D9RenderTextureCore()
 	D3D9RenderTextureCore::~D3D9RenderTextureCore()
+	{ }
+
+	void D3D9RenderTextureCore::initialize()
 	{
 	{
+		RenderTextureCore::initialize();
 
 
+		initializeSurfaces();
 	}
 	}
 
 
 	void D3D9RenderTextureCore::initializeSurfaces()
 	void D3D9RenderTextureCore::initializeSurfaces()
@@ -86,9 +89,14 @@ namespace BansheeEngine
 		return bs_new<RenderTextureProperties>();
 		return bs_new<RenderTextureProperties>();
 	}
 	}
 
 
-	RenderTextureCore* D3D9RenderTexture::createCore(RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
+	CoreObjectCore* D3D9RenderTexture::createCore() const
 	{
 	{
-		return bs_new<D3D9RenderTextureCore>(this, properties, colorSurfaceDesc, depthStencilSurfaceDesc);
+		RenderTextureProperties* coreProperties = bs_new<RenderTextureProperties>();
+		RenderTextureProperties* myProperties = static_cast<RenderTextureProperties*>(mProperties);
+
+		*coreProperties = *myProperties;
+
+		return bs_new<D3D9RenderTextureCore>(const_cast<D3D9RenderTexture*>(this),
+			coreProperties, mColorSurfaceDesc, mDepthStencilSurfaceDesc);
 	}
 	}
 }
 }

+ 112 - 72
BansheeD3D9RenderSystem/Source/BsD3D9RenderWindow.cpp

@@ -12,26 +12,49 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	void D3D9RenderWindowProperties::copyToBuffer(UINT8* buffer) const
+	{
+		*(D3D9RenderWindowProperties*)buffer = *this;
+	}
+
+	void D3D9RenderWindowProperties::copyFromBuffer(UINT8* buffer)
+	{
+		*this = *(D3D9RenderWindowProperties*)buffer;
+	}
+
+	UINT32 D3D9RenderWindowProperties::getSize() const
+	{
+		return sizeof(D3D9RenderWindowProperties);
+	}
+
 	D3D9RenderWindowCore::D3D9RenderWindowCore(D3D9RenderWindow* parent, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, HINSTANCE instance)
 	D3D9RenderWindowCore::D3D9RenderWindowCore(D3D9RenderWindow* parent, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, HINSTANCE instance)
-		: RenderWindowCore(parent, properties), mInstance(instance), mIsDepthBuffered(true), mIsChild(false),
-		mStyle(0), mWindowedStyle(0), mWindowedStyleEx(0), mDevice(nullptr), mIsExternal(false), mHWnd(0), mDisplayFrequency(0), mDeviceValid(false)
+		: RenderWindowCore(parent, properties), mInstance(instance), mIsDepthBuffered(true), mIsChild(false), mDesc(desc),
+		mStyle(0), mWindowedStyle(0), mWindowedStyleEx(0), mDevice(nullptr), mIsExternal(false), mDisplayFrequency(0), mDeviceValid(false)
+	{ }
+
+	D3D9RenderWindowCore::~D3D9RenderWindowCore()
+	{ }
+
+	void D3D9RenderWindowCore::initialize()
 	{
 	{
+		RenderWindowCore::initialize();
+
 		HINSTANCE hInst = mInstance;
 		HINSTANCE hInst = mInstance;
 
 
 		mMultisampleType = D3DMULTISAMPLE_NONE;
 		mMultisampleType = D3DMULTISAMPLE_NONE;
 		mMultisampleQuality = 0;
 		mMultisampleQuality = 0;
-		mDisplayFrequency = Math::roundToInt(desc.videoMode.getRefreshRate());
+		mDisplayFrequency = Math::roundToInt(mDesc.videoMode.getRefreshRate());
 
 
 		HWND parentHWnd = 0;
 		HWND parentHWnd = 0;
 		HWND externalHandle = 0;
 		HWND externalHandle = 0;
 
 
 		NameValuePairList::const_iterator opt;
 		NameValuePairList::const_iterator opt;
-		opt = desc.platformSpecific.find("parentWindowHandle");
-		if (opt != desc.platformSpecific.end())
+		opt = mDesc.platformSpecific.find("parentWindowHandle");
+		if (opt != mDesc.platformSpecific.end())
 			parentHWnd = (HWND)parseUnsignedInt(opt->second);
 			parentHWnd = (HWND)parseUnsignedInt(opt->second);
 
 
-		opt = desc.platformSpecific.find("externalWindowHandle");
-		if (opt != desc.platformSpecific.end())
+		opt = mDesc.platformSpecific.find("externalWindowHandle");
+		if (opt != mDesc.platformSpecific.end())
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
 
 
 		mIsChild = parentHWnd != 0;
 		mIsChild = parentHWnd != 0;
@@ -39,21 +62,21 @@ namespace BansheeEngine
 		mWindowedStyle = WS_VISIBLE | WS_CLIPCHILDREN;
 		mWindowedStyle = WS_VISIBLE | WS_CLIPCHILDREN;
 		mWindowedStyleEx = 0;
 		mWindowedStyleEx = 0;
 
 
-		if (!desc.fullscreen || mIsChild)
+		if (!mDesc.fullscreen || mIsChild)
 		{
 		{
 			if (parentHWnd)
 			if (parentHWnd)
 			{
 			{
-				if (desc.toolWindow)
+				if (mDesc.toolWindow)
 					mWindowedStyleEx = WS_EX_TOOLWINDOW;
 					mWindowedStyleEx = WS_EX_TOOLWINDOW;
 				else
 				else
 					mWindowedStyle |= WS_CHILD;
 					mWindowedStyle |= WS_CHILD;
 			}
 			}
 
 
-			if (!parentHWnd || desc.toolWindow)
+			if (!parentHWnd || mDesc.toolWindow)
 			{
 			{
-				if (desc.border == WindowBorder::None)
+				if (mDesc.border == WindowBorder::None)
 					mWindowedStyle |= WS_POPUP;
 					mWindowedStyle |= WS_POPUP;
-				else if (desc.border == WindowBorder::Fixed)
+				else if (mDesc.border == WindowBorder::Fixed)
 					mWindowedStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 					mWindowedStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 					WS_SYSMENU | WS_MINIMIZEBOX;
 					WS_SYSMENU | WS_MINIMIZEBOX;
 				else
 				else
@@ -72,7 +95,7 @@ namespace BansheeEngine
 			UINT32 numOutputs = videoModeInfo.getNumOutputs();
 			UINT32 numOutputs = videoModeInfo.getNumOutputs();
 			if (numOutputs > 0)
 			if (numOutputs > 0)
 			{
 			{
-				UINT32 actualMonitorIdx = std::min(desc.videoMode.getOutputIdx(), numOutputs - 1);
+				UINT32 actualMonitorIdx = std::min(mDesc.videoMode.getOutputIdx(), numOutputs - 1);
 				const D3D9VideoOutputInfo& outputInfo = static_cast<const D3D9VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
 				const D3D9VideoOutputInfo& outputInfo = static_cast<const D3D9VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
 				hMonitor = outputInfo.getMonitorHandle();
 				hMonitor = outputInfo.getMonitorHandle();
 			}
 			}
@@ -83,8 +106,8 @@ namespace BansheeEngine
 				POINT windowAnchorPoint;
 				POINT windowAnchorPoint;
 
 
 				// Fill in anchor point.
 				// Fill in anchor point.
-				windowAnchorPoint.x = desc.left;
-				windowAnchorPoint.y = desc.top;
+				windowAnchorPoint.x = mDesc.left;
+				windowAnchorPoint.y = mDesc.top;
 
 
 				// Get the nearest monitor to this window.
 				// Get the nearest monitor to this window.
 				hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTOPRIMARY);
 				hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTOPRIMARY);
@@ -96,11 +119,11 @@ namespace BansheeEngine
 			GetMonitorInfo(hMonitor, &monitorInfo);
 			GetMonitorInfo(hMonitor, &monitorInfo);
 
 
 			unsigned int winWidth, winHeight;
 			unsigned int winWidth, winHeight;
-			winWidth = desc.videoMode.getWidth();
-			winHeight = desc.videoMode.getHeight();
+			winWidth = mDesc.videoMode.getWidth();
+			winHeight = mDesc.videoMode.getHeight();
 
 
-			UINT32 left = desc.left;
-			UINT32 top = desc.top;
+			UINT32 left = mDesc.left;
+			UINT32 top = mDesc.top;
 
 
 			// No specified top left -> Center the window in the middle of the monitor
 			// No specified top left -> Center the window in the middle of the monitor
 			if (left == -1 || top == -1)
 			if (left == -1 || top == -1)
@@ -128,14 +151,14 @@ namespace BansheeEngine
 				top += monitorInfo.rcWork.top;
 				top += monitorInfo.rcWork.top;
 			}
 			}
 
 
-			props->mWidth = desc.videoMode.getWidth();
-			props->mHeight = desc.videoMode.getHeight();
+			props->mWidth = mDesc.videoMode.getWidth();
+			props->mHeight = mDesc.videoMode.getHeight();
 			props->mTop = top;
 			props->mTop = top;
 			props->mLeft = left;
 			props->mLeft = left;
 
 
 			DWORD dwStyle = 0;
 			DWORD dwStyle = 0;
 			DWORD dwStyleEx = 0;
 			DWORD dwStyleEx = 0;
-			if (desc.fullscreen && !mIsChild)
+			if (mDesc.fullscreen && !mIsChild)
 			{
 			{
 				dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_POPUP;
 				dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_POPUP;
 				props->mTop = monitorInfo.rcMonitor.top;
 				props->mTop = monitorInfo.rcMonitor.top;
@@ -146,9 +169,9 @@ namespace BansheeEngine
 				dwStyle = mWindowedStyle;
 				dwStyle = mWindowedStyle;
 				dwStyleEx = mWindowedStyleEx;
 				dwStyleEx = mWindowedStyleEx;
 
 
-				getAdjustedWindowSize(desc.videoMode.getWidth(), desc.videoMode.getHeight(), dwStyle, &winWidth, &winHeight);
+				getAdjustedWindowSize(mDesc.videoMode.getWidth(), mDesc.videoMode.getHeight(), dwStyle, &winWidth, &winHeight);
 
 
-				if (!desc.outerDimensions)
+				if (!mDesc.outerDimensions)
 				{
 				{
 					// Calculate window dimensions required
 					// Calculate window dimensions required
 					// to get the requested client area
 					// to get the requested client area
@@ -182,36 +205,40 @@ namespace BansheeEngine
 			// Create our main window
 			// Create our main window
 			// Pass pointer to self
 			// Pass pointer to self
 			mIsExternal = false;
 			mIsExternal = false;
-			mHWnd = CreateWindowEx(dwStyleEx, "D3D9Wnd", desc.title.c_str(), dwStyle,
+			props->mHWnd = CreateWindowEx(dwStyleEx, "D3D9Wnd", mDesc.title.c_str(), dwStyle,
 				props->mLeft, props->mTop, winWidth, winHeight, parentHWnd, 0, hInst, this);
 				props->mLeft, props->mTop, winWidth, winHeight, parentHWnd, 0, hInst, this);
 			mStyle = dwStyle;
 			mStyle = dwStyle;
 		}
 		}
 		else
 		else
 		{
 		{
-			mHWnd = externalHandle;
+			props->mHWnd = externalHandle;
 			mIsExternal = true;
 			mIsExternal = true;
 		}
 		}
 
 
 		RECT rc;
 		RECT rc;
-		GetWindowRect(mHWnd, &rc);
+		GetWindowRect(props->mHWnd, &rc);
 		props->mTop = rc.top;
 		props->mTop = rc.top;
 		props->mLeft = rc.left;
 		props->mLeft = rc.left;
 
 
-		GetClientRect(mHWnd, &rc);
+		GetClientRect(props->mHWnd, &rc);
 		props->mWidth = rc.right;
 		props->mWidth = rc.right;
 		props->mHeight = rc.bottom;
 		props->mHeight = rc.bottom;
 
 
-		props->mName = desc.title;
-		mIsDepthBuffered = desc.depthBuffer;
-		props->mIsFullScreen = desc.fullscreen && !mIsChild;
+		mIsDepthBuffered = mDesc.depthBuffer;
+		props->mIsFullScreen = mDesc.fullscreen && !mIsChild;
 		props->mColorDepth = 32;
 		props->mColorDepth = 32;
 		props->mActive = true;
 		props->mActive = true;
 
 
 		D3D9RenderSystem* rs = static_cast<D3D9RenderSystem*>(RenderSystem::instancePtr());
 		D3D9RenderSystem* rs = static_cast<D3D9RenderSystem*>(RenderSystem::instancePtr());
 		rs->registerWindow(*this);
 		rs->registerWindow(*this);
+
+		// Sync HWnd to CoreObject immediately
+		D3D9RenderWindow* parent = static_cast<D3D9RenderWindow*>(mParent);
+		D3D9RenderWindowProperties* parentProps = static_cast<D3D9RenderWindowProperties*>(parent->mProperties);
+		parentProps->mHWnd = props->mHWnd;
 	}
 	}
 
 
-	D3D9RenderWindowCore::~D3D9RenderWindowCore()
+	void D3D9RenderWindowCore::destroy()
 	{
 	{
 		if (mDevice != nullptr)
 		if (mDevice != nullptr)
 		{
 		{
@@ -219,17 +246,18 @@ namespace BansheeEngine
 			mDevice = nullptr;
 			mDevice = nullptr;
 		}
 		}
 
 
-		if (mHWnd && !mIsExternal)
+		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		if (props->mHWnd && !mIsExternal)
 		{
 		{
-			DestroyWindow(mHWnd);
+			DestroyWindow(props->mHWnd);
 		}
 		}
 
 
-		mHWnd = 0;
-
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		props->mHWnd = 0;
 		props->mActive = false;
 		props->mActive = false;
 
 
 		markCoreDirty();
 		markCoreDirty();
+
+		RenderWindowCore::destroy();
 	}
 	}
 
 
 	void D3D9RenderWindowCore::setFullscreen(UINT32 width, UINT32 height, float refreshRate, UINT32 monitorIdx)
 	void D3D9RenderWindowCore::setFullscreen(UINT32 width, UINT32 height, float refreshRate, UINT32 monitorIdx)
@@ -298,7 +326,7 @@ namespace BansheeEngine
 		getAdjustedWindowSize(props->mWidth, props->mHeight, mStyle, &winWidth, &winHeight);
 		getAdjustedWindowSize(props->mWidth, props->mHeight, mStyle, &winWidth, &winHeight);
 
 
 		// Deal with centering when switching down to smaller resolution
 		// Deal with centering when switching down to smaller resolution
-		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
+		HMONITOR hMonitor = MonitorFromWindow(props->mHWnd, MONITOR_DEFAULTTONEAREST);
 		MONITORINFO monitorInfo;
 		MONITORINFO monitorInfo;
 		memset(&monitorInfo, 0, sizeof(MONITORINFO));
 		memset(&monitorInfo, 0, sizeof(MONITORINFO));
 		monitorInfo.cbSize = sizeof(MONITORINFO);
 		monitorInfo.cbSize = sizeof(MONITORINFO);
@@ -310,9 +338,9 @@ namespace BansheeEngine
 		int left = screenw > int(winWidth) ? ((screenw - int(winWidth)) / 2) : 0;
 		int left = screenw > int(winWidth) ? ((screenw - int(winWidth)) / 2) : 0;
 		int top = screenh > int(winHeight) ? ((screenh - int(winHeight)) / 2) : 0;
 		int top = screenh > int(winHeight) ? ((screenh - int(winHeight)) / 2) : 0;
 
 
-		SetWindowLong(mHWnd, GWL_STYLE, mStyle);
-		SetWindowLong(mHWnd, GWL_EXSTYLE, mWindowedStyleEx);
-		SetWindowPos(mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight,
+		SetWindowLong(props->mHWnd, GWL_STYLE, mStyle);
+		SetWindowLong(props->mHWnd, GWL_EXSTYLE, mWindowedStyleEx);
+		SetWindowPos(props->mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight,
 			SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);
 			SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);
 
 
 		mDevice->invalidate(this);
 		mDevice->invalidate(this);
@@ -331,9 +359,9 @@ namespace BansheeEngine
 		if (!mIsExternal)
 		if (!mIsExternal)
 		{
 		{
 			if (hidden)
 			if (hidden)
-				ShowWindow(mHWnd, SW_HIDE);
+				ShowWindow(props->mHWnd, SW_HIDE);
 			else
 			else
-				ShowWindow(mHWnd, SW_SHOWNORMAL);
+				ShowWindow(props->mHWnd, SW_SHOWNORMAL);
 		}
 		}
 
 
 		markCoreDirty();
 		markCoreDirty();
@@ -345,12 +373,12 @@ namespace BansheeEngine
 
 
 		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
 		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
 
 
-		if (mHWnd && !props->mIsFullScreen)
+		if (props->mHWnd && !props->mIsFullScreen)
 		{
 		{
 			props->mLeft = left;
 			props->mLeft = left;
 			props->mTop = top;
 			props->mTop = top;
 
 
-			SetWindowPos(mHWnd, 0, top, left, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+			SetWindowPos(props->mHWnd, 0, top, left, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 			markCoreDirty();
 			markCoreDirty();
 		}
 		}
 	}
 	}
@@ -361,7 +389,7 @@ namespace BansheeEngine
 
 
 		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
 		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
 
 
-		if (mHWnd && !props->mIsFullScreen)
+		if (props->mHWnd && !props->mIsFullScreen)
 		{
 		{
 			props->mWidth = width;
 			props->mWidth = width;
 			props->mHeight = height;
 			props->mHeight = height;
@@ -369,7 +397,7 @@ namespace BansheeEngine
 			unsigned int winWidth, winHeight;
 			unsigned int winWidth, winHeight;
 			getAdjustedWindowSize(width, height, mStyle, &winWidth, &winHeight);
 			getAdjustedWindowSize(width, height, mStyle, &winWidth, &winHeight);
 
 
-			SetWindowPos(mHWnd, 0, 0, 0, winWidth, winHeight,
+			SetWindowPos(props->mHWnd, 0, 0, 0, winWidth, winHeight,
 				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 
 
 			markCoreDirty();
 			markCoreDirty();
@@ -440,7 +468,9 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		if (!mHWnd || IsIconic(mHWnd))
+		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+
+		if (!props->mHWnd || IsIconic(props->mHWnd))
 			return;
 			return;
 	
 	
 		updateWindowRect();
 		updateWindowRect();
@@ -455,13 +485,15 @@ namespace BansheeEngine
 	void D3D9RenderWindowCore::getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight,
 	void D3D9RenderWindowCore::getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight,
 		DWORD style, UINT32* winWidth, UINT32* winHeight)
 		DWORD style, UINT32* winWidth, UINT32* winHeight)
 	{
 	{
+		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+
 		RECT rc;
 		RECT rc;
 		SetRect(&rc, 0, 0, clientWidth, clientHeight);
 		SetRect(&rc, 0, 0, clientWidth, clientHeight);
 		AdjustWindowRect(&rc, style, false);
 		AdjustWindowRect(&rc, style, false);
 		*winWidth = rc.right - rc.left;
 		*winWidth = rc.right - rc.left;
 		*winHeight = rc.bottom - rc.top;
 		*winHeight = rc.bottom - rc.top;
 
 
-		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
+		HMONITOR hMonitor = MonitorFromWindow(props->mHWnd, MONITOR_DEFAULTTONEAREST);
 
 
 		MONITORINFO monitorInfo;
 		MONITORINFO monitorInfo;
 
 
@@ -479,7 +511,8 @@ namespace BansheeEngine
 	}
 	}
 	
 	
 	void D3D9RenderWindowCore::_buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const
 	void D3D9RenderWindowCore::_buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const
-	{			
+	{	
+		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
 		IDirect3D9* pD3D = D3D9RenderSystem::getDirect3D9();
 		IDirect3D9* pD3D = D3D9RenderSystem::getDirect3D9();
 		D3DDEVTYPE devType = D3DDEVTYPE_HAL;
 		D3DDEVTYPE devType = D3DDEVTYPE_HAL;
 
 
@@ -487,14 +520,14 @@ namespace BansheeEngine
 			devType = mDevice->getDeviceType();		
 			devType = mDevice->getDeviceType();		
 	
 	
 		ZeroMemory( presentParams, sizeof(D3DPRESENT_PARAMETERS) );
 		ZeroMemory( presentParams, sizeof(D3DPRESENT_PARAMETERS) );
-		presentParams->Windowed = !getProperties().isFullScreen();
+		presentParams->Windowed = !props->mIsFullScreen;
 		presentParams->SwapEffect = D3DSWAPEFFECT_DISCARD;
 		presentParams->SwapEffect = D3DSWAPEFFECT_DISCARD;
 		presentParams->BackBufferCount = 1;
 		presentParams->BackBufferCount = 1;
 		presentParams->EnableAutoDepthStencil = mIsDepthBuffered;
 		presentParams->EnableAutoDepthStencil = mIsDepthBuffered;
-		presentParams->hDeviceWindow = mHWnd;
-		presentParams->BackBufferWidth = getProperties().getWidth();
-		presentParams->BackBufferHeight	= getProperties().getHeight();
-		presentParams->FullScreen_RefreshRateInHz = getProperties().isFullScreen() ? mDisplayFrequency : 0;
+		presentParams->hDeviceWindow = props->mHWnd;
+		presentParams->BackBufferWidth = props->mWidth;
+		presentParams->BackBufferHeight = props->mHeight;
+		presentParams->FullScreen_RefreshRateInHz = props->mIsFullScreen ? mDisplayFrequency : 0;
 		
 		
 		if (presentParams->BackBufferWidth == 0)		
 		if (presentParams->BackBufferWidth == 0)		
 			presentParams->BackBufferWidth = 1;					
 			presentParams->BackBufferWidth = 1;					
@@ -583,6 +616,13 @@ namespace BansheeEngine
 		presentParams->MultiSampleQuality = (multisampleQuality == 0) ? 0 : multisampleQuality;
 		presentParams->MultiSampleQuality = (multisampleQuality == 0) ? 0 : multisampleQuality;
 	}
 	}
 
 
+	HWND D3D9RenderWindowCore::_getWindowHandle() const
+	{
+		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+
+		return props->getHWnd();
+	}
+
 	IDirect3DDevice9* D3D9RenderWindowCore::_getD3D9Device() const
 	IDirect3DDevice9* D3D9RenderWindowCore::_getD3D9Device() const
 	{
 	{
 		return mDevice->getD3D9Device();
 		return mDevice->getD3D9Device();
@@ -617,7 +657,7 @@ namespace BansheeEngine
 		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
 		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
 
 
 		// Update top left parameters
 		// Update top left parameters
-		result = GetWindowRect(mHWnd, &rc);
+		result = GetWindowRect(_getWindowHandle(), &rc);
 		if (result == FALSE)
 		if (result == FALSE)
 		{
 		{
 			props->mTop = 0;
 			props->mTop = 0;
@@ -633,7 +673,7 @@ namespace BansheeEngine
 		props->mLeft = rc.left;
 		props->mLeft = rc.left;
 
 
 		// Width and height represent drawable area only
 		// Width and height represent drawable area only
-		result = GetClientRect(mHWnd, &rc);
+		result = GetClientRect(_getWindowHandle(), &rc);
 		if (result == FALSE)
 		if (result == FALSE)
 		{
 		{
 			props->mTop = 0;
 			props->mTop = 0;
@@ -658,7 +698,7 @@ namespace BansheeEngine
 	}
 	}
 
 
 	D3D9RenderWindow::D3D9RenderWindow(HINSTANCE instance)
 	D3D9RenderWindow::D3D9RenderWindow(HINSTANCE instance)
-		:mInstance(instance), mHWnd(0)
+		:mInstance(instance)
 	{
 	{
 
 
 	}
 	}
@@ -667,10 +707,11 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_CORE_THREAD;
 		THROW_IF_CORE_THREAD;
 
 
+		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
 		if (name == "WINDOW")
 		if (name == "WINDOW")
 		{
 		{
 			HWND *pWnd = (HWND*)pData;
 			HWND *pWnd = (HWND*)pData;
-			*pWnd = mHWnd;
+			*pWnd = props->getHWnd();
 			return;
 			return;
 		}
 		}
 
 
@@ -683,7 +724,8 @@ namespace BansheeEngine
 		pos.x = screenPos.x;
 		pos.x = screenPos.x;
 		pos.y = screenPos.y;
 		pos.y = screenPos.y;
 
 
-		ScreenToClient(mHWnd, &pos);
+		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		ScreenToClient(props->getHWnd(), &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
@@ -693,29 +735,27 @@ namespace BansheeEngine
 		pos.x = windowPos.x;
 		pos.x = windowPos.x;
 		pos.y = windowPos.y;
 		pos.y = windowPos.y;
 
 
-		ClientToScreen(mHWnd, &pos);
+		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		ClientToScreen(props->getHWnd(), &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
-	void D3D9RenderWindow::initialize_internal()
-	{
-		RenderWindow::initialize_internal();
-
-		mCore->getCustomAttribute("WINDOW", (void*)&mHWnd);
-	}
-
 	D3D9RenderWindowCore* D3D9RenderWindow::getCore() const
 	D3D9RenderWindowCore* D3D9RenderWindow::getCore() const
 	{
 	{
-		return static_cast<D3D9RenderWindowCore*>(mCore);
+		return static_cast<D3D9RenderWindowCore*>(mCoreSpecific);
 	}
 	}
 
 
 	RenderTargetProperties* D3D9RenderWindow::createProperties() const
 	RenderTargetProperties* D3D9RenderWindow::createProperties() const
 	{
 	{
-		return bs_new<RenderWindowProperties>();
+		return bs_new<D3D9RenderWindowProperties>();
 	}
 	}
 
 
-	RenderWindowCore* D3D9RenderWindow::createCore(RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc)
+	CoreObjectCore* D3D9RenderWindow::createCore() const
 	{
 	{
-		return bs_new<D3D9RenderWindowCore>(this, properties, desc, mInstance);
+		D3D9RenderWindowProperties* coreProperties = bs_new<D3D9RenderWindowProperties>();
+		D3D9RenderWindowProperties* myProperties = static_cast<D3D9RenderWindowProperties*>(mProperties);
+
+		*coreProperties = *myProperties;
+		return bs_new<D3D9RenderWindowCore>(const_cast<D3D9RenderWindow*>(this), coreProperties, mDesc, mInstance);
 	}
 	}
 }
 }

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

@@ -11,7 +11,7 @@ int CALLBACK WinMain(
 	_In_  int nCmdShow
 	_In_  int nCmdShow
 	)
 	)
 {
 {
-	EditorApplication::startUp(RenderSystemPlugin::OpenGL);
+	EditorApplication::startUp(RenderSystemPlugin::DX9);
 	EditorApplication::instance().runMainLoop();
 	EditorApplication::instance().runMainLoop();
 	EditorApplication::shutDown();
 	EditorApplication::shutDown();
 
 

+ 12 - 2
BansheeGLRenderSystem/Include/BsGLMultiRenderTexture.h

@@ -26,6 +26,16 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class GLTextureManager;
 		friend class GLTextureManager;
 
 
+		/**
+		 * @copydoc	CoreObjectCore::initialize
+		 */
+		virtual void initialize();
+
+		/**
+		 * @copydoc	CoreObjectCore::destroy
+		 */
+		virtual void destroy();
+
 	private:
 	private:
 		GLFrameBufferObject* mFB;
 		GLFrameBufferObject* mFB;
 	};
 	};
@@ -56,8 +66,8 @@ namespace BansheeEngine
 		virtual RenderTargetProperties* createProperties() const;
 		virtual RenderTargetProperties* createProperties() const;
 
 
 		/**
 		/**
-		 * @copydoc	MultiRenderTexture::createCore
+		 * @copydoc	RenderTexture::createCore
 		 */
 		 */
-		virtual MultiRenderTextureCore* createCore(MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc);
+		virtual CoreObjectCore* createCore() const;
 	};
 	};
 }
 }

+ 11 - 2
BansheeGLRenderSystem/Include/BsGLRenderTexture.h

@@ -32,6 +32,16 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class GLRenderTexture;
 		friend class GLRenderTexture;
 
 
+		/**
+		 * @copydoc	CoreObjectCore::initialize
+		 */
+		virtual void initialize();
+
+		/**
+		 * @copydoc	CoreObjectCore::destroy
+		 */
+		virtual void destroy();
+
 		GLFrameBufferObject* mFB;
 		GLFrameBufferObject* mFB;
     };
     };
 
 
@@ -63,8 +73,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc	RenderTexture::createCore
 		 * @copydoc	RenderTexture::createCore
 		 */
 		 */
-		virtual RenderTextureCore* createCore(RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-			const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
+		virtual CoreObjectCore* createCore() const;
 	};
 	};
 
 
     /**
     /**

+ 35 - 8
BansheeGLRenderSystem/Include/BsWin32Window.h

@@ -15,9 +15,31 @@ namespace BansheeEngine
 	public:
 	public:
 		virtual ~Win32RenderWindowProperties() { }
 		virtual ~Win32RenderWindowProperties() { }
 
 
+		/**
+		 * @brief	Retrieves the window handle.
+		 */
+		HWND getHWnd() const { return mHWnd; }
+
 	private:
 	private:
 		friend class Win32WindowCore;
 		friend class Win32WindowCore;
 		friend class Win32Window;
 		friend class Win32Window;
+
+		/**
+		 * @copydoc	RenderTargetProperties::copyToBuffer
+		 */
+		virtual void copyToBuffer(UINT8* buffer) const;
+
+		/**
+		 * @copydoc	RenderTargetProperties::copyFromBuffer
+		 */
+		virtual void copyFromBuffer(UINT8* buffer);
+
+		/**
+		 * @copydoc	RenderTargetProperties::getSize
+		 */
+		virtual UINT32 getSize() const;
+
+		HWND mHWnd = 0;
 	};
 	};
 
 
 	/**
 	/**
@@ -94,6 +116,16 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class Win32GLSupport;
 		friend class Win32GLSupport;
 
 
+		/**
+		 * @copydoc	CoreObjectCore::initialize
+		 */
+		virtual void initialize();
+
+		/**
+		 * @copydoc	CoreObjectCore::destroy
+		 */
+		virtual void destroy();
+
 		/**
 		/**
 		 * @brief	Calculates window size based on provided client area size and currently set window style. 
 		 * @brief	Calculates window size based on provided client area size and currently set window style. 
 		 */
 		 */
@@ -101,7 +133,6 @@ namespace BansheeEngine
 
 
 	protected:
 	protected:
 		Win32GLSupport &mGLSupport;
 		Win32GLSupport &mGLSupport;
-		HWND mHWnd;
 		HDC	mHDC;
 		HDC	mHDC;
 		DWORD mWindowedStyle;
 		DWORD mWindowedStyle;
 		DWORD mWindowedStyleEx;
 		DWORD mWindowedStyleEx;
@@ -111,6 +142,7 @@ namespace BansheeEngine
 		bool mIsExternalGLControl;
 		bool mIsExternalGLControl;
 		int mDisplayFrequency;
 		int mDisplayFrequency;
 		Win32Context *mContext;
 		Win32Context *mContext;
+		RENDER_WINDOW_DESC mDesc;
     };
     };
 
 
 	/**
 	/**
@@ -151,14 +183,10 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class GLRenderWindowManager;
 		friend class GLRenderWindowManager;
 		friend class Win32GLSupport;
 		friend class Win32GLSupport;
+		friend class Win32WindowCore;
 
 
 		Win32Window(Win32GLSupport& glsupport);
 		Win32Window(Win32GLSupport& glsupport);
 
 
-		/**
-		 * @copydoc	RenderWindow::initialize_internal
-		 */
-		virtual void initialize_internal();
-
 		/**
 		/**
 		 * @copydoc	RenderWindow::createProperties
 		 * @copydoc	RenderWindow::createProperties
 		 */
 		 */
@@ -167,10 +195,9 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc	RenderWindow::createCore
 		 * @copydoc	RenderWindow::createCore
 		 */
 		 */
-		virtual RenderWindowCore* createCore(RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc);
+		virtual CoreObjectCore* createCore() const;
 
 
 	private:
 	private:
 		Win32GLSupport& mGLSupport;
 		Win32GLSupport& mGLSupport;
-		HWND mHWnd;
 	};
 	};
 }
 }

+ 22 - 4
BansheeGLRenderSystem/Source/BsGLMultiRenderTexture.cpp

@@ -5,7 +5,15 @@ namespace BansheeEngine
 {
 {
 	GLMultiRenderTextureCore::GLMultiRenderTextureCore(GLMultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
 	GLMultiRenderTextureCore::GLMultiRenderTextureCore(GLMultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
 		:MultiRenderTextureCore(parent, properties, desc), mFB(nullptr)
 		:MultiRenderTextureCore(parent, properties, desc), mFB(nullptr)
+	{ }
+
+	GLMultiRenderTextureCore::~GLMultiRenderTextureCore()
+	{ }
+
+	void GLMultiRenderTextureCore::initialize()
 	{
 	{
+		MultiRenderTextureCore::initialize();
+
 		if (mFB != nullptr)
 		if (mFB != nullptr)
 			bs_delete(mFB);
 			bs_delete(mFB);
 
 
@@ -30,7 +38,7 @@ namespace BansheeEngine
 					surfaceDesc.zoffset = mColorSurfaces[i]->getFirstArraySlice();
 					surfaceDesc.zoffset = mColorSurfaces[i]->getFirstArraySlice();
 					colorBuffer = glColorSurface->getBuffer(0, mColorSurfaces[i]->getMostDetailedMip());
 					colorBuffer = glColorSurface->getBuffer(0, mColorSurfaces[i]->getMostDetailedMip());
 				}
 				}
-				
+
 				surfaceDesc.numSamples = getProperties().getMultisampleCount();
 				surfaceDesc.numSamples = getProperties().getMultisampleCount();
 				surfaceDesc.buffer = colorBuffer;
 				surfaceDesc.buffer = colorBuffer;
 
 
@@ -59,12 +67,16 @@ namespace BansheeEngine
 		{
 		{
 			mFB->unbindDepthStencil();
 			mFB->unbindDepthStencil();
 		}
 		}
+
+		MultiRenderTextureCore::initialize();
 	}
 	}
 
 
-	GLMultiRenderTextureCore::~GLMultiRenderTextureCore()
+	void GLMultiRenderTextureCore::destroy()
 	{
 	{
 		if (mFB != nullptr)
 		if (mFB != nullptr)
 			bs_delete(mFB);
 			bs_delete(mFB);
+
+		MultiRenderTextureCore::destroy();
 	}
 	}
 
 
 	void GLMultiRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
 	void GLMultiRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
@@ -84,8 +96,14 @@ namespace BansheeEngine
 		return bs_new<MultiRenderTextureProperties>();
 		return bs_new<MultiRenderTextureProperties>();
 	}
 	}
 
 
-	MultiRenderTextureCore* GLMultiRenderTexture::createCore(MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
+	CoreObjectCore* GLMultiRenderTexture::createCore() const
 	{
 	{
-		return bs_new<GLMultiRenderTextureCore>(this, properties, desc);
+		MultiRenderTextureProperties* coreProperties = bs_new<MultiRenderTextureProperties>();
+		MultiRenderTextureProperties* myProperties = static_cast<MultiRenderTextureProperties*>(mProperties);
+
+		*coreProperties = *myProperties;
+
+		return bs_new<GLMultiRenderTextureCore>(const_cast<GLMultiRenderTexture*>(this),
+			coreProperties, mDesc);
 	}
 	}
 }
 }

+ 21 - 6
BansheeGLRenderSystem/Source/BsGLRenderTexture.cpp

@@ -26,7 +26,15 @@ namespace BansheeEngine
 	GLRenderTextureCore::GLRenderTextureCore(GLRenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
 	GLRenderTextureCore::GLRenderTextureCore(GLRenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
 		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
 		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
 		:RenderTextureCore(parent, properties, colorSurfaceDesc, depthStencilSurfaceDesc), mFB(nullptr)
 		:RenderTextureCore(parent, properties, colorSurfaceDesc, depthStencilSurfaceDesc), mFB(nullptr)
+	{ }
+
+	GLRenderTextureCore::~GLRenderTextureCore()
+	{ }
+
+	void GLRenderTextureCore::initialize()
 	{
 	{
+		RenderTextureCore::initialize();
+
 		if (mFB != nullptr)
 		if (mFB != nullptr)
 			bs_delete<PoolAlloc>(mFB);
 			bs_delete<PoolAlloc>(mFB);
 
 
@@ -35,7 +43,7 @@ namespace BansheeEngine
 		GLTexture* glTexture = static_cast<GLTexture*>(mColorSurface->getTexture().get());
 		GLTexture* glTexture = static_cast<GLTexture*>(mColorSurface->getTexture().get());
 
 
 		GLSurfaceDesc surfaceDesc;
 		GLSurfaceDesc surfaceDesc;
-		surfaceDesc.numSamples = properties->getMultisampleCount();
+		surfaceDesc.numSamples = mProperties->getMultisampleCount();
 
 
 		if (glTexture->getTextureType() != TEX_TYPE_3D)
 		if (glTexture->getTextureType() != TEX_TYPE_3D)
 		{
 		{
@@ -55,17 +63,19 @@ namespace BansheeEngine
 
 
 		if (glDepthStencilTexture->getTextureType() != TEX_TYPE_3D)
 		if (glDepthStencilTexture->getTextureType() != TEX_TYPE_3D)
 		{
 		{
-			depthStencilBuffer = glDepthStencilTexture->getBuffer(mDepthStencilSurface->getFirstArraySlice(), 
+			depthStencilBuffer = glDepthStencilTexture->getBuffer(mDepthStencilSurface->getFirstArraySlice(),
 				mDepthStencilSurface->getMostDetailedMip());
 				mDepthStencilSurface->getMostDetailedMip());
 		}
 		}
 
 
 		mFB->bindDepthStencil(depthStencilBuffer);
 		mFB->bindDepthStencil(depthStencilBuffer);
 	}
 	}
 
 
-	GLRenderTextureCore::~GLRenderTextureCore()
+	void GLRenderTextureCore::destroy()
 	{
 	{
 		if (mFB != nullptr)
 		if (mFB != nullptr)
 			bs_delete<PoolAlloc>(mFB);
 			bs_delete<PoolAlloc>(mFB);
+
+		RenderTextureCore::destroy();
 	}
 	}
 
 
 	void GLRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
 	void GLRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
@@ -85,10 +95,15 @@ namespace BansheeEngine
 		return bs_new<RenderTextureProperties>();
 		return bs_new<RenderTextureProperties>();
 	}
 	}
 
 
-	RenderTextureCore* GLRenderTexture::createCore(RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
+	CoreObjectCore* GLRenderTexture::createCore() const
 	{
 	{
-		return bs_new<GLRenderTextureCore>(this, properties, colorSurfaceDesc, depthStencilSurfaceDesc);
+		RenderTextureProperties* coreProperties = bs_new<RenderTextureProperties>();
+		RenderTextureProperties* myProperties = static_cast<RenderTextureProperties*>(mProperties);
+
+		*coreProperties = *myProperties;
+
+		return bs_new<GLRenderTextureCore>(const_cast<GLRenderTexture*>(this),
+			coreProperties, mColorSurfaceDesc, mDepthStencilSurfaceDesc);
 	}
 	}
 
 
 	GLRTTManager::GLRTTManager()
 	GLRTTManager::GLRTTManager()

+ 109 - 77
BansheeGLRenderSystem/Source/BsWin32Window.cpp

@@ -19,10 +19,33 @@ namespace BansheeEngine
 {
 {
 	#define _MAX_CLASS_NAME_ 128
 	#define _MAX_CLASS_NAME_ 128
 
 
+	void Win32RenderWindowProperties::copyToBuffer(UINT8* buffer) const
+	{
+		*(Win32RenderWindowProperties*)buffer = *this;
+	}
+
+	void Win32RenderWindowProperties::copyFromBuffer(UINT8* buffer)
+	{
+		*this = *(Win32RenderWindowProperties*)buffer;
+	}
+
+	UINT32 Win32RenderWindowProperties::getSize() const
+	{
+		return sizeof(Win32RenderWindowProperties);
+	}
+
 	Win32WindowCore::Win32WindowCore(Win32Window* parentWnd, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, Win32GLSupport& glsupport)
 	Win32WindowCore::Win32WindowCore(Win32Window* parentWnd, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, Win32GLSupport& glsupport)
-		:RenderWindowCore(parentWnd, properties), mGLSupport(glsupport), mContext(0), mWindowedStyle(0), mWindowedStyleEx(0), mHWnd(0), mIsExternal(false),
-		mIsExternalGLControl(false), mDisplayFrequency(0), mDeviceName(nullptr)
+		:RenderWindowCore(parentWnd, properties), mGLSupport(glsupport), mContext(0), mWindowedStyle(0), mWindowedStyleEx(0), mIsExternal(false),
+		mIsExternalGLControl(false), mDisplayFrequency(0), mDeviceName(nullptr), mDesc(desc)
+	{ }
+
+	Win32WindowCore::~Win32WindowCore()
+	{ }
+
+	void Win32WindowCore::initialize()
 	{
 	{
+		RenderWindowCore::initialize();
+
 #ifdef BS_STATIC_LIB
 #ifdef BS_STATIC_LIB
 		HINSTANCE hInst = GetModuleHandle(NULL);
 		HINSTANCE hInst = GetModuleHandle(NULL);
 #else
 #else
@@ -31,37 +54,35 @@ namespace BansheeEngine
 
 
 		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
 		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
 
 
-		mHWnd = 0;
-		props->mName = desc.title;
-		props->mIsFullScreen = desc.fullscreen;
+		props->mIsFullScreen = mDesc.fullscreen;
 		mIsChild = false;
 		mIsChild = false;
-		mDisplayFrequency = Math::roundToInt(desc.videoMode.getRefreshRate());
+		mDisplayFrequency = Math::roundToInt(mDesc.videoMode.getRefreshRate());
 		props->mColorDepth = 32;
 		props->mColorDepth = 32;
 		HWND parent = 0;
 		HWND parent = 0;
 
 
 		NameValuePairList::const_iterator opt;
 		NameValuePairList::const_iterator opt;
-		NameValuePairList::const_iterator end = desc.platformSpecific.end();
+		NameValuePairList::const_iterator end = mDesc.platformSpecific.end();
 
 
-		if ((opt = desc.platformSpecific.find("externalWindowHandle")) != end)
+		if ((opt = mDesc.platformSpecific.find("externalWindowHandle")) != end)
 		{
 		{
-			mHWnd = (HWND)parseUnsignedInt(opt->second);
-			if (mHWnd)
+			props->mHWnd = (HWND)parseUnsignedInt(opt->second);
+			if (props->mHWnd)
 			{
 			{
 				mIsExternal = true;
 				mIsExternal = true;
 			}
 			}
 
 
-			if ((opt = desc.platformSpecific.find("externalGLControl")) != end) {
+			if ((opt = mDesc.platformSpecific.find("externalGLControl")) != end) {
 				mIsExternalGLControl = parseBool(opt->second);
 				mIsExternalGLControl = parseBool(opt->second);
 			}
 			}
 		}
 		}
 
 
 		HGLRC glrc = 0;
 		HGLRC glrc = 0;
-		if ((opt = desc.platformSpecific.find("externalGLContext")) != end)
+		if ((opt = mDesc.platformSpecific.find("externalGLContext")) != end)
 		{
 		{
 			glrc = (HGLRC)parseUnsignedLong(opt->second);
 			glrc = (HGLRC)parseUnsignedLong(opt->second);
 		}
 		}
 
 
-		if ((opt = desc.platformSpecific.find("parentWindowHandle")) != end)
+		if ((opt = mDesc.platformSpecific.find("parentWindowHandle")) != end)
 		{
 		{
 			parent = (HWND)parseUnsignedInt(opt->second);
 			parent = (HWND)parseUnsignedInt(opt->second);
 			mIsChild = true;
 			mIsChild = true;
@@ -73,7 +94,7 @@ namespace BansheeEngine
 		UINT32 numOutputs = videoModeInfo.getNumOutputs();
 		UINT32 numOutputs = videoModeInfo.getNumOutputs();
 		if (numOutputs > 0)
 		if (numOutputs > 0)
 		{
 		{
-			UINT32 actualMonitorIdx = std::min(desc.videoMode.getOutputIdx(), numOutputs - 1);
+			UINT32 actualMonitorIdx = std::min(mDesc.videoMode.getOutputIdx(), numOutputs - 1);
 			const Win32VideoOutputInfo& outputInfo = static_cast<const Win32VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
 			const Win32VideoOutputInfo& outputInfo = static_cast<const Win32VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
 			hMonitor = outputInfo.getMonitorHandle();
 			hMonitor = outputInfo.getMonitorHandle();
 		}
 		}
@@ -92,17 +113,17 @@ namespace BansheeEngine
 		{
 		{
 			if (parent)
 			if (parent)
 			{
 			{
-				if (desc.toolWindow)
+				if (mDesc.toolWindow)
 					mWindowedStyleEx = WS_EX_TOOLWINDOW;
 					mWindowedStyleEx = WS_EX_TOOLWINDOW;
 				else
 				else
 					mWindowedStyle |= WS_CHILD;
 					mWindowedStyle |= WS_CHILD;
 			}
 			}
 
 
-			if (!parent || desc.toolWindow)
+			if (!parent || mDesc.toolWindow)
 			{
 			{
-				if (desc.border == WindowBorder::None)
+				if (mDesc.border == WindowBorder::None)
 					mWindowedStyle |= WS_POPUP;
 					mWindowedStyle |= WS_POPUP;
-				else if (desc.border == WindowBorder::Fixed)
+				else if (mDesc.border == WindowBorder::Fixed)
 					mWindowedStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 					mWindowedStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 					WS_SYSMENU | WS_MINIMIZEBOX;
 					WS_SYSMENU | WS_MINIMIZEBOX;
 				else
 				else
@@ -120,8 +141,8 @@ namespace BansheeEngine
 				POINT windowAnchorPoint;
 				POINT windowAnchorPoint;
 
 
 				// Fill in anchor point.
 				// Fill in anchor point.
-				windowAnchorPoint.x = desc.left;
-				windowAnchorPoint.y = desc.top;
+				windowAnchorPoint.x = mDesc.left;
+				windowAnchorPoint.y = mDesc.top;
 
 
 				// Get the nearest monitor to this window.
 				// Get the nearest monitor to this window.
 				hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTONEAREST);
 				hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTONEAREST);
@@ -139,8 +160,8 @@ namespace BansheeEngine
 
 
 			strcpy_s(mDeviceName, devNameLen + 1, monitorInfoEx.szDevice);
 			strcpy_s(mDeviceName, devNameLen + 1, monitorInfoEx.szDevice);
 
 
-			UINT32 left = desc.left;
-			UINT32 top = desc.top;
+			UINT32 left = mDesc.left;
+			UINT32 top = mDesc.top;
 
 
 			// No specified top left -> Center the window in the middle of the monitor
 			// No specified top left -> Center the window in the middle of the monitor
 			if (left == -1 || top == -1)
 			if (left == -1 || top == -1)
@@ -149,7 +170,7 @@ namespace BansheeEngine
 				int screenh = monitorInfoEx.rcWork.bottom - monitorInfoEx.rcWork.top;
 				int screenh = monitorInfoEx.rcWork.bottom - monitorInfoEx.rcWork.top;
 
 
 				unsigned int winWidth, winHeight;
 				unsigned int winWidth, winHeight;
-				getAdjustedWindowSize(desc.videoMode.getWidth(), desc.videoMode.getHeight(), &winWidth, &winHeight);
+				getAdjustedWindowSize(mDesc.videoMode.getWidth(), mDesc.videoMode.getHeight(), &winWidth, &winHeight);
 
 
 				// clamp window dimensions to screen size
 				// clamp window dimensions to screen size
 				int outerw = (int(winWidth) < screenw) ? int(winWidth) : screenw;
 				int outerw = (int(winWidth) < screenw) ? int(winWidth) : screenw;
@@ -171,8 +192,8 @@ namespace BansheeEngine
 				top += monitorInfoEx.rcWork.top;
 				top += monitorInfoEx.rcWork.top;
 			}
 			}
 
 
-			props->mWidth = desc.videoMode.getWidth();
-			props->mHeight = desc.videoMode.getHeight();
+			props->mWidth = mDesc.videoMode.getWidth();
+			props->mHeight = mDesc.videoMode.getHeight();
 			props->mTop = top;
 			props->mTop = top;
 			props->mLeft = left;
 			props->mLeft = left;
 
 
@@ -192,7 +213,7 @@ namespace BansheeEngine
 				int screenw = GetSystemMetrics(SM_CXSCREEN);
 				int screenw = GetSystemMetrics(SM_CXSCREEN);
 				int screenh = GetSystemMetrics(SM_CYSCREEN);
 				int screenh = GetSystemMetrics(SM_CYSCREEN);
 
 
-				if (!desc.outerDimensions)
+				if (!mDesc.outerDimensions)
 				{
 				{
 					// Calculate window dimensions required
 					// Calculate window dimensions required
 					// to get the requested client area
 					// to get the requested client area
@@ -251,26 +272,26 @@ namespace BansheeEngine
 			}
 			}
 
 
 			// Pass pointer to self as WM_CREATE parameter
 			// Pass pointer to self as WM_CREATE parameter
-			mHWnd = CreateWindowEx(dwStyleEx, "GLWindow", desc.title.c_str(),
+			props->mHWnd = CreateWindowEx(dwStyleEx, "GLWindow", mDesc.title.c_str(),
 				dwStyle, props->mLeft, props->mTop, props->mWidth, props->mHeight, parent, 0, hInst, this);
 				dwStyle, props->mLeft, props->mTop, props->mWidth, props->mHeight, parent, 0, hInst, this);
 		}
 		}
 
 
 		RECT rc;
 		RECT rc;
 
 
-		GetWindowRect(mHWnd, &rc);
+		GetWindowRect(props->mHWnd, &rc);
 		props->mTop = rc.top;
 		props->mTop = rc.top;
 		props->mLeft = rc.left;
 		props->mLeft = rc.left;
 
 
-		GetClientRect(mHWnd, &rc);
+		GetClientRect(props->mHWnd, &rc);
 		props->mWidth = rc.right;
 		props->mWidth = rc.right;
 		props->mHeight = rc.bottom;
 		props->mHeight = rc.bottom;
 
 
-		mHDC = GetDC(mHWnd);
+		mHDC = GetDC(props->mHWnd);
 
 
 		if (!mIsExternalGLControl)
 		if (!mIsExternalGLControl)
 		{
 		{
 			int testMultisample = props->mMultisampleCount;
 			int testMultisample = props->mMultisampleCount;
-			bool testHwGamma = desc.gamma;
+			bool testHwGamma = mDesc.gamma;
 			bool formatOk = mGLSupport.selectPixelFormat(mHDC, props->mColorDepth, testMultisample, testHwGamma);
 			bool formatOk = mGLSupport.selectPixelFormat(mHDC, props->mColorDepth, testMultisample, testHwGamma);
 			if (!formatOk)
 			if (!formatOk)
 			{
 			{
@@ -281,7 +302,7 @@ namespace BansheeEngine
 					formatOk = mGLSupport.selectPixelFormat(mHDC, props->mColorDepth, testMultisample, testHwGamma);
 					formatOk = mGLSupport.selectPixelFormat(mHDC, props->mColorDepth, testMultisample, testHwGamma);
 				}
 				}
 
 
-				if (!formatOk && desc.gamma)
+				if (!formatOk && mDesc.gamma)
 				{
 				{
 					// Try without sRGB
 					// Try without sRGB
 					testHwGamma = false;
 					testHwGamma = false;
@@ -289,7 +310,7 @@ namespace BansheeEngine
 					formatOk = mGLSupport.selectPixelFormat(mHDC, props->mColorDepth, testMultisample, testHwGamma);
 					formatOk = mGLSupport.selectPixelFormat(mHDC, props->mColorDepth, testMultisample, testHwGamma);
 				}
 				}
 
 
-				if (!formatOk && desc.gamma && (props->mMultisampleCount > 0))
+				if (!formatOk && mDesc.gamma && (props->mMultisampleCount > 0))
 				{
 				{
 					// Try without both
 					// Try without both
 					testHwGamma = false;
 					testHwGamma = false;
@@ -310,15 +331,20 @@ namespace BansheeEngine
 
 
 		props->mActive = true;
 		props->mActive = true;
 		mContext = mGLSupport.createContext(mHDC, glrc);
 		mContext = mGLSupport.createContext(mHDC, glrc);
+
+		// Sync HWnd to CoreObject immediately
+		Win32Window* parentWnd = static_cast<Win32Window*>(mParent);
+		Win32RenderWindowProperties* parentProps = static_cast<Win32RenderWindowProperties*>(parentWnd->mProperties);
+		parentProps->mHWnd = props->mHWnd;
 	}
 	}
 
 
-	Win32WindowCore::~Win32WindowCore()
+	void Win32WindowCore::destroy()
 	{
 	{
-		if (!mHWnd)
-			return;
-
 		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
 		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
 
 
+		if (!props->mHWnd)
+			return;
+
 		// Unregister and destroy GLContext
 		// Unregister and destroy GLContext
 		bs_delete(mContext);
 		bs_delete(mContext);
 
 
@@ -326,17 +352,17 @@ namespace BansheeEngine
 		{
 		{
 			if (props->mIsFullScreen)
 			if (props->mIsFullScreen)
 				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
 				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
-			DestroyWindow(mHWnd);
+			DestroyWindow(props->mHWnd);
 		}
 		}
 		else
 		else
 		{
 		{
 			// just release the DC
 			// just release the DC
-			ReleaseDC(mHWnd, mHDC);
+			ReleaseDC(props->mHWnd, mHDC);
 		}
 		}
 
 
 		props->mActive = false;
 		props->mActive = false;
 		mHDC = 0; // no release thanks to CS_OWNDC wndclass style
 		mHDC = 0; // no release thanks to CS_OWNDC wndclass style
-		mHWnd = 0;
+		props->mHWnd = 0;
 
 
 		if (mDeviceName != NULL)
 		if (mDeviceName != NULL)
 		{
 		{
@@ -345,6 +371,8 @@ namespace BansheeEngine
 		}
 		}
 
 
 		markCoreDirty();
 		markCoreDirty();
+
+		RenderWindowCore::destroy();
 	}
 	}
 
 
 	void Win32WindowCore::setFullscreen(UINT32 width, UINT32 height, float refreshRate, UINT32 monitorIdx)
 	void Win32WindowCore::setFullscreen(UINT32 width, UINT32 height, float refreshRate, UINT32 monitorIdx)
@@ -396,7 +424,7 @@ namespace BansheeEngine
 		props->mWidth = width;
 		props->mWidth = width;
 		props->mHeight = height;
 		props->mHeight = height;
 
 
-		SetWindowPos(mHWnd, HWND_TOP, props->mLeft, props->mTop, width, height, SWP_NOACTIVATE);
+		SetWindowPos(props->mHWnd, HWND_TOP, props->mLeft, props->mTop, width, height, SWP_NOACTIVATE);
 
 
 		markCoreDirty();
 		markCoreDirty();
 	}
 	}
@@ -429,7 +457,7 @@ namespace BansheeEngine
 		getAdjustedWindowSize(props->mWidth, props->mHeight, &winWidth, &winHeight);
 		getAdjustedWindowSize(props->mWidth, props->mHeight, &winWidth, &winHeight);
 
 
 		// Deal with centering when switching down to smaller resolution
 		// Deal with centering when switching down to smaller resolution
-		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
+		HMONITOR hMonitor = MonitorFromWindow(props->mHWnd, MONITOR_DEFAULTTONEAREST);
 		MONITORINFO monitorInfo;
 		MONITORINFO monitorInfo;
 		memset(&monitorInfo, 0, sizeof(MONITORINFO));
 		memset(&monitorInfo, 0, sizeof(MONITORINFO));
 		monitorInfo.cbSize = sizeof(MONITORINFO);
 		monitorInfo.cbSize = sizeof(MONITORINFO);
@@ -441,9 +469,9 @@ namespace BansheeEngine
 		INT32 left = screenw > INT32(winWidth) ? ((screenw - INT32(winWidth)) / 2) : 0;
 		INT32 left = screenw > INT32(winWidth) ? ((screenw - INT32(winWidth)) / 2) : 0;
 		INT32 top = screenh > INT32(winHeight) ? ((screenh - INT32(winHeight)) / 2) : 0;
 		INT32 top = screenh > INT32(winHeight) ? ((screenh - INT32(winHeight)) / 2) : 0;
 
 
-		SetWindowLong(mHWnd, GWL_STYLE, mWindowedStyle);
-		SetWindowLong(mHWnd, GWL_EXSTYLE, mWindowedStyleEx);
-		SetWindowPos(mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight,
+		SetWindowLong(props->mHWnd, GWL_STYLE, mWindowedStyle);
+		SetWindowLong(props->mHWnd, GWL_EXSTYLE, mWindowedStyleEx);
+		SetWindowPos(props->mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight,
 			SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);
 			SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);
 
 
 		_windowMovedOrResized();
 		_windowMovedOrResized();
@@ -456,12 +484,12 @@ namespace BansheeEngine
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
 		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
 		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
-		if (mHWnd && !props->mIsFullScreen)
+		if (props->mHWnd && !props->mIsFullScreen)
 		{
 		{
 			props->mLeft = left;
 			props->mLeft = left;
 			props->mTop = top;
 			props->mTop = top;
 
 
-			SetWindowPos(mHWnd, 0, left, top, 0, 0,
+			SetWindowPos(props->mHWnd, 0, left, top, 0, 0,
 				SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 				SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 
 
 			markCoreDirty();
 			markCoreDirty();
@@ -473,16 +501,16 @@ namespace BansheeEngine
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
 		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
 		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
-		if (mHWnd && !props->mIsFullScreen)
+		if (props->mHWnd && !props->mIsFullScreen)
 		{
 		{
 			props->mWidth = width;
 			props->mWidth = width;
 			props->mHeight = height;
 			props->mHeight = height;
 
 
 			RECT rc = { 0, 0, width, height };
 			RECT rc = { 0, 0, width, height };
-			AdjustWindowRect(&rc, GetWindowLong(mHWnd, GWL_STYLE), false);
+			AdjustWindowRect(&rc, GetWindowLong(props->mHWnd, GWL_STYLE), false);
 			width = rc.right - rc.left;
 			width = rc.right - rc.left;
 			height = rc.bottom - rc.top;
 			height = rc.bottom - rc.top;
-			SetWindowPos(mHWnd, 0, 0, 0, width, height,
+			SetWindowPos(props->mHWnd, 0, 0, 0, width, height,
 				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 
 
 			markCoreDirty();
 			markCoreDirty();
@@ -554,6 +582,8 @@ namespace BansheeEngine
 
 
 	void Win32WindowCore::getCustomAttribute(const String& name, void* pData) const
 	void Win32WindowCore::getCustomAttribute(const String& name, void* pData) const
 	{
 	{
+		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
+
 		if(name == "GLCONTEXT") 
 		if(name == "GLCONTEXT") 
 		{
 		{
 			*static_cast<GLContext**>(pData) = mContext;
 			*static_cast<GLContext**>(pData) = mContext;
@@ -562,7 +592,7 @@ namespace BansheeEngine
 		else if(name == "WINDOW")
 		else if(name == "WINDOW")
 		{
 		{
 			HWND *pHwnd = (HWND*)pData;
 			HWND *pHwnd = (HWND*)pData;
-			*pHwnd = mHWnd;
+			*pHwnd = props->mHWnd;
 			return;
 			return;
 		} 
 		} 
 	}
 	}
@@ -571,13 +601,14 @@ namespace BansheeEngine
 	{	
 	{	
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
+		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
 		if (mDeviceName != NULL && state == false)
 		if (mDeviceName != NULL && state == false)
 		{
 		{
 			HWND hActiveWindow = GetActiveWindow();
 			HWND hActiveWindow = GetActiveWindow();
 			char classNameSrc[_MAX_CLASS_NAME_ + 1];
 			char classNameSrc[_MAX_CLASS_NAME_ + 1];
 			char classNameDst[_MAX_CLASS_NAME_ + 1];
 			char classNameDst[_MAX_CLASS_NAME_ + 1];
 
 
-			GetClassName(mHWnd, classNameSrc, _MAX_CLASS_NAME_);
+			GetClassName(props->mHWnd, classNameSrc, _MAX_CLASS_NAME_);
 			GetClassName(hActiveWindow, classNameDst, _MAX_CLASS_NAME_);
 			GetClassName(hActiveWindow, classNameDst, _MAX_CLASS_NAME_);
 
 
 			if (strcmp(classNameDst, classNameSrc) == 0)
 			if (strcmp(classNameDst, classNameSrc) == 0)
@@ -586,7 +617,6 @@ namespace BansheeEngine
 			}						
 			}						
 		}
 		}
 		
 		
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
 		props->mActive = state;
 		props->mActive = state;
 
 
 		if(props->mIsFullScreen)
 		if(props->mIsFullScreen)
@@ -594,11 +624,11 @@ namespace BansheeEngine
 			if( state == false )
 			if( state == false )
 			{	//Restore Desktop
 			{	//Restore Desktop
 				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
 				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
-				ShowWindow(mHWnd, SW_SHOWMINNOACTIVE);
+				ShowWindow(props->mHWnd, SW_SHOWMINNOACTIVE);
 			}
 			}
 			else
 			else
 			{	//Restore App
 			{	//Restore App
-				ShowWindow(mHWnd, SW_SHOWNORMAL);
+				ShowWindow(props->mHWnd, SW_SHOWNORMAL);
 
 
 				DEVMODE displayDeviceMode;
 				DEVMODE displayDeviceMode;
 
 
@@ -629,9 +659,9 @@ namespace BansheeEngine
 		if (!mIsExternal)
 		if (!mIsExternal)
 		{
 		{
 			if (hidden)
 			if (hidden)
-				ShowWindow(mHWnd, SW_HIDE);
+				ShowWindow(props->mHWnd, SW_HIDE);
 			else
 			else
-				ShowWindow(mHWnd, SW_SHOWNORMAL);
+				ShowWindow(props->mHWnd, SW_SHOWNORMAL);
 		}
 		}
 
 
 		markCoreDirty();
 		markCoreDirty();
@@ -639,17 +669,17 @@ namespace BansheeEngine
 
 
 	void Win32WindowCore::_windowMovedOrResized()
 	void Win32WindowCore::_windowMovedOrResized()
 	{
 	{
-		if (!mHWnd || IsIconic(mHWnd))
+		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
+
+		if (!props->mHWnd || IsIconic(props->mHWnd))
 			return;
 			return;
 
 
 		RECT rc;
 		RECT rc;
-
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
-		GetWindowRect(mHWnd, &rc);
+		GetWindowRect(props->mHWnd, &rc);
 		props->mTop = rc.top;
 		props->mTop = rc.top;
 		props->mLeft = rc.left;
 		props->mLeft = rc.left;
 
 
-		GetClientRect(mHWnd, &rc);
+		GetClientRect(props->mHWnd, &rc);
 		props->mWidth = rc.right - rc.left;
 		props->mWidth = rc.right - rc.left;
 		props->mHeight = rc.bottom - rc.top;
 		props->mHeight = rc.bottom - rc.top;
 
 
@@ -660,6 +690,8 @@ namespace BansheeEngine
 
 
 	void Win32WindowCore::getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight, UINT32* winWidth, UINT32* winHeight)
 	void Win32WindowCore::getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight, UINT32* winWidth, UINT32* winHeight)
 	{
 	{
+		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
+
 		RECT rc;
 		RECT rc;
 		SetRect(&rc, 0, 0, clientWidth, clientHeight);
 		SetRect(&rc, 0, 0, clientWidth, clientHeight);
 		AdjustWindowRectEx(&rc, mWindowedStyle, false, mWindowedStyleEx);
 		AdjustWindowRectEx(&rc, mWindowedStyle, false, mWindowedStyleEx);
@@ -667,7 +699,7 @@ namespace BansheeEngine
 		*winHeight = rc.bottom - rc.top;
 		*winHeight = rc.bottom - rc.top;
 
 
 		// Adjust to monitor
 		// Adjust to monitor
-		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
+		HMONITOR hMonitor = MonitorFromWindow(props->mHWnd, MONITOR_DEFAULTTONEAREST);
 
 
 		// Get monitor info	
 		// Get monitor info	
 		MONITORINFO monitorInfo;
 		MONITORINFO monitorInfo;
@@ -696,10 +728,11 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_CORE_THREAD;
 		THROW_IF_CORE_THREAD;
 
 
+		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
 		if (name == "WINDOW")
 		if (name == "WINDOW")
 		{
 		{
 			HWND *pWnd = (HWND*)pData;
 			HWND *pWnd = (HWND*)pData;
-			*pWnd = mHWnd;
+			*pWnd = props->mHWnd;
 			return;
 			return;
 		}
 		}
 
 
@@ -712,7 +745,8 @@ namespace BansheeEngine
 		pos.x = screenPos.x;
 		pos.x = screenPos.x;
 		pos.y = screenPos.y;
 		pos.y = screenPos.y;
 
 
-		ScreenToClient(mHWnd, &pos);
+		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
+		ScreenToClient(props->mHWnd, &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
@@ -722,29 +756,27 @@ namespace BansheeEngine
 		pos.x = windowPos.x;
 		pos.x = windowPos.x;
 		pos.y = windowPos.y;
 		pos.y = windowPos.y;
 
 
-		ClientToScreen(mHWnd, &pos);
+		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
+		ClientToScreen(props->mHWnd, &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
 	Win32WindowCore* Win32Window::getCore() const
 	Win32WindowCore* Win32Window::getCore() const
 	{
 	{
-		return static_cast<Win32WindowCore*>(mCore);
-	}
-
-	void Win32Window::initialize_internal()
-	{
-		RenderWindow::initialize_internal();
-
-		mCore->getCustomAttribute("WINDOW", (void*)&mHWnd);
+		return static_cast<Win32WindowCore*>(mCoreSpecific);
 	}
 	}
 
 
 	RenderTargetProperties* Win32Window::createProperties() const
 	RenderTargetProperties* Win32Window::createProperties() const
 	{
 	{
-		return bs_new<RenderWindowProperties>();
+		return bs_new<Win32RenderWindowProperties>();
 	}
 	}
 
 
-	RenderWindowCore* Win32Window::createCore(RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc)
+	CoreObjectCore* Win32Window::createCore() const
 	{
 	{
-		return bs_new<Win32WindowCore>(this, properties, desc, mGLSupport);
+		Win32RenderWindowProperties* coreProperties = bs_new<Win32RenderWindowProperties>();
+		Win32RenderWindowProperties* myProperties = static_cast<Win32RenderWindowProperties*>(mProperties);
+
+		*coreProperties = *myProperties;
+		return bs_new<Win32WindowCore>(const_cast<Win32Window*>(this), coreProperties, mDesc, mGLSupport);
 	}
 	}
 }
 }