Parcourir la source

First part of render target refactor in order to get only core versions used on core thread

Marko Pintera il y a 11 ans
Parent
commit
88ee5b68fd
89 fichiers modifiés avec 1675 ajouts et 1463 suppressions
  1. 1 0
      BansheeCore/Include/BsCameraProxy.h
  2. 1 1
      BansheeCore/Include/BsCommonTypes.h
  3. 1 1
      BansheeCore/Include/BsCoreThreadAccessor.h
  4. 5 2
      BansheeCore/Include/BsHardwareBufferManager.h
  5. 35 36
      BansheeCore/Include/BsMultiRenderTexture.h
  6. 6 5
      BansheeCore/Include/BsRenderSystem.h
  7. 10 63
      BansheeCore/Include/BsRenderTarget.h
  8. 54 46
      BansheeCore/Include/BsRenderTexture.h
  9. 43 48
      BansheeCore/Include/BsRenderWindow.h
  10. 63 5
      BansheeCore/Include/BsRenderWindowManager.h
  11. 45 10
      BansheeCore/Include/BsTextureManager.h
  12. 2 2
      BansheeCore/Include/BsTransientMesh.h
  13. 4 5
      BansheeCore/Include/Win32/BsPlatformImpl.h
  14. 3 3
      BansheeCore/Source/BsCoreThreadAccessor.cpp
  15. 2 2
      BansheeCore/Source/BsHardwareBufferManager.cpp
  16. 1 1
      BansheeCore/Source/BsIndexBuffer.cpp
  17. 67 44
      BansheeCore/Source/BsMultiRenderTexture.cpp
  18. 3 6
      BansheeCore/Source/BsRenderSystem.cpp
  19. 16 62
      BansheeCore/Source/BsRenderTarget.cpp
  20. 76 55
      BansheeCore/Source/BsRenderTexture.cpp
  21. 75 45
      BansheeCore/Source/BsRenderWindow.cpp
  22. 82 9
      BansheeCore/Source/BsRenderWindowManager.cpp
  23. 1 1
      BansheeCore/Source/BsTexture.cpp
  24. 40 34
      BansheeCore/Source/BsTextureManager.cpp
  25. 2 2
      BansheeCore/Source/BsTransientMesh.cpp
  26. 1 1
      BansheeCore/Source/BsVertexBuffer.cpp
  27. 7 23
      BansheeCore/Source/Win32/BsPlatformImpl.cpp
  28. 5 4
      BansheeCore/Source/Win32/BsPlatformWndProc.cpp
  29. 2 2
      BansheeD3D11RenderSystem/Include/BsD3D11HardwareBufferManager.h
  30. 13 8
      BansheeD3D11RenderSystem/Include/BsD3D11MultiRenderTexture.h
  31. 10 2
      BansheeD3D11RenderSystem/Include/BsD3D11RenderSystem.h
  32. 11 11
      BansheeD3D11RenderSystem/Include/BsD3D11RenderTexture.h
  33. 21 35
      BansheeD3D11RenderSystem/Include/BsD3D11RenderWindow.h
  34. 19 1
      BansheeD3D11RenderSystem/Include/BsD3D11RenderWindowManager.h
  35. 19 5
      BansheeD3D11RenderSystem/Include/BsD3D11TextureManager.h
  36. 2 2
      BansheeD3D11RenderSystem/Source/BsD3D11HardwareBufferManager.cpp
  37. 5 18
      BansheeD3D11RenderSystem/Source/BsD3D11MultiRenderTexture.cpp
  38. 28 17
      BansheeD3D11RenderSystem/Source/BsD3D11RenderSystem.cpp
  39. 5 16
      BansheeD3D11RenderSystem/Source/BsD3D11RenderTexture.cpp
  40. 104 139
      BansheeD3D11RenderSystem/Source/BsD3D11RenderWindow.cpp
  41. 20 2
      BansheeD3D11RenderSystem/Source/BsD3D11RenderWindowManager.cpp
  42. 14 11
      BansheeD3D11RenderSystem/Source/BsD3D11TextureManager.cpp
  43. 2 2
      BansheeD3D9RenderSystem/Include/BsD3D9HardwareBufferManager.h
  44. 12 8
      BansheeD3D9RenderSystem/Include/BsD3D9MultiRenderTexture.h
  45. 13 3
      BansheeD3D9RenderSystem/Include/BsD3D9RenderSystem.h
  46. 16 14
      BansheeD3D9RenderSystem/Include/BsD3D9RenderTexture.h
  47. 21 39
      BansheeD3D9RenderSystem/Include/BsD3D9RenderWindow.h
  48. 19 1
      BansheeD3D9RenderSystem/Include/BsD3D9RenderWindowManager.h
  49. 19 2
      BansheeD3D9RenderSystem/Include/BsD3D9TextureManager.h
  50. 2 2
      BansheeD3D9RenderSystem/Source/BsD3D9HardwareBufferManager.cpp
  51. 4 14
      BansheeD3D9RenderSystem/Source/BsD3D9MultiRenderTexture.cpp
  52. 60 51
      BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp
  53. 4 15
      BansheeD3D9RenderSystem/Source/BsD3D9RenderTexture.cpp
  54. 109 140
      BansheeD3D9RenderSystem/Source/BsD3D9RenderWindow.cpp
  55. 16 2
      BansheeD3D9RenderSystem/Source/BsD3D9RenderWindowManager.cpp
  56. 14 4
      BansheeD3D9RenderSystem/Source/BsD3D9TextureManager.cpp
  57. 4 2
      BansheeEditor/Include/BsScenePicking.h
  58. 2 1
      BansheeEditor/Source/BsEditorWindow.cpp
  59. 1 1
      BansheeEditor/Source/BsGUIMenuBar.cpp
  60. 1 1
      BansheeEditor/Source/BsGUIWindowFrameWidget.cpp
  61. 5 3
      BansheeEditor/Source/BsGizmoManager.cpp
  62. 4 3
      BansheeEditor/Source/BsHandleDrawManager.cpp
  63. 17 11
      BansheeEditor/Source/BsScenePicking.cpp
  64. 1 1
      BansheeEditorExec/BsEditorExec.cpp
  65. 1 1
      BansheeEngine/Include/BsGUIManager.h
  66. 1 0
      BansheeEngine/Source/BsCameraHandler.cpp
  67. 3 4
      BansheeEngine/Source/BsGUIManager.cpp
  68. 1 1
      BansheeEngine/Source/BsGUIRenderTexture.cpp
  69. 2 2
      BansheeGLRenderSystem/Include/BsGLHardwareBufferManager.h
  70. 16 17
      BansheeGLRenderSystem/Include/BsGLMultiRenderTexture.h
  71. 10 2
      BansheeGLRenderSystem/Include/BsGLRenderSystem.h
  72. 31 35
      BansheeGLRenderSystem/Include/BsGLRenderTexture.h
  73. 19 1
      BansheeGLRenderSystem/Include/BsGLRenderWindowManager.h
  74. 11 0
      BansheeGLRenderSystem/Include/BsGLSupport.h
  75. 24 2
      BansheeGLRenderSystem/Include/BsGLTextureManager.h
  76. 6 1
      BansheeGLRenderSystem/Include/BsWin32GLSupport.h
  77. 1 0
      BansheeGLRenderSystem/Include/BsWin32Prerequisites.h
  78. 22 36
      BansheeGLRenderSystem/Include/BsWin32Window.h
  79. 2 2
      BansheeGLRenderSystem/Source/BsGLHardwareBufferManager.cpp
  80. 5 17
      BansheeGLRenderSystem/Source/BsGLMultiRenderTexture.cpp
  81. 44 32
      BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp
  82. 9 20
      BansheeGLRenderSystem/Source/BsGLRenderTexture.cpp
  83. 18 1
      BansheeGLRenderSystem/Source/BsGLRenderWindowManager.cpp
  84. 18 4
      BansheeGLRenderSystem/Source/BsGLTextureManager.cpp
  85. 13 7
      BansheeGLRenderSystem/Source/BsWin32GLSupport.cpp
  86. 130 162
      BansheeGLRenderSystem/Source/BsWin32Window.cpp
  87. 1 1
      BansheeRenderer/Include/BsBansheeRenderer.h
  88. 7 6
      BansheeRenderer/Source/BsBansheeRenderer.cpp
  89. 10 4
      TODO.txt

+ 1 - 0
BansheeCore/Include/BsCameraProxy.h

@@ -15,6 +15,7 @@ namespace BansheeEngine
 	public:
 	public:
 		void calcWorldFrustum();
 		void calcWorldFrustum();
 
 
+		SPtr<RenderTargetCore> renderTarget;
 		Viewport viewport;
 		Viewport viewport;
 		Matrix4 viewMatrix;
 		Matrix4 viewMatrix;
 		Matrix4 projMatrix;
 		Matrix4 projMatrix;

+ 1 - 1
BansheeCore/Include/BsCommonTypes.h

@@ -375,7 +375,7 @@ namespace BansheeEngine
 		 *			valid size.
 		 *			valid size.
 		 */
 		 */
 		template<class T>
 		template<class T>
-		const T& getData()
+		const T& getData() const
 		{
 		{
 			assert(sizeof(T) == size);
 			assert(sizeof(T) == size);
 
 

+ 1 - 1
BansheeCore/Include/BsCoreThreadAccessor.h

@@ -52,7 +52,7 @@ namespace BansheeEngine
 		void setVertexDeclaration(const VertexDeclarationPtr& vertexDeclaration);
 		void setVertexDeclaration(const VertexDeclarationPtr& vertexDeclaration);
 
 
 		/** @copydoc RenderSystem::setViewport() */
 		/** @copydoc RenderSystem::setViewport() */
-		void setViewport(Viewport vp);
+		void setViewport(const Rect2& vp);
 
 
 		/** @copydoc RenderSystem::setDrawOperation() */
 		/** @copydoc RenderSystem::setDrawOperation() */
 		void setDrawOperation(DrawOperationType op);
 		void setDrawOperation(DrawOperationType op);

+ 5 - 2
BansheeCore/Include/BsHardwareBufferManager.h

@@ -115,15 +115,18 @@ namespace BansheeEngine
 		virtual SPtr<IndexBufferCore> createIndexBuffer(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 		virtual SPtr<IndexBufferCore> createIndexBuffer(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 
 	protected:
 	protected:
+		friend class IndexBuffer;
+		friend class VertexBuffer;
+
 		/**
 		/**
 		 * @copydoc	createVertexBuffer
 		 * @copydoc	createVertexBuffer
 		 */
 		 */
-		virtual SPtr<VertexBufferCore> createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
+		virtual SPtr<VertexBufferCore> createVertexBufferInternal(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
 
 
 		/**
 		/**
 		 * @copydoc	createIndexBuffer
 		 * @copydoc	createIndexBuffer
 		 */
 		 */
-		virtual SPtr<IndexBufferCore> createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
+		virtual SPtr<IndexBufferCore> createIndexBufferInternal(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
 	};
 	};
 }
 }
 
 

+ 35 - 36
BansheeCore/Include/BsMultiRenderTexture.h

@@ -22,26 +22,12 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT MultiRenderTextureProperties : public RenderTargetProperties
 	class BS_CORE_EXPORT MultiRenderTextureProperties : public RenderTargetProperties
 	{
 	{
 	public:
 	public:
+		MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_DESC& desc);
 		virtual ~MultiRenderTextureProperties() { }
 		virtual ~MultiRenderTextureProperties() { }
 
 
 	protected:
 	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;
 	};
 	};
 
 
 	/**
 	/**
@@ -55,14 +41,6 @@ namespace BansheeEngine
 	public:
 	public:
 		virtual ~MultiRenderTextureCore();
 		virtual ~MultiRenderTextureCore();
 
 
-	protected:
-		MultiRenderTextureCore(MultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc);
-
-		/**
-		 * @copydoc	RenderTargetCore::getNonCore
-		 */
-		MultiRenderTexture* getNonCore() const;
-
 		/**
 		/**
 		 * @copydoc	CoreObjectCore::initialize
 		 * @copydoc	CoreObjectCore::initialize
 		 */
 		 */
@@ -73,6 +51,24 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual void destroy();
 		virtual void destroy();
 
 
+		/**
+		 * @brief	Returns properties that describe the render texture.
+		 */
+		const MultiRenderTextureProperties& getProperties() const;
+
+	protected:
+		MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_DESC& desc);
+
+		/**
+		 * @copydoc	CoreObjectCore::syncFromCore
+		 */
+		virtual CoreSyncData syncFromCore(FrameAlloc* allocator);
+
+		/**
+		 * @copydoc	CoreObjectCore::syncToCore
+		 */
+		virtual void syncToCore(const CoreSyncData& data);
+
 	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
@@ -102,35 +98,38 @@ namespace BansheeEngine
 		virtual ~MultiRenderTexture() { }
 		virtual ~MultiRenderTexture() { }
 
 
 		/**
 		/**
-		 * @copydoc	RenderTarget::initialize
+		 * @brief	Retrieves a core implementation of a render texture usable only from the
+		 *			core thread.
 		 */
 		 */
-		void initialize(const MULTI_RENDER_TEXTURE_DESC& desc);
+		SPtr<MultiRenderTextureCore> getCore() const;
 
 
 		/**
 		/**
-		 * @copydoc	RenderTexture::requiresTextureFlipping
+		 * @copydoc	TextureManager::createMultiRenderTexture
 		 */
 		 */
-		virtual bool requiresTextureFlipping() const { return false; }
+		static MultiRenderTexturePtr create(const MULTI_RENDER_TEXTURE_DESC& desc);
 
 
 		/**
 		/**
 		 * @brief	Returns properties that describe the render texture.
 		 * @brief	Returns properties that describe the render texture.
 		 */
 		 */
 		const MultiRenderTextureProperties& getProperties() const;
 		const MultiRenderTextureProperties& getProperties() const;
 
 
+	protected:
+		MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
+
 		/**
 		/**
-		 * @brief	Retrieves a core implementation of a render texture usable only from the
-		 *			core thread.
-		 *
-		 * @note	Core thread only.
+		 * @copydoc	RenderTarget::createCore
 		 */
 		 */
-		SPtr<MultiRenderTextureCore> getCore() const;
+		SPtr<CoreObjectCore> createCore() const;
 
 
 		/**
 		/**
-		 * @copydoc	TextureManager::createMultiRenderTexture
+		 * @copydoc	CoreObjectCore::syncToCore
 		 */
 		 */
-		static MultiRenderTexturePtr create(const MULTI_RENDER_TEXTURE_DESC& desc);
+		virtual CoreSyncData syncToCore(FrameAlloc* allocator);
 
 
-	protected:
-		MultiRenderTexture() { }
+		/**
+		 * @copydoc	CoreObjectCore::syncFromCore
+		 */
+		virtual void syncFromCore(const CoreSyncData& data);
 
 
 		MULTI_RENDER_TEXTURE_DESC mDesc;
 		MULTI_RENDER_TEXTURE_DESC mDesc;
 	};
 	};

+ 6 - 5
BansheeCore/Include/BsRenderSystem.h

@@ -106,9 +106,10 @@ namespace BansheeEngine
 
 
 		/**
 		/**
 		 * @brief	Sets the active viewport that will be used for all render operations.
 		 * @brief	Sets the active viewport that will be used for all render operations.
-		 *			Viewport will change active render target if needed.
+		 *
+		 * @param	area	Area of the viewport, in normalized ([0,1] range) coordinates.
 		 */
 		 */
-		virtual void setViewport(Viewport vp) = 0;
+		virtual void setViewport(const Rect2& area) = 0;
 
 
 		/**
 		/**
 		 * @brief	Sets the provided vertex buffers starting at the specified source index.
 		 * @brief	Sets the provided vertex buffers starting at the specified source index.
@@ -151,7 +152,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Swap the front and back buffer of the specified render target.
 		 * @brief	Swap the front and back buffer of the specified render target.
 		 */
 		 */
-		virtual void swapBuffers(RenderTargetPtr target);
+		virtual void swapBuffers(const SPtr<RenderTargetCore>& target);
 
 
 		/**
 		/**
 		 * @brief	Gets the capabilities of the render system.
 		 * @brief	Gets the capabilities of the render system.
@@ -236,7 +237,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Change the render target into which we want to draw.
 		 * @brief	Change the render target into which we want to draw.
 		 */
 		 */
-        virtual void setRenderTarget(RenderTargetPtr target) = 0;
+        virtual void setRenderTarget(const SPtr<RenderTargetCore>& target) = 0;
 
 
 		/**
 		/**
 		 * @brief	Updates the resource with the specified data.
 		 * @brief	Updates the resource with the specified data.
@@ -362,7 +363,7 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class RenderSystemManager;
 		friend class RenderSystemManager;
 
 
-		RenderTargetPtr mActiveRenderTarget;
+		SPtr<RenderTargetCore> mActiveRenderTarget;
 
 
 		DriverVersion mDriverVersion;
 		DriverVersion mDriverVersion;
 		CullingMode mCullingMode;
 		CullingMode mCullingMode;

+ 10 - 63
BansheeCore/Include/BsRenderTarget.h

@@ -96,21 +96,6 @@ namespace BansheeEngine
 		friend class RenderTargetCore;
 		friend class RenderTargetCore;
 		friend class RenderTarget;
 		friend class RenderTarget;
 
 
-		/**
-		 * @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;
 		UINT32 mColorDepth = 32;
 		UINT32 mColorDepth = 32;
@@ -145,35 +130,29 @@ namespace BansheeEngine
 			FB_AUTO
 			FB_AUTO
 		};
 		};
 
 
-		RenderTargetCore(RenderTarget* parent, RenderTargetProperties* properties);
-		virtual ~RenderTargetCore();
+		RenderTargetCore();
+		virtual ~RenderTargetCore() { }
 
 
 		/**
 		/**
 		 * @brief	Makes the render target active or inactive. (e.g. for a window, it will hide or restore the window).
 		 * @brief	Makes the render target active or inactive. (e.g. for a window, it will hide or restore the window).
-		 *
-		 * @note	Core thread only.
 		 */
 		 */
-		virtual void setActive(bool state) { mProperties->mActive = state; markCoreDirty(); }
+		virtual void setActive(bool state);
 
 
 		/**
 		/**
 		 * @brief	Sets a priority that determines in which orders the render targets the processed.
 		 * @brief	Sets a priority that determines in which orders the render targets the processed.
 		 * 			
 		 * 			
 		 * @param	priority	The priority. Higher value means the target will be rendered sooner.
 		 * @param	priority	The priority. Higher value means the target will be rendered sooner.
 		 */
 		 */
-		void setPriority(INT32 priority) { mProperties->mPriority = priority; markCoreDirty(); }
+		void setPriority(INT32 priority);
 
 
 		/**
 		/**
 		 * @brief	Swaps the frame buffers to display the next frame.
 		 * @brief	Swaps the frame buffers to display the next frame.
-		 *
-		 * @note	Core thread only.
 		 */
 		 */
 		virtual void swapBuffers() {};
 		virtual void swapBuffers() {};
 
 
 		/**
 		/**
 		 * @brief	Queries the render target for a custom attribute. This may be anything and is
 		 * @brief	Queries the render target for a custom attribute. This may be anything and is
 		 *			implementation specific.
 		 *			implementation specific.
-		 *
-		 * @note	Core thread only.
 		 */
 		 */
 		virtual void getCustomAttribute(const String& name, void* pData) const;
 		virtual void getCustomAttribute(const String& name, void* pData) const;
 
 
@@ -182,26 +161,13 @@ namespace BansheeEngine
 		 */
 		 */
 		const RenderTargetProperties& getProperties() const;
 		const RenderTargetProperties& getProperties() const;
 
 
-		/**
-		 * @brief	Returns the non core version of the render target.
-		 */
-		RenderTarget* getNonCore() const { return mParent; }
-
 	protected:
 	protected:
 		friend class RenderTarget;
 		friend class RenderTarget;
 
 
 		/**
 		/**
-		 * @copydoc	CoreObjectCore::syncFromCore
-		 */
-		virtual CoreSyncData syncFromCore(FrameAlloc* allocator);
-
-		/**
-		 * @copydoc	CoreObjectCore::syncToCore
+		 * @brief	Returns properties that describe the render target.
 		 */
 		 */
-		virtual void syncToCore(const CoreSyncData& data);
-
-		RenderTargetProperties* mProperties;
-		RenderTarget* mParent;
+		virtual const RenderTargetProperties& getPropertiesInternal() const = 0;
 	};
 	};
 
 
 	/**
 	/**
@@ -214,13 +180,7 @@ namespace BansheeEngine
     class BS_CORE_EXPORT RenderTarget : public CoreObject
     class BS_CORE_EXPORT RenderTarget : public CoreObject
     {
     {
     public:
     public:
-        virtual ~RenderTarget();
-
-		/**
-		 * @brief	Does the texture need to be vertically flipped because of different screen space coordinate systems.
-		 *			(i.e. is origin top left or bottom left. Engine default is top left.)
-		 */
-		virtual bool requiresTextureFlipping() const = 0;
+		virtual ~RenderTarget() { }
 
 
 		/**
 		/**
 		 * @brief	Queries the render target for a custom attribute. This may be anything and is
 		 * @brief	Queries the render target for a custom attribute. This may be anything and is
@@ -249,24 +209,11 @@ namespace BansheeEngine
 		mutable Event<void()> onResized;
 		mutable Event<void()> onResized;
 
 
     protected:
     protected:
-		RenderTarget();
-
-		/**
-		 * @brief	Creates a new instance of render target properties used for storing
-		 *			render target data and providing easy access to it.
-		 */
-		virtual RenderTargetProperties* createProperties() const = 0;
-
-		/**
-		 * @copydoc	CoreObject::syncToCore
-		 */
-		virtual CoreSyncData syncToCore(FrameAlloc* allocator);
+		friend class RenderTargetCore;
 
 
 		/**
 		/**
-		 * @copydoc	CoreObject::syncFromCore
+		 * @brief	Returns properties that describe the render target.
 		 */
 		 */
-		virtual void syncFromCore(const CoreSyncData& data);
-
-		RenderTargetProperties* mProperties;
+		virtual const RenderTargetProperties& getPropertiesInternal() const = 0;
     };
     };
 }
 }

+ 54 - 46
BansheeCore/Include/BsRenderTexture.h

@@ -21,26 +21,12 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT RenderTextureProperties : public RenderTargetProperties
 	class BS_CORE_EXPORT RenderTextureProperties : public RenderTargetProperties
 	{
 	{
 	public:
 	public:
+		RenderTextureProperties(const RENDER_TEXTURE_DESC& desc, bool requiresFlipping);
 		virtual ~RenderTextureProperties() { }
 		virtual ~RenderTextureProperties() { }
 
 
 	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;
 	};
 	};
 
 
 	/**
 	/**
@@ -51,44 +37,62 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT RenderTextureCore : public RenderTargetCore
 	class BS_CORE_EXPORT RenderTextureCore : public RenderTargetCore
 	{
 	{
 	public:
 	public:
-		RenderTextureCore(RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-			const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
+		RenderTextureCore(const RENDER_TEXTURE_DESC& desc);
 		virtual ~RenderTextureCore();
 		virtual ~RenderTextureCore();
 
 
 		/**
 		/**
-		 * @brief	Returns properties that describe the render texture.
+		 * @copydoc	CoreObjectCore::initialize
 		 */
 		 */
-		const RenderTextureProperties& getProperties() const { return *static_cast<RenderTextureProperties*>(mProperties); }
+		virtual void initialize();
 
 
 		/**
 		/**
-		 * @copydoc	RenderTargetCore::getNonCore
+		 * @copydoc	CoreObjectCore::destroy
 		 */
 		 */
-		RenderTexture* getNonCore() const;
+		virtual void destroy();
 
 
-	private:
 		/**
 		/**
-		 * @brief	Throws an exception of the color and depth/stencil buffers aren't compatible.
+		 * @brief	Returns a color surface texture you may bind as an input to an GPU program.
+		 *
+		 * @note	Be aware that you cannot bind a render texture for reading and writing at the same time.
 		 */
 		 */
-		void throwIfBuffersDontMatch() const;
+		const TexturePtr& getBindableColorTexture() const { return mDesc.colorSurface.texture; }
+
+		/**
+		 * @brief	Returns a depth/stencil surface texture you may bind as an input to an GPU program.
+		 *
+		 * @note		Be aware that you cannot bind a render texture for reading and writing at the same time.
+		 */
+		const TexturePtr& getBindableDepthStencilTexture() const { return mDesc.depthStencilSurface.texture; }
+
+		/**
+		 * @brief	Returns properties that describe the render texture.
+		 */
+		const RenderTextureProperties& getProperties() const;
 
 
 	protected:
 	protected:
-		friend class RenderTexture;
+		/**
+		 * @copydoc	CoreObjectCore::syncFromCore
+		 */
+		virtual CoreSyncData syncFromCore(FrameAlloc* allocator);
 
 
 		/**
 		/**
-		 * @copydoc	CoreObjectCore::initialize
+		 * @copydoc	CoreObjectCore::syncToCore
 		 */
 		 */
-		virtual void initialize();
+		virtual void syncToCore(const CoreSyncData& data);
 
 
+	private:
 		/**
 		/**
-		 * @copydoc	CoreObjectCore::destroy
+		 * @brief	Throws an exception of the color and depth/stencil buffers aren't compatible.
 		 */
 		 */
-		virtual void destroy();
+		void throwIfBuffersDontMatch() const;
+
+	protected:
+		friend class RenderTexture;
 
 
 		TextureViewPtr mColorSurface;
 		TextureViewPtr mColorSurface;
 		TextureViewPtr mDepthStencilSurface;
 		TextureViewPtr mDepthStencilSurface;
 
 
-		RENDER_SURFACE_DESC mColorSurfaceDesc;
-		RENDER_SURFACE_DESC mDepthStencilSurfaceDesc;
+		RENDER_TEXTURE_DESC mDesc;
 	};
 	};
 
 
 	/**
 	/**
@@ -124,11 +128,6 @@ namespace BansheeEngine
 		 */
 		 */
 		static RenderTexturePtr create(const RENDER_TEXTURE_DESC& desc);
 		static RenderTexturePtr create(const RENDER_TEXTURE_DESC& desc);
 
 
-		/**
-		 * @copydoc	RenderTexture::requiresTextureFlipping
-		 */
-		virtual bool requiresTextureFlipping() const { return false; }
-
 		/**
 		/**
 		 * @brief	Returns a color surface texture you may bind as an input to an GPU program.
 		 * @brief	Returns a color surface texture you may bind as an input to an GPU program.
 		 *
 		 *
@@ -143,11 +142,6 @@ namespace BansheeEngine
 		 */
 		 */
 		const HTexture& getBindableDepthStencilTexture() const { return mBindableDepthStencilTex; }
 		const HTexture& getBindableDepthStencilTexture() const { return mBindableDepthStencilTex; }
 
 
-		/**
-		 * @brief	Returns properties that describe the render texture.
-		 */
-		const RenderTextureProperties& getProperties() const;
-
 		/**
 		/**
 		 * @brief	Retrieves a core implementation of a render texture usable only from the
 		 * @brief	Retrieves a core implementation of a render texture usable only from the
 		 *			core thread.
 		 *			core thread.
@@ -156,21 +150,35 @@ namespace BansheeEngine
 		 */
 		 */
 		SPtr<RenderTextureCore> getCore() const;
 		SPtr<RenderTextureCore> getCore() const;
 
 
+		/**
+		 * @brief	Returns properties that describe the render texture.
+		 */
+		const RenderTextureProperties& getProperties() const;
+
 	protected:
 	protected:
 		friend class TextureManager;
 		friend class TextureManager;
 
 
-		RenderTexture() { }
+		RenderTexture(const RENDER_TEXTURE_DESC& desc);
+
+		/**
+		 * @copydoc	RenderTexture::createCore
+		 */
+		virtual SPtr<CoreObjectCore> createCore() const;
+
+		/**
+		 * @copydoc	CoreObjectCore::syncToCore
+		 */
+		virtual CoreSyncData syncToCore(FrameAlloc* allocator);
 
 
 		/**
 		/**
-		 * @copydoc	RenderTarget::initialize
+		 * @copydoc	CoreObjectCore::syncFromCore
 		 */
 		 */
-		virtual void initialize(const RENDER_TEXTURE_DESC& desc);
+		virtual void syncFromCore(const CoreSyncData& data);
 
 
 	protected:
 	protected:
 		HTexture mBindableColorTex;
 		HTexture mBindableColorTex;
 		HTexture mBindableDepthStencilTex;
 		HTexture mBindableDepthStencilTex;
 
 
-		RENDER_SURFACE_DESC mColorSurfaceDesc;
-		RENDER_SURFACE_DESC mDepthStencilSurfaceDesc;
+		RENDER_TEXTURE_DESC mDesc;
 	};
 	};
 }
 }

+ 43 - 48
BansheeCore/Include/BsRenderWindow.h

@@ -57,6 +57,7 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT RenderWindowProperties : public RenderTargetProperties
 	class BS_CORE_EXPORT RenderWindowProperties : public RenderTargetProperties
 	{
 	{
 	public:
 	public:
+		RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
 		virtual ~RenderWindowProperties() { }
 		virtual ~RenderWindowProperties() { }
 
 
 		/**
 		/**
@@ -94,21 +95,6 @@ namespace BansheeEngine
 		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;
@@ -125,9 +111,14 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT RenderWindowCore : public RenderTargetCore
 	class BS_CORE_EXPORT RenderWindowCore : public RenderTargetCore
 	{
 	{
 	public:
 	public:
-		RenderWindowCore(RenderWindow* parent, RenderWindowProperties* properties);
+		RenderWindowCore(const RENDER_WINDOW_DESC& desc);
 		virtual ~RenderWindowCore() { }
 		virtual ~RenderWindowCore() { }
 
 
+		/**
+		 * @copydoc	RenderTargetCore::destroy
+		 */
+		virtual void destroy();
+
 		/** 
 		/** 
 		 * @brief	Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
 		 * @brief	Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
 		 *
 		 *
@@ -136,8 +127,7 @@ namespace BansheeEngine
 		 * @param	refreshRate	Refresh rate of the window in Hertz.
 		 * @param	refreshRate	Refresh rate of the window in Hertz.
 		 * @param	monitorIdx	Index of the monitor to go fullscreen on.
 		 * @param	monitorIdx	Index of the monitor to go fullscreen on.
 		 *
 		 *
-		 * @note	Core thread.
-		 *			If the exact provided mode isn't available, closest one is used instead.
+		 * @note	If the exact provided mode isn't available, closest one is used instead.
 		 */
 		 */
 		virtual void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) { }
 		virtual void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) { }
 
 
@@ -145,8 +135,6 @@ namespace BansheeEngine
 		* @brief	Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
 		* @brief	Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
 		*
 		*
 		* @param	videoMode	Mode retrieved from VideoModeInfo in RenderSystem.
 		* @param	videoMode	Mode retrieved from VideoModeInfo in RenderSystem.
-		*
-		* @note		Core thread.
 		*/
 		*/
 		virtual void setFullscreen(const VideoMode& mode) { }
 		virtual void setFullscreen(const VideoMode& mode) { }
 
 
@@ -155,41 +143,28 @@ namespace BansheeEngine
 		 *
 		 *
 		 * @param	Window width in pixels.
 		 * @param	Window width in pixels.
 		 * @param	Window height in pixels.
 		 * @param	Window height in pixels.
-		 *
-		 * @note	Core thread.
 		 */
 		 */
 		virtual void setWindowed(UINT32 width, UINT32 height) { }
 		virtual void setWindowed(UINT32 width, UINT32 height) { }
 
 
         /**
         /**
          * @brief	Hide or show the window.
          * @brief	Hide or show the window.
-		 *
-		 * @note	Core thread.
          */
          */
         virtual void setHidden(bool hidden);
         virtual void setHidden(bool hidden);
 
 
         /**
         /**
          * @brief	Change the size of the window.
          * @brief	Change the size of the window.
-		 *
-		 * @note	Core thread.
          */
          */
         virtual void resize(UINT32 width, UINT32 height) = 0;
         virtual void resize(UINT32 width, UINT32 height) = 0;
 
 
         /**
         /**
          * @brief	Reposition the window.
          * @brief	Reposition the window.
-		 *
-		 * @note	Core thread.
          */
          */
         virtual void move(INT32 left, INT32 top) = 0;
         virtual void move(INT32 left, INT32 top) = 0;
 
 
 		/**
 		/**
-		 * @brief	Returns properties that describe the render texture.
-		 */
-		const RenderWindowProperties& getProperties() const { return *static_cast<RenderWindowProperties*>(mProperties); }
-
-		/**
-		 * @copydoc	RenderTargetCore::getNonCore
+		 * @brief	Returns properties that describe the render window.
 		 */
 		 */
-		RenderWindow* getNonCore() const;
+		const RenderWindowProperties& getProperties() const;
 
 
 	protected:
 	protected:
 		friend class RenderWindow;
 		friend class RenderWindow;
@@ -215,6 +190,18 @@ namespace BansheeEngine
 		 * @note	Core thread.
 		 * @note	Core thread.
 		 */
 		 */
 		virtual void _windowFocusLost();
 		virtual void _windowFocusLost();
+
+		/**
+		 * @copydoc	CoreObjectCore::syncFromCore
+		 */
+		virtual CoreSyncData syncFromCore(FrameAlloc* allocator);
+
+		/**
+		 * @copydoc	CoreObjectCore::syncToCore
+		 */
+		virtual void syncToCore(const CoreSyncData& data);
+
+		RENDER_WINDOW_DESC mDesc;
 	};
 	};
 
 
 	/**
 	/**
@@ -229,11 +216,6 @@ namespace BansheeEngine
     public:
     public:
 		virtual ~RenderWindow() { }
 		virtual ~RenderWindow() { }
 
 
-		/**
-		 * @copydoc	RenderTarget::initialize
-		 */
-		virtual void initialize(const RENDER_WINDOW_DESC& desc);
-
 		/**
 		/**
 		 * @copydoc	RenderTarget::destroy
 		 * @copydoc	RenderTarget::destroy
 		 */
 		 */
@@ -249,19 +231,17 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual Vector2I windowToScreenPos(const Vector2I& windowPos) const = 0;
 		virtual Vector2I windowToScreenPos(const Vector2I& windowPos) const = 0;
 
 
-		/**
-		 * @brief	Returns properties that describe the render window.
-		 */
-		const RenderWindowProperties& getProperties() const;
-
 		/**
 		/**
 		 * @brief	Retrieves a core implementation of a render window usable only from the
 		 * @brief	Retrieves a core implementation of a render window usable only from the
 		 *			core thread.
 		 *			core thread.
-		 *
-		 * @note	Core thread only.
 		 */
 		 */
 		SPtr<RenderWindowCore> getCore() const;
 		SPtr<RenderWindowCore> getCore() const;
 
 
+		/**
+		 * @brief	Returns properties that describe the render window.
+		 */
+		const RenderWindowProperties& getProperties() const;
+
 		/**
 		/**
 		 * @brief	Creates a new render window using the specified options. Optionally
 		 * @brief	Creates a new render window using the specified options. Optionally
 		 *			makes the created window a child of another window.
 		 *			makes the created window a child of another window.
@@ -271,7 +251,22 @@ namespace BansheeEngine
     protected:
     protected:
 		friend class RenderWindowManager;
 		friend class RenderWindowManager;
 
 
-		RenderWindow() { }
+		RenderWindow(const RENDER_WINDOW_DESC& desc);
+
+		/**
+		 * @copydoc	RenderTarget::createCore
+		 */
+		SPtr<CoreObjectCore> createCore() const;
+
+		/**
+		 * @copydoc	CoreObjectCore::syncToCore
+		 */
+		virtual CoreSyncData syncToCore(FrameAlloc* allocator);
+
+		/**
+		 * @copydoc	CoreObjectCore::syncFromCore
+		 */
+		virtual void syncFromCore(const CoreSyncData& data);
 
 
 	protected:
 	protected:
 		RENDER_WINDOW_DESC mDesc;
 		RENDER_WINDOW_DESC mDesc;

+ 63 - 5
BansheeCore/Include/BsRenderWindowManager.h

@@ -10,7 +10,7 @@ namespace BansheeEngine
 	/**
 	/**
 	 * @brief	Handles creation and internal updates relating to render windows.
 	 * @brief	Handles creation and internal updates relating to render windows.
 	 *
 	 *
-	 * @note	Sim thread.
+	 * @note	Sim thread only.
 	 */
 	 */
 	class BS_CORE_EXPORT RenderWindowManager : public Module<RenderWindowManager>
 	class BS_CORE_EXPORT RenderWindowManager : public Module<RenderWindowManager>
 	{
 	{
@@ -44,13 +44,13 @@ namespace BansheeEngine
 		 * @brief	Event that is triggered when a window loses focus.
 		 * @brief	Event that is triggered when a window loses focus.
 		 */
 		 */
 		Event<void(RenderWindow&)> onFocusLost;
 		Event<void(RenderWindow&)> onFocusLost;
-	protected:
-		friend class RenderWindow;
 
 
 		/**
 		/**
-		 * @copydoc	create
+		 * @brief	Event that is triggered when mouse leaves a window.
 		 */
 		 */
-		virtual RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow) = 0;
+		Event<void(RenderWindow&)> onMouseLeftWindow;
+	protected:
+		friend class RenderWindow;
 
 
 		/**
 		/**
 		 * @brief	Called by the core thread when window is destroyed.
 		 * @brief	Called by the core thread when window is destroyed.
@@ -72,12 +72,70 @@ namespace BansheeEngine
 		 */
 		 */
 		void windowMovedOrResized(RenderWindowCore* window);
 		void windowMovedOrResized(RenderWindowCore* window);
 
 
+		/**
+		 * @brief	Called by the core thread when mouse leaves a window.
+		 */
+		void windowMouseLeft(RenderWindowCore* window);
+
+		/**
+		 * @brief	Finds a sim thread equivalent of the provided core thread window implementation.
+		 */
+		RenderWindow* getNonCore(const RenderWindowCore* window) const;
+
+		/**
+		 * @copydoc	create
+		 */
+		virtual RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, const RenderWindowPtr& parentWindow) = 0;
+
 	protected:
 	protected:
 		BS_MUTEX(mWindowMutex);
 		BS_MUTEX(mWindowMutex);
 		Vector<RenderWindow*> mCreatedWindows;
 		Vector<RenderWindow*> mCreatedWindows;
+		Map<const RenderWindowCore*, RenderWindow*> mCoreToNonCoreMap;
 
 
 		RenderWindow* mWindowInFocus;
 		RenderWindow* mWindowInFocus;
 		RenderWindow* mNewWindowInFocus;
 		RenderWindow* mNewWindowInFocus;
 		Vector<RenderWindow*> mMovedOrResizedWindows;
 		Vector<RenderWindow*> mMovedOrResizedWindows;
+		Vector<RenderWindow*> mMouseLeftWindows;
+	};
+
+	/**
+	 * @brief	Handles creation and internal updates relating to render windows.
+	 *
+	 * @note	Core thread only.
+	 */
+	class BS_CORE_EXPORT RenderWindowCoreManager : public Module<RenderWindowCoreManager>
+	{
+	public:
+		/**
+		 * @copydoc	RenderWindowCoreManager::create
+		 */
+		SPtr<RenderWindowCore> create(RENDER_WINDOW_DESC& desc);
+
+		/**
+		 * @brief	Returns a list of all open render windows.
+		 */
+		Vector<RenderWindowCore*> getRenderWindows() const;
+
+	protected:
+		friend class RenderWindowCore;
+		friend class RenderWindow;
+
+		/**
+		 * @copydoc	create
+		 */
+		virtual SPtr<RenderWindowCore> createInternal(RENDER_WINDOW_DESC& desc) = 0;
+
+		/**
+		 * @brief	Called whenever a window is created.
+		 */
+		void windowCreated(RenderWindowCore* window);
+
+		/**
+		 * @brief	Called by the core thread when window is destroyed.
+		 */
+		void windowDestroyed(RenderWindowCore* window);
+
+		BS_MUTEX(mWindowMutex);
+		Vector<RenderWindowCore*> mCreatedWindows;
 	};
 	};
 }
 }

+ 45 - 10
BansheeCore/Include/BsTextureManager.h

@@ -12,13 +12,12 @@ namespace BansheeEngine
      * @brief	Defines interface for creation of textures. Render systems
      * @brief	Defines interface for creation of textures. Render systems
 	 *			provide their own implementations.
 	 *			provide their own implementations.
 	 *
 	 *
-	 * @note	Thread safe.
+	 * @note	Sim thread only.
      */
      */
     class BS_CORE_EXPORT TextureManager : public Module<TextureManager>
     class BS_CORE_EXPORT TextureManager : public Module<TextureManager>
     {
     {
     public:
     public:
-        TextureManager();
-        virtual ~TextureManager();
+		virtual ~TextureManager() { }
 
 
 		/**
 		/**
 		 * @copydoc	Texture::create(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32, const String&)
 		 * @copydoc	Texture::create(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32, const String&)
@@ -84,11 +83,6 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) = 0;
 		virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) = 0;
 
 
-		/**
-		 * @brief	Returns tiny dummy texture for use when no other is available.
-		 */
-		const HTexture& getDummyTexture() const { return mDummyTexture; }
-
 	protected:
 	protected:
 		/**
 		/**
 		 * @brief	Creates an empty and uninitialized texture of a specific type. This is to be implemented
 		 * @brief	Creates an empty and uninitialized texture of a specific type. This is to be implemented
@@ -100,13 +94,54 @@ namespace BansheeEngine
 		 * @brief	Creates an empty and uninitialized render texture of a specific type. This 
 		 * @brief	Creates an empty and uninitialized render texture of a specific type. This 
 		 *			is to be implemented by render systems with their own implementations.
 		 *			is to be implemented by render systems with their own implementations.
 		 */
 		 */
-		virtual RenderTexturePtr createRenderTextureImpl() = 0;
+		virtual RenderTexturePtr createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc) = 0;
 
 
 		/**
 		/**
 		 * @brief	Creates an empty and uninitialized multi render texture of a specific type. This is 
 		 * @brief	Creates an empty and uninitialized multi render texture of a specific type. This is 
 		 *			to be implemented by render systems with their own implementations.
 		 *			to be implemented by render systems with their own implementations.
 		 */
 		 */
-		virtual MultiRenderTexturePtr createMultiRenderTextureImpl() = 0;
+		virtual MultiRenderTexturePtr createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc) = 0;
+    };
+
+/**
+     * @brief	Defines interface for creation of textures. Render systems
+	 *			provide their own implementations.
+	 *
+	 * @note	Core thread only.
+     */
+    class BS_CORE_EXPORT TextureCoreManager : public Module<TextureCoreManager>
+    {
+    public:
+		virtual ~TextureCoreManager() { }
+
+		/**
+		 * @copydoc	TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC&)
+		 */
+		SPtr<RenderTextureCore> createRenderTexture(const RENDER_TEXTURE_DESC& desc);
+
+		/**
+		 * @copydoc	TextureManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC&)
+		 */
+		SPtr<MultiRenderTextureCore> createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
+
+		/**
+		 * @brief	Returns tiny dummy texture for use when no other is available.
+		 */
+		const HTexture& getDummyTexture() const { return mDummyTexture; }
+
+	protected:
+		friend class RenderTexture;
+		friend class MultiRenderTexture;
+
+		/**
+		 * @copydoc	TextureManager::createRenderTextureImpl
+		 */
+		virtual SPtr<RenderTextureCore> createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc) = 0;
+
+		/**
+		 * @copydoc	TextureManager::createMultiRenderTextureImpl
+		 */
+		virtual SPtr<MultiRenderTextureCore> createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_DESC& desc) = 0;
 
 
 		/**
 		/**
 		 * @copydoc	Module::onStartUp
 		 * @copydoc	Module::onStartUp

+ 2 - 2
BansheeCore/Include/BsTransientMesh.h

@@ -33,12 +33,12 @@ namespace BansheeEngine
 		 /**
 		 /**
 		 * @copydoc MeshBase::getVertexData
 		 * @copydoc MeshBase::getVertexData
 		 */
 		 */
-		SPtr<VertexData> _getVertexData() const;
+		SPtr<VertexData> getVertexData() const;
 
 
 		 /**
 		 /**
 		 * @copydoc MeshBase::getIndexData
 		 * @copydoc MeshBase::getIndexData
 		 */
 		 */
-		SPtr<IndexBufferCore> _getIndexBuffer() const;
+		SPtr<IndexBufferCore> getIndexBuffer() const;
 
 
 		/**
 		/**
 		 * @brief	Returns the ID that uniquely identifies this mesh in the parent heap.
 		 * @brief	Returns the ID that uniquely identifies this mesh in the parent heap.

+ 4 - 5
BansheeCore/Include/Win32/BsPlatformImpl.h

@@ -152,7 +152,7 @@ namespace BansheeEngine
 		 * 			All provided areas are relative to the specified window.
 		 * 			All provided areas are relative to the specified window.
 		 * 			Mostly useful for frameless windows that don't have typical caption bar.
 		 * 			Mostly useful for frameless windows that don't have typical caption bar.
 		 */
 		 */
-		static void setCaptionNonClientAreas(const RenderWindow& window, const Vector<Rect2I>& nonClientAreas);
+		static void setCaptionNonClientAreas(const RenderWindowCore& window, const Vector<Rect2I>& nonClientAreas);
 
 
 		/**
 		/**
 		 * @brief	Sets custom non client areas for the specified window. Using custom client
 		 * @brief	Sets custom non client areas for the specified window. Using custom client
@@ -163,7 +163,7 @@ namespace BansheeEngine
 		 * 			All provided areas are relative to the specified window.
 		 * 			All provided areas are relative to the specified window.
 		 * 			Mostly useful for frameless windows that don't have typical border.
 		 * 			Mostly useful for frameless windows that don't have typical border.
 		 */
 		 */
-		static void setResizeNonClientAreas(const RenderWindow& window, const Vector<NonClientResizeArea>& nonClientAreas);
+		static void setResizeNonClientAreas(const RenderWindowCore& window, const Vector<NonClientResizeArea>& nonClientAreas);
 
 
 		/**
 		/**
 		 * @brief	Resets the non client areas for the specified windows and allows 
 		 * @brief	Resets the non client areas for the specified windows and allows 
@@ -171,7 +171,7 @@ namespace BansheeEngine
 		 * 			
 		 * 			
 		 * @note	Thread safe.
 		 * @note	Thread safe.
 		 */
 		 */
-		static void resetNonClientAreas(const RenderWindow& window);
+		static void resetNonClientAreas(const RenderWindowCore& window);
 
 
 		/**
 		/**
 		 * @brief	Adds a string to the clipboard.
 		 * @brief	Adds a string to the clipboard.
@@ -270,7 +270,7 @@ namespace BansheeEngine
 		 * 			
 		 * 			
 		 * @note	Sim thread only.
 		 * @note	Sim thread only.
 		 */
 		 */
-		static Event<void(RenderWindow*)> onMouseLeftWindow;
+		static Event<void(RenderWindowCore*)> onMouseLeftWindow;
 
 
 		/**
 		/**
 		 * @brief	Triggered whenever the pointer moves.
 		 * @brief	Triggered whenever the pointer moves.
@@ -356,7 +356,6 @@ namespace BansheeEngine
 		static Map<const RenderWindowCore*, WindowNonClientAreaData> mNonClientAreas;
 		static Map<const RenderWindowCore*, WindowNonClientAreaData> mNonClientAreas;
 
 
 		static bool mIsTrackingMouse;
 		static bool mIsTrackingMouse;
-		static Vector<RenderWindowCore*> mMouseLeftWindows;
 		static Stack<RenderWindowCore*> mModalWindowStack;
 		static Stack<RenderWindowCore*> mModalWindowStack;
 
 
 		static NativeDropTargetData mDropTargets;
 		static NativeDropTargetData mDropTargets;

+ 3 - 3
BansheeCore/Source/BsCoreThreadAccessor.cpp

@@ -88,7 +88,7 @@ namespace BansheeEngine
 		mCommandQueue->queue(std::bind(&RenderSystem::setVertexDeclaration, RenderSystem::instancePtr(), vertexDeclaration));
 		mCommandQueue->queue(std::bind(&RenderSystem::setVertexDeclaration, RenderSystem::instancePtr(), vertexDeclaration));
 	}
 	}
 
 
-	void CoreThreadAccessorBase::setViewport(Viewport vp)
+	void CoreThreadAccessorBase::setViewport(const Rect2& vp)
 	{
 	{
 		mCommandQueue->queue(std::bind(&RenderSystem::setViewport, RenderSystem::instancePtr(), vp));
 		mCommandQueue->queue(std::bind(&RenderSystem::setViewport, RenderSystem::instancePtr(), vp));
 	}
 	}
@@ -120,7 +120,7 @@ namespace BansheeEngine
 
 
 	void CoreThreadAccessorBase::setRenderTarget(RenderTargetPtr target)
 	void CoreThreadAccessorBase::setRenderTarget(RenderTargetPtr target)
 	{
 	{
-		mCommandQueue->queue(std::bind(&RenderSystem::setRenderTarget, RenderSystem::instancePtr(), target));
+		mCommandQueue->queue(std::bind(&RenderSystem::setRenderTarget, RenderSystem::instancePtr(), target->getCore()));
 	}
 	}
 
 
 	void CoreThreadAccessorBase::bindGpuProgram(HGpuProgram prg)
 	void CoreThreadAccessorBase::bindGpuProgram(HGpuProgram prg)
@@ -160,7 +160,7 @@ namespace BansheeEngine
 
 
 	void CoreThreadAccessorBase::swapBuffers(RenderTargetPtr target)
 	void CoreThreadAccessorBase::swapBuffers(RenderTargetPtr target)
 	{
 	{
-		mCommandQueue->queue(std::bind(&RenderSystem::swapBuffers, RenderSystem::instancePtr(), target));
+		mCommandQueue->queue(std::bind(&RenderSystem::swapBuffers, RenderSystem::instancePtr(), target->getCore()));
 	}
 	}
 
 
 	void CoreThreadAccessorBase::draw(UINT32 vertexOffset, UINT32 vertexCount)
 	void CoreThreadAccessorBase::draw(UINT32 vertexOffset, UINT32 vertexCount)

+ 2 - 2
BansheeCore/Source/BsHardwareBufferManager.cpp

@@ -70,7 +70,7 @@ namespace BansheeEngine
 	{
 	{
 		assert(numIndexes > 0);
 		assert(numIndexes > 0);
 
 
-		SPtr<IndexBufferCore> ibuf = createIndexBufferImpl(itype, numIndexes, usage);
+		SPtr<IndexBufferCore> ibuf = createIndexBufferInternal(itype, numIndexes, usage);
 		ibuf->initialize();
 		ibuf->initialize();
 		return ibuf;
 		return ibuf;
 
 
@@ -80,7 +80,7 @@ namespace BansheeEngine
 	{
 	{
 		assert(numVerts > 0);
 		assert(numVerts > 0);
 
 
-		SPtr<VertexBufferCore> vbuf = createVertexBufferImpl(vertexSize, numVerts, usage, streamOut);
+		SPtr<VertexBufferCore> vbuf = createVertexBufferInternal(vertexSize, numVerts, usage, streamOut);
 		vbuf->initialize();
 		vbuf->initialize();
 		return vbuf;
 		return vbuf;
 	}
 	}

+ 1 - 1
BansheeCore/Source/BsIndexBuffer.cpp

@@ -37,7 +37,7 @@ namespace BansheeEngine
 
 
 	SPtr<CoreObjectCore> IndexBuffer::createCore() const
 	SPtr<CoreObjectCore> IndexBuffer::createCore() const
 	{
 	{
-		return HardwareBufferCoreManager::instance().createIndexBuffer(mProperties.mIndexType, mProperties.mNumIndexes, mUsage);
+		return HardwareBufferCoreManager::instance().createIndexBufferInternal(mProperties.mIndexType, mProperties.mNumIndexes, mUsage);
 	}
 	}
 
 
 	IndexBufferPtr IndexBuffer::create(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
 	IndexBufferPtr IndexBuffer::create(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)

+ 67 - 44
BansheeCore/Source/BsMultiRenderTexture.cpp

@@ -4,26 +4,34 @@
 #include "BsDebug.h"
 #include "BsDebug.h"
 #include "BsCoreThread.h"
 #include "BsCoreThread.h"
 #include "BsTextureManager.h"
 #include "BsTextureManager.h"
+#include "BsFrameAlloc.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	void MultiRenderTextureProperties::copyToBuffer(UINT8* buffer) const
+	MultiRenderTextureProperties::MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_DESC& desc)
 	{
 	{
-		*(MultiRenderTextureProperties*)buffer = *this;
-	}
+		for (size_t i = 0; i < desc.colorSurfaces.size(); i++)
+		{
+			TexturePtr texture = desc.colorSurfaces[i].texture;
 
 
-	void MultiRenderTextureProperties::copyFromBuffer(UINT8* buffer)
-	{
-		*this = *(MultiRenderTextureProperties*)buffer;
-	}
+			if (texture != nullptr)
+			{
+				mWidth = texture->getWidth();
+				mHeight = texture->getWidth();
+				mColorDepth = BansheeEngine::PixelUtil::getNumElemBits(texture->getFormat());
+				mActive = true;
+				mHwGamma = texture->isHardwareGammaEnabled();
+				mMultisampleCount = texture->getMultisampleCount();
+				mIsWindow = false;
+				mRequiresTextureFlipping = requiresTextureFlipping();
 
 
-	UINT32 MultiRenderTextureProperties::getSize() const
-	{
-		return sizeof(MultiRenderTextureProperties);
+				break;
+			}
+		}
 	}
 	}
 
 
-	MultiRenderTextureCore::MultiRenderTextureCore(MultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
-		:RenderTargetCore(parent, properties), mDesc(desc)
+	MultiRenderTextureCore::MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_DESC& desc)
+		:mDesc(desc)
 	{ }
 	{ }
 
 
 	MultiRenderTextureCore::~MultiRenderTextureCore()
 	MultiRenderTextureCore::~MultiRenderTextureCore()
@@ -85,6 +93,28 @@ namespace BansheeEngine
 		RenderTargetCore::destroy();
 		RenderTargetCore::destroy();
 	}
 	}
 
 
+	CoreSyncData MultiRenderTextureCore::syncFromCore(FrameAlloc* allocator)
+	{
+		UINT32 size = sizeof(MultiRenderTextureProperties);
+		UINT8* buffer = allocator->alloc(size);
+
+		MultiRenderTextureProperties& props = const_cast<MultiRenderTextureProperties&>(getProperties());
+
+		memcpy(buffer, &props, size);
+		return CoreSyncData(buffer, size);
+	}
+
+	void MultiRenderTextureCore::syncToCore(const CoreSyncData& data)
+	{
+		MultiRenderTextureProperties& props = const_cast<MultiRenderTextureProperties&>(getProperties());
+		props = data.getData<MultiRenderTextureProperties>();
+	}
+
+	const MultiRenderTextureProperties& MultiRenderTextureCore::getProperties() const
+	{
+		return static_cast<const MultiRenderTextureProperties&>(getPropertiesInternal());
+	}
+
 	void MultiRenderTextureCore::throwIfBuffersDontMatch() const
 	void MultiRenderTextureCore::throwIfBuffersDontMatch() const
 	{
 	{
 		TextureViewPtr firstSurfaceDesc = nullptr;
 		TextureViewPtr firstSurfaceDesc = nullptr;
@@ -149,53 +179,46 @@ namespace BansheeEngine
 		throw std::exception("The method or operation is not implemented.");
 		throw std::exception("The method or operation is not implemented.");
 	}
 	}
 
 
-	MultiRenderTexture* MultiRenderTextureCore::getNonCore() const
+	MultiRenderTexture::MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
+		:mDesc(desc)
 	{
 	{
-		return static_cast<MultiRenderTexture*>(mParent);
+
 	}
 	}
 
 
-	void MultiRenderTexture::initialize(const MULTI_RENDER_TEXTURE_DESC& desc)
+	SPtr<CoreObjectCore> MultiRenderTexture::createCore() const
 	{
 	{
-		mDesc = desc;
-
-		mProperties = createProperties();
-		MultiRenderTextureProperties* properties = static_cast<MultiRenderTextureProperties*>(mProperties);
-		for (size_t i = 0; i < desc.colorSurfaces.size(); i++)
-		{
-			TexturePtr texture = desc.colorSurfaces[i].texture;
-
-			if (texture != nullptr)
-			{
-				properties->mWidth = texture->getWidth();
-				properties->mHeight = texture->getWidth();
-				properties->mColorDepth = BansheeEngine::PixelUtil::getNumElemBits(texture->getFormat());
-				properties->mActive = true;
-				properties->mHwGamma = texture->isHardwareGammaEnabled();
-				properties->mMultisampleCount = texture->getMultisampleCount();
-				properties->mIsWindow = false;
-				properties->mRequiresTextureFlipping = requiresTextureFlipping();
+		return TextureCoreManager::instance().createMultiRenderTextureInternal(mDesc);
+	}
 
 
-				break;
-			}
-		}
+	SPtr<MultiRenderTextureCore> MultiRenderTexture::getCore() const
+	{
+		return std::static_pointer_cast<MultiRenderTextureCore>(mCoreSpecific);
+	}
 
 
-		RenderTarget::initialize();
+	MultiRenderTexturePtr MultiRenderTexture::create(const MULTI_RENDER_TEXTURE_DESC& desc)
+	{
+		return TextureManager::instance().createMultiRenderTexture(desc);
 	}
 	}
 
 
-	const MultiRenderTextureProperties& MultiRenderTexture::getProperties() const
+	CoreSyncData MultiRenderTexture::syncToCore(FrameAlloc* allocator)
 	{
 	{
-		THROW_IF_CORE_THREAD;
+		UINT32 size = sizeof(MultiRenderTextureProperties);
+		UINT8* buffer = allocator->alloc(size);
 
 
-		return static_cast<const MultiRenderTextureProperties&>(RenderTarget::getProperties());
+		MultiRenderTextureProperties& props = const_cast<MultiRenderTextureProperties&>(getProperties());
+
+		memcpy(buffer, &props, size);
+		return CoreSyncData(buffer, size);
 	}
 	}
 
 
-	SPtr<MultiRenderTextureCore> MultiRenderTexture::getCore() const
+	void MultiRenderTexture::syncFromCore(const CoreSyncData& data)
 	{
 	{
-		return std::static_pointer_cast<MultiRenderTextureCore>(mCoreSpecific);
+		MultiRenderTextureProperties& props = const_cast<MultiRenderTextureProperties&>(getProperties());
+		props = data.getData<MultiRenderTextureProperties>();
 	}
 	}
 
 
-	MultiRenderTexturePtr MultiRenderTexture::create(const MULTI_RENDER_TEXTURE_DESC& desc)
+	const MultiRenderTextureProperties& MultiRenderTexture::getProperties() const
 	{
 	{
-		return TextureManager::instance().createMultiRenderTexture(desc);
+		return static_cast<const MultiRenderTextureProperties&>(getPropertiesInternal());
 	}
 	}
 }
 }

+ 3 - 6
BansheeCore/Source/BsRenderSystem.cpp

@@ -205,16 +205,13 @@ namespace BansheeEngine
         return false;
         return false;
 	}
 	}
 
 
-	void RenderSystem::swapBuffers(RenderTargetPtr target)
+	void RenderSystem::swapBuffers(const SPtr<RenderTargetCore>& target)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		if (target->isInitialized())
-		{
-			target->getCore()->swapBuffers();
+		target->swapBuffers();
 
 
-			BS_INC_RENDER_STAT(NumPresents);
-		}
+		BS_INC_RENDER_STAT(NumPresents);
 	}
 	}
 
 
 	void RenderSystem::writeSubresource(GpuResourcePtr resource, UINT32 subresourceIdx, const GpuResourceDataPtr& data, bool discardEntireBuffer, AsyncOp& asyncOp)
 	void RenderSystem::writeSubresource(GpuResourcePtr resource, UINT32 subresourceIdx, const GpuResourceDataPtr& data, bool discardEntireBuffer, AsyncOp& asyncOp)

+ 16 - 62
BansheeCore/Source/BsRenderTarget.cpp

@@ -7,45 +7,30 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	void RenderTargetProperties::copyToBuffer(UINT8* buffer) const
+	RenderTargetCore::RenderTargetCore()
 	{
 	{
-		*(RenderTargetProperties*)buffer = *this;
-	}
 
 
-	void RenderTargetProperties::copyFromBuffer(UINT8* buffer)
-	{
-		*this = *(RenderTargetProperties*)buffer;
 	}
 	}
 
 
-	UINT32 RenderTargetProperties::getSize() const
-	{
-		return sizeof(RenderTargetProperties);
-	}
-
-	RenderTargetCore::RenderTargetCore(RenderTarget* parent, RenderTargetProperties* properties)
-		:mProperties(properties), mParent(parent)
-	{
+	void RenderTargetCore::setActive(bool state)
+	{ 
+		RenderTargetProperties& props = const_cast<RenderTargetProperties&>(getProperties());
 
 
+		props.mActive = state;
+		markCoreDirty();
 	}
 	}
 
 
-	RenderTargetCore::~RenderTargetCore()
-	{
-		bs_delete(mProperties);
-	}
+	void RenderTargetCore::setPriority(INT32 priority) 
+	{ 
+		RenderTargetProperties& props = const_cast<RenderTargetProperties&>(getProperties());
 
 
-	CoreSyncData RenderTargetCore::syncFromCore(FrameAlloc* allocator)
-	{
-		UINT8* buffer = allocator->alloc(mProperties->getSize());
-		mProperties->copyToBuffer(buffer);
-
-		return CoreSyncData(buffer, mProperties->getSize());
+		props.mPriority = priority;
+		markCoreDirty();
 	}
 	}
 
 
-	void RenderTargetCore::syncToCore(const CoreSyncData& data)
-	{
-		assert(data.getBufferSize() == mProperties->getSize());
-
-		mProperties->copyFromBuffer(data.getBuffer());
+	const RenderTargetProperties& RenderTargetCore::getProperties() const
+	{ 
+		return getPropertiesInternal(); 
 	}
 	}
 
 
 	void RenderTargetCore::getCustomAttribute(const String& name, void* pData) const
 	void RenderTargetCore::getCustomAttribute(const String& name, void* pData) const
@@ -53,52 +38,21 @@ namespace BansheeEngine
 		BS_EXCEPT(InvalidParametersException, "Attribute not found.");
 		BS_EXCEPT(InvalidParametersException, "Attribute not found.");
 	}
 	}
 
 
-	const RenderTargetProperties& RenderTargetCore::getProperties() const
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		return *mProperties;
-	}
-
 	SPtr<RenderTargetCore> RenderTarget::getCore() const
 	SPtr<RenderTargetCore> RenderTarget::getCore() const
 	{
 	{
 		return std::static_pointer_cast<RenderTargetCore>(mCoreSpecific);
 		return std::static_pointer_cast<RenderTargetCore>(mCoreSpecific);
 	}
 	}
 
 
-	RenderTarget::RenderTarget()
-		:mProperties(nullptr)
-	{
-	}
-
-	RenderTarget::~RenderTarget()
-	{
-		bs_delete(mProperties);
-	}
-
 	const RenderTargetProperties& RenderTarget::getProperties() const
 	const RenderTargetProperties& RenderTarget::getProperties() const
 	{
 	{
 		THROW_IF_CORE_THREAD;
 		THROW_IF_CORE_THREAD;
 
 
-		return *mProperties;
-	}
-
-	CoreSyncData RenderTarget::syncToCore(FrameAlloc* allocator)
-	{
-		UINT8* buffer = allocator->alloc(mProperties->getSize());
-		mProperties->copyToBuffer(buffer);
-
-		return CoreSyncData(buffer, mProperties->getSize());
-	}
-
-	void RenderTarget::syncFromCore(const CoreSyncData& data)
-	{
-		assert(data.getBufferSize() == mProperties->getSize());
-
-		mProperties->copyFromBuffer(data.getBuffer());
+		return getPropertiesInternal();
 	}
 	}
 
 
 	void RenderTarget::getCustomAttribute(const String& name, void* pData) const
 	void RenderTarget::getCustomAttribute(const String& name, void* pData) const
 	{
 	{
 		BS_EXCEPT(InvalidParametersException, "Attribute not found.");
 		BS_EXCEPT(InvalidParametersException, "Attribute not found.");
 	}
 	}
+
 }        
 }        

+ 76 - 55
BansheeCore/Source/BsRenderTexture.cpp

@@ -5,28 +5,30 @@
 #include "BsTextureManager.h"
 #include "BsTextureManager.h"
 #include "BsResources.h"
 #include "BsResources.h"
 #include "BsCoreThread.h"
 #include "BsCoreThread.h"
+#include "BsFrameAlloc.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	void RenderTextureProperties::copyToBuffer(UINT8* buffer) const
+	RenderTextureProperties::RenderTextureProperties(const RENDER_TEXTURE_DESC& desc, bool requiresFlipping)
 	{
 	{
-		*(RenderTextureProperties*)buffer = *this;
-	}
+		TexturePtr texture = desc.colorSurface.texture;
 
 
-	void RenderTextureProperties::copyFromBuffer(UINT8* buffer)
-	{
-		*this = *(RenderTextureProperties*)buffer;
-	}
+		if (texture != nullptr)
+		{
+			mWidth = texture->getWidth();
+			mHeight = texture->getHeight();
+			mColorDepth = BansheeEngine::PixelUtil::getNumElemBits(texture->getFormat());
+			mHwGamma = texture->isHardwareGammaEnabled();
+			mMultisampleCount = texture->getMultisampleCount();
+		}
 
 
-	UINT32 RenderTextureProperties::getSize() const
-	{
-		return sizeof(RenderTextureProperties);
+		mActive = true;
+		mIsWindow = false;
+		mRequiresTextureFlipping = requiresFlipping;
 	}
 	}
 
 
-	RenderTextureCore::RenderTextureCore(RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
-		:RenderTargetCore(parent, properties), mColorSurface(nullptr), mDepthStencilSurface(nullptr), 
-		mColorSurfaceDesc(colorSurfaceDesc), mDepthStencilSurfaceDesc(depthStencilSurfaceDesc)
+	RenderTextureCore::RenderTextureCore(const RENDER_TEXTURE_DESC& desc)
+		:mColorSurface(nullptr), mDepthStencilSurface(nullptr), mDesc(desc)
 	{ }
 	{ }
 
 
 	RenderTextureCore::~RenderTextureCore()
 	RenderTextureCore::~RenderTextureCore()
@@ -36,26 +38,28 @@ namespace BansheeEngine
 	{
 	{
 		RenderTargetCore::initialize();
 		RenderTargetCore::initialize();
 
 
-		if (mColorSurfaceDesc.texture != nullptr)
+		const RENDER_SURFACE_DESC& colorSurface = mDesc.colorSurface;
+		if (colorSurface.texture != nullptr)
 		{
 		{
-			TexturePtr texture = mColorSurfaceDesc.texture;
+			TexturePtr texture = colorSurface.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, mColorSurfaceDesc.mipLevel, 1,
-				mColorSurfaceDesc.face, 1, GVU_RENDERTARGET);
+			mColorSurface = Texture::requestView(texture, colorSurface.mipLevel, 1,
+				colorSurface.face, 1, GVU_RENDERTARGET);
 		}
 		}
 
 
-		if (mDepthStencilSurfaceDesc.texture != nullptr)
+		const RENDER_SURFACE_DESC& depthStencilSurface = mDesc.depthStencilSurface;
+		if (depthStencilSurface.texture != nullptr)
 		{
 		{
-			TexturePtr texture = mDepthStencilSurfaceDesc.texture;
+			TexturePtr texture = 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, mDepthStencilSurfaceDesc.mipLevel, 1,
-				mDepthStencilSurfaceDesc.face, 1, GVU_DEPTHSTENCIL);
+			mDepthStencilSurface = Texture::requestView(texture, depthStencilSurface.mipLevel, 1,
+				depthStencilSurface.face, 1, GVU_DEPTHSTENCIL);
 		}
 		}
 
 
 		throwIfBuffersDontMatch();
 		throwIfBuffersDontMatch();
@@ -91,6 +95,28 @@ namespace BansheeEngine
 		RenderTargetCore::destroy();
 		RenderTargetCore::destroy();
 	}
 	}
 
 
+	CoreSyncData RenderTextureCore::syncFromCore(FrameAlloc* allocator)
+	{
+		UINT32 size = sizeof(RenderTextureProperties);
+		UINT8* buffer = allocator->alloc(size);
+
+		RenderTextureProperties& props = const_cast<RenderTextureProperties&>(getProperties());
+
+		memcpy(buffer, &props, size);
+		return CoreSyncData(buffer, size);
+	}
+
+	void RenderTextureCore::syncToCore(const CoreSyncData& data)
+	{
+		RenderTextureProperties& props = const_cast<RenderTextureProperties&>(getProperties());
+		props = data.getData<RenderTextureProperties>();
+	}
+
+	const RenderTextureProperties& RenderTextureCore::getProperties() const
+	{
+		return static_cast<const RenderTextureProperties&>(getPropertiesInternal());
+	}
+
 	void RenderTextureCore::throwIfBuffersDontMatch() const
 	void RenderTextureCore::throwIfBuffersDontMatch() const
 	{
 	{
 		if (mColorSurface == nullptr || mDepthStencilSurface == nullptr)
 		if (mColorSurface == nullptr || mDepthStencilSurface == nullptr)
@@ -108,11 +134,6 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	RenderTexture* RenderTextureCore::getNonCore() const
-	{
-		return static_cast<RenderTexture*>(mParent);
-	}
-
 	RenderTexturePtr RenderTexture::create(TextureType textureType, UINT32 width, UINT32 height, 
 	RenderTexturePtr RenderTexture::create(TextureType textureType, UINT32 width, UINT32 height, 
 		PixelFormat format, bool hwGamma, UINT32 multisampleCount, 
 		PixelFormat format, bool hwGamma, UINT32 multisampleCount, 
 		bool createDepth, PixelFormat depthStencilFormat)
 		bool createDepth, PixelFormat depthStencilFormat)
@@ -126,39 +147,14 @@ namespace BansheeEngine
 		return TextureManager::instance().createRenderTexture(desc);
 		return TextureManager::instance().createRenderTexture(desc);
 	}
 	}
 
 
-	const RenderTextureProperties& RenderTexture::getProperties() const 
-	{ 
-		THROW_IF_CORE_THREAD;
-
-		return static_cast<const RenderTextureProperties&>(RenderTarget::getProperties()); 
-	}
-
 	SPtr<RenderTextureCore> RenderTexture::getCore() const 
 	SPtr<RenderTextureCore> RenderTexture::getCore() const 
 	{ 
 	{ 
 		return std::static_pointer_cast<RenderTextureCore>(mCoreSpecific); 
 		return std::static_pointer_cast<RenderTextureCore>(mCoreSpecific); 
 	}
 	}
 
 
-	void RenderTexture::initialize(const RENDER_TEXTURE_DESC& desc)
+	RenderTexture::RenderTexture(const RENDER_TEXTURE_DESC& desc)
 	{
 	{
-		mColorSurfaceDesc = desc.colorSurface;
-		mDepthStencilSurfaceDesc = desc.depthStencilSurface;
-
-		TexturePtr texture = desc.colorSurface.texture;
-
-		mProperties = createProperties();
-		RenderTextureProperties* properties = static_cast<RenderTextureProperties*>(mProperties);
-		if (texture != nullptr)
-		{
-			properties->mWidth = texture->getWidth();
-			properties->mHeight = texture->getHeight();
-			properties->mColorDepth = BansheeEngine::PixelUtil::getNumElemBits(texture->getFormat());
-			properties->mHwGamma = texture->isHardwareGammaEnabled();
-			properties->mMultisampleCount = texture->getMultisampleCount();
-		}
-
-		properties->mActive = true;
-		properties->mIsWindow = false;
-		properties->mRequiresTextureFlipping = requiresTextureFlipping();
+		mDesc = desc;
 
 
 		// Create non-persistent resource handles for the used textures (we only need them because a lot of the code accepts only handles,
 		// Create non-persistent resource handles for the used textures (we only need them because a lot of the code accepts only handles,
 		// since they're non persistent they don't really have any benefit over shared pointers)
 		// since they're non persistent they don't really have any benefit over shared pointers)
@@ -167,7 +163,32 @@ namespace BansheeEngine
 
 
 		if (desc.depthStencilSurface.texture != nullptr)
 		if (desc.depthStencilSurface.texture != nullptr)
 			mBindableDepthStencilTex = static_resource_cast<Texture>(gResources()._createResourceHandle(desc.depthStencilSurface.texture));
 			mBindableDepthStencilTex = static_resource_cast<Texture>(gResources()._createResourceHandle(desc.depthStencilSurface.texture));
+	}
 
 
-		RenderTarget::initialize();
+	SPtr<CoreObjectCore> RenderTexture::createCore() const
+	{
+		return TextureCoreManager::instance().createRenderTextureInternal(mDesc);
+	}
+
+	CoreSyncData RenderTexture::syncToCore(FrameAlloc* allocator)
+	{
+		UINT32 size = sizeof(RenderTextureProperties);
+		UINT8* buffer = allocator->alloc(size);
+
+		RenderTextureProperties& props = const_cast<RenderTextureProperties&>(getProperties());
+
+		memcpy(buffer, &props, size);
+		return CoreSyncData(buffer, size);
+	}
+
+	void RenderTexture::syncFromCore(const CoreSyncData& data)
+	{
+		RenderTextureProperties& props = const_cast<RenderTextureProperties&>(getProperties());
+		props = data.getData<RenderTextureProperties>();
+	}
+
+	const RenderTextureProperties& RenderTexture::getProperties() const
+	{
+		return static_cast<const RenderTextureProperties&>(getPropertiesInternal());
 	}
 	}
 }
 }

+ 75 - 45
BansheeCore/Source/BsRenderWindow.cpp

@@ -3,28 +3,40 @@
 #include "BsRenderWindowManager.h"
 #include "BsRenderWindowManager.h"
 #include "BsViewport.h"
 #include "BsViewport.h"
 #include "BsPlatform.h"
 #include "BsPlatform.h"
+#include "BsFrameAlloc.h"
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
-	void RenderWindowProperties::copyToBuffer(UINT8* buffer) const
+	RenderWindowProperties::RenderWindowProperties(const RENDER_WINDOW_DESC& desc)
 	{
 	{
-		*(RenderWindowProperties*)buffer = *this;
+		mWidth = desc.videoMode.getWidth();
+		mHeight = desc.videoMode.getHeight();
+		mHwGamma = desc.gamma;
+		mVSync = desc.vsync;
+		mVSyncInterval = desc.vsyncInterval;
+		mMultisampleCount = desc.multisampleCount;
+		mLeft = desc.left;
+		mTop = desc.top;
+		mIsFullScreen = desc.fullscreen;
+		mHidden = desc.hidden;
+		mIsModal = desc.modal;
+		mIsWindow = true;
+		mRequiresTextureFlipping = false;
 	}
 	}
 
 
-	void RenderWindowProperties::copyFromBuffer(UINT8* buffer)
+	RenderWindowCore::RenderWindowCore(const RENDER_WINDOW_DESC& desc)
+		:mDesc(desc)
 	{
 	{
-		*this = *(RenderWindowProperties*)buffer;
-	}
 
 
-	UINT32 RenderWindowProperties::getSize() const
-	{
-		return sizeof(RenderWindowProperties);
 	}
 	}
 
 
-	RenderWindowCore::RenderWindowCore(RenderWindow* parent, RenderWindowProperties* properties)
-		:RenderTargetCore(parent, properties)
+	void RenderWindowCore::destroy()
 	{
 	{
+		Platform::resetNonClientAreas(*this);
 
 
+		RenderWindowCoreManager::instance().windowDestroyed(this);
+
+		RenderTargetCore::destroy();
 	}
 	}
 
 
 	void RenderWindowCore::setHidden(bool hidden)
 	void RenderWindowCore::setHidden(bool hidden)
@@ -32,6 +44,23 @@ namespace BansheeEngine
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 	}
 	}
 
 
+	CoreSyncData RenderWindowCore::syncFromCore(FrameAlloc* allocator)
+	{
+		UINT32 size = sizeof(RenderWindowProperties);
+		UINT8* buffer = allocator->alloc(size);
+
+		RenderWindowProperties& props = const_cast<RenderWindowProperties&>(getProperties());
+
+		memcpy(buffer, &props, size);
+		return CoreSyncData(buffer, size);
+	}
+
+	void RenderWindowCore::syncToCore(const CoreSyncData& data)
+	{
+		RenderWindowProperties& props = const_cast<RenderWindowProperties&>(getProperties());
+		props = data.getData<RenderWindowProperties>();
+	}
+
 	void RenderWindowCore::_windowMovedOrResized()
 	void RenderWindowCore::_windowMovedOrResized()
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
@@ -41,8 +70,8 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		RenderWindowProperties* properties = static_cast<RenderWindowProperties*>(mProperties);
-		properties->mHasFocus = true;
+		RenderWindowProperties& properties = const_cast<RenderWindowProperties&>(getProperties());
+		properties.mHasFocus = true;
 
 
 		markCoreDirty();
 		markCoreDirty();
 	}
 	}
@@ -51,55 +80,28 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		RenderWindowProperties* properties = static_cast<RenderWindowProperties*>(mProperties);
-		properties->mHasFocus = false;
+		RenderWindowProperties& properties = const_cast<RenderWindowProperties&>(getProperties());
+		properties.mHasFocus = false;
 
 
 		markCoreDirty();
 		markCoreDirty();
 	}
 	}
 
 
-	RenderWindow* RenderWindowCore::getNonCore() const 
-	{ 
-		return static_cast<RenderWindow*>(mParent); 
-	}
-
-	void RenderWindow::initialize(const RENDER_WINDOW_DESC& desc)
+	const RenderWindowProperties& RenderWindowCore::getProperties() const
 	{
 	{
-		mDesc = desc;
-
-		mProperties = createProperties();
-		RenderWindowProperties* properties = static_cast<RenderWindowProperties*>(mProperties);
-
-		properties->mWidth = desc.videoMode.getWidth();
-		properties->mHeight = desc.videoMode.getHeight();
-		properties->mHwGamma = desc.gamma;
-		properties->mVSync = desc.vsync;
-		properties->mVSyncInterval = desc.vsyncInterval;
-		properties->mMultisampleCount = desc.multisampleCount;
-		properties->mLeft = desc.left;
-		properties->mTop = desc.top;
-		properties->mIsFullScreen = desc.fullscreen;
-		properties->mHidden = desc.hidden;
-		properties->mIsModal = desc.modal;
-		properties->mIsWindow = true;
-		properties->mRequiresTextureFlipping = requiresTextureFlipping();
-
-		RenderTarget::initialize();
+		return static_cast<const RenderWindowProperties&>(getPropertiesInternal());
 	}
 	}
 
 
 	void RenderWindow::destroy()
 	void RenderWindow::destroy()
 	{
 	{
-		Platform::resetNonClientAreas(*this);
-
 		RenderWindowManager::instance().windowDestroyed(this);
 		RenderWindowManager::instance().windowDestroyed(this);
 
 
 		RenderTarget::destroy();
 		RenderTarget::destroy();
 	}
 	}
 
 
-	const RenderWindowProperties& RenderWindow::getProperties() const
+	RenderWindow::RenderWindow(const RENDER_WINDOW_DESC& desc)
+		:mDesc(desc)
 	{
 	{
-		THROW_IF_CORE_THREAD;
 
 
-		return static_cast<const RenderWindowProperties&>(RenderTarget::getProperties());
 	}
 	}
 
 
 	SPtr<RenderWindowCore> RenderWindow::getCore() const
 	SPtr<RenderWindowCore> RenderWindow::getCore() const
@@ -107,8 +109,36 @@ namespace BansheeEngine
 		return std::static_pointer_cast<RenderWindowCore>(mCoreSpecific);
 		return std::static_pointer_cast<RenderWindowCore>(mCoreSpecific);
 	}
 	}
 
 
+	SPtr<CoreObjectCore> RenderWindow::createCore() const
+	{
+		RENDER_WINDOW_DESC desc = mDesc;
+		return RenderWindowCoreManager::instance().createInternal(desc);
+	}
+
 	RenderWindowPtr RenderWindow::create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow)
 	RenderWindowPtr RenderWindow::create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow)
 	{
 	{
 		return RenderWindowManager::instance().create(desc, parentWindow);
 		return RenderWindowManager::instance().create(desc, parentWindow);
 	}
 	}
+
+	CoreSyncData RenderWindow::syncToCore(FrameAlloc* allocator)
+	{
+		UINT32 size = sizeof(RenderWindowProperties);
+		UINT8* buffer = allocator->alloc(size);
+
+		RenderWindowProperties& props = const_cast<RenderWindowProperties&>(getProperties());
+
+		memcpy(buffer, &props, size);
+		return CoreSyncData(buffer, size);
+	}
+
+	void RenderWindow::syncFromCore(const CoreSyncData& data)
+	{
+		RenderWindowProperties& props = const_cast<RenderWindowProperties&>(getProperties());
+		props = data.getData<RenderWindowProperties>();
+	}
+
+	const RenderWindowProperties& RenderWindow::getProperties() const
+	{
+		return static_cast<const RenderWindowProperties&>(getPropertiesInternal());
+	}
 }
 }

+ 82 - 9
BansheeCore/Source/BsRenderWindowManager.cpp

@@ -11,18 +11,20 @@ namespace BansheeEngine
 		Platform::onWindowFocusReceived.connect(std::bind(&RenderWindowManager::windowFocusReceived, this, _1));
 		Platform::onWindowFocusReceived.connect(std::bind(&RenderWindowManager::windowFocusReceived, this, _1));
 		Platform::onWindowFocusLost.connect(std::bind(&RenderWindowManager::windowFocusLost, this, _1));
 		Platform::onWindowFocusLost.connect(std::bind(&RenderWindowManager::windowFocusLost, this, _1));
 		Platform::onWindowMovedOrResized.connect(std::bind(&RenderWindowManager::windowMovedOrResized, this, _1));
 		Platform::onWindowMovedOrResized.connect(std::bind(&RenderWindowManager::windowMovedOrResized, this, _1));
+		Platform::onMouseLeftWindow.connect(std::bind(&RenderWindowManager::windowMouseLeft, this, _1));
 	}
 	}
 
 
 	RenderWindowPtr RenderWindowManager::create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow)
 	RenderWindowPtr RenderWindowManager::create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow)
 	{
 	{
 		RenderWindowPtr renderWindow = createImpl(desc, parentWindow);
 		RenderWindowPtr renderWindow = createImpl(desc, parentWindow);
 		renderWindow->_setThisPtr(renderWindow);
 		renderWindow->_setThisPtr(renderWindow);
-		renderWindow->initialize(desc);
+		renderWindow->initialize();
 
 
 		{
 		{
 			BS_LOCK_MUTEX(mWindowMutex);
 			BS_LOCK_MUTEX(mWindowMutex);
 
 
 			mCreatedWindows.push_back(renderWindow.get());
 			mCreatedWindows.push_back(renderWindow.get());
+			mCoreToNonCoreMap[renderWindow->getCore().get()] = renderWindow.get();
 		}
 		}
 		
 		
 		return renderWindow;
 		return renderWindow;
@@ -44,15 +46,18 @@ namespace BansheeEngine
 
 
 			if(iterFind2 != mMovedOrResizedWindows.end())
 			if(iterFind2 != mMovedOrResizedWindows.end())
 				mMovedOrResizedWindows.erase(iterFind2);
 				mMovedOrResizedWindows.erase(iterFind2);
+
+			mCoreToNonCoreMap.erase(window->getCore().get());
 		}
 		}
 	}
 	}
 
 
-	void RenderWindowManager::windowFocusReceived(RenderWindowCore* window)
+	void RenderWindowManager::windowFocusReceived(RenderWindowCore* coreWindow)
 	{
 	{
-		window->_windowFocusReceived();
+		coreWindow->_windowFocusReceived();
+		RenderWindow* window = getNonCore(coreWindow);
 
 
 		BS_LOCK_MUTEX(mWindowMutex);
 		BS_LOCK_MUTEX(mWindowMutex);
-		mNewWindowInFocus = window->getNonCore();
+		mNewWindowInFocus = window;
 	}
 	}
 
 
 	void RenderWindowManager::windowFocusLost(RenderWindowCore* window)
 	void RenderWindowManager::windowFocusLost(RenderWindowCore* window)
@@ -63,32 +68,45 @@ namespace BansheeEngine
 		mNewWindowInFocus = nullptr;
 		mNewWindowInFocus = nullptr;
 	}
 	}
 
 
-	void RenderWindowManager::windowMovedOrResized(RenderWindowCore* window)
+	void RenderWindowManager::windowMovedOrResized(RenderWindowCore* coreWindow)
 	{
 	{
+		RenderWindow* window = getNonCore(coreWindow);
 		bool isValidWindow = false;
 		bool isValidWindow = false;
 		{
 		{
 			BS_LOCK_MUTEX(mWindowMutex);
 			BS_LOCK_MUTEX(mWindowMutex);
 
 
-			isValidWindow = std::find(begin(mCreatedWindows), end(mCreatedWindows), window->getNonCore()) != mCreatedWindows.end();
+			isValidWindow = std::find(begin(mCreatedWindows), end(mCreatedWindows), window) != mCreatedWindows.end();
 		}
 		}
 
 
 		if(!isValidWindow)
 		if(!isValidWindow)
 			return;
 			return;
 
 
-		window->_windowMovedOrResized();
+		coreWindow->_windowMovedOrResized();
 
 
 		BS_LOCK_MUTEX(mWindowMutex);
 		BS_LOCK_MUTEX(mWindowMutex);
 
 
-		auto iterFind = std::find(begin(mMovedOrResizedWindows), end(mMovedOrResizedWindows), window->getNonCore());
+		auto iterFind = std::find(begin(mMovedOrResizedWindows), end(mMovedOrResizedWindows), window);
 
 
 		if(iterFind == end(mMovedOrResizedWindows))
 		if(iterFind == end(mMovedOrResizedWindows))
-			mMovedOrResizedWindows.push_back(window->getNonCore());
+			mMovedOrResizedWindows.push_back(window);
+	}
+
+	void RenderWindowManager::windowMouseLeft(RenderWindowCore* coreWindow)
+	{
+		BS_LOCK_MUTEX(mWindowMutex);
+
+		RenderWindow* window = getNonCore(coreWindow);
+		auto iterFind = std::find(begin(mMouseLeftWindows), end(mMouseLeftWindows), window);
+
+		if (iterFind == end(mMouseLeftWindows))
+			mMouseLeftWindows.push_back(window);
 	}
 	}
 
 
 	void RenderWindowManager::_update()
 	void RenderWindowManager::_update()
 	{
 	{
 		RenderWindow* newWinInFocus = nullptr;
 		RenderWindow* newWinInFocus = nullptr;
 		Vector<RenderWindow*> movedOrResizedWindows;
 		Vector<RenderWindow*> movedOrResizedWindows;
+		Vector<RenderWindow*> mouseLeftWindows;
 
 
 		{
 		{
 			BS_LOCK_MUTEX(mWindowMutex);
 			BS_LOCK_MUTEX(mWindowMutex);
@@ -96,6 +114,9 @@ namespace BansheeEngine
 
 
 			movedOrResizedWindows = mMovedOrResizedWindows;
 			movedOrResizedWindows = mMovedOrResizedWindows;
 			mMovedOrResizedWindows.clear();
 			mMovedOrResizedWindows.clear();
+
+			mouseLeftWindows = mMouseLeftWindows;
+			mMouseLeftWindows.clear();
 		}
 		}
 
 
 		if(mWindowInFocus != newWinInFocus)
 		if(mWindowInFocus != newWinInFocus)
@@ -120,6 +141,12 @@ namespace BansheeEngine
 			if(!window->onResized.empty())
 			if(!window->onResized.empty())
 				window->onResized();
 				window->onResized();
 		}
 		}
+
+		if (!onMouseLeftWindow.empty())
+		{
+			for (auto& window : mouseLeftWindows)
+				onMouseLeftWindow(*window);
+		}			
 	}
 	}
 
 
 	Vector<RenderWindow*> RenderWindowManager::getRenderWindows() const
 	Vector<RenderWindow*> RenderWindowManager::getRenderWindows() const
@@ -128,4 +155,50 @@ namespace BansheeEngine
 
 
 		return mCreatedWindows;
 		return mCreatedWindows;
 	}
 	}
+
+	RenderWindow* RenderWindowManager::getNonCore(const RenderWindowCore* window) const
+	{
+		auto iterFind = mCoreToNonCoreMap.find(window);
+
+		if (iterFind != mCoreToNonCoreMap.end())
+			return iterFind->second;
+
+		return nullptr;
+	}
+
+	SPtr<RenderWindowCore> RenderWindowCoreManager::create(RENDER_WINDOW_DESC& desc)
+	{
+		SPtr<RenderWindowCore> renderWindow = createInternal(desc);
+		renderWindow->initialize();
+
+		return renderWindow;
+	}
+
+	void RenderWindowCoreManager::windowCreated(RenderWindowCore* window)
+	{
+		BS_LOCK_MUTEX(mWindowMutex);
+
+		mCreatedWindows.push_back(window);
+	}
+
+	void RenderWindowCoreManager::windowDestroyed(RenderWindowCore* window)
+	{
+		{
+			BS_LOCK_MUTEX(mWindowMutex);
+
+			auto iterFind = std::find(begin(mCreatedWindows), end(mCreatedWindows), window);
+
+			if (iterFind == mCreatedWindows.end())
+				BS_EXCEPT(InternalErrorException, "Trying to destroy a window that is not in the created windows list.");
+
+			mCreatedWindows.erase(iterFind);
+		}
+	}
+
+	Vector<RenderWindowCore*> RenderWindowCoreManager::getRenderWindows() const
+	{
+		BS_LOCK_MUTEX(mWindowMutex);
+
+		return mCreatedWindows;
+	}
 }
 }

+ 1 - 1
BansheeCore/Source/BsTexture.cpp

@@ -458,6 +458,6 @@ namespace BansheeEngine
 
 
 	const HTexture& Texture::dummy()
 	const HTexture& Texture::dummy()
 	{
 	{
-		return TextureManager::instance().getDummyTexture();
+		return TextureCoreManager::instance().getDummyTexture();
 	}
 	}
 }
 }

+ 40 - 34
BansheeCore/Source/BsTextureManager.cpp

@@ -6,36 +6,6 @@
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
-    TextureManager::TextureManager()
-    {
-        // Subclasses should register (when this is fully constructed)
-    }
-
-    TextureManager::~TextureManager()
-    {
-        // subclasses should unregister with resource group manager
-    }
-
-	void TextureManager::onStartUp()
-	{
-		// Internally this will call our createTextureImpl virtual method. But since this is guaranteed
-		// to be the last class in the hierarchy, we can call a virtual method from constructor.
-		mDummyTexture = Texture::create(TEX_TYPE_2D, 2, 2, 0, PF_R8G8B8A8);
-
-		UINT32 subresourceIdx = mDummyTexture->mapToSubresourceIdx(0, 0);
-		PixelDataPtr data = mDummyTexture->allocateSubresourceBuffer(subresourceIdx);
-
-		data->setColorAt(Color::Red, 0, 0);
-		data->setColorAt(Color::Red, 0, 1);
-		data->setColorAt(Color::Red, 1, 0);
-		data->setColorAt(Color::Red, 1, 1);
-
-		AsyncOp op;
-
-		data->_lock();
-		RenderSystem::instance().writeSubresource(mDummyTexture.getInternalPtr(), mDummyTexture->mapToSubresourceIdx(0, 0), data, false, op);
-	}
-
     TexturePtr TextureManager::createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, int numMipmaps,
     TexturePtr TextureManager::createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, int numMipmaps,
         PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount)
         PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount)
     {
     {
@@ -82,19 +52,55 @@ namespace BansheeEngine
 
 
 	RenderTexturePtr TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC& desc)
 	RenderTexturePtr TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC& desc)
 	{
 	{
-		RenderTexturePtr newRT = createRenderTextureImpl();
+		RenderTexturePtr newRT = createRenderTextureImpl(desc);
 		newRT->_setThisPtr(newRT);
 		newRT->_setThisPtr(newRT);
-		newRT->initialize(desc);
+		newRT->initialize();
 
 
 		return newRT;
 		return newRT;
 	}
 	}
 
 
 	MultiRenderTexturePtr TextureManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
 	MultiRenderTexturePtr TextureManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
 	{
 	{
-		MultiRenderTexturePtr newRT = createMultiRenderTextureImpl();
+		MultiRenderTexturePtr newRT = createMultiRenderTextureImpl(desc);
 		newRT->_setThisPtr(newRT);
 		newRT->_setThisPtr(newRT);
-		newRT->initialize(desc);
+		newRT->initialize();
+
+		return newRT;
+	}
+
+	SPtr<RenderTextureCore> TextureCoreManager::createRenderTexture(const RENDER_TEXTURE_DESC& desc)
+	{
+		SPtr<RenderTextureCore> newRT = createRenderTextureInternal(desc);
+		newRT->initialize();
+
+		return newRT;
+	}
+
+	SPtr<MultiRenderTextureCore> TextureCoreManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
+	{
+		SPtr<MultiRenderTextureCore> newRT = createMultiRenderTextureInternal(desc);
+		newRT->initialize();
 
 
 		return newRT;
 		return newRT;
 	}
 	}
+
+	void TextureCoreManager::onStartUp()
+	{
+		// Internally this will call our createTextureImpl virtual method. But since this is guaranteed
+		// to be the last class in the hierarchy, we can call a virtual method from constructor.
+		mDummyTexture = Texture::create(TEX_TYPE_2D, 2, 2, 0, PF_R8G8B8A8);
+
+		UINT32 subresourceIdx = mDummyTexture->mapToSubresourceIdx(0, 0);
+		PixelDataPtr data = mDummyTexture->allocateSubresourceBuffer(subresourceIdx);
+
+		data->setColorAt(Color::Red, 0, 0);
+		data->setColorAt(Color::Red, 0, 1);
+		data->setColorAt(Color::Red, 1, 0);
+		data->setColorAt(Color::Red, 1, 1);
+
+		AsyncOp op;
+
+		data->_lock();
+		RenderSystem::instance().writeSubresource(mDummyTexture.getInternalPtr(), mDummyTexture->mapToSubresourceIdx(0, 0), data, false, op);
+	}
 }
 }

+ 2 - 2
BansheeCore/Source/BsTransientMesh.cpp

@@ -31,12 +31,12 @@ namespace BansheeEngine
 		BS_EXCEPT(InvalidStateException, "Reading is not supported on a transient mesh.");
 		BS_EXCEPT(InvalidStateException, "Reading is not supported on a transient mesh.");
 	}
 	}
 
 
-	SPtr<VertexData> TransientMesh::_getVertexData() const
+	SPtr<VertexData> TransientMesh::getVertexData() const
 	{
 	{
 		return mParentHeap->getVertexData();
 		return mParentHeap->getVertexData();
 	}
 	}
 
 
-	SPtr<IndexBufferCore> TransientMesh::_getIndexBuffer() const
+	SPtr<IndexBufferCore> TransientMesh::getIndexBuffer() const
 	{
 	{
 		return mParentHeap->getIndexBuffer();
 		return mParentHeap->getIndexBuffer();
 	}
 	}

+ 1 - 1
BansheeCore/Source/BsVertexBuffer.cpp

@@ -27,7 +27,7 @@ namespace BansheeEngine
 
 
 	SPtr<CoreObjectCore> VertexBuffer::createCore() const
 	SPtr<CoreObjectCore> VertexBuffer::createCore() const
 	{
 	{
-		return HardwareBufferCoreManager::instance().createVertexBuffer(mProperties.mVertexSize, 
+		return HardwareBufferCoreManager::instance().createVertexBufferInternal(mProperties.mVertexSize, 
 			mProperties.mNumVertices, mUsage, mStreamOut);
 			mProperties.mNumVertices, mUsage, mStreamOut);
 	}
 	}
 
 

+ 7 - 23
BansheeCore/Source/Win32/BsPlatformImpl.cpp

@@ -9,8 +9,6 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	Event<void(RenderWindow*)> Platform::onMouseLeftWindow;
-
 	Event<void(const Vector2I&, OSPointerButtonStates)> Platform::onCursorMoved;
 	Event<void(const Vector2I&, OSPointerButtonStates)> Platform::onCursorMoved;
 	Event<void(const Vector2I&, OSMouseButton button, OSPointerButtonStates)> Platform::onCursorButtonPressed;
 	Event<void(const Vector2I&, OSMouseButton button, OSPointerButtonStates)> Platform::onCursorButtonPressed;
 	Event<void(const Vector2I&, OSMouseButton button, OSPointerButtonStates)> Platform::onCursorButtonReleased;
 	Event<void(const Vector2I&, OSMouseButton button, OSPointerButtonStates)> Platform::onCursorButtonReleased;
@@ -22,11 +20,11 @@ namespace BansheeEngine
 	Event<void(RenderWindowCore*)> Platform::onWindowFocusReceived;
 	Event<void(RenderWindowCore*)> Platform::onWindowFocusReceived;
 	Event<void(RenderWindowCore*)> Platform::onWindowFocusLost;
 	Event<void(RenderWindowCore*)> Platform::onWindowFocusLost;
 	Event<void(RenderWindowCore*)> Platform::onWindowMovedOrResized;
 	Event<void(RenderWindowCore*)> Platform::onWindowMovedOrResized;
+	Event<void(RenderWindowCore*)> Platform::onMouseLeftWindow;
 	Event<void()> Platform::onMouseCaptureChanged;
 	Event<void()> Platform::onMouseCaptureChanged;
 
 
 	Map<const RenderWindowCore*, WindowNonClientAreaData> Platform::mNonClientAreas;
 	Map<const RenderWindowCore*, WindowNonClientAreaData> Platform::mNonClientAreas;
 	bool Platform::mIsTrackingMouse = false;
 	bool Platform::mIsTrackingMouse = false;
-	Vector<RenderWindowCore*> Platform::mMouseLeftWindows;
 
 
 	Stack<RenderWindowCore*> Platform::mModalWindowStack;
 	Stack<RenderWindowCore*> Platform::mModalWindowStack;
 
 
@@ -259,25 +257,25 @@ namespace BansheeEngine
 		PostMessage(hwnd, WM_SETCURSOR, WPARAM(hwnd), (LPARAM)MAKELONG(HTCLIENT, WM_MOUSEMOVE));
 		PostMessage(hwnd, WM_SETCURSOR, WPARAM(hwnd), (LPARAM)MAKELONG(HTCLIENT, WM_MOUSEMOVE));
 	}
 	}
 
 
-	void Platform::setCaptionNonClientAreas(const RenderWindow& window, const Vector<Rect2I>& nonClientAreas)
+	void Platform::setCaptionNonClientAreas(const RenderWindowCore& window, const Vector<Rect2I>& nonClientAreas)
 	{
 	{
 		BS_LOCK_MUTEX(mSync);
 		BS_LOCK_MUTEX(mSync);
 
 
-		mNonClientAreas[window.getCore().get()].moveAreas = nonClientAreas;
+		mNonClientAreas[&window].moveAreas = nonClientAreas;
 	}
 	}
 
 
-	void Platform::setResizeNonClientAreas(const RenderWindow& window, const Vector<NonClientResizeArea>& nonClientAreas)
+	void Platform::setResizeNonClientAreas(const RenderWindowCore& window, const Vector<NonClientResizeArea>& nonClientAreas)
 	{
 	{
 		BS_LOCK_MUTEX(mSync);
 		BS_LOCK_MUTEX(mSync);
 
 
-		mNonClientAreas[window.getCore().get()].resizeAreas = nonClientAreas;
+		mNonClientAreas[&window].resizeAreas = nonClientAreas;
 	}
 	}
 
 
-	void Platform::resetNonClientAreas(const RenderWindow& window)
+	void Platform::resetNonClientAreas(const RenderWindowCore& window)
 	{
 	{
 		BS_LOCK_MUTEX(mSync);
 		BS_LOCK_MUTEX(mSync);
 
 
-		auto iterFind = mNonClientAreas.find(window.getCore().get());
+		auto iterFind = mNonClientAreas.find(&window);
 
 
 		if(iterFind != end(mNonClientAreas))
 		if(iterFind != end(mNonClientAreas))
 			mNonClientAreas.erase(iterFind);
 			mNonClientAreas.erase(iterFind);
@@ -453,20 +451,6 @@ namespace BansheeEngine
 
 
 	void Platform::_update()
 	void Platform::_update()
 	{
 	{
-		Vector<RenderWindowCore*> windowsCopy;
-		{
-			BS_LOCK_MUTEX(mSync);
-
-			windowsCopy = mMouseLeftWindows;
-			mMouseLeftWindows.clear();
-		}
-		
-		for(auto& window : windowsCopy)
-		{
-			if(!onMouseLeftWindow.empty())
-				onMouseLeftWindow(window->getNonCore());
-		}
-
 		for(auto& dropTarget : mDropTargets.data->dropTargetsPerWindow)
 		for(auto& dropTarget : mDropTargets.data->dropTargetsPerWindow)
 		{
 		{
 			dropTarget.second->update();
 			dropTarget.second->update();

+ 5 - 4
BansheeCore/Source/Win32/BsPlatformWndProc.cpp

@@ -29,10 +29,10 @@ namespace BansheeEngine
 				}
 				}
 				else
 				else
 				{
 				{
-					Vector<RenderWindow*> renderWindows = RenderWindowManager::instance().getRenderWindows();
+					Vector<RenderWindowCore*> renderWindows = RenderWindowCoreManager::instance().getRenderWindows();
 					for(auto& renderWindow : renderWindows)
 					for(auto& renderWindow : renderWindows)
 					{
 					{
-						if(renderWindow->getCore().get() == newWindow)
+						if(renderWindow == newWindow)
 							continue;
 							continue;
 
 
 						HWND curHwnd;
 						HWND curHwnd;
@@ -104,7 +104,7 @@ namespace BansheeEngine
 
 
 				if(reenableWindows)
 				if(reenableWindows)
 				{
 				{
-					Vector<RenderWindow*> renderWindows = RenderWindowManager::instance().getRenderWindows();
+					Vector<RenderWindowCore*> renderWindows = RenderWindowCoreManager::instance().getRenderWindows();
 					for(auto& renderWindow : renderWindows)
 					for(auto& renderWindow : renderWindows)
 					{
 					{
 						HWND curHwnd;
 						HWND curHwnd;
@@ -231,7 +231,8 @@ namespace BansheeEngine
 
 
 				BS_LOCK_MUTEX(mSync);
 				BS_LOCK_MUTEX(mSync);
 
 
-				mMouseLeftWindows.push_back(win);
+				if (!onMouseLeftWindow.empty())
+					onMouseLeftWindow(win);
 			}
 			}
 			break;
 			break;
 		case WM_LBUTTONUP:
 		case WM_LBUTTONUP:

+ 2 - 2
BansheeD3D11RenderSystem/Include/BsD3D11HardwareBufferManager.h

@@ -40,12 +40,12 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc HardwareBufferCoreManager::createVertexBufferImpl
 		 * @copydoc HardwareBufferCoreManager::createVertexBufferImpl
 		 */
 		 */
-		SPtr<VertexBufferCore> createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
+		SPtr<VertexBufferCore> createVertexBufferInternal(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
 
 
 		/**
 		/**
 		 * @copydoc HardwareBufferCoreManager::createIndexBufferImpl
 		 * @copydoc HardwareBufferCoreManager::createIndexBufferImpl
 		 */
 		 */
-		SPtr<IndexBufferCore> createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+		SPtr<IndexBufferCore> createIndexBufferInternal(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 
 		D3D11Device& mDevice;
 		D3D11Device& mDevice;
 	};
 	};

+ 13 - 8
BansheeD3D11RenderSystem/Include/BsD3D11MultiRenderTexture.h

@@ -15,15 +15,23 @@ namespace BansheeEngine
 	class BS_D3D11_EXPORT D3D11MultiRenderTextureCore : public MultiRenderTextureCore
 	class BS_D3D11_EXPORT D3D11MultiRenderTextureCore : public MultiRenderTextureCore
 	{
 	{
 	public:
 	public:
-		D3D11MultiRenderTextureCore(D3D11MultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc);
+		D3D11MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_DESC& desc);
 		virtual ~D3D11MultiRenderTextureCore();
 		virtual ~D3D11MultiRenderTextureCore();
 		
 		
 		/**
 		/**
 		 * @copydoc	MultiRenderTextureCore::getCustomAttribute
 		 * @copydoc	MultiRenderTextureCore::getCustomAttribute
 		 */
 		 */
 		void getCustomAttribute(const String& name, void* pData) const;
 		void getCustomAttribute(const String& name, void* pData) const;
+
 	protected:
 	protected:
 		friend class D3D11MultiRenderTexture;
 		friend class D3D11MultiRenderTexture;
+
+		/**
+		 * @copydoc	MultiRenderTextureCore::getProperties
+		 */
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
+
+		MultiRenderTextureProperties mProperties;
 	};
 	};
 
 
 	/**
 	/**
@@ -39,16 +47,13 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class D3D11TextureManager;
 		friend class D3D11TextureManager;
 
 
-		D3D11MultiRenderTexture() { }
+		D3D11MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
 
 
 		/**
 		/**
-		 * @copydoc	MultiRenderTexture::createProperties
+		 * @copydoc	MultiRenderTexture::getProperties
 		 */
 		 */
-		virtual RenderTargetProperties* createProperties() const;
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
 
 
-		/**
-		 * @copydoc	RenderTexture::createCore
-		 */
-		virtual SPtr<CoreObjectCore> createCore() const;
+		MultiRenderTextureProperties mProperties;
 	};
 	};
 }
 }

+ 10 - 2
BansheeD3D11RenderSystem/Include/BsD3D11RenderSystem.h

@@ -84,12 +84,12 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc	RenderSystem::setRenderTarget
 		 * @copydoc	RenderSystem::setRenderTarget
 		 */
 		 */
-		void setRenderTarget(RenderTargetPtr target);
+		void setRenderTarget(const SPtr<RenderTargetCore>& target);
 
 
 		/**
 		/**
 		 * @copydoc	RenderSystem::setViewport
 		 * @copydoc	RenderSystem::setViewport
 		 */
 		 */
-		void setViewport(Viewport vp);
+		void setViewport(const Rect2& vp);
 
 
 		/**
 		/**
 		 * @copydoc	RenderSystem::setScissorRect
 		 * @copydoc	RenderSystem::setScissorRect
@@ -225,6 +225,13 @@ namespace BansheeEngine
 		 */
 		 */
 		void applyInputLayout();
 		void applyInputLayout();
 
 
+		/**
+		 * @brief	Recalculates actual viewport dimensions based on currently 
+		 *			set viewport normalized dimensions and render target and applies
+		 *			them for further rendering.
+		 */
+		void applyViewport();
+
 		/**
 		/**
 		 * @brief	Creates and populates a set of render system capabilities describing which functionality
 		 * @brief	Creates and populates a set of render system capabilities describing which functionality
 		 *			is available.
 		 *			is available.
@@ -246,6 +253,7 @@ namespace BansheeEngine
 		std::pair<TexturePtr, TextureViewPtr> mBoundUAVs[D3D11_PS_CS_UAV_REGISTER_COUNT];
 		std::pair<TexturePtr, TextureViewPtr> mBoundUAVs[D3D11_PS_CS_UAV_REGISTER_COUNT];
 
 
 		UINT32 mStencilRef;
 		UINT32 mStencilRef;
+		Rect2 mViewportNorm;
 		D3D11_VIEWPORT mViewport;
 		D3D11_VIEWPORT mViewport;
 		D3D11_RECT mScissorRect;
 		D3D11_RECT mScissorRect;
 
 

+ 11 - 11
BansheeD3D11RenderSystem/Include/BsD3D11RenderTexture.h

@@ -16,9 +16,7 @@ namespace BansheeEngine
 	class D3D11RenderTextureCore : public RenderTextureCore
 	class D3D11RenderTextureCore : public RenderTextureCore
 	{
 	{
 	public:
 	public:
-		D3D11RenderTextureCore(D3D11RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-			const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
-
+		D3D11RenderTextureCore(const RENDER_TEXTURE_DESC& desc);
 		virtual ~D3D11RenderTextureCore() { }
 		virtual ~D3D11RenderTextureCore() { }
 
 
 		/**
 		/**
@@ -27,7 +25,12 @@ namespace BansheeEngine
 		void getCustomAttribute(const String& name, void* pData) const;
 		void getCustomAttribute(const String& name, void* pData) const;
 
 
 	protected:
 	protected:
-		friend class D3D11RenderTexture;
+		/**
+		 * @copydoc	RenderTextureCore::getProperties
+		 */
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
+
+		RenderTextureProperties mProperties;
 	};
 	};
 
 
 	/**
 	/**
@@ -43,16 +46,13 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class D3D11TextureManager;
 		friend class D3D11TextureManager;
 
 
-		D3D11RenderTexture() { }
+		D3D11RenderTexture(const RENDER_TEXTURE_DESC& desc);
 
 
 		/**
 		/**
-		 * @copydoc	RenderTexture::createProperties
+		 * @copydoc	RenderTexture::getProperties
 		 */
 		 */
-		virtual RenderTargetProperties* createProperties() const;
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
 
 
-		/**
-		 * @copydoc	RenderTexture::createCore
-		 */
-		virtual SPtr<CoreObjectCore> createCore() const;
+		RenderTextureProperties mProperties;
 	};
 	};
 }
 }

+ 21 - 35
BansheeD3D11RenderSystem/Include/BsD3D11RenderWindow.h

@@ -13,33 +13,12 @@ namespace BansheeEngine
 	class BS_D3D11_EXPORT D3D11RenderWindowProperties : public RenderWindowProperties
 	class BS_D3D11_EXPORT D3D11RenderWindowProperties : public RenderWindowProperties
 	{
 	{
 	public:
 	public:
+		D3D11RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
 		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;
 	};
 	};
 
 
 	/**
 	/**
@@ -53,7 +32,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc	RenderWindowCore::RenderWindowCore
 		 * @copydoc	RenderWindowCore::RenderWindowCore
 		 */
 		 */
-		D3D11RenderWindowCore(D3D11RenderWindow* parent, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc,
+		D3D11RenderWindowCore(const RENDER_WINDOW_DESC& desc,
 			D3D11Device& device, IDXGIFactory* DXGIFactory);
 			D3D11Device& device, IDXGIFactory* DXGIFactory);
 
 
 		~D3D11RenderWindowCore();
 		~D3D11RenderWindowCore();
@@ -161,6 +140,11 @@ namespace BansheeEngine
 		 */
 		 */
 		void resizeSwapChainBuffers(UINT32 width, UINT32 height);
 		void resizeSwapChainBuffers(UINT32 width, UINT32 height);
 
 
+		/**
+		 * @copydoc	RenderWindowCore::getProperties
+		 */
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
+
 	protected:
 	protected:
 		D3D11Device& mDevice;
 		D3D11Device& mDevice;
 		IDXGIFactory* mDXGIFactory;
 		IDXGIFactory* mDXGIFactory;
@@ -179,8 +163,9 @@ namespace BansheeEngine
 
 
 		IDXGISwapChain*	mSwapChain;
 		IDXGISwapChain*	mSwapChain;
 		DXGI_SWAP_CHAIN_DESC mSwapChainDesc;
 		DXGI_SWAP_CHAIN_DESC mSwapChainDesc;
+		HWND mHWnd;
 
 
-		RENDER_WINDOW_DESC mDesc;
+		D3D11RenderWindowProperties mProperties;
 	};
 	};
 
 
 	/**
 	/**
@@ -194,12 +179,7 @@ namespace BansheeEngine
 		~D3D11RenderWindow() { }
 		~D3D11RenderWindow() { }
 
 
 		/**
 		/**
-		 * @copydoc RenderWindow::requiresTextureFlipping
-		 */
-		bool requiresTextureFlipping() const { return false; }
-
-		/**
-		 * @copydoc RenderWindow::getCustomAttribute
+		 * @copydoc RenderWindow::screenToWindowPos
 		 */
 		 */
 		void getCustomAttribute(const String& name, void* pData) const;
 		void getCustomAttribute(const String& name, void* pData) const;
 
 
@@ -213,24 +193,30 @@ namespace BansheeEngine
 		 */
 		 */
 		Vector2I windowToScreenPos(const Vector2I& windowPos) const;
 		Vector2I windowToScreenPos(const Vector2I& windowPos) const;
 
 
+		/**
+		 * @copydoc	RenderWindow::getCore
+		 */
+		SPtr<D3D11RenderWindowCore> getCore() const;
+
 	protected:
 	protected:
 		friend class D3D11RenderWindowManager;
 		friend class D3D11RenderWindowManager;
 		friend class D3D11RenderWindowCore;
 		friend class D3D11RenderWindowCore;
 
 
-		D3D11RenderWindow(D3D11Device& device, IDXGIFactory* DXGIFactory);
+		D3D11RenderWindow(const RENDER_WINDOW_DESC& desc, D3D11Device& device, IDXGIFactory* DXGIFactory);
 
 
 		/**
 		/**
-		 * @copydoc	RenderWindow::createProperties
+		 * @copydoc	RenderWindowCore::getProperties
 		 */
 		 */
-		virtual RenderTargetProperties* createProperties() const;
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
 
 
 		/**
 		/**
-		 * @copydoc	RenderWindow::createCore
+		 * @brief	Retrieves internal window handle.
 		 */
 		 */
-		virtual SPtr<CoreObjectCore> createCore() const;
+		HWND getHWnd() const;
 
 
 	private:
 	private:
 		D3D11Device& mDevice;
 		D3D11Device& mDevice;
 		IDXGIFactory* mDXGIFactory;
 		IDXGIFactory* mDXGIFactory;
+		D3D11RenderWindowProperties mProperties;
 	};
 	};
 }
 }

+ 19 - 1
BansheeD3D11RenderSystem/Include/BsD3D11RenderWindowManager.h

@@ -17,7 +17,25 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderWindowManager::createImpl
 		 * @copydoc RenderWindowManager::createImpl
 		 */
 		 */
-		RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow);
+		RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, const RenderWindowPtr& parentWindow);
+
+	private:
+		D3D11RenderSystem* mRenderSystem;
+	};
+
+	/**
+	 * @copydoc	RenderWindowCoreManager
+	 */
+	class BS_D3D11_EXPORT D3D11RenderWindowCoreManager : public RenderWindowCoreManager
+	{
+	public:
+		D3D11RenderWindowCoreManager(D3D11RenderSystem* renderSystem);
+
+	protected:
+		/**
+		 * @copydoc RenderWindowCoreManager::createInternal
+		 */
+		virtual SPtr<RenderWindowCore> createInternal(RENDER_WINDOW_DESC& desc);
 
 
 	private:
 	private:
 		D3D11RenderSystem* mRenderSystem;
 		D3D11RenderSystem* mRenderSystem;

+ 19 - 5
BansheeD3D11RenderSystem/Include/BsD3D11TextureManager.h

@@ -11,9 +11,6 @@ namespace BansheeEngine
 	class BS_D3D11_EXPORT D3D11TextureManager : public TextureManager
 	class BS_D3D11_EXPORT D3D11TextureManager : public TextureManager
 	{
 	{
 	public:
 	public:
-		D3D11TextureManager();
-		~D3D11TextureManager();
-
 		/**
 		/**
 		 * @copydoc	TextureManager::getNativeFormat
 		 * @copydoc	TextureManager::getNativeFormat
 		 */
 		 */
@@ -28,11 +25,28 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc	TextureManager::createRenderTextureImpl
 		 * @copydoc	TextureManager::createRenderTextureImpl
 		 */
 		 */
-		RenderTexturePtr createRenderTextureImpl();
+		RenderTexturePtr createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc);
 
 
 		/**
 		/**
 		 * @copydoc	TextureManager::createMultiRenderTextureImpl
 		 * @copydoc	TextureManager::createMultiRenderTextureImpl
 		 */
 		 */
-		MultiRenderTexturePtr createMultiRenderTextureImpl();
+		MultiRenderTexturePtr createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc);
+	};
+
+	/**
+	 * @brief	Handles creation of DirectX 11 textures.
+	 */
+	class BS_D3D11_EXPORT D3D11TextureCoreManager : public TextureCoreManager
+	{
+	protected:		
+		/**
+		 * @copydoc	TextureCoreManager::createRenderTextureInternal
+		 */
+		SPtr<RenderTextureCore> createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc);
+
+		/**
+		 * @copydoc	TextureCoreManager::createMultiRenderTextureInternal
+		 */
+		SPtr<MultiRenderTextureCore> createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_DESC& desc);
 	};
 	};
 }
 }

+ 2 - 2
BansheeD3D11RenderSystem/Source/BsD3D11HardwareBufferManager.cpp

@@ -30,13 +30,13 @@ namespace BansheeEngine
 		: mDevice(device)
 		: mDevice(device)
 	{ }
 	{ }
 
 
-	SPtr<VertexBufferCore> D3D11HardwareBufferCoreManager::createVertexBufferImpl(UINT32 vertexSize,
+	SPtr<VertexBufferCore> D3D11HardwareBufferCoreManager::createVertexBufferInternal(UINT32 vertexSize,
 		UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 		UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 	{
 	{
 		return bs_shared_ptr<D3D11VertexBufferCore>(mDevice, vertexSize, numVerts, usage, streamOut);
 		return bs_shared_ptr<D3D11VertexBufferCore>(mDevice, vertexSize, numVerts, usage, streamOut);
 	}
 	}
 
 
-	SPtr<IndexBufferCore> D3D11HardwareBufferCoreManager::createIndexBufferImpl(IndexType itype,
+	SPtr<IndexBufferCore> D3D11HardwareBufferCoreManager::createIndexBufferInternal(IndexType itype,
 		UINT32 numIndexes, GpuBufferUsage usage)
 		UINT32 numIndexes, GpuBufferUsage usage)
 	{
 	{
 		return bs_shared_ptr<D3D11IndexBufferCore>(mDevice, itype, numIndexes, usage);
 		return bs_shared_ptr<D3D11IndexBufferCore>(mDevice, itype, numIndexes, usage);

+ 5 - 18
BansheeD3D11RenderSystem/Source/BsD3D11MultiRenderTexture.cpp

@@ -5,9 +5,8 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	D3D11MultiRenderTextureCore::D3D11MultiRenderTextureCore(D3D11MultiRenderTexture* parent, 
-		MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
-		:MultiRenderTextureCore(parent, properties, desc)
+	D3D11MultiRenderTextureCore::D3D11MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_DESC& desc)
+		:MultiRenderTextureCore(desc), mProperties(desc)
 	{
 	{
 
 
 	}
 	}
@@ -40,19 +39,7 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	RenderTargetProperties* D3D11MultiRenderTexture::createProperties() const
-	{
-		return bs_new<MultiRenderTextureProperties>();
-	}
-
-	SPtr<CoreObjectCore> D3D11MultiRenderTexture::createCore() const
-	{
-		MultiRenderTextureProperties* coreProperties = bs_new<MultiRenderTextureProperties>();
-		MultiRenderTextureProperties* myProperties = static_cast<MultiRenderTextureProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
-
-		return bs_shared_ptr<D3D11MultiRenderTextureCore>(const_cast<D3D11MultiRenderTexture*>(this),
-			coreProperties, mDesc);
-	}
+	D3D11MultiRenderTexture::D3D11MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
+		:MultiRenderTexture(desc), mProperties(desc)
+	{ }
 }
 }

+ 28 - 17
BansheeD3D11RenderSystem/Source/BsD3D11RenderSystem.cpp

@@ -34,6 +34,7 @@ namespace BansheeEngine
 		, mActiveD3DDriver(nullptr), mFeatureLevel(D3D_FEATURE_LEVEL_11_0)
 		, mActiveD3DDriver(nullptr), mFeatureLevel(D3D_FEATURE_LEVEL_11_0)
 		, mHLSLFactory(nullptr), mIAManager(nullptr)
 		, mHLSLFactory(nullptr), mIAManager(nullptr)
 		, mStencilRef(0), mActiveDrawOp(DOT_TRIANGLE_LIST)
 		, mStencilRef(0), mActiveDrawOp(DOT_TRIANGLE_LIST)
+		, mViewportNorm(0.0f, 0.0f, 1.0f, 1.0f)
 	{
 	{
 		mClipPlanesDirty = false; // DX11 handles clip planes through shaders
 		mClipPlanesDirty = false; // DX11 handles clip planes through shaders
 	}
 	}
@@ -107,6 +108,7 @@ namespace BansheeEngine
 
 
 		// Create the texture manager for use by others		
 		// Create the texture manager for use by others		
 		TextureManager::startUp<D3D11TextureManager>();
 		TextureManager::startUp<D3D11TextureManager>();
+		TextureCoreManager::startUp<D3D11TextureCoreManager>();
 
 
 		// Create hardware buffer manager		
 		// Create hardware buffer manager		
 		HardwareBufferManager::startUp<D3D11HardwareBufferManager>(std::ref(*mDevice));
 		HardwareBufferManager::startUp<D3D11HardwareBufferManager>(std::ref(*mDevice));
@@ -114,6 +116,7 @@ namespace BansheeEngine
 
 
 		// Create render window manager
 		// Create render window manager
 		RenderWindowManager::startUp<D3D11RenderWindowManager>(this);
 		RenderWindowManager::startUp<D3D11RenderWindowManager>(this);
+		RenderWindowCoreManager::startUp<D3D11RenderWindowCoreManager>(this);
 
 
 		// Create & register HLSL factory		
 		// Create & register HLSL factory		
 		mHLSLFactory = bs_new<D3D11HLSLProgramFactory>();
 		mHLSLFactory = bs_new<D3D11HLSLProgramFactory>();
@@ -168,9 +171,11 @@ namespace BansheeEngine
 		mActiveVertexShader = nullptr;
 		mActiveVertexShader = nullptr;
 
 
 		RenderStateManager::shutDown();
 		RenderStateManager::shutDown();
+		RenderWindowCoreManager::shutDown();
 		RenderWindowManager::shutDown();
 		RenderWindowManager::shutDown();
 		HardwareBufferCoreManager::shutDown();
 		HardwareBufferCoreManager::shutDown();
 		HardwareBufferManager::shutDown();
 		HardwareBufferManager::shutDown();
+		TextureCoreManager::shutDown();
 		TextureManager::shutDown();
 		TextureManager::shutDown();
 
 
 		SAFE_RELEASE(mDXGIFactory);
 		SAFE_RELEASE(mDXGIFactory);
@@ -368,26 +373,31 @@ namespace BansheeEngine
 		// Not used
 		// Not used
 	}
 	}
 
 
-	void D3D11RenderSystem::setViewport(Viewport vp)
+	void D3D11RenderSystem::setViewport(const Rect2& vp)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		// Set render target
-		RenderTargetPtr target = vp.getTarget();
-		setRenderTarget(target);
+		mViewportNorm = vp;
+		applyViewport();
+	}
+
+	void D3D11RenderSystem::applyViewport()
+	{
+		if (mActiveRenderTarget == nullptr)
+			return;
 
 
-		const RenderTargetProperties& rtProps = target->getCore()->getProperties();
+		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
 
 
 		// Set viewport dimensions
 		// Set viewport dimensions
-		mViewport.TopLeftX = (FLOAT)(rtProps.getWidth() * vp.getNormalizedX());
-		mViewport.TopLeftY = (FLOAT)(rtProps.getHeight() * vp.getNormalizedY());
-		mViewport.Width = (FLOAT)(rtProps.getWidth() * vp.getNormalizedWidth());
-		mViewport.Height = (FLOAT)(rtProps.getHeight() * vp.getNormalizedHeight());
+		mViewport.TopLeftX = (FLOAT)(rtProps.getWidth() * mViewportNorm.x);
+		mViewport.TopLeftY = (FLOAT)(rtProps.getHeight() * mViewportNorm.y);
+		mViewport.Width = (FLOAT)(rtProps.getWidth() * mViewportNorm.width);
+		mViewport.Height = (FLOAT)(rtProps.getHeight() * mViewportNorm.height);
 
 
-		if (target->requiresTextureFlipping())
+		if (rtProps.requiresTextureFlipping())
 		{
 		{
 			// Convert "top-left" to "bottom-left"
 			// Convert "top-left" to "bottom-left"
-			mViewport.TopLeftY = target->getCore()->getProperties().getHeight() - mViewport.Height - mViewport.TopLeftY;
+			mViewport.TopLeftY = rtProps.getHeight() - mViewport.Height - mViewport.TopLeftY;
 		}
 		}
 
 
 		mViewport.MinDepth = 0.0f;
 		mViewport.MinDepth = 0.0f;
@@ -689,7 +699,7 @@ namespace BansheeEngine
 		if(mActiveRenderTarget == nullptr)
 		if(mActiveRenderTarget == nullptr)
 			return;
 			return;
 
 
-		const RenderTargetProperties& rtProps = mActiveRenderTarget->getCore()->getProperties();
+		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
 
 
 		Rect2I clearArea((int)mViewport.TopLeftX, (int)mViewport.TopLeftY, (int)mViewport.Width, (int)mViewport.Height);
 		Rect2I clearArea((int)mViewport.TopLeftX, (int)mViewport.TopLeftY, (int)mViewport.Width, (int)mViewport.Height);
 
 
@@ -720,7 +730,7 @@ namespace BansheeEngine
 			ID3D11RenderTargetView** views = bs_newN<ID3D11RenderTargetView*, ScratchAlloc>(maxRenderTargets);
 			ID3D11RenderTargetView** views = bs_newN<ID3D11RenderTargetView*, ScratchAlloc>(maxRenderTargets);
 			memset(views, 0, sizeof(ID3D11RenderTargetView*) * maxRenderTargets);
 			memset(views, 0, sizeof(ID3D11RenderTargetView*) * maxRenderTargets);
 
 
-			mActiveRenderTarget->getCore()->getCustomAttribute("RTV", views);
+			mActiveRenderTarget->getCustomAttribute("RTV", views);
 			if (!views[0])
 			if (!views[0])
 			{
 			{
 				bs_deleteN<ScratchAlloc>(views, maxRenderTargets);
 				bs_deleteN<ScratchAlloc>(views, maxRenderTargets);
@@ -746,7 +756,7 @@ namespace BansheeEngine
 		if((buffers & FBT_DEPTH) != 0 || (buffers & FBT_STENCIL) != 0)
 		if((buffers & FBT_DEPTH) != 0 || (buffers & FBT_STENCIL) != 0)
 		{
 		{
 			ID3D11DepthStencilView* depthStencilView = nullptr;
 			ID3D11DepthStencilView* depthStencilView = nullptr;
-			mActiveRenderTarget->getCore()->getCustomAttribute("DSV", &depthStencilView);
+			mActiveRenderTarget->getCustomAttribute("DSV", &depthStencilView);
 
 
 			D3D11_CLEAR_FLAG clearFlag;
 			D3D11_CLEAR_FLAG clearFlag;
 
 
@@ -764,7 +774,7 @@ namespace BansheeEngine
 		BS_INC_RENDER_STAT(NumClears);
 		BS_INC_RENDER_STAT(NumClears);
 	}
 	}
 
 
-	void D3D11RenderSystem::setRenderTarget(RenderTargetPtr target)
+	void D3D11RenderSystem::setRenderTarget(const SPtr<RenderTargetCore>& target)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
@@ -774,7 +784,7 @@ namespace BansheeEngine
 		UINT32 maxRenderTargets = mCurrentCapabilities->getNumMultiRenderTargets();
 		UINT32 maxRenderTargets = mCurrentCapabilities->getNumMultiRenderTargets();
 		ID3D11RenderTargetView** views = bs_newN<ID3D11RenderTargetView*, ScratchAlloc>(maxRenderTargets);
 		ID3D11RenderTargetView** views = bs_newN<ID3D11RenderTargetView*, ScratchAlloc>(maxRenderTargets);
 		memset(views, 0, sizeof(ID3D11RenderTargetView*) * maxRenderTargets);
 		memset(views, 0, sizeof(ID3D11RenderTargetView*) * maxRenderTargets);
-		target->getCore()->getCustomAttribute("RTV", views);
+		target->getCustomAttribute("RTV", views);
 		if (!views[0])
 		if (!views[0])
 		{
 		{
 			bs_deleteN<ScratchAlloc>(views, maxRenderTargets);
 			bs_deleteN<ScratchAlloc>(views, maxRenderTargets);
@@ -783,7 +793,7 @@ namespace BansheeEngine
 
 
 		// Retrieve depth stencil
 		// Retrieve depth stencil
 		ID3D11DepthStencilView* depthStencilView = nullptr;
 		ID3D11DepthStencilView* depthStencilView = nullptr;
-		target->getCore()->getCustomAttribute("DSV", &depthStencilView);
+		target->getCustomAttribute("DSV", &depthStencilView);
 
 
 		// Bind render targets
 		// Bind render targets
 		mDevice->getImmediateContext()->OMSetRenderTargets(maxRenderTargets, views, depthStencilView);
 		mDevice->getImmediateContext()->OMSetRenderTargets(maxRenderTargets, views, depthStencilView);
@@ -791,6 +801,7 @@ namespace BansheeEngine
 			BS_EXCEPT(RenderingAPIException, "Failed to setRenderTarget : " + mDevice->getErrorDescription());
 			BS_EXCEPT(RenderingAPIException, "Failed to setRenderTarget : " + mDevice->getErrorDescription());
 
 
 		bs_deleteN<ScratchAlloc>(views, maxRenderTargets);
 		bs_deleteN<ScratchAlloc>(views, maxRenderTargets);
+		applyViewport();
 
 
 		BS_INC_RENDER_STAT(NumRenderTargetChanges);
 		BS_INC_RENDER_STAT(NumRenderTargetChanges);
 	}
 	}

+ 5 - 16
BansheeD3D11RenderSystem/Source/BsD3D11RenderTexture.cpp

@@ -9,9 +9,8 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	D3D11RenderTextureCore::D3D11RenderTextureCore(D3D11RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
-		:RenderTextureCore(parent, properties, colorSurfaceDesc, depthStencilSurfaceDesc)
+	D3D11RenderTextureCore::D3D11RenderTextureCore(const RENDER_TEXTURE_DESC& desc)
+		:RenderTextureCore(desc), mProperties(desc, false)
 	{ }
 	{ }
 
 
 	void D3D11RenderTextureCore::getCustomAttribute(const String& name, void* pData) const
 	void D3D11RenderTextureCore::getCustomAttribute(const String& name, void* pData) const
@@ -33,19 +32,9 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	RenderTargetProperties* D3D11RenderTexture::createProperties() const
-	{
-		return bs_new<RenderTextureProperties>();
-	}
-
-	SPtr<CoreObjectCore> D3D11RenderTexture::createCore() const
-	{
-		RenderTextureProperties* coreProperties = bs_new<RenderTextureProperties>();
-		RenderTextureProperties* myProperties = static_cast<RenderTextureProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
+	D3D11RenderTexture::D3D11RenderTexture(const RENDER_TEXTURE_DESC& desc)
+		:RenderTexture(desc), mProperties(desc, false)
+	{ 
 
 
-		return bs_shared_ptr<D3D11RenderTextureCore>(const_cast<D3D11RenderTexture*>(this), 
-			coreProperties, mColorSurfaceDesc, mDepthStencilSurfaceDesc);
 	}
 	}
 }
 }

+ 104 - 139
BansheeD3D11RenderSystem/Source/BsD3D11RenderWindow.cpp

@@ -15,25 +15,14 @@
 
 
 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);
-	}
+	D3D11RenderWindowProperties::D3D11RenderWindowProperties(const RENDER_WINDOW_DESC& desc)
+		:RenderWindowProperties(desc)
+	{ }
 
 
-	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),
+	D3D11RenderWindowCore::D3D11RenderWindowCore(const RENDER_WINDOW_DESC& desc, D3D11Device& device, IDXGIFactory* DXGIFactory)
+		: RenderWindowCore(desc), mProperties(desc), mDevice(device), mDXGIFactory(DXGIFactory), mIsExternal(false), mSizing(false),
 		 mRenderTargetView(nullptr), mBackBuffer(nullptr), mSwapChain(nullptr), mDepthStencilView(nullptr), mIsChild(false), 
 		 mRenderTargetView(nullptr), mBackBuffer(nullptr), mSwapChain(nullptr), mDepthStencilView(nullptr), mIsChild(false), 
-		 mRefreshRateNumerator(0), mRefreshRateDenominator(0), mDesc(desc)
+		 mRefreshRateNumerator(0), mRefreshRateDenominator(0), mHWnd(0)
 	{ }
 	{ }
 
 
 	D3D11RenderWindowCore::~D3D11RenderWindowCore()
 	D3D11RenderWindowCore::~D3D11RenderWindowCore()
@@ -45,7 +34,7 @@ namespace BansheeEngine
 
 
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 
 
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties& props = mProperties;
 
 
 		mMultisampleType.Count = 1;
 		mMultisampleType.Count = 1;
 		mMultisampleType.Quality = 0;
 		mMultisampleType.Quality = 0;
@@ -62,10 +51,10 @@ namespace BansheeEngine
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
 
 
 		mIsChild = parentHWnd != 0;
 		mIsChild = parentHWnd != 0;
-		props->mIsFullScreen = mDesc.fullscreen && !mIsChild;
-		props->mColorDepth = 32;
+		props.mIsFullScreen = mDesc.fullscreen && !mIsChild;
+		props.mColorDepth = 32;
 
 
-		props->mActive = true;
+		props.mActive = true;
 
 
 		if (mDesc.videoMode.isCustom())
 		if (mDesc.videoMode.isCustom())
 		{
 		{
@@ -97,7 +86,7 @@ namespace BansheeEngine
 
 
 		if (!externalHandle)
 		if (!externalHandle)
 		{
 		{
-			DWORD dwStyle = (getProperties().isHidden() ? 0 : WS_VISIBLE) | WS_CLIPCHILDREN;
+			DWORD dwStyle = (props.isHidden() ? 0 : WS_VISIBLE) | WS_CLIPCHILDREN;
 			DWORD dwStyleEx = 0;
 			DWORD dwStyleEx = 0;
 			RECT rc;
 			RECT rc;
 			MONITORINFO monitorInfo;
 			MONITORINFO monitorInfo;
@@ -153,10 +142,10 @@ namespace BansheeEngine
 				top += monitorInfo.rcWork.top;
 				top += monitorInfo.rcWork.top;
 			}
 			}
 
 
-			props->mWidth = mDesc.videoMode.getWidth();
-			props->mHeight = mDesc.videoMode.getHeight();
-			props->mTop = top;
-			props->mLeft = left;
+			props.mWidth = mDesc.videoMode.getWidth();
+			props.mHeight = mDesc.videoMode.getHeight();
+			props.mTop = top;
+			props.mLeft = left;
 
 
 			if (!mDesc.fullscreen)
 			if (!mDesc.fullscreen)
 			{
 			{
@@ -183,29 +172,29 @@ namespace BansheeEngine
 				{
 				{
 					// Calculate window dimensions required
 					// Calculate window dimensions required
 					// to get the requested client area
 					// to get the requested client area
-					SetRect(&rc, 0, 0, props->mWidth, props->mHeight);
+					SetRect(&rc, 0, 0, props.mWidth, props.mHeight);
 					AdjustWindowRect(&rc, dwStyle, false);
 					AdjustWindowRect(&rc, dwStyle, false);
-					props->mWidth = rc.right - rc.left;
-					props->mHeight = rc.bottom - rc.top;
+					props.mWidth = rc.right - rc.left;
+					props.mHeight = rc.bottom - rc.top;
 
 
 					// Clamp width and height to the desktop dimensions
 					// Clamp width and height to the desktop dimensions
 					int screenw = GetSystemMetrics(SM_CXSCREEN);
 					int screenw = GetSystemMetrics(SM_CXSCREEN);
 					int screenh = GetSystemMetrics(SM_CYSCREEN);
 					int screenh = GetSystemMetrics(SM_CYSCREEN);
-					if ((int)props->mWidth > screenw)
-						props->mWidth = screenw;
-					if ((int)props->mHeight > screenh)
-						props->mHeight = screenh;
-					if (props->mLeft < 0)
-						props->mLeft = (screenw - props->mWidth) / 2;
-					if (props->mTop < 0)
-						props->mTop = (screenh - props->mHeight) / 2;
+					if ((int)props.mWidth > screenw)
+						props.mWidth = screenw;
+					if ((int)props.mHeight > screenh)
+						props.mHeight = screenh;
+					if (props.mLeft < 0)
+						props.mLeft = (screenw - props.mWidth) / 2;
+					if (props.mTop < 0)
+						props.mTop = (screenh - props.mHeight) / 2;
 				}
 				}
 			}
 			}
 			else
 			else
 			{
 			{
 				dwStyle |= WS_POPUP;
 				dwStyle |= WS_POPUP;
-				props->mTop = 0;
-				props->mLeft = 0;
+				props.mTop = 0;
+				props.mLeft = 0;
 			}
 			}
 
 
 			UINT classStyle = 0;
 			UINT classStyle = 0;
@@ -225,27 +214,27 @@ namespace BansheeEngine
 			// Create our main window
 			// Create our main window
 			// Pass pointer to self
 			// Pass pointer to self
 			mIsExternal = false;
 			mIsExternal = false;
-			props->mHWnd = CreateWindowEx(dwStyleEx, "D3D11Wnd", mDesc.title.c_str(), dwStyle,
-				props->mLeft, props->mTop, props->mWidth, props->mHeight, parentHWnd, 0, hInst, this);
+			mHWnd = CreateWindowEx(dwStyleEx, "D3D11Wnd", mDesc.title.c_str(), dwStyle,
+				props.mLeft, props.mTop, props.mWidth, props.mHeight, parentHWnd, 0, hInst, this);
 		}
 		}
 		else
 		else
 		{
 		{
-			props->mHWnd = externalHandle;
+			mHWnd = externalHandle;
 			mIsExternal = true;
 			mIsExternal = true;
 		}
 		}
 
 
 		RECT rc;
 		RECT rc;
-		GetWindowRect(props->mHWnd, &rc);
-		props->mTop = rc.top;
-		props->mLeft = rc.left;
+		GetWindowRect(mHWnd, &rc);
+		props.mTop = rc.top;
+		props.mLeft = rc.left;
 
 
-		GetClientRect(props->mHWnd, &rc);
-		props->mWidth = rc.right;
-		props->mHeight = rc.bottom;
+		GetClientRect(mHWnd, &rc);
+		props.mWidth = rc.right;
+		props.mHeight = rc.bottom;
 
 
 		createSwapChain();
 		createSwapChain();
 
 
-		if (getProperties().isFullScreen())
+		if (props.isFullScreen())
 		{
 		{
 			if (outputInfo != nullptr)
 			if (outputInfo != nullptr)
 				mSwapChain->SetFullscreenState(true, outputInfo->getDXGIOutput());
 				mSwapChain->SetFullscreenState(true, outputInfo->getDXGIOutput());
@@ -254,28 +243,23 @@ namespace BansheeEngine
 		}
 		}
 
 
 		createSizeDependedD3DResources();
 		createSizeDependedD3DResources();
-		mDXGIFactory->MakeWindowAssociation(props->mHWnd, NULL);
-		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;
+		mDXGIFactory->MakeWindowAssociation(mHWnd, NULL);
+		setHidden(props.isHidden());
 	}
 	}
 
 
 	void D3D11RenderWindowCore::destroy()
 	void D3D11RenderWindowCore::destroy()
 	{
 	{
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties& props = mProperties;
 
 
-		props->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 (props->mHWnd && !mIsExternal)
+		if (mHWnd && !mIsExternal)
 		{
 		{
-			DestroyWindow(props->mHWnd);
+			DestroyWindow(mHWnd);
 		}
 		}
 
 
 		if (mDepthStencilView != nullptr)
 		if (mDepthStencilView != nullptr)
@@ -284,7 +268,7 @@ namespace BansheeEngine
 			mDepthStencilView = nullptr;
 			mDepthStencilView = nullptr;
 		}
 		}
 
 
-		props->mHWnd = 0;
+		mHWnd = 0;
 
 
 		destroySizeDependedD3DResources();
 		destroySizeDependedD3DResources();
 
 
@@ -308,14 +292,14 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties& props = mProperties;
 
 
-		if (props->mHWnd && !props->mIsFullScreen)
+		if (mHWnd && !props.mIsFullScreen)
 		{
 		{
-			props->mTop = top;
-			props->mLeft = left;
+			props.mTop = top;
+			props.mLeft = left;
 
 
-			SetWindowPos(props->mHWnd, 0, top, left, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+			SetWindowPos(mHWnd, 0, top, left, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 			markCoreDirty();			
 			markCoreDirty();			
 		}
 		}
 	}
 	}
@@ -324,19 +308,19 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties& props = mProperties;
 
 
-		if (props->mHWnd && !props->mIsFullScreen)
+		if (mHWnd && !props.mIsFullScreen)
 		{
 		{
-			props->mWidth = width;
-			props->mHeight = height;
+			props.mWidth = width;
+			props.mHeight = height;
 
 
 			RECT rc = { 0, 0, width, height };
 			RECT rc = { 0, 0, width, height };
-			AdjustWindowRect(&rc, GetWindowLong(props->mHWnd, GWL_STYLE), false);
+			AdjustWindowRect(&rc, GetWindowLong(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(props->mHWnd, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
+			SetWindowPos(mHWnd, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 			markCoreDirty();
 			markCoreDirty();
 		}
 		}
 	}
 	}
@@ -345,18 +329,18 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties& props = mProperties;
 
 
-		if (props->mHWnd && mSwapChain)
+		if (mHWnd && mSwapChain)
 		{
 		{
 			if (state)
 			if (state)
 			{
 			{
-				ShowWindow(props->mHWnd, SW_RESTORE);
-				mSwapChain->SetFullscreenState(props->mIsFullScreen, nullptr);
+				ShowWindow(mHWnd, SW_RESTORE);
+				mSwapChain->SetFullscreenState(props.mIsFullScreen, nullptr);
 			}
 			}
 			else
 			else
 			{
 			{
-				ShowWindow(props->mHWnd, SW_SHOWMINIMIZED);
+				ShowWindow(mHWnd, SW_SHOWMINIMIZED);
 				mSwapChain->SetFullscreenState(FALSE, nullptr);
 				mSwapChain->SetFullscreenState(FALSE, nullptr);
 			}
 			}
 		}
 		}
@@ -368,15 +352,15 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties& props = mProperties;
 
 
-		props->mHidden = hidden;
+		props.mHidden = hidden;
 		if (!mIsExternal)
 		if (!mIsExternal)
 		{
 		{
 			if (hidden)
 			if (hidden)
-				ShowWindow(props->mHWnd, SW_HIDE);
+				ShowWindow(mHWnd, SW_HIDE);
 			else
 			else
-				ShowWindow(props->mHWnd, SW_SHOWNORMAL);
+				ShowWindow(mHWnd, SW_SHOWNORMAL);
 		}
 		}
 
 
 		markCoreDirty();
 		markCoreDirty();
@@ -413,10 +397,9 @@ namespace BansheeEngine
 
 
 		outputInfo.getDXGIOutput()->FindClosestMatchingMode(&modeDesc, &nearestMode, nullptr);
 		outputInfo.getDXGIOutput()->FindClosestMatchingMode(&modeDesc, &nearestMode, nullptr);
 
 
-		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
-		properties->mIsFullScreen = true;
-		properties->mWidth = width;
-		properties->mHeight = height;
+		mProperties.mIsFullScreen = true;
+		mProperties.mWidth = width;
+		mProperties.mHeight = height;
 
 
 		mSwapChain->ResizeTarget(&nearestMode);
 		mSwapChain->ResizeTarget(&nearestMode);
 		mSwapChain->SetFullscreenState(true, outputInfo.getDXGIOutput()); 
 		mSwapChain->SetFullscreenState(true, outputInfo.getDXGIOutput()); 
@@ -447,10 +430,9 @@ namespace BansheeEngine
 
 
 		const D3D11VideoMode& videoMode = static_cast<const D3D11VideoMode&>(mode);
 		const D3D11VideoMode& videoMode = static_cast<const D3D11VideoMode&>(mode);
 
 
-		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
-		properties->mIsFullScreen = true;
-		properties->mWidth = mode.getWidth();
-		properties->mHeight = mode.getHeight();
+		mProperties.mIsFullScreen = true;
+		mProperties.mWidth = mode.getWidth();
+		mProperties.mHeight = mode.getHeight();
 
 
 		mSwapChain->ResizeTarget(&videoMode.getDXGIModeDesc());
 		mSwapChain->ResizeTarget(&videoMode.getDXGIModeDesc());
 		mSwapChain->SetFullscreenState(true, outputInfo.getDXGIOutput());
 		mSwapChain->SetFullscreenState(true, outputInfo.getDXGIOutput());
@@ -462,10 +444,9 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
-		properties->mWidth = width;
-		properties->mHeight = height;
-		properties->mIsFullScreen = false;
+		mProperties.mWidth = width;
+		mProperties.mHeight = height;
+		mProperties.mIsFullScreen = false;
 
 
 		mSwapChainDesc.Windowed = true;
 		mSwapChainDesc.Windowed = true;
 		mSwapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
 		mSwapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
@@ -490,18 +471,15 @@ namespace BansheeEngine
 
 
 	HWND D3D11RenderWindowCore::_getWindowHandle() const
 	HWND D3D11RenderWindowCore::_getWindowHandle() const
 	{
 	{
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
-		return props->mHWnd;
+		return 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 = props->mHWnd;
+			*pWnd = mHWnd;
 			return;
 			return;
 		}
 		}
 
 
@@ -594,20 +572,19 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties& props = mProperties;
 
 
-		if (!props->mHWnd || IsIconic(props->mHWnd))
+		if (!mHWnd || IsIconic(mHWnd))
 			return;
 			return;
 
 
 		RECT rc;
 		RECT rc;
-		GetWindowRect(props->mHWnd, &rc);
+		GetWindowRect(mHWnd, &rc);
 
 
-		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
-		properties->mTop = rc.top;
-		properties->mLeft = rc.left;
+		mProperties.mTop = rc.top;
+		mProperties.mLeft = rc.left;
 		markCoreDirty();
 		markCoreDirty();
 
 
-		GetClientRect(props->mHWnd, &rc);
+		GetClientRect(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;
 
 
@@ -626,17 +603,17 @@ namespace BansheeEngine
 	{
 	{
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 
 
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
+		D3D11RenderWindowProperties& props = 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	= props->mHWnd;
-		mSwapChainDesc.BufferDesc.Width = props->mWidth;
-		mSwapChainDesc.BufferDesc.Height = props->mHeight;
+		mSwapChainDesc.OutputWindow	= mHWnd;
+		mSwapChainDesc.BufferDesc.Width = props.mWidth;
+		mSwapChainDesc.BufferDesc.Height = props.mHeight;
 		mSwapChainDesc.BufferDesc.Format = format;
 		mSwapChainDesc.BufferDesc.Format = format;
 
 
-		if (props->mIsFullScreen)
+		if (props.mIsFullScreen)
 		{
 		{
 			mSwapChainDesc.BufferDesc.RefreshRate.Numerator = mRefreshRateNumerator;
 			mSwapChainDesc.BufferDesc.RefreshRate.Numerator = mRefreshRateNumerator;
 			mSwapChainDesc.BufferDesc.RefreshRate.Denominator = mRefreshRateDenominator;
 			mSwapChainDesc.BufferDesc.RefreshRate.Denominator = mRefreshRateDenominator;
@@ -658,7 +635,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(props->mMultisampleCount, 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;
 		
 		
@@ -734,17 +711,16 @@ namespace BansheeEngine
 	{
 	{
 		destroySizeDependedD3DResources();
 		destroySizeDependedD3DResources();
 
 
-		UINT Flags = getProperties().isFullScreen() ? DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH : 0;
+		UINT Flags = mProperties.isFullScreen() ? DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH : 0;
 		HRESULT hr = mSwapChain->ResizeBuffers(mSwapChainDesc.BufferCount, width, height, mSwapChainDesc.BufferDesc.Format, Flags);
 		HRESULT hr = mSwapChain->ResizeBuffers(mSwapChainDesc.BufferCount, width, height, mSwapChainDesc.BufferDesc.Format, Flags);
 
 
 		if(hr != S_OK)
 		if(hr != S_OK)
 			BS_EXCEPT(InternalErrorException, "Call to ResizeBuffers failed.");
 			BS_EXCEPT(InternalErrorException, "Call to ResizeBuffers failed.");
 
 
-		D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
 		mSwapChain->GetDesc(&mSwapChainDesc);
 		mSwapChain->GetDesc(&mSwapChainDesc);
-		properties->mWidth = mSwapChainDesc.BufferDesc.Width;
-		properties->mHeight = mSwapChainDesc.BufferDesc.Height;
-		properties->mIsFullScreen = (0 == mSwapChainDesc.Windowed); // Alt-Enter together with SetWindowAssociation() can change this state
+		mProperties.mWidth = mSwapChainDesc.BufferDesc.Width;
+		mProperties.mHeight = mSwapChainDesc.BufferDesc.Height;
+		mProperties.mIsFullScreen = (0 == mSwapChainDesc.Windowed); // Alt-Enter together with SetWindowAssociation() can change this state
 		markCoreDirty();
 		markCoreDirty();
 
 
 		createSizeDependedD3DResources();
 		createSizeDependedD3DResources();
@@ -768,26 +744,20 @@ namespace BansheeEngine
 		return pDXGIDevice;
 		return pDXGIDevice;
 	}
 	}
 
 
-	D3D11RenderWindow::D3D11RenderWindow(D3D11Device& device, IDXGIFactory* DXGIFactory)
-		:mDevice(device), mDXGIFactory(DXGIFactory)
+	D3D11RenderWindow::D3D11RenderWindow(const RENDER_WINDOW_DESC& desc, D3D11Device& device, IDXGIFactory* DXGIFactory)
+		:RenderWindow(desc), mProperties(desc), mDevice(device), mDXGIFactory(DXGIFactory)
 	{
 	{
 
 
 	}
 	}
 
 
 	void D3D11RenderWindow::getCustomAttribute(const String& name, void* pData) const
 	void D3D11RenderWindow::getCustomAttribute(const String& name, void* pData) const
 	{
 	{
-		THROW_IF_CORE_THREAD;
-
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
-
 		if (name == "WINDOW")
 		if (name == "WINDOW")
 		{
 		{
-			HWND *pWnd = (HWND*)pData;
-			*pWnd = props->mHWnd;
+			HWND *pHwnd = (HWND*)pData;
+			*pHwnd = getHWnd();
 			return;
 			return;
 		}
 		}
-
-		RenderWindow::getCustomAttribute(name, pData);
 	}
 	}
 
 
 	Vector2I D3D11RenderWindow::screenToWindowPos(const Vector2I& screenPos) const
 	Vector2I D3D11RenderWindow::screenToWindowPos(const Vector2I& screenPos) const
@@ -796,8 +766,7 @@ namespace BansheeEngine
 		pos.x = screenPos.x;
 		pos.x = screenPos.x;
 		pos.y = screenPos.y;
 		pos.y = screenPos.y;
 
 
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
-		ScreenToClient(props->mHWnd, &pos);
+		ScreenToClient(getHWnd(), &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
@@ -807,23 +776,19 @@ namespace BansheeEngine
 		pos.x = windowPos.x;
 		pos.x = windowPos.x;
 		pos.y = windowPos.y;
 		pos.y = windowPos.y;
 
 
-		D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
-		ClientToScreen(props->mHWnd, &pos);
+		ClientToScreen(getHWnd(), &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
-	RenderTargetProperties* D3D11RenderWindow::createProperties() const
+	SPtr<D3D11RenderWindowCore> D3D11RenderWindow::getCore() const
 	{
 	{
-		return bs_new<D3D11RenderWindowProperties>();
+		return std::static_pointer_cast<D3D11RenderWindowCore>(mCoreSpecific);
 	}
 	}
 
 
-	SPtr<CoreObjectCore> D3D11RenderWindow::createCore() const
+	HWND D3D11RenderWindow::getHWnd() const
 	{
 	{
-		D3D11RenderWindowProperties* coreProperties = bs_new<D3D11RenderWindowProperties>();
-		D3D11RenderWindowProperties* myProperties = static_cast<D3D11RenderWindowProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
-
-		return bs_shared_ptr<D3D11RenderWindowCore>(const_cast<D3D11RenderWindow*>(this), coreProperties, mDesc, mDevice, mDXGIFactory);
+		// HACK: I'm accessing core method from sim thread, which means an invalid handle
+		// could be returned here if requested too soon after initialization.
+		return getCore()->_getWindowHandle();
 	}
 	}
 }
 }

+ 20 - 2
BansheeD3D11RenderSystem/Source/BsD3D11RenderWindowManager.cpp

@@ -11,7 +11,7 @@ namespace BansheeEngine
 		assert(mRenderSystem != nullptr);
 		assert(mRenderSystem != nullptr);
 	}
 	}
 
 
-	RenderWindowPtr D3D11RenderWindowManager::createImpl(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow)
+	RenderWindowPtr D3D11RenderWindowManager::createImpl(RENDER_WINDOW_DESC& desc, const RenderWindowPtr& parentWindow)
 	{
 	{
 		RenderSystem* rs = RenderSystem::instancePtr();
 		RenderSystem* rs = RenderSystem::instancePtr();
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(rs);
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(rs);
@@ -24,7 +24,25 @@ namespace BansheeEngine
 		}
 		}
 
 
 		// Create the window
 		// Create the window
-		D3D11RenderWindow* renderWindow = new (bs_alloc<D3D11RenderWindow, PoolAlloc>()) D3D11RenderWindow(d3d11rs->getPrimaryDevice(), d3d11rs->getDXGIFactory());
+		D3D11RenderWindow* renderWindow = new (bs_alloc<D3D11RenderWindow, PoolAlloc>()) D3D11RenderWindow(desc, d3d11rs->getPrimaryDevice(), d3d11rs->getDXGIFactory());
 		return bs_core_ptr<D3D11RenderWindow, PoolAlloc>(renderWindow);
 		return bs_core_ptr<D3D11RenderWindow, PoolAlloc>(renderWindow);
 	}
 	}
+
+	D3D11RenderWindowCoreManager::D3D11RenderWindowCoreManager(D3D11RenderSystem* renderSystem)
+		:mRenderSystem(renderSystem)
+	{
+		assert(mRenderSystem != nullptr);
+	}
+
+	SPtr<RenderWindowCore> D3D11RenderWindowCoreManager::createInternal(RENDER_WINDOW_DESC& desc)
+	{
+		RenderSystem* rs = RenderSystem::instancePtr();
+		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(rs);
+
+		// Create the window
+		D3D11RenderWindowCore* renderWindow = new (bs_alloc<D3D11RenderWindowCore, GenAlloc>()) D3D11RenderWindowCore(desc, d3d11rs->getPrimaryDevice(), d3d11rs->getDXGIFactory());
+		windowCreated(renderWindow);
+
+		return bs_shared_ptr<D3D11RenderWindowCore, GenAlloc>(renderWindow);
+	}
 }
 }

+ 14 - 11
BansheeD3D11RenderSystem/Source/BsD3D11TextureManager.cpp

@@ -7,13 +7,6 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	D3D11TextureManager::D3D11TextureManager() 
-		:TextureManager()
-	{ }
-
-	D3D11TextureManager::~D3D11TextureManager()
-	{ }
-
 	TexturePtr D3D11TextureManager::createTextureImpl()
 	TexturePtr D3D11TextureManager::createTextureImpl()
 	{
 	{
 		D3D11Texture* tex = new (bs_alloc<D3D11Texture, PoolAlloc>()) D3D11Texture(); 
 		D3D11Texture* tex = new (bs_alloc<D3D11Texture, PoolAlloc>()) D3D11Texture(); 
@@ -21,16 +14,16 @@ namespace BansheeEngine
 		return bs_core_ptr<D3D11Texture, PoolAlloc>(tex);
 		return bs_core_ptr<D3D11Texture, PoolAlloc>(tex);
 	}
 	}
 
 
-	RenderTexturePtr D3D11TextureManager::createRenderTextureImpl()
+	RenderTexturePtr D3D11TextureManager::createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc)
 	{
 	{
-		D3D11RenderTexture* tex = new (bs_alloc<D3D11RenderTexture, PoolAlloc>()) D3D11RenderTexture();
+		D3D11RenderTexture* tex = new (bs_alloc<D3D11RenderTexture, PoolAlloc>()) D3D11RenderTexture(desc);
 
 
 		return bs_core_ptr<D3D11RenderTexture, PoolAlloc>(tex);
 		return bs_core_ptr<D3D11RenderTexture, PoolAlloc>(tex);
 	}
 	}
 
 
-	MultiRenderTexturePtr D3D11TextureManager::createMultiRenderTextureImpl()
+	MultiRenderTexturePtr D3D11TextureManager::createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc)
 	{
 	{
-		D3D11MultiRenderTexture* tex = new (bs_alloc<D3D11MultiRenderTexture, PoolAlloc>()) D3D11MultiRenderTexture();
+		D3D11MultiRenderTexture* tex = new (bs_alloc<D3D11MultiRenderTexture, PoolAlloc>()) D3D11MultiRenderTexture(desc);
 
 
 		return bs_core_ptr<D3D11MultiRenderTexture, PoolAlloc>(tex);
 		return bs_core_ptr<D3D11MultiRenderTexture, PoolAlloc>(tex);
 	}
 	}
@@ -42,4 +35,14 @@ namespace BansheeEngine
 
 
 		return D3D11Mappings::getPF(d3dPF);
 		return D3D11Mappings::getPF(d3dPF);
 	}
 	}
+
+	SPtr<RenderTextureCore> D3D11TextureCoreManager::createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc)
+	{
+		return bs_shared_ptr<D3D11RenderTextureCore>(desc);
+	}
+
+	SPtr<MultiRenderTextureCore> D3D11TextureCoreManager::createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_DESC& desc)
+	{
+		return bs_shared_ptr<D3D11MultiRenderTextureCore>(desc);
+	}
 }
 }

+ 2 - 2
BansheeD3D9RenderSystem/Include/BsD3D9HardwareBufferManager.h

@@ -35,11 +35,11 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc HardwareBufferCoreManager::createVertexBufferImpl
 		 * @copydoc HardwareBufferCoreManager::createVertexBufferImpl
 		 */
 		 */
-		SPtr<VertexBufferCore> createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
+		SPtr<VertexBufferCore> createVertexBufferInternal(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
 
 
 		/**
 		/**
 		 * @copydoc HardwareBufferCoreManager::createIndexBufferImpl
 		 * @copydoc HardwareBufferCoreManager::createIndexBufferImpl
 		 */
 		 */
-		SPtr<IndexBufferCore> createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+		SPtr<IndexBufferCore> createIndexBufferInternal(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
     };
     };
 }
 }

+ 12 - 8
BansheeD3D9RenderSystem/Include/BsD3D9MultiRenderTexture.h

@@ -15,7 +15,7 @@ namespace BansheeEngine
 	class BS_D3D9_EXPORT D3D9MultiRenderTextureCore : public MultiRenderTextureCore
 	class BS_D3D9_EXPORT D3D9MultiRenderTextureCore : public MultiRenderTextureCore
 	{
 	{
 	public:
 	public:
-		D3D9MultiRenderTextureCore(D3D9MultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc);
+		D3D9MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_DESC& desc);
 		virtual ~D3D9MultiRenderTextureCore();
 		virtual ~D3D9MultiRenderTextureCore();
 		
 		
 		/**
 		/**
@@ -31,8 +31,15 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual void initialize();
 		virtual void initialize();
 
 
+		/**
+		 * @copydoc	MultiRenderTextureCore::getProperties
+		 */
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
+
 		Vector<IDirect3DSurface9*> mDX9ColorSurfaces;
 		Vector<IDirect3DSurface9*> mDX9ColorSurfaces;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
+
+		MultiRenderTextureProperties mProperties;
 	};
 	};
 
 
 	/**
 	/**
@@ -48,16 +55,13 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class D3D9TextureManager;
 		friend class D3D9TextureManager;
 
 
-		D3D9MultiRenderTexture() { }
+		D3D9MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
 
 
 		/**
 		/**
-		 * @copydoc	MultiRenderTexture::createProperties
+		 * @copydoc	MultiRenderTexture::getProperties
 		 */
 		 */
-		virtual RenderTargetProperties* createProperties() const;
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
 
 
-		/**
-		 * @copydoc	RenderTexture::createCore
-		 */
-		virtual SPtr<CoreObjectCore> createCore() const;
+		MultiRenderTextureProperties mProperties;
 	};
 	};
 }
 }

+ 13 - 3
BansheeD3D9RenderSystem/Include/BsD3D9RenderSystem.h

@@ -33,7 +33,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderSystem::setRenderTarget()
 		 * @copydoc RenderSystem::setRenderTarget()
 		 */
 		 */
-		void setRenderTarget(RenderTargetPtr target);
+		void setRenderTarget(const SPtr<RenderTargetCore>& target);
 
 
 		/**
 		/**
 		 * @copydoc RenderSystem::bindGpuProgram()
 		 * @copydoc RenderSystem::bindGpuProgram()
@@ -104,7 +104,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderSystem::setViewport()
 		 * @copydoc RenderSystem::setViewport()
 		 */
 		 */
-		void setViewport(Viewport vp);
+		void setViewport(const Rect2& vp);
 
 
 		/**
 		/**
 		 * @copydoc RenderSystem::beginFrame()
 		 * @copydoc RenderSystem::beginFrame()
@@ -235,8 +235,10 @@ namespace BansheeEngine
 		friend class D3D9RenderWindow;
 		friend class D3D9RenderWindow;
 		friend class D3D9Device;
 		friend class D3D9Device;
 		friend class D3D9TextureManager;
 		friend class D3D9TextureManager;
+		friend class D3D9TextureCoreManager;
 		friend class D3D9DeviceManager;
 		friend class D3D9DeviceManager;
 		friend class D3D9RenderWindowManager;
 		friend class D3D9RenderWindowManager;
+		friend class D3D9RenderWindowCoreManager;
 
 
 		/**
 		/**
 		 * @copydoc	RenderSystem::initialize_internal
 		 * @copydoc	RenderSystem::initialize_internal
@@ -287,7 +289,7 @@ namespace BansheeEngine
 		 *
 		 *
 		 * @note	Also performs an initialization step when called the first time.
 		 * @note	Also performs an initialization step when called the first time.
 		 */
 		 */
-		RenderSystemCapabilities* updateRenderSystemCapabilities(D3D9RenderWindow* renderWindow);
+		RenderSystemCapabilities* updateRenderSystemCapabilities(D3D9RenderWindowCore* renderWindow);
 
 
 		/**
 		/**
 		 * @brief	Updates render system capabilities with vertex shader related data.
 		 * @brief	Updates render system capabilities with vertex shader related data.
@@ -529,6 +531,13 @@ namespace BansheeEngine
 		 */
 		 */
 		void clearArea(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0, const Rect2I& clearArea = Rect2I::EMPTY);
 		void clearArea(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0, const Rect2I& clearArea = Rect2I::EMPTY);
 
 
+		/**
+		 * @brief	Recalculates actual viewport dimensions based on currently 
+		 *			set viewport normalized dimensions and render target and applies
+		 *			them for further rendering.
+		 */
+		void applyViewport();
+
 		/**
 		/**
 		 * @brief	Triggered when device has been lost.
 		 * @brief	Triggered when device has been lost.
 		 */
 		 */
@@ -569,6 +578,7 @@ namespace BansheeEngine
 
 
 		HINSTANCE mhInstance;
 		HINSTANCE mhInstance;
 
 
+		Rect2 mViewportNorm;
 		UINT32 mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight;
 		UINT32 mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight;
 		RECT mScissorRect;
 		RECT mScissorRect;
 
 

+ 16 - 14
BansheeD3D9RenderSystem/Include/BsD3D9RenderTexture.h

@@ -16,8 +16,7 @@ namespace BansheeEngine
 	class BS_D3D9_EXPORT D3D9RenderTextureCore : public RenderTextureCore, public D3D9Resource
 	class BS_D3D9_EXPORT D3D9RenderTextureCore : public RenderTextureCore, public D3D9Resource
 	{
 	{
 	public:
 	public:
-		D3D9RenderTextureCore(D3D9RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-			const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
+		D3D9RenderTextureCore(const RENDER_TEXTURE_DESC& desc);
 
 
 		virtual ~D3D9RenderTextureCore();
 		virtual ~D3D9RenderTextureCore();
 
 
@@ -64,18 +63,24 @@ namespace BansheeEngine
 		 */
 		 */
 		void releaseSurfaces();
 		void releaseSurfaces();
 
 
+		/**
+		 * @copydoc	RenderTextureCore::getProperties
+		 */
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
+
 	protected:
 	protected:
 		IDirect3DSurface9* mDX9ColorSurface;
 		IDirect3DSurface9* mDX9ColorSurface;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
 		bool mIsBindableToShader;
 		bool mIsBindableToShader;
+		RenderTextureProperties mProperties;
 	};
 	};
 
 
 	/**
 	/**
-	* @brief	DirectX 9 implementation of a render texture.
-	*
-	* @note		Sim thread only.
-	*/
-	class BS_D3D9_EXPORT D3D9RenderTexture : public RenderTexture
+	 * @brief	DirectX 9 implementation of a render texture.
+	 *
+	 * @note	Sim thread only.
+	 */
+	class D3D9RenderTexture : public RenderTexture
 	{
 	{
 	public:
 	public:
 		virtual ~D3D9RenderTexture() { }
 		virtual ~D3D9RenderTexture() { }
@@ -83,16 +88,13 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class D3D9TextureManager;
 		friend class D3D9TextureManager;
 
 
-		D3D9RenderTexture() { }
+		D3D9RenderTexture(const RENDER_TEXTURE_DESC& desc);
 
 
 		/**
 		/**
-		 * @copydoc	RenderTexture::createProperties
+		 * @copydoc	RenderTexture::getProperties
 		 */
 		 */
-		virtual RenderTargetProperties* createProperties() const;
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
 
 
-		/**
-		 * @copydoc	RenderTexture::createCore
-		 */
-		virtual SPtr<CoreObjectCore> createCore() const;
+		RenderTextureProperties mProperties;
 	};
 	};
 }
 }

+ 21 - 39
BansheeD3D9RenderSystem/Include/BsD3D9RenderWindow.h

@@ -14,33 +14,12 @@ namespace BansheeEngine
 	class BS_D3D9_EXPORT D3D9RenderWindowProperties : public RenderWindowProperties
 	class BS_D3D9_EXPORT D3D9RenderWindowProperties : public RenderWindowProperties
 	{
 	{
 	public:
 	public:
+		D3D9RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
 		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;
 	};
 	};
 
 
 	/**
 	/**
@@ -51,7 +30,7 @@ namespace BansheeEngine
 	class BS_D3D9_EXPORT D3D9RenderWindowCore : public RenderWindowCore
 	class BS_D3D9_EXPORT D3D9RenderWindowCore : public RenderWindowCore
 	{
 	{
 	public:
 	public:
-		D3D9RenderWindowCore(D3D9RenderWindow* parent, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, HINSTANCE instance);
+		D3D9RenderWindowCore(const RENDER_WINDOW_DESC& desc, HINSTANCE instance);
 		~D3D9RenderWindowCore();
 		~D3D9RenderWindowCore();
 		
 		
 		/**
 		/**
@@ -168,6 +147,11 @@ namespace BansheeEngine
 		void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight,
 		void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight,
 			DWORD style, UINT32* winWidth, UINT32* winHeight);
 			DWORD style, UINT32* winWidth, UINT32* winHeight);
 
 
+		/**
+		 * @copydoc	RenderWindowCore::getProperties
+		 */
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
+
 	protected:
 	protected:
 		HINSTANCE mInstance;
 		HINSTANCE mInstance;
 		D3D9Device* mDevice;
 		D3D9Device* mDevice;
@@ -182,7 +166,9 @@ namespace BansheeEngine
 		DWORD mWindowedStyleEx;
 		DWORD mWindowedStyleEx;
 		bool mIsDepthBuffered;
 		bool mIsDepthBuffered;
 		bool mIsChild;
 		bool mIsChild;
-		RENDER_WINDOW_DESC mDesc;
+		HWND mHWnd;
+
+		D3D9RenderWindowProperties mProperties;
 	};
 	};
 
 
 	/**
 	/**
@@ -198,22 +184,17 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderWindow::screenToWindowPos
 		 * @copydoc RenderWindow::screenToWindowPos
 		 */
 		 */
-		Vector2I screenToWindowPos(const Vector2I& screenPos) const;
-
-		/**
-		 * @copydoc RenderWindow::windowToScreenPos
-		 */
-		Vector2I windowToScreenPos(const Vector2I& windowPos) const;
+		void getCustomAttribute(const String& name, void* pData) const;
 
 
 		/**
 		/**
-		 * @copydoc RenderWindow::requiresTextureFlipping
+		 * @copydoc RenderWindow::screenToWindowPos
 		 */
 		 */
-		bool requiresTextureFlipping() const { return false; }
+		Vector2I screenToWindowPos(const Vector2I& screenPos) const;
 
 
 		/**
 		/**
-		 * @copydoc RenderWindow::getCustomAttribute
+		 * @copydoc RenderWindow::windowToScreenPos
 		 */
 		 */
-		void getCustomAttribute(const String& name, void* pData) const;
+		Vector2I windowToScreenPos(const Vector2I& windowPos) const;
 
 
 		/**
 		/**
 		 * @copydoc	RenderWindow::getCore
 		 * @copydoc	RenderWindow::getCore
@@ -224,19 +205,20 @@ namespace BansheeEngine
 		friend class D3D9RenderWindowManager;
 		friend class D3D9RenderWindowManager;
 		friend class D3D9RenderWindowCore;
 		friend class D3D9RenderWindowCore;
 
 
-		D3D9RenderWindow(HINSTANCE instance);
+		D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, HINSTANCE instance);
 
 
 		/**
 		/**
-		 * @copydoc	RenderWindow::createProperties
+		 * @copydoc	RenderWindowCore::getProperties
 		 */
 		 */
-		virtual RenderTargetProperties* createProperties() const;
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
 
 
 		/**
 		/**
-		 * @copydoc	RenderWindow::createCore
+		 * @brief	Retrieves internal window handle.
 		 */
 		 */
-		virtual SPtr<CoreObjectCore> createCore() const;
+		HWND getHWnd() const;
 
 
 	private:
 	private:
 		HINSTANCE mInstance;
 		HINSTANCE mInstance;
+		D3D9RenderWindowProperties mProperties;
 	};
 	};
 }
 }

+ 19 - 1
BansheeD3D9RenderSystem/Include/BsD3D9RenderWindowManager.h

@@ -17,7 +17,25 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderWindowManager::createImpl()
 		 * @copydoc RenderWindowManager::createImpl()
 		 */
 		 */
-		RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow);
+		RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, const RenderWindowPtr& parentWindow);
+
+	private:
+		D3D9RenderSystem* mRenderSystem;
+	};
+
+	/**
+	 * @brief	Handles creation of windows for DirectX 9.
+	 */
+	class BS_D3D9_EXPORT D3D9RenderWindowCoreManager : public RenderWindowCoreManager
+	{
+	public:
+		D3D9RenderWindowCoreManager(D3D9RenderSystem* renderSystem);
+
+	protected:
+		/**
+		 * @copydoc RenderWindowCoreManager::createInternal
+		 */
+		SPtr<RenderWindowCore> createInternal(RENDER_WINDOW_DESC& desc);
 
 
 	private:
 	private:
 		D3D9RenderSystem* mRenderSystem;
 		D3D9RenderSystem* mRenderSystem;

+ 19 - 2
BansheeD3D9RenderSystem/Include/BsD3D9TextureManager.h

@@ -29,11 +29,28 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc TextureManager::createRenderTextureImpl
 		 * @copydoc TextureManager::createRenderTextureImpl
 		 */
 		 */
-		RenderTexturePtr createRenderTextureImpl();
+		RenderTexturePtr createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc);
 
 
 		/**
 		/**
 		 * @copydoc TextureManager::createMultiRenderTextureImpl
 		 * @copydoc TextureManager::createMultiRenderTextureImpl
 		 */
 		 */
-		MultiRenderTexturePtr createMultiRenderTextureImpl();
+		MultiRenderTexturePtr createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc);
+	};
+
+	/**
+	 * @brief	Handles creation of DirectX 9 textures.
+	 */
+	class BS_D3D9_EXPORT D3D9TextureCoreManager : public TextureCoreManager
+	{
+	protected:		
+		/**
+		 * @copydoc	TextureCoreManager::createRenderTextureInternal
+		 */
+		SPtr<RenderTextureCore> createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc);
+
+		/**
+		 * @copydoc	TextureCoreManager::createMultiRenderTextureInternal
+		 */
+		SPtr<MultiRenderTextureCore> createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_DESC& desc);
 	};
 	};
 }
 }

+ 2 - 2
BansheeD3D9RenderSystem/Source/BsD3D9HardwareBufferManager.cpp

@@ -27,14 +27,14 @@ namespace BansheeEngine
 		return bs_core_ptr<D3D9VertexDeclaration, PoolAlloc>(decl);
 		return bs_core_ptr<D3D9VertexDeclaration, PoolAlloc>(decl);
     }
     }
 
 
-	SPtr<VertexBufferCore> D3D9HardwareBufferCoreManager::createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
+	SPtr<VertexBufferCore> D3D9HardwareBufferCoreManager::createVertexBufferInternal(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 	{
 	{
 		assert(numVerts > 0);
 		assert(numVerts > 0);
 
 
 		return bs_shared_ptr<D3D9VertexBufferCore>(vertexSize, numVerts, usage, streamOut);
 		return bs_shared_ptr<D3D9VertexBufferCore>(vertexSize, numVerts, usage, streamOut);
 	}
 	}
 
 
-	SPtr<IndexBufferCore> D3D9HardwareBufferCoreManager::createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+	SPtr<IndexBufferCore> D3D9HardwareBufferCoreManager::createIndexBufferInternal(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
 	{
 	{
 		assert(numIndexes > 0);
 		assert(numIndexes > 0);
 
 

+ 4 - 14
BansheeD3D9RenderSystem/Source/BsD3D9MultiRenderTexture.cpp

@@ -4,8 +4,8 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	D3D9MultiRenderTextureCore::D3D9MultiRenderTextureCore(D3D9MultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
-		:MultiRenderTextureCore(parent, properties, desc), mDX9DepthStencilSurface(nullptr)
+	D3D9MultiRenderTextureCore::D3D9MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_DESC& desc)
+		:MultiRenderTextureCore(desc), mProperties(desc), mDX9DepthStencilSurface(nullptr)
 	{ }
 	{ }
 
 
 	D3D9MultiRenderTextureCore::~D3D9MultiRenderTextureCore()
 	D3D9MultiRenderTextureCore::~D3D9MultiRenderTextureCore()
@@ -81,19 +81,9 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	RenderTargetProperties* D3D9MultiRenderTexture::createProperties() const
+	D3D9MultiRenderTexture::D3D9MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
+		:MultiRenderTexture(desc), mProperties(desc)
 	{
 	{
-		return bs_new<MultiRenderTextureProperties>();
-	}
-
-	SPtr<CoreObjectCore> D3D9MultiRenderTexture::createCore() const
-	{
-		MultiRenderTextureProperties* coreProperties = bs_new<MultiRenderTextureProperties>();
-		MultiRenderTextureProperties* myProperties = static_cast<MultiRenderTextureProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
 
 
-		return bs_shared_ptr<D3D9MultiRenderTextureCore>(const_cast<D3D9MultiRenderTexture*>(this),
-			coreProperties, mDesc);
 	}
 	}
 }
 }

+ 60 - 51
BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp

@@ -39,7 +39,7 @@ namespace BansheeEngine
 		mViewportLeft(0), mViewportTop(0), mViewportWidth(0), mViewportHeight(0),
 		mViewportLeft(0), mViewportTop(0), mViewportWidth(0), mViewportHeight(0),
 		mIsFrameInProgress(false), mRestoreFrameOnReset(false), mhInstance(hInstance),
 		mIsFrameInProgress(false), mRestoreFrameOnReset(false), mhInstance(hInstance),
 		mpD3D(nullptr), mDriverList(nullptr), mActiveD3DDriver(nullptr), mHLSLProgramFactory(nullptr),
 		mpD3D(nullptr), mDriverList(nullptr), mActiveD3DDriver(nullptr), mHLSLProgramFactory(nullptr),
-		mDeviceManager(nullptr), mResourceManager(nullptr)
+		mDeviceManager(nullptr), mResourceManager(nullptr), mViewportNorm(0.0f, 0.0f, 1.0f, 1.0f)
 	{
 	{
 		msD3D9RenderSystem = this;
 		msD3D9RenderSystem = this;
 
 
@@ -105,17 +105,19 @@ namespace BansheeEngine
 
 
 		// Create render window manager
 		// Create render window manager
 		RenderWindowManager::startUp<D3D9RenderWindowManager>(this);
 		RenderWindowManager::startUp<D3D9RenderWindowManager>(this);
+		RenderWindowCoreManager::startUp<D3D9RenderWindowCoreManager>(this);
 
 
 		// Create render state manager
 		// Create render state manager
 		RenderStateManager::startUp();
 		RenderStateManager::startUp();
 
 
 		// Create primary window and finalize initialization
 		// Create primary window and finalize initialization
 		RenderWindowPtr primaryWindow = RenderWindow::create(mPrimaryWindowDesc);
 		RenderWindowPtr primaryWindow = RenderWindow::create(mPrimaryWindowDesc);
-		D3D9RenderWindow* d3d9renderWindow = static_cast<D3D9RenderWindow*>(primaryWindow.get());
+		D3D9RenderWindowCore* d3d9renderWindow = static_cast<D3D9RenderWindowCore*>(primaryWindow->getCore().get());
 		updateRenderSystemCapabilities(d3d9renderWindow);
 		updateRenderSystemCapabilities(d3d9renderWindow);
 
 
 		// Create the texture manager for use by others		
 		// Create the texture manager for use by others		
 		TextureManager::startUp<D3D9TextureManager>();
 		TextureManager::startUp<D3D9TextureManager>();
+		TextureCoreManager::startUp<D3D9TextureCoreManager>();
 
 
 		QueryManager::startUp<D3D9QueryManager>();
 		QueryManager::startUp<D3D9QueryManager>();
 
 
@@ -149,9 +151,11 @@ namespace BansheeEngine
 		mActiveD3DDriver = NULL;	
 		mActiveD3DDriver = NULL;	
 
 
 		QueryManager::shutDown();
 		QueryManager::shutDown();
+		TextureCoreManager::shutDown();
 		TextureManager::shutDown();
 		TextureManager::shutDown();
 		HardwareBufferCoreManager::shutDown();
 		HardwareBufferCoreManager::shutDown();
 		HardwareBufferManager::shutDown();
 		HardwareBufferManager::shutDown();
+		RenderWindowCoreManager::shutDown();
 		RenderWindowManager::shutDown();
 		RenderWindowManager::shutDown();
 		RenderStateManager::shutDown();
 		RenderStateManager::shutDown();
 
 
@@ -1029,27 +1033,28 @@ namespace BansheeEngine
 			setSamplerState( static_cast<DWORD>(unit), D3DSAMP_MAXANISOTROPY, maxAnisotropy );
 			setSamplerState( static_cast<DWORD>(unit), D3DSAMP_MAXANISOTROPY, maxAnisotropy );
 	}
 	}
 
 
-	void D3D9RenderSystem::setRenderTarget(RenderTargetPtr target)
+	void D3D9RenderSystem::setRenderTarget(const SPtr<RenderTargetCore>& target)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
 		mActiveRenderTarget = target;
 		mActiveRenderTarget = target;
+		const RenderTargetProperties& rtProps = target->getProperties();
 
 
 		HRESULT hr;
 		HRESULT hr;
 
 
 		// Possibly change device if the target is a window
 		// Possibly change device if the target is a window
-		if (target->getCore()->getProperties().isWindow())
+		if (rtProps.isWindow())
 		{
 		{
-			D3D9RenderWindow* window = static_cast<D3D9RenderWindow*>(target.get());
-			mDeviceManager->setActiveRenderTargetDevice(window->getCore()->_getDevice());
-			window->getCore()->_validateDevice();
+			D3D9RenderWindowCore* window = static_cast<D3D9RenderWindowCore*>(target.get());
+			mDeviceManager->setActiveRenderTargetDevice(window->_getDevice());
+			window->_validateDevice();
 		}
 		}
 
 
 		// Retrieve render surfaces
 		// Retrieve render surfaces
 		UINT32 maxRenderTargets = mCurrentCapabilities->getNumMultiRenderTargets();
 		UINT32 maxRenderTargets = mCurrentCapabilities->getNumMultiRenderTargets();
 		IDirect3DSurface9** pBack = bs_newN<IDirect3DSurface9*, ScratchAlloc>(maxRenderTargets);
 		IDirect3DSurface9** pBack = bs_newN<IDirect3DSurface9*, ScratchAlloc>(maxRenderTargets);
 		memset(pBack, 0, sizeof(IDirect3DSurface9*) * maxRenderTargets);
 		memset(pBack, 0, sizeof(IDirect3DSurface9*) * maxRenderTargets);
-		target->getCore()->getCustomAttribute("DDBACKBUFFER", pBack);
+		target->getCustomAttribute("DDBACKBUFFER", pBack);
 		if (!pBack[0])
 		if (!pBack[0])
 		{
 		{
 			bs_deleteN<ScratchAlloc>(pBack, maxRenderTargets);
 			bs_deleteN<ScratchAlloc>(pBack, maxRenderTargets);
@@ -1059,7 +1064,7 @@ namespace BansheeEngine
 		IDirect3DSurface9* pDepth = NULL;
 		IDirect3DSurface9* pDepth = NULL;
 
 
 		if (!pDepth)
 		if (!pDepth)
-			target->getCore()->getCustomAttribute("D3DZBUFFER", &pDepth);
+			target->getCustomAttribute("D3DZBUFFER", &pDepth);
 		
 		
 		// Bind render targets
 		// Bind render targets
 		for(UINT32 x = 0; x < maxRenderTargets; ++x)
 		for(UINT32 x = 0; x < maxRenderTargets; ++x)
@@ -1081,50 +1086,19 @@ namespace BansheeEngine
 			BS_EXCEPT(RenderingAPIException, "Failed to setDepthStencil : " + msg);
 			BS_EXCEPT(RenderingAPIException, "Failed to setDepthStencil : " + msg);
 		}
 		}
 
 
+		// Set sRGB write mode
+		setRenderState(D3DRS_SRGBWRITEENABLE, rtProps.isHwGammaEnabled());
+		applyViewport();
+
 		BS_INC_RENDER_STAT(NumRenderTargetChanges);
 		BS_INC_RENDER_STAT(NumRenderTargetChanges);
 	}
 	}
 
 
-	void D3D9RenderSystem::setViewport(Viewport vp)
+	void D3D9RenderSystem::setViewport(const Rect2& vp)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		// ok, it's different, time to set render target and viewport params
-		D3DVIEWPORT9 d3dvp;
-		HRESULT hr;
-
-		// Set render target
-		RenderTargetPtr target = vp.getTarget();
-		setRenderTarget(target);
-
-		const RenderTargetProperties& rtProps = target->getCore()->getProperties();
-
-		setCullingMode( mCullingMode );
-
-		// Set viewport dimensions
-		mViewportLeft = (UINT32)(rtProps.getWidth() * vp.getNormalizedX());
-		mViewportTop = (UINT32)(rtProps.getHeight() * vp.getNormalizedY());
-		mViewportWidth = (UINT32)(rtProps.getWidth() * vp.getNormalizedWidth());
-		mViewportHeight = (UINT32)(rtProps.getHeight() * vp.getNormalizedHeight());
-
-		d3dvp.X = mViewportLeft;
-		d3dvp.Y = mViewportTop;
-		d3dvp.Width = mViewportWidth;
-		d3dvp.Height = mViewportHeight;
-		if (target->requiresTextureFlipping())
-		{
-			// Convert "top-left" to "bottom-left"
-			d3dvp.Y = rtProps.getHeight() - d3dvp.Height - d3dvp.Y;
-		}
-
-		// Z-values from 0.0 to 1.0 (TODO: standardise with OpenGL)
-		d3dvp.MinZ = 0.0f;
-		d3dvp.MaxZ = 1.0f;
-
-		if( FAILED( hr = getActiveD3D9Device()->SetViewport( &d3dvp ) ) )
-			BS_EXCEPT(RenderingAPIException, "Failed to set viewport.");
-
-		// Set sRGB write mode
-		setRenderState(D3DRS_SRGBWRITEENABLE, rtProps.isHwGammaEnabled());
+		mViewportNorm = vp;
+		applyViewport();
 	}
 	}
 
 
 	void D3D9RenderSystem::beginFrame()
 	void D3D9RenderSystem::beginFrame()
@@ -1343,7 +1317,7 @@ namespace BansheeEngine
 		if(mActiveRenderTarget == nullptr)
 		if(mActiveRenderTarget == nullptr)
 			return;
 			return;
 
 
-		const RenderTargetProperties& rtProps = mActiveRenderTarget->getCore()->getProperties();
+		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
 		Rect2I clearRect(0, 0, rtProps.getWidth(), rtProps.getHeight());
 		Rect2I clearRect(0, 0, rtProps.getWidth(), rtProps.getHeight());
 
 
 		clearArea(buffers, color, depth, stencil, clearRect);
 		clearArea(buffers, color, depth, stencil, clearRect);
@@ -1379,7 +1353,7 @@ namespace BansheeEngine
 			flags |= D3DCLEAR_STENCIL;
 			flags |= D3DCLEAR_STENCIL;
 		}
 		}
 
 
-		const RenderTargetProperties& rtProps = mActiveRenderTarget->getCore()->getProperties();
+		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
 
 
 		bool clearEntireTarget = clearRect.width == 0 || clearRect.height == 0;
 		bool clearEntireTarget = clearRect.width == 0 || clearRect.height == 0;
 		clearEntireTarget |= (clearRect.x == 0 && clearRect.y == 0 && clearRect.width == rtProps.getWidth() && clearRect.height == rtProps.getHeight());
 		clearEntireTarget |= (clearRect.x == 0 && clearRect.y == 0 && clearRect.width == rtProps.getWidth() && clearRect.height == rtProps.getHeight());
@@ -1569,7 +1543,7 @@ namespace BansheeEngine
 		return D3DPT_TRIANGLELIST;
 		return D3DPT_TRIANGLELIST;
 	}
 	}
 
 
-	RenderSystemCapabilities* D3D9RenderSystem::updateRenderSystemCapabilities(D3D9RenderWindow* renderWindow)
+	RenderSystemCapabilities* D3D9RenderSystem::updateRenderSystemCapabilities(D3D9RenderWindowCore* renderWindow)
 	{			
 	{			
 		RenderSystemCapabilities* rsc = mCurrentCapabilities;
 		RenderSystemCapabilities* rsc = mCurrentCapabilities;
 		if (rsc == nullptr)
 		if (rsc == nullptr)
@@ -1754,7 +1728,7 @@ namespace BansheeEngine
 			D3DFMT_A16B16G16R16F, D3DFMT_R32F, D3DFMT_G32R32F, 
 			D3DFMT_A16B16G16R16F, D3DFMT_R32F, D3DFMT_G32R32F, 
 			D3DFMT_A32B32G32R32F};
 			D3DFMT_A32B32G32R32F};
 		IDirect3DSurface9* bbSurf;
 		IDirect3DSurface9* bbSurf;
-		renderWindow->getCore()->getCustomAttribute("DDBACKBUFFER", &bbSurf);
+		renderWindow->getCustomAttribute("DDBACKBUFFER", &bbSurf);
 		D3DSURFACE_DESC bbSurfDesc;
 		D3DSURFACE_DESC bbSurfDesc;
 		bbSurf->GetDesc(&bbSurfDesc);
 		bbSurf->GetDesc(&bbSurfDesc);
 
 
@@ -2305,4 +2279,39 @@ namespace BansheeEngine
 		getActiveD3D9Device()->GetSamplerState(static_cast<DWORD>(unit), D3DSAMP_MAXANISOTROPY, &oldVal);
 		getActiveD3D9Device()->GetSamplerState(static_cast<DWORD>(unit), D3DSAMP_MAXANISOTROPY, &oldVal);
 		return oldVal;
 		return oldVal;
 	}
 	}
+
+	void D3D9RenderSystem::applyViewport()
+	{
+		if (mActiveRenderTarget == nullptr)
+			return;
+
+		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
+		D3DVIEWPORT9 d3dvp;
+		HRESULT hr;
+
+		setCullingMode(mCullingMode);
+
+		// Set viewport dimensions
+		mViewportLeft = (UINT32)(rtProps.getWidth() * mViewportNorm.x);
+		mViewportTop = (UINT32)(rtProps.getHeight() * mViewportNorm.y);
+		mViewportWidth = (UINT32)(rtProps.getWidth() * mViewportNorm.width);
+		mViewportHeight = (UINT32)(rtProps.getHeight() * mViewportNorm.height);
+
+		d3dvp.X = mViewportLeft;
+		d3dvp.Y = mViewportTop;
+		d3dvp.Width = mViewportWidth;
+		d3dvp.Height = mViewportHeight;
+		if (rtProps.requiresTextureFlipping())
+		{
+			// Convert "top-left" to "bottom-left"
+			d3dvp.Y = rtProps.getHeight() - d3dvp.Height - d3dvp.Y;
+		}
+
+		// Z-values from 0.0 to 1.0 (TODO: standardise with OpenGL)
+		d3dvp.MinZ = 0.0f;
+		d3dvp.MaxZ = 1.0f;
+
+		if (FAILED(hr = getActiveD3D9Device()->SetViewport(&d3dvp)))
+			BS_EXCEPT(RenderingAPIException, "Failed to set viewport.");
+	}
 }
 }

+ 4 - 15
BansheeD3D9RenderSystem/Source/BsD3D9RenderTexture.cpp

@@ -6,9 +6,8 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	D3D9RenderTextureCore::D3D9RenderTextureCore(D3D9RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
-		:RenderTextureCore(parent, properties, colorSurfaceDesc, depthStencilSurfaceDesc), mDX9ColorSurface(nullptr), 
+	D3D9RenderTextureCore::D3D9RenderTextureCore(const RENDER_TEXTURE_DESC& desc)
+		:RenderTextureCore(desc), mProperties(desc, false), mDX9ColorSurface(nullptr),
 		mDX9DepthStencilSurface(nullptr), mIsBindableToShader(false)
 		mDX9DepthStencilSurface(nullptr), mIsBindableToShader(false)
 	{ }
 	{ }
 
 
@@ -84,19 +83,9 @@ namespace BansheeEngine
 		initializeSurfaces();
 		initializeSurfaces();
 	}
 	}
 
 
-	RenderTargetProperties* D3D9RenderTexture::createProperties() const
+	D3D9RenderTexture::D3D9RenderTexture(const RENDER_TEXTURE_DESC& desc)
+		:RenderTexture(desc), mProperties(desc, false)
 	{
 	{
-		return bs_new<RenderTextureProperties>();
-	}
-
-	SPtr<CoreObjectCore> D3D9RenderTexture::createCore() const
-	{
-		RenderTextureProperties* coreProperties = bs_new<RenderTextureProperties>();
-		RenderTextureProperties* myProperties = static_cast<RenderTextureProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
 
 
-		return bs_shared_ptr<D3D9RenderTextureCore>(const_cast<D3D9RenderTexture*>(this),
-			coreProperties, mColorSurfaceDesc, mDepthStencilSurfaceDesc);
 	}
 	}
 }
 }

+ 109 - 140
BansheeD3D9RenderSystem/Source/BsD3D9RenderWindow.cpp

@@ -12,23 +12,14 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	void D3D9RenderWindowProperties::copyToBuffer(UINT8* buffer) const
+	D3D9RenderWindowProperties::D3D9RenderWindowProperties(const RENDER_WINDOW_DESC& desc)
+		:RenderWindowProperties(desc)
 	{
 	{
-		*(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)
-		: RenderWindowCore(parent, properties), mInstance(instance), mIsDepthBuffered(true), mIsChild(false), mDesc(desc),
+	D3D9RenderWindowCore::D3D9RenderWindowCore(const RENDER_WINDOW_DESC& desc, HINSTANCE instance)
+		: RenderWindowCore(desc), mInstance(instance), mProperties(desc), mIsDepthBuffered(true), mIsChild(false), mHWnd(0),
 		mStyle(0), mWindowedStyle(0), mWindowedStyleEx(0), mDevice(nullptr), mIsExternal(false), mDisplayFrequency(0), mDeviceValid(false)
 		mStyle(0), mWindowedStyle(0), mWindowedStyleEx(0), mDevice(nullptr), mIsExternal(false), mDisplayFrequency(0), mDeviceValid(false)
 	{ }
 	{ }
 
 
@@ -84,7 +75,7 @@ namespace BansheeEngine
 			}
 			}
 		}
 		}
 
 
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		D3D9RenderWindowProperties& props = mProperties;
 		if (!externalHandle)
 		if (!externalHandle)
 		{
 		{
 			MONITORINFO monitorInfo;
 			MONITORINFO monitorInfo;
@@ -151,18 +142,18 @@ namespace BansheeEngine
 				top += monitorInfo.rcWork.top;
 				top += monitorInfo.rcWork.top;
 			}
 			}
 
 
-			props->mWidth = mDesc.videoMode.getWidth();
-			props->mHeight = mDesc.videoMode.getHeight();
-			props->mTop = top;
-			props->mLeft = left;
+			props.mWidth = mDesc.videoMode.getWidth();
+			props.mHeight = mDesc.videoMode.getHeight();
+			props.mTop = top;
+			props.mLeft = left;
 
 
 			DWORD dwStyle = 0;
 			DWORD dwStyle = 0;
 			DWORD dwStyleEx = 0;
 			DWORD dwStyleEx = 0;
 			if (mDesc.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->mLeft = monitorInfo.rcMonitor.left;
+				props.mTop = monitorInfo.rcMonitor.top;
+				props.mLeft = monitorInfo.rcMonitor.left;
 			}
 			}
 			else
 			else
 			{
 			{
@@ -175,23 +166,23 @@ namespace BansheeEngine
 				{
 				{
 					// Calculate window dimensions required
 					// Calculate window dimensions required
 					// to get the requested client area
 					// to get the requested client area
-					SetRect(&rc, 0, 0, props->mWidth, props->mHeight);
+					SetRect(&rc, 0, 0, props.mWidth, props.mHeight);
 					AdjustWindowRect(&rc, dwStyle, false);
 					AdjustWindowRect(&rc, dwStyle, false);
-					props->mWidth = rc.right - rc.left;
-					props->mHeight = rc.bottom - rc.top;
+					props.mWidth = rc.right - rc.left;
+					props.mHeight = rc.bottom - rc.top;
 
 
 					// Clamp window rect to the nearest display monitor.
 					// Clamp window rect to the nearest display monitor.
-					if (props->mLeft < monitorInfo.rcWork.left)
-						props->mLeft = monitorInfo.rcWork.left;
+					if (props.mLeft < monitorInfo.rcWork.left)
+						props.mLeft = monitorInfo.rcWork.left;
 
 
-					if (props->mTop < monitorInfo.rcWork.top)
-						props->mTop = monitorInfo.rcWork.top;
+					if (props.mTop < monitorInfo.rcWork.top)
+						props.mTop = monitorInfo.rcWork.top;
 
 
-					if (static_cast<int>(winWidth) > monitorInfo.rcWork.right - props->mLeft)
-						winWidth = monitorInfo.rcWork.right - props->mLeft;
+					if (static_cast<int>(winWidth) > monitorInfo.rcWork.right - props.mLeft)
+						winWidth = monitorInfo.rcWork.right - props.mLeft;
 
 
-					if (static_cast<int>(winHeight) > monitorInfo.rcWork.bottom - props->mTop)
-						winHeight = monitorInfo.rcWork.bottom - props->mTop;
+					if (static_cast<int>(winHeight) > monitorInfo.rcWork.bottom - props.mTop)
+						winHeight = monitorInfo.rcWork.bottom - props.mTop;
 				}
 				}
 			}
 			}
 
 
@@ -205,37 +196,32 @@ namespace BansheeEngine
 			// Create our main window
 			// Create our main window
 			// Pass pointer to self
 			// Pass pointer to self
 			mIsExternal = false;
 			mIsExternal = false;
-			props->mHWnd = CreateWindowEx(dwStyleEx, "D3D9Wnd", mDesc.title.c_str(), dwStyle,
-				props->mLeft, props->mTop, winWidth, winHeight, parentHWnd, 0, hInst, this);
+			mHWnd = CreateWindowEx(dwStyleEx, "D3D9Wnd", mDesc.title.c_str(), dwStyle,
+				props.mLeft, props.mTop, winWidth, winHeight, parentHWnd, 0, hInst, this);
 			mStyle = dwStyle;
 			mStyle = dwStyle;
 		}
 		}
 		else
 		else
 		{
 		{
-			props->mHWnd = externalHandle;
+			mHWnd = externalHandle;
 			mIsExternal = true;
 			mIsExternal = true;
 		}
 		}
 
 
 		RECT rc;
 		RECT rc;
-		GetWindowRect(props->mHWnd, &rc);
-		props->mTop = rc.top;
-		props->mLeft = rc.left;
+		GetWindowRect(mHWnd, &rc);
+		props.mTop = rc.top;
+		props.mLeft = rc.left;
 
 
-		GetClientRect(props->mHWnd, &rc);
-		props->mWidth = rc.right;
-		props->mHeight = rc.bottom;
+		GetClientRect(mHWnd, &rc);
+		props.mWidth = rc.right;
+		props.mHeight = rc.bottom;
 
 
 		mIsDepthBuffered = mDesc.depthBuffer;
 		mIsDepthBuffered = mDesc.depthBuffer;
-		props->mIsFullScreen = mDesc.fullscreen && !mIsChild;
-		props->mColorDepth = 32;
-		props->mActive = true;
+		props.mIsFullScreen = mDesc.fullscreen && !mIsChild;
+		props.mColorDepth = 32;
+		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;
 	}
 	}
 
 
 	void D3D9RenderWindowCore::destroy()
 	void D3D9RenderWindowCore::destroy()
@@ -246,14 +232,13 @@ namespace BansheeEngine
 			mDevice = nullptr;
 			mDevice = nullptr;
 		}
 		}
 
 
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
-		if (props->mHWnd && !mIsExternal)
+		if (mHWnd && !mIsExternal)
 		{
 		{
-			DestroyWindow(props->mHWnd);
+			DestroyWindow(mHWnd);
 		}
 		}
 
 
-		props->mHWnd = 0;
-		props->mActive = false;
+		mHWnd = 0;
+		mProperties.mActive = false;
 
 
 		markCoreDirty();
 		markCoreDirty();
 
 
@@ -275,14 +260,14 @@ namespace BansheeEngine
 		UINT32 actualMonitorIdx = std::min(monitorIdx, numOutputs - 1);
 		UINT32 actualMonitorIdx = std::min(monitorIdx, numOutputs - 1);
 		const D3D9VideoOutputInfo& outputInfo = static_cast<const D3D9VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
 		const D3D9VideoOutputInfo& outputInfo = static_cast<const D3D9VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
 
 
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
-		bool oldFullscreen = props->mIsFullScreen;
+		D3D9RenderWindowProperties& props = mProperties;
+		bool oldFullscreen = props.mIsFullScreen;
 
 
-		props->mWidth = width;
-		props->mHeight = height;
+		props.mWidth = width;
+		props.mHeight = height;
 		mDisplayFrequency = Math::roundToInt(refreshRate);
 		mDisplayFrequency = Math::roundToInt(refreshRate);
 
 
-		props->mIsFullScreen = true;
+		props.mIsFullScreen = true;
 
 
 		HMONITOR hMonitor = outputInfo.getMonitorHandle();
 		HMONITOR hMonitor = outputInfo.getMonitorHandle();
 		MONITORINFO monitorInfo;
 		MONITORINFO monitorInfo;
@@ -291,8 +276,8 @@ namespace BansheeEngine
 		monitorInfo.cbSize = sizeof(MONITORINFO);
 		monitorInfo.cbSize = sizeof(MONITORINFO);
 		GetMonitorInfo(hMonitor, &monitorInfo);
 		GetMonitorInfo(hMonitor, &monitorInfo);
 
 
-		props->mTop = monitorInfo.rcMonitor.top;
-		props->mLeft = monitorInfo.rcMonitor.left;
+		props.mTop = monitorInfo.rcMonitor.top;
+		props.mLeft = monitorInfo.rcMonitor.left;
 
 
 		// Invalidate device, which resets it
 		// Invalidate device, which resets it
 		mDevice->invalidate(this);
 		mDevice->invalidate(this);
@@ -312,21 +297,21 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		D3D9RenderWindowProperties& props = mProperties;
 
 
-		if (!props->mIsFullScreen)
+		if (!props.mIsFullScreen)
 			return;
 			return;
 
 
-		props->mIsFullScreen = false;
+		props.mIsFullScreen = false;
 		mStyle = mWindowedStyle;
 		mStyle = mWindowedStyle;
-		props->mWidth = width;
-		props->mHeight = height;
+		props.mWidth = width;
+		props.mHeight = height;
 
 
 		unsigned int winWidth, winHeight;
 		unsigned int winWidth, winHeight;
-		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(props->mHWnd, MONITOR_DEFAULTTONEAREST);
+		HMONITOR hMonitor = MonitorFromWindow(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);
@@ -338,9 +323,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(props->mHWnd, GWL_STYLE, mStyle);
-		SetWindowLong(props->mHWnd, GWL_EXSTYLE, mWindowedStyleEx);
-		SetWindowPos(props->mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight,
+		SetWindowLong(mHWnd, GWL_STYLE, mStyle);
+		SetWindowLong(mHWnd, GWL_EXSTYLE, mWindowedStyleEx);
+		SetWindowPos(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);
@@ -353,15 +338,15 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		D3D9RenderWindowProperties& props = mProperties;
 
 
-		props->mHidden = hidden;
+		props.mHidden = hidden;
 		if (!mIsExternal)
 		if (!mIsExternal)
 		{
 		{
 			if (hidden)
 			if (hidden)
-				ShowWindow(props->mHWnd, SW_HIDE);
+				ShowWindow(mHWnd, SW_HIDE);
 			else
 			else
-				ShowWindow(props->mHWnd, SW_SHOWNORMAL);
+				ShowWindow(mHWnd, SW_SHOWNORMAL);
 		}
 		}
 
 
 		markCoreDirty();
 		markCoreDirty();
@@ -371,14 +356,14 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		D3D9RenderWindowProperties& props = mProperties;
 
 
-		if (props->mHWnd && !props->mIsFullScreen)
+		if (mHWnd && !props.mIsFullScreen)
 		{
 		{
-			props->mLeft = left;
-			props->mTop = top;
+			props.mLeft = left;
+			props.mTop = top;
 
 
-			SetWindowPos(props->mHWnd, 0, top, left, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+			SetWindowPos(mHWnd, 0, top, left, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 			markCoreDirty();
 			markCoreDirty();
 		}
 		}
 	}
 	}
@@ -387,17 +372,17 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		D3D9RenderWindowProperties& props = mProperties;
 
 
-		if (props->mHWnd && !props->mIsFullScreen)
+		if (mHWnd && !props.mIsFullScreen)
 		{
 		{
-			props->mWidth = width;
-			props->mHeight = height;
+			props.mWidth = width;
+			props.mHeight = height;
 
 
 			unsigned int winWidth, winHeight;
 			unsigned int winWidth, winHeight;
 			getAdjustedWindowSize(width, height, mStyle, &winWidth, &winHeight);
 			getAdjustedWindowSize(width, height, mStyle, &winWidth, &winHeight);
 
 
-			SetWindowPos(props->mHWnd, 0, 0, 0, winWidth, winHeight,
+			SetWindowPos(mHWnd, 0, 0, 0, winWidth, winHeight,
 				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 
 
 			markCoreDirty();
 			markCoreDirty();
@@ -468,9 +453,9 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		D3D9RenderWindowProperties& props = mProperties;
 
 
-		if (!props->mHWnd || IsIconic(props->mHWnd))
+		if (!mHWnd || IsIconic(mHWnd))
 			return;
 			return;
 	
 	
 		updateWindowRect();
 		updateWindowRect();
@@ -485,7 +470,7 @@ 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);
+		D3D9RenderWindowProperties& props = mProperties;
 
 
 		RECT rc;
 		RECT rc;
 		SetRect(&rc, 0, 0, clientWidth, clientHeight);
 		SetRect(&rc, 0, 0, clientWidth, clientHeight);
@@ -493,7 +478,7 @@ namespace BansheeEngine
 		*winWidth = rc.right - rc.left;
 		*winWidth = rc.right - rc.left;
 		*winHeight = rc.bottom - rc.top;
 		*winHeight = rc.bottom - rc.top;
 
 
-		HMONITOR hMonitor = MonitorFromWindow(props->mHWnd, MONITOR_DEFAULTTONEAREST);
+		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
 
 
 		MONITORINFO monitorInfo;
 		MONITORINFO monitorInfo;
 
 
@@ -512,7 +497,7 @@ namespace BansheeEngine
 	
 	
 	void D3D9RenderWindowCore::_buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const
 	void D3D9RenderWindowCore::_buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const
 	{	
 	{	
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		const D3D9RenderWindowProperties& props = mProperties;
 		IDirect3D9* pD3D = D3D9RenderSystem::getDirect3D9();
 		IDirect3D9* pD3D = D3D9RenderSystem::getDirect3D9();
 		D3DDEVTYPE devType = D3DDEVTYPE_HAL;
 		D3DDEVTYPE devType = D3DDEVTYPE_HAL;
 
 
@@ -520,14 +505,14 @@ namespace BansheeEngine
 			devType = mDevice->getDeviceType();		
 			devType = mDevice->getDeviceType();		
 	
 	
 		ZeroMemory( presentParams, sizeof(D3DPRESENT_PARAMETERS) );
 		ZeroMemory( presentParams, sizeof(D3DPRESENT_PARAMETERS) );
-		presentParams->Windowed = !props->mIsFullScreen;
+		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 = props->mHWnd;
-		presentParams->BackBufferWidth = props->mWidth;
-		presentParams->BackBufferHeight = props->mHeight;
-		presentParams->FullScreen_RefreshRateInHz = props->mIsFullScreen ? mDisplayFrequency : 0;
+		presentParams->hDeviceWindow = 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;					
@@ -535,9 +520,9 @@ namespace BansheeEngine
 		if (presentParams->BackBufferHeight == 0)	
 		if (presentParams->BackBufferHeight == 0)	
 			presentParams->BackBufferHeight = 1;					
 			presentParams->BackBufferHeight = 1;					
 
 
-		if (getProperties().getVSync())
+		if (props.getVSync())
 		{
 		{
-			if (getProperties().isFullScreen())
+			if (props.isFullScreen())
 			{
 			{
 				switch(mVSyncInterval)
 				switch(mVSyncInterval)
 				{
 				{
@@ -609,8 +594,8 @@ namespace BansheeEngine
 		D3DMULTISAMPLE_TYPE multisampleType;
 		D3DMULTISAMPLE_TYPE multisampleType;
 		DWORD multisampleQuality;
 		DWORD multisampleQuality;
 
 
-		rs->determineMultisampleSettings(mDevice->getD3D9Device(), getProperties().getMultisampleCount(), 
-			presentParams->BackBufferFormat, getProperties().isFullScreen(), &multisampleType, &multisampleQuality);
+		rs->determineMultisampleSettings(mDevice->getD3D9Device(), props.getMultisampleCount(),
+			presentParams->BackBufferFormat, props.isFullScreen(), &multisampleType, &multisampleQuality);
 
 
 		presentParams->MultiSampleType = multisampleType;
 		presentParams->MultiSampleType = multisampleType;
 		presentParams->MultiSampleQuality = (multisampleQuality == 0) ? 0 : multisampleQuality;
 		presentParams->MultiSampleQuality = (multisampleQuality == 0) ? 0 : multisampleQuality;
@@ -618,9 +603,7 @@ namespace BansheeEngine
 
 
 	HWND D3D9RenderWindowCore::_getWindowHandle() const
 	HWND D3D9RenderWindowCore::_getWindowHandle() const
 	{
 	{
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
-
-		return props->getHWnd();
+		return mHWnd;
 	}
 	}
 
 
 	IDirect3DDevice9* D3D9RenderWindowCore::_getD3D9Device() const
 	IDirect3DDevice9* D3D9RenderWindowCore::_getD3D9Device() const
@@ -654,39 +637,39 @@ namespace BansheeEngine
 		RECT rc;
 		RECT rc;
 		BOOL result;
 		BOOL result;
 
 
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
+		D3D9RenderWindowProperties& props = mProperties;
 
 
 		// Update top left parameters
 		// Update top left parameters
 		result = GetWindowRect(_getWindowHandle(), &rc);
 		result = GetWindowRect(_getWindowHandle(), &rc);
 		if (result == FALSE)
 		if (result == FALSE)
 		{
 		{
-			props->mTop = 0;
-			props->mLeft = 0;
-			props->mWidth = 0;
-			props->mHeight = 0;
+			props.mTop = 0;
+			props.mLeft = 0;
+			props.mWidth = 0;
+			props.mHeight = 0;
 
 
 			markCoreDirty();
 			markCoreDirty();
 			return;
 			return;
 		}
 		}
 		
 		
-		props->mTop = rc.top;
-		props->mLeft = rc.left;
+		props.mTop = rc.top;
+		props.mLeft = rc.left;
 
 
 		// Width and height represent drawable area only
 		// Width and height represent drawable area only
 		result = GetClientRect(_getWindowHandle(), &rc);
 		result = GetClientRect(_getWindowHandle(), &rc);
 		if (result == FALSE)
 		if (result == FALSE)
 		{
 		{
-			props->mTop = 0;
-			props->mLeft = 0;
-			props->mWidth = 0;
-			props->mHeight = 0;
+			props.mTop = 0;
+			props.mLeft = 0;
+			props.mWidth = 0;
+			props.mHeight = 0;
 
 
 			markCoreDirty();
 			markCoreDirty();
 			return;
 			return;
 		}
 		}
 
 
-		props->mWidth = rc.right - rc.left;
-		props->mHeight = rc.bottom - rc.top;
+		props.mWidth = rc.right - rc.left;
+		props.mHeight = rc.bottom - rc.top;
 
 
 		markCoreDirty();
 		markCoreDirty();
 	}
 	}
@@ -697,25 +680,20 @@ namespace BansheeEngine
 		return mDeviceValid;
 		return mDeviceValid;
 	}
 	}
 
 
-	D3D9RenderWindow::D3D9RenderWindow(HINSTANCE instance)
-		:mInstance(instance)
+	D3D9RenderWindow::D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, HINSTANCE instance)
+		:RenderWindow(desc), mInstance(instance), mProperties(desc)
 	{
 	{
 
 
 	}
 	}
 
 
 	void D3D9RenderWindow::getCustomAttribute(const String& name, void* pData) const
 	void D3D9RenderWindow::getCustomAttribute(const String& name, void* pData) const
 	{
 	{
-		THROW_IF_CORE_THREAD;
-
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
 		if (name == "WINDOW")
 		if (name == "WINDOW")
 		{
 		{
-			HWND *pWnd = (HWND*)pData;
-			*pWnd = props->getHWnd();
+			HWND *pHwnd = (HWND*)pData;
+			*pHwnd = getHWnd();
 			return;
 			return;
 		}
 		}
-
-		RenderWindow::getCustomAttribute(name, pData);
 	}
 	}
 
 
 	Vector2I D3D9RenderWindow::screenToWindowPos(const Vector2I& screenPos) const
 	Vector2I D3D9RenderWindow::screenToWindowPos(const Vector2I& screenPos) const
@@ -724,8 +702,7 @@ namespace BansheeEngine
 		pos.x = screenPos.x;
 		pos.x = screenPos.x;
 		pos.y = screenPos.y;
 		pos.y = screenPos.y;
 
 
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
-		ScreenToClient(props->getHWnd(), &pos);
+		ScreenToClient(getHWnd(), &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
@@ -735,27 +712,19 @@ namespace BansheeEngine
 		pos.x = windowPos.x;
 		pos.x = windowPos.x;
 		pos.y = windowPos.y;
 		pos.y = windowPos.y;
 
 
-		D3D9RenderWindowProperties* props = static_cast<D3D9RenderWindowProperties*>(mProperties);
-		ClientToScreen(props->getHWnd(), &pos);
+		ClientToScreen(getHWnd(), &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
-	SPtr<D3D9RenderWindowCore> D3D9RenderWindow::getCore() const
+	HWND D3D9RenderWindow::getHWnd() const
 	{
 	{
-		return std::static_pointer_cast<D3D9RenderWindowCore>(mCoreSpecific);
+		// HACK: I'm accessing core method from sim thread, which means an invalid handle
+		// could be returned here if requested too soon after initialization.
+		return getCore()->_getWindowHandle();
 	}
 	}
 
 
-	RenderTargetProperties* D3D9RenderWindow::createProperties() const
-	{
-		return bs_new<D3D9RenderWindowProperties>();
-	}
-
-	SPtr<CoreObjectCore> D3D9RenderWindow::createCore() const
+	SPtr<D3D9RenderWindowCore> D3D9RenderWindow::getCore() const
 	{
 	{
-		D3D9RenderWindowProperties* coreProperties = bs_new<D3D9RenderWindowProperties>();
-		D3D9RenderWindowProperties* myProperties = static_cast<D3D9RenderWindowProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
-		return bs_shared_ptr<D3D9RenderWindowCore>(const_cast<D3D9RenderWindow*>(this), coreProperties, mDesc, mInstance);
+		return std::static_pointer_cast<D3D9RenderWindowCore>(mCoreSpecific);
 	}
 	}
 }
 }

+ 16 - 2
BansheeD3D9RenderSystem/Source/BsD3D9RenderWindowManager.cpp

@@ -11,7 +11,7 @@ namespace BansheeEngine
 		assert(mRenderSystem != nullptr);
 		assert(mRenderSystem != nullptr);
 	}
 	}
 
 
-	RenderWindowPtr D3D9RenderWindowManager::createImpl(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow)
+	RenderWindowPtr D3D9RenderWindowManager::createImpl(RENDER_WINDOW_DESC& desc, const RenderWindowPtr& parentWindow)
 	{
 	{
 		if(parentWindow != nullptr)
 		if(parentWindow != nullptr)
 		{
 		{
@@ -20,8 +20,22 @@ namespace BansheeEngine
 			desc.platformSpecific["parentWindowHandle"] = toString((UINT64)hWnd);
 			desc.platformSpecific["parentWindowHandle"] = toString((UINT64)hWnd);
 		}
 		}
 
 
-		D3D9RenderWindow* window = new (bs_alloc<D3D9RenderWindow, PoolAlloc>()) D3D9RenderWindow(mRenderSystem->getInstanceHandle());
+		D3D9RenderWindow* window = new (bs_alloc<D3D9RenderWindow, PoolAlloc>()) D3D9RenderWindow(desc, mRenderSystem->getInstanceHandle());
 
 
 		return RenderWindowPtr(window, &CoreObject::_deleteDelayed<D3D9RenderWindow, PoolAlloc>);
 		return RenderWindowPtr(window, &CoreObject::_deleteDelayed<D3D9RenderWindow, PoolAlloc>);
 	}
 	}
+
+	D3D9RenderWindowCoreManager::D3D9RenderWindowCoreManager(D3D9RenderSystem* renderSystem)
+		:mRenderSystem(renderSystem)
+	{
+		assert(mRenderSystem != nullptr);
+	}
+
+	SPtr<RenderWindowCore> D3D9RenderWindowCoreManager::createInternal(RENDER_WINDOW_DESC& desc)
+	{
+		D3D9RenderWindowCore* window = new (bs_alloc<D3D9RenderWindowCore, GenAlloc>()) D3D9RenderWindowCore(desc, mRenderSystem->getInstanceHandle());
+		windowCreated(window);
+
+		return bs_shared_ptr<D3D9RenderWindowCore, GenAlloc>(window);
+	}
 }
 }

+ 14 - 4
BansheeD3D9RenderSystem/Source/BsD3D9TextureManager.cpp

@@ -22,16 +22,16 @@ namespace BansheeEngine
 		return bs_core_ptr<D3D9Texture, PoolAlloc>(tex);
 		return bs_core_ptr<D3D9Texture, PoolAlloc>(tex);
     }
     }
 
 
-	RenderTexturePtr D3D9TextureManager::createRenderTextureImpl()
+	RenderTexturePtr D3D9TextureManager::createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc)
 	{
 	{
-		D3D9RenderTexture* tex = new (bs_alloc<D3D9RenderTexture, PoolAlloc>()) D3D9RenderTexture();
+		D3D9RenderTexture* tex = new (bs_alloc<D3D9RenderTexture, PoolAlloc>()) D3D9RenderTexture(desc);
 
 
 		return bs_core_ptr<D3D9RenderTexture, PoolAlloc>(tex);
 		return bs_core_ptr<D3D9RenderTexture, PoolAlloc>(tex);
 	}
 	}
 
 
-	MultiRenderTexturePtr D3D9TextureManager::createMultiRenderTextureImpl()
+	MultiRenderTexturePtr D3D9TextureManager::createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc)
 	{
 	{
-		D3D9MultiRenderTexture* tex = new (bs_alloc<D3D9MultiRenderTexture, PoolAlloc>()) D3D9MultiRenderTexture();
+		D3D9MultiRenderTexture* tex = new (bs_alloc<D3D9MultiRenderTexture, PoolAlloc>()) D3D9MultiRenderTexture(desc);
 
 
 		return bs_core_ptr<D3D9MultiRenderTexture, PoolAlloc>(tex);
 		return bs_core_ptr<D3D9MultiRenderTexture, PoolAlloc>(tex);
 	}
 	}
@@ -52,4 +52,14 @@ namespace BansheeEngine
 			return D3D9Mappings::_getClosestSupportedPF(format);
 			return D3D9Mappings::_getClosestSupportedPF(format);
 		}
 		}
 	}
 	}
+
+	SPtr<RenderTextureCore> D3D9TextureCoreManager::createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc)
+	{
+		return bs_shared_ptr<D3D9RenderTextureCore>(desc);
+	}
+
+	SPtr<MultiRenderTextureCore> D3D9TextureCoreManager::createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_DESC& desc)
+	{
+		return bs_shared_ptr<D3D9MultiRenderTextureCore>(desc);
+	}
 }
 }

+ 4 - 2
BansheeEditor/Include/BsScenePicking.h

@@ -55,8 +55,10 @@ namespace BansheeEngine
 		Color encodeIndex(UINT32 index);
 		Color encodeIndex(UINT32 index);
 		UINT32 decodeIndex(Color color);
 		UINT32 decodeIndex(Color color);
 
 
-		void corePickingBegin(const Viewport& viewport, const RenderableSet& renderables, const Vector2I& position, const Vector2I& area);
-		void corePickingEnd(const Viewport& viewport, const Vector2I& position, const Vector2I& area, AsyncOp& asyncOp);
+		void corePickingBegin(const SPtr<RenderTargetCore>& target, const Rect2& viewportArea, const RenderableSet& renderables, 
+			const Vector2I& position, const Vector2I& area);
+		void corePickingEnd(const SPtr<RenderTargetCore>& target, const Rect2& viewportArea, const Vector2I& position, 
+			const Vector2I& area, AsyncOp& asyncOp);
 
 
 		static const float ALPHA_CUTOFF;
 		static const float ALPHA_CUTOFF;
 
 

+ 2 - 1
BansheeEditor/Source/BsEditorWindow.cpp

@@ -2,6 +2,7 @@
 #include "BsEditorWidgetContainer.h"
 #include "BsEditorWidgetContainer.h"
 #include "BsEditorWindowManager.h"
 #include "BsEditorWindowManager.h"
 #include "BsDragAndDropManager.h"
 #include "BsDragAndDropManager.h"
+#include "BsRenderWindow.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
@@ -39,7 +40,7 @@ namespace BansheeEngine
 
 
 		mWidgets->setSize(widgetWidth, widgetHeight);
 		mWidgets->setSize(widgetWidth, widgetHeight);
 
 
-		Platform::setCaptionNonClientAreas(*mRenderWindow.get(), mWidgets->getDraggableAreas());
+		Platform::setCaptionNonClientAreas(*mRenderWindow->getCore().get(), mWidgets->getDraggableAreas());
 	}
 	}
 
 
 	void EditorWindow::widgetRemoved()
 	void EditorWindow::widgetRemoved()

+ 1 - 1
BansheeEditor/Source/BsGUIMenuBar.cpp

@@ -324,6 +324,6 @@ namespace BansheeEngine
 			nonClientAreas.push_back(emptyArea);
 			nonClientAreas.push_back(emptyArea);
 		}
 		}
 
 
-		Platform::setCaptionNonClientAreas(*mParentWindow, nonClientAreas);
+		Platform::setCaptionNonClientAreas(*mParentWindow->getCore(), nonClientAreas);
 	}
 	}
 }
 }

+ 1 - 1
BansheeEditor/Source/BsGUIWindowFrameWidget.cpp

@@ -101,6 +101,6 @@ namespace BansheeEngine
 		nonClientAreas[7].area = Rect2I(x + width - RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH, 
 		nonClientAreas[7].area = Rect2I(x + width - RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH, 
 			RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
 			RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
 
 
-		Platform::setResizeNonClientAreas(*mParentWindow, nonClientAreas);
+		Platform::setResizeNonClientAreas(*mParentWindow->getCore(), nonClientAreas);
 	}
 	}
 }
 }

+ 5 - 3
BansheeEditor/Source/BsGizmoManager.cpp

@@ -713,11 +713,13 @@ namespace BansheeEngine
 
 
 	void GizmoManagerCore::render(const CameraProxy& camera)
 	void GizmoManagerCore::render(const CameraProxy& camera)
 	{
 	{
-		if (camera.viewport.getTarget() != mSceneRenderTarget)
+		SPtr<RenderTargetCore> sceneRenderTarget = mSceneRenderTarget->getCore();
+
+		if (camera.renderTarget != sceneRenderTarget)
 			return;
 			return;
 
 
-		float width = (float)mSceneRenderTarget->getCore()->getProperties().getWidth();
-		float height = (float)mSceneRenderTarget->getCore()->getProperties().getHeight();
+		float width = (float)sceneRenderTarget->getProperties().getWidth();
+		float height = (float)sceneRenderTarget->getProperties().getHeight();
 
 
 		Rect2 normArea = camera.viewport.getNormArea();
 		Rect2 normArea = camera.viewport.getNormArea();
 
 

+ 4 - 3
BansheeEditor/Source/BsHandleDrawManager.cpp

@@ -214,11 +214,12 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		if (camera.viewport.getTarget() != mSceneRenderTarget)
+		SPtr<RenderTargetCore> sceneRenderTarget = mSceneRenderTarget->getCore();
+		if (camera.renderTarget != sceneRenderTarget)
 			return;
 			return;
 
 
-		float width = (float)mSceneRenderTarget->getCore()->getProperties().getWidth();
-		float height = (float)mSceneRenderTarget->getCore()->getProperties().getHeight();
+		float width = (float)sceneRenderTarget->getProperties().getWidth();
+		float height = (float)sceneRenderTarget->getProperties().getHeight();
 
 
 		Rect2 normArea = camera.viewport.getNormArea();
 		Rect2 normArea = camera.viewport.getNormArea();
 
 

+ 17 - 11
BansheeEditor/Source/BsScenePicking.cpp

@@ -189,12 +189,14 @@ namespace BansheeEngine
 
 
 		UINT32 firstGizmoIdx = (UINT32)pickData.size();
 		UINT32 firstGizmoIdx = (UINT32)pickData.size();
 
 
-		Viewport vp = cam->getViewport()->clone();
-		gCoreAccessor().queueCommand(std::bind(&ScenePicking::corePickingBegin, this, vp, std::cref(pickData), position, area));
+		SPtr<RenderTargetCore> target = cam->getViewport()->getTarget()->getCore();
+		gCoreAccessor().queueCommand(std::bind(&ScenePicking::corePickingBegin, this, target, 
+			cam->getViewport()->getNormArea(), std::cref(pickData), position, area));
 
 
 		GizmoManager::instance().renderForPicking(cam, [&](UINT32 inputIdx) { return encodeIndex(firstGizmoIdx + inputIdx); });
 		GizmoManager::instance().renderForPicking(cam, [&](UINT32 inputIdx) { return encodeIndex(firstGizmoIdx + inputIdx); });
 
 
-		AsyncOp op = gCoreAccessor().queueReturnCommand(std::bind(&ScenePicking::corePickingEnd, this, vp, position, area, _1));
+		AsyncOp op = gCoreAccessor().queueReturnCommand(std::bind(&ScenePicking::corePickingEnd, this, target, 
+			cam->getViewport()->getNormArea(), position, area, _1));
 		gCoreAccessor().submitToCoreThread(true);
 		gCoreAccessor().submitToCoreThread(true);
 
 
 		assert(op.hasCompleted());
 		assert(op.hasCompleted());
@@ -224,12 +226,14 @@ namespace BansheeEngine
 		return results;
 		return results;
 	}
 	}
 
 
-	void ScenePicking::corePickingBegin(const Viewport& viewport, const RenderableSet& renderables, const Vector2I& position, const Vector2I& area)
+	void ScenePicking::corePickingBegin(const SPtr<RenderTargetCore>& target, const Rect2& viewportArea, 
+		const RenderableSet& renderables, const Vector2I& position, const Vector2I& area)
 	{
 	{
 		RenderSystem& rs = RenderSystem::instance();
 		RenderSystem& rs = RenderSystem::instance();
 
 
 		rs.beginFrame();
 		rs.beginFrame();
-		rs.setViewport(viewport);
+		rs.setRenderTarget(target);
+		rs.setViewport(viewportArea);
 		rs.clearRenderTarget(FBT_COLOR | FBT_DEPTH | FBT_STENCIL, Color::White);
 		rs.clearRenderTarget(FBT_COLOR | FBT_DEPTH | FBT_STENCIL, Color::White);
 		rs.setScissorRect(position.x, position.y, position.x + area.x, position.y + area.y);
 		rs.setScissorRect(position.x, position.y, position.x + area.x, position.y + area.y);
 
 
@@ -275,17 +279,19 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	void ScenePicking::corePickingEnd(const Viewport& vp, const Vector2I& position, const Vector2I& area, AsyncOp& asyncOp)
+	void ScenePicking::corePickingEnd(const SPtr<RenderTargetCore>& target, const Rect2& viewportArea, const Vector2I& position, 
+		const Vector2I& area, AsyncOp& asyncOp)
 	{
 	{
-		RenderTargetPtr rt = vp.getTarget();
-		if (rt->getCore()->getProperties().isWindow())
+		const RenderTargetProperties& rtProps = target->getProperties();
+
+		if (rtProps.isWindow())
 		{
 		{
 			// TODO: When I do implement this then I will likely want a method in RenderTarget that unifies both render window and render texture readback
 			// TODO: When I do implement this then I will likely want a method in RenderTarget that unifies both render window and render texture readback
 			BS_EXCEPT(NotImplementedException, "Picking is not supported on render windows as framebuffer readback methods aren't implemented");
 			BS_EXCEPT(NotImplementedException, "Picking is not supported on render windows as framebuffer readback methods aren't implemented");
 		}
 		}
 
 
-		RenderTexturePtr rtt = std::static_pointer_cast<RenderTexture>(rt);
-		TexturePtr outputTexture = rtt->getBindableColorTexture().getInternalPtr();
+		SPtr<RenderTextureCore> rtt = std::static_pointer_cast<RenderTextureCore>(target);
+		TexturePtr outputTexture = rtt->getBindableColorTexture();
 
 
 		if (position.x < 0 || position.x >= (INT32)outputTexture->getWidth() ||
 		if (position.x < 0 || position.x >= (INT32)outputTexture->getWidth() ||
 			position.y < 0 || position.y >= (INT32)outputTexture->getHeight())
 			position.y < 0 || position.y >= (INT32)outputTexture->getHeight())
@@ -309,7 +315,7 @@ namespace BansheeEngine
 		UINT32 maxWidth = std::min((UINT32)(position.x + area.x), outputPixelData->getWidth());
 		UINT32 maxWidth = std::min((UINT32)(position.x + area.x), outputPixelData->getWidth());
 		UINT32 maxHeight = std::min((UINT32)(position.y + area.y), outputPixelData->getHeight());
 		UINT32 maxHeight = std::min((UINT32)(position.y + area.y), outputPixelData->getHeight());
 
 
-		if (rt->requiresTextureFlipping())
+		if (rtProps.requiresTextureFlipping())
 		{
 		{
 			UINT32 vertOffset = outputPixelData->getHeight() - 1;
 			UINT32 vertOffset = outputPixelData->getHeight() - 1;
 
 

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

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

+ 1 - 1
BansheeEngine/Include/BsGUIManager.h

@@ -272,7 +272,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Called when the mouse leaves the specified window.
 		 * @brief	Called when the mouse leaves the specified window.
 		 */
 		 */
-		void onMouseLeftWindow(RenderWindow* win);
+		void onMouseLeftWindow(RenderWindow& win);
 
 
 		/**
 		/**
 		 * @brief	Converts pointer buttons to mouse buttons.
 		 * @brief	Converts pointer buttons to mouse buttons.

+ 1 - 0
BansheeEngine/Source/BsCameraHandler.cpp

@@ -682,6 +682,7 @@ namespace BansheeEngine
 		proxy->projMatrix = getProjectionMatrixRS();
 		proxy->projMatrix = getProjectionMatrixRS();
 		proxy->viewMatrix = getViewMatrix();
 		proxy->viewMatrix = getViewMatrix();
 		proxy->worldMatrix.setTRS(mPosition, mRotation, Vector3::ONE);
 		proxy->worldMatrix.setTRS(mPosition, mRotation, Vector3::ONE);
+		proxy->renderTarget = mViewport->getTarget()->getCore();
 		proxy->viewport = mViewport->clone();
 		proxy->viewport = mViewport->clone();
 		proxy->frustum = getFrustum();
 		proxy->frustum = getFrustum();
 		proxy->ignoreSceneRenderables = mIgnoreSceneRenderables;
 		proxy->ignoreSceneRenderables = mIgnoreSceneRenderables;

+ 3 - 4
BansheeEngine/Source/BsGUIManager.cpp

@@ -81,8 +81,7 @@ namespace BansheeEngine
 
 
 		mWindowGainedFocusConn = RenderWindowManager::instance().onFocusGained.connect(std::bind(&GUIManager::onWindowFocusGained, this, _1));
 		mWindowGainedFocusConn = RenderWindowManager::instance().onFocusGained.connect(std::bind(&GUIManager::onWindowFocusGained, this, _1));
 		mWindowLostFocusConn = RenderWindowManager::instance().onFocusLost.connect(std::bind(&GUIManager::onWindowFocusLost, this, _1));
 		mWindowLostFocusConn = RenderWindowManager::instance().onFocusLost.connect(std::bind(&GUIManager::onWindowFocusLost, this, _1));
-
-		mMouseLeftWindowConn = Platform::onMouseLeftWindow.connect(std::bind(&GUIManager::onMouseLeftWindow, this, _1));
+		mMouseLeftWindowConn = RenderWindowManager::instance().onMouseLeftWindow.connect(std::bind(&GUIManager::onMouseLeftWindow, this, _1));
 
 
 		mInputCaret = bs_new<GUIInputCaret, PoolAlloc>();
 		mInputCaret = bs_new<GUIInputCaret, PoolAlloc>();
 		mInputSelection = bs_new<GUIInputSelection, PoolAlloc>();
 		mInputSelection = bs_new<GUIInputSelection, PoolAlloc>();
@@ -1300,7 +1299,7 @@ namespace BansheeEngine
 
 
 	// We stop getting mouse move events once it leaves the window, so make sure
 	// We stop getting mouse move events once it leaves the window, so make sure
 	// nothing stays in hover state
 	// nothing stays in hover state
-	void GUIManager::onMouseLeftWindow(RenderWindow* win)
+	void GUIManager::onMouseLeftWindow(RenderWindow& win)
 	{
 	{
 		bool buttonStates[3];
 		bool buttonStates[3];
 		buttonStates[0] = false;
 		buttonStates[0] = false;
@@ -1314,7 +1313,7 @@ namespace BansheeEngine
 			GUIElement* element = elementInfo.element;
 			GUIElement* element = elementInfo.element;
 			GUIWidget* widget = elementInfo.widget;
 			GUIWidget* widget = elementInfo.widget;
 
 
-			if(widget->getTarget()->getTarget().get() != win)
+			if(widget->getTarget()->getTarget().get() != &win)
 			{
 			{
 				mNewElementsUnderPointer.push_back(elementInfo);
 				mNewElementsUnderPointer.push_back(elementInfo);
 				continue;
 				continue;

+ 1 - 1
BansheeEngine/Source/BsGUIRenderTexture.cpp

@@ -44,7 +44,7 @@ namespace BansheeEngine
 
 
 		if (mSourceTexture != nullptr)
 		if (mSourceTexture != nullptr)
 		{
 		{
-			if (mSourceTexture->requiresTextureFlipping())
+			if (mSourceTexture->getProperties().requiresTextureFlipping())
 			{
 			{
 				mDesc.uvOffset = Vector2(0.0f, 1.0f);
 				mDesc.uvOffset = Vector2(0.0f, 1.0f);
 				mDesc.uvScale = Vector2(1.0f, -1.0f);
 				mDesc.uvScale = Vector2(1.0f, -1.0f);

+ 2 - 2
BansheeGLRenderSystem/Include/BsGLHardwareBufferManager.h

@@ -41,12 +41,12 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc HardwareBufferCoreManager::createVertexBufferImpl
 		 * @copydoc HardwareBufferCoreManager::createVertexBufferImpl
 		 */
 		 */
-        SPtr<VertexBufferCore> createVertexBufferImpl(UINT32 vertexSize, 
+        SPtr<VertexBufferCore> createVertexBufferInternal(UINT32 vertexSize, 
             UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
             UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
 
 
 		/**
 		/**
 		 * @copydoc HardwareBufferCoreManager::createIndexBufferImpl
 		 * @copydoc HardwareBufferCoreManager::createIndexBufferImpl
 		 */
 		 */
-        SPtr<IndexBufferCore> createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+        SPtr<IndexBufferCore> createIndexBufferInternal(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
     };
     };
 }
 }

+ 16 - 17
BansheeGLRenderSystem/Include/BsGLMultiRenderTexture.h

@@ -16,7 +16,7 @@ namespace BansheeEngine
 	class BS_RSGL_EXPORT GLMultiRenderTextureCore : public MultiRenderTextureCore
 	class BS_RSGL_EXPORT GLMultiRenderTextureCore : public MultiRenderTextureCore
 	{
 	{
 	public:
 	public:
-		GLMultiRenderTextureCore(GLMultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc);
+		GLMultiRenderTextureCore(const MULTI_RENDER_TEXTURE_DESC& desc);
 		virtual ~GLMultiRenderTextureCore();
 		virtual ~GLMultiRenderTextureCore();
 
 
 		/**
 		/**
@@ -38,36 +38,35 @@ namespace BansheeEngine
 
 
 	private:
 	private:
 		GLFrameBufferObject* mFB;
 		GLFrameBufferObject* mFB;
+
+		/**
+		 * @copydoc	MultiRenderTextureCore::getProperties
+		 */
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
+
+		MultiRenderTextureProperties mProperties;
 	};
 	};
 
 
 	/**
 	/**
-	 * @brief	OpenGL implementation of a render texture with multiple color surfaces.
-	 *
-	 * @note	Sim thread only.
-	 */
+	* @brief	OpenGL implementation of a render texture with multiple color surfaces.
+	*
+	* @note	Sim thread only.
+	*/
 	class BS_RSGL_EXPORT GLMultiRenderTexture : public MultiRenderTexture
 	class BS_RSGL_EXPORT GLMultiRenderTexture : public MultiRenderTexture
 	{
 	{
 	public:
 	public:
 		virtual ~GLMultiRenderTexture() { }
 		virtual ~GLMultiRenderTexture() { }
 
 
-		/**
-		 * @copydoc	MultiRenderTexture::requiresTextureFlipping
-		 */
-		bool requiresTextureFlipping() const { return true; }
-
 	protected:
 	protected:
 		friend class GLTextureManager;
 		friend class GLTextureManager;
 
 
-		GLMultiRenderTexture() { }
+		GLMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
 
 
 		/**
 		/**
-		 * @copydoc	MultiRenderTexture::createProperties
+		 * @copydoc	MultiRenderTexture::getProperties
 		 */
 		 */
-		virtual RenderTargetProperties* createProperties() const;
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
 
 
-		/**
-		 * @copydoc	RenderTexture::createCore
-		 */
-		virtual SPtr<CoreObjectCore> createCore() const;
+		MultiRenderTextureProperties mProperties;
 	};
 	};
 }
 }

+ 10 - 2
BansheeGLRenderSystem/Include/BsGLRenderSystem.h

@@ -31,7 +31,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderSystem::setRenderTarget()
 		 * @copydoc RenderSystem::setRenderTarget()
 		 */
 		 */
-        void setRenderTarget(RenderTargetPtr target);
+		void setRenderTarget(const SPtr<RenderTargetCore>& target);
 
 
         /**
         /**
 		 * @copydoc RenderSystem::setVertexBuffers()
 		 * @copydoc RenderSystem::setVertexBuffers()
@@ -92,7 +92,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderSystem::setViewport()
 		 * @copydoc RenderSystem::setViewport()
 		 */
 		 */
-		void setViewport(Viewport vp);
+		void setViewport(const Rect2& area);
 
 
 		/**
 		/**
 		 * @copydoc RenderSystem::bindGpuProgram()
 		 * @copydoc RenderSystem::bindGpuProgram()
@@ -497,6 +497,13 @@ namespace BansheeEngine
 		/* 							UTILITY METHODS                      		*/
 		/* 							UTILITY METHODS                      		*/
 		/************************************************************************/
 		/************************************************************************/
 
 
+		/**
+		 * @brief	Recalculates actual viewport dimensions based on currently 
+		 *			set viewport normalized dimensions and render target and applies
+		 *			them for further rendering.
+		 */
+		void applyViewport();
+
 		/**
 		/**
 		 * @brief	Converts the provided matrix m into a representation usable by OpenGL.
 		 * @brief	Converts the provided matrix m into a representation usable by OpenGL.
 		 */
 		 */
@@ -519,6 +526,7 @@ namespace BansheeEngine
 		bool checkForErrors() const;
 		bool checkForErrors() const;
 
 
 	private:
 	private:
+		Rect2 mViewportNorm;
 		UINT32 mScissorTop, mScissorBottom, mScissorLeft, mScissorRight;
 		UINT32 mScissorTop, mScissorBottom, mScissorLeft, mScissorRight;
 		UINT32 mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight;
 		UINT32 mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight;
 
 

+ 31 - 35
BansheeGLRenderSystem/Include/BsGLRenderTexture.h

@@ -19,9 +19,7 @@ namespace BansheeEngine
     class BS_RSGL_EXPORT GLRenderTextureCore : public RenderTextureCore
     class BS_RSGL_EXPORT GLRenderTextureCore : public RenderTextureCore
     {
     {
 	public:
 	public:
-		GLRenderTextureCore(GLRenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-			const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
-
+		GLRenderTextureCore(const RENDER_TEXTURE_DESC& desc);
 		virtual ~GLRenderTextureCore();
 		virtual ~GLRenderTextureCore();
 
 
 		/**
 		/**
@@ -33,48 +31,23 @@ namespace BansheeEngine
 		friend class GLRenderTexture;
 		friend class GLRenderTexture;
 
 
 		/**
 		/**
-		 * @copydoc	CoreObjectCore::initialize
+		 * @copydoc	RenderTextureCore::initialize
 		 */
 		 */
 		virtual void initialize();
 		virtual void initialize();
 
 
 		/**
 		/**
-		 * @copydoc	CoreObjectCore::destroy
+		 * @copydoc	RenderTextureCore::destroy
 		 */
 		 */
 		virtual void destroy();
 		virtual void destroy();
 
 
-		GLFrameBufferObject* mFB;
-    };
-
-	/**
-	 * @brief	OpenGL implementation of a render texture.
-	 *
-	 * @note	Sim thread only.
-	 */
-	class BS_RSGL_EXPORT GLRenderTexture : public RenderTexture
-	{
-	public:
-		virtual ~GLRenderTexture() { }
-
-	protected:
-		friend class GLTextureManager;
-
-		GLRenderTexture() { }
-
 		/**
 		/**
-		 * @copydoc	RenderTexture::requiresTextureFlipping
+		 * @copydoc	RenderTextureCore::getProperties
 		 */
 		 */
-		bool requiresTextureFlipping() const { return true; }
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
 
 
-		/**
-		 * @copydoc	RenderTexture::createProperties
-		 */
-		virtual RenderTargetProperties* createProperties() const;
-
-		/**
-		 * @copydoc	RenderTexture::createCore
-		 */
-		virtual SPtr<CoreObjectCore> createCore() const;
-	};
+		RenderTextureProperties mProperties;
+		GLFrameBufferObject* mFB;
+    };
 
 
     /**
     /**
      * @brief	Manager that handles valid render texture formats.
      * @brief	Manager that handles valid render texture formats.
@@ -152,4 +125,27 @@ namespace BansheeEngine
 		GLuint mBlitReadFBO;
 		GLuint mBlitReadFBO;
 		GLuint mBlitWriteFBO;
 		GLuint mBlitWriteFBO;
     };
     };
+
+	/**
+	 * @brief	DirectX 9 implementation of a render texture.
+	 *
+	 * @note	Sim thread only.
+	 */
+	class GLRenderTexture : public RenderTexture
+	{
+	public:
+		virtual ~GLRenderTexture() { }
+
+	protected:
+		friend class GLTextureManager;
+
+		GLRenderTexture(const RENDER_TEXTURE_DESC& desc);
+
+		/**
+		 * @copydoc	RenderTexture::getProperties
+		 */
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
+
+		RenderTextureProperties mProperties;
+	};
 }
 }

+ 19 - 1
BansheeGLRenderSystem/Include/BsGLRenderWindowManager.h

@@ -17,7 +17,25 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderWindowManager::createImpl()
 		 * @copydoc RenderWindowManager::createImpl()
 		 */
 		 */
-		RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow);
+		RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, const RenderWindowPtr& parentWindow);
+
+	private:
+		GLRenderSystem* mRenderSystem;
+	};
+
+	/**
+	 * @brief	Manager that handles window creation for OpenGL.
+	 */
+	class BS_RSGL_EXPORT GLRenderWindowCoreManager : public RenderWindowCoreManager
+	{
+	public:
+		GLRenderWindowCoreManager(GLRenderSystem* renderSystem);
+
+	protected:
+		/**
+		 * @copydoc RenderWindowCoreManager::createInternal
+		 */
+		SPtr<RenderWindowCore> createInternal(RENDER_WINDOW_DESC& desc);
 
 
 	private:
 	private:
 		GLRenderSystem* mRenderSystem;
 		GLRenderSystem* mRenderSystem;

+ 11 - 0
BansheeGLRenderSystem/Include/BsGLSupport.h

@@ -27,6 +27,17 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual RenderWindowPtr newWindow(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow) = 0;
 		virtual RenderWindowPtr newWindow(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow) = 0;
 
 
+		/**
+		 * @brief	Creates a new render window using the specified descriptor.
+		 *
+		 * @param	desc			Description of a render window to create.
+		 * @param	parentWindow	Optional parent window if the window shouldn't be a main window. First
+		 *							created window cannot have a parent.
+		 *
+		 * @param	Returns newly created window.
+		 */
+		virtual SPtr<RenderWindowCore> newWindowCore(RENDER_WINDOW_DESC& desc) = 0;
+
 		/**
 		/**
 		 * @brief	Called when OpenGL is being initialized.
 		 * @brief	Called when OpenGL is being initialized.
 		 */
 		 */

+ 24 - 2
BansheeGLRenderSystem/Include/BsGLTextureManager.h

@@ -31,13 +31,35 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc	TextureManager::createRenderTextureImpl
 		 * @copydoc	TextureManager::createRenderTextureImpl
 		 */
 		 */
-		RenderTexturePtr createRenderTextureImpl();
+		RenderTexturePtr createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc);
 
 
 		/**
 		/**
 		 * @copydoc	TextureManager::createMultiRenderTextureImpl
 		 * @copydoc	TextureManager::createMultiRenderTextureImpl
 		 */
 		 */
-		MultiRenderTexturePtr createMultiRenderTextureImpl();
+		MultiRenderTexturePtr createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc);
 
 
         GLSupport& mGLSupport;
         GLSupport& mGLSupport;
     };
     };
+
+	/**
+	 * @brief	Handles creation of OpenGL textures.
+	 */
+	class BS_RSGL_EXPORT GLTextureCoreManager : public TextureCoreManager
+	{
+	public:
+		GLTextureCoreManager(GLSupport& support);
+
+	protected:		
+		/**
+		 * @copydoc	TextureCoreManager::createRenderTextureInternal
+		 */
+		SPtr<RenderTextureCore> createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc);
+
+		/**
+		 * @copydoc	TextureCoreManager::createMultiRenderTextureInternal
+		 */
+		SPtr<MultiRenderTextureCore> createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_DESC& desc);
+
+		GLSupport& mGLSupport;
+	};
 }
 }

+ 6 - 1
BansheeGLRenderSystem/Include/BsWin32GLSupport.h

@@ -20,6 +20,11 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual RenderWindowPtr newWindow(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow);
 		virtual RenderWindowPtr newWindow(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow);
 
 
+		/**
+		 * @copydoc	GLSupport::newWindowCore
+		 */
+		virtual SPtr<RenderWindowCore> newWindowCore(RENDER_WINDOW_DESC& desc);
+
 		/**
 		/**
 		 * @copydoc	GLSupport::start
 		 * @copydoc	GLSupport::start
 		 */
 		 */
@@ -80,7 +85,7 @@ namespace BansheeEngine
 		static LRESULT CALLBACK dummyWndProc(HWND hwnd, UINT umsg, WPARAM wp, LPARAM lp);
 		static LRESULT CALLBACK dummyWndProc(HWND hwnd, UINT umsg, WPARAM wp, LPARAM lp);
 
 
 		Vector<DEVMODE> mDevModes;
 		Vector<DEVMODE> mDevModes;
-		Win32Window *mInitialWindow;
+		Win32WindowCore *mInitialWindow;
 		Vector<int> mMultisampleLevels;
 		Vector<int> mMultisampleLevels;
 		bool mHasPixelFormatARB;
 		bool mHasPixelFormatARB;
         bool mHasMultisample;
         bool mHasMultisample;

+ 1 - 0
BansheeGLRenderSystem/Include/BsWin32Prerequisites.h

@@ -8,6 +8,7 @@ namespace BansheeEngine
     class Win32GLSupport;
     class Win32GLSupport;
     class Win32Window;
     class Win32Window;
     class Win32Context;
     class Win32Context;
+	class Win32WindowCore;
 
 
 	/**
 	/**
 	 * @brief	Retrieves last Windows API error and returns a description of it.
 	 * @brief	Retrieves last Windows API error and returns a description of it.

+ 22 - 36
BansheeGLRenderSystem/Include/BsWin32Window.h

@@ -13,33 +13,12 @@ namespace BansheeEngine
 	class BS_RSGL_EXPORT Win32RenderWindowProperties : public RenderWindowProperties
 	class BS_RSGL_EXPORT Win32RenderWindowProperties : public RenderWindowProperties
 	{
 	{
 	public:
 	public:
+		Win32RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
 		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;
 	};
 	};
 
 
 	/**
 	/**
@@ -50,7 +29,7 @@ namespace BansheeEngine
     class BS_RSGL_EXPORT Win32WindowCore : public RenderWindowCore
     class BS_RSGL_EXPORT Win32WindowCore : public RenderWindowCore
     {
     {
     public:
     public:
-		Win32WindowCore(Win32Window* parent, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, Win32GLSupport &glsupport);
+		Win32WindowCore(const RENDER_WINDOW_DESC& desc, Win32GLSupport &glsupport);
 		~Win32WindowCore();
 		~Win32WindowCore();
 
 
 		/**
 		/**
@@ -113,6 +92,11 @@ namespace BansheeEngine
 		 */
 		 */
 		HDC _getHDC() const { return mHDC; }
 		HDC _getHDC() const { return mHDC; }
 
 
+		/**
+		 * @brief	Returns internal window handle.
+		 */
+		HWND _getHWnd() const { return mHWnd; }
+
 	protected:
 	protected:
 		friend class Win32GLSupport;
 		friend class Win32GLSupport;
 
 
@@ -131,6 +115,11 @@ namespace BansheeEngine
 		 */
 		 */
 		void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight, UINT32* winWidth, UINT32* winHeight);
 		void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight, UINT32* winWidth, UINT32* winHeight);
 
 
+		/**
+		 * @copydoc	RenderWindowCore::getProperties
+		 */
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
+
 	protected:
 	protected:
 		Win32GLSupport &mGLSupport;
 		Win32GLSupport &mGLSupport;
 		HDC	mHDC;
 		HDC	mHDC;
@@ -141,8 +130,9 @@ namespace BansheeEngine
 		char* mDeviceName;
 		char* mDeviceName;
 		bool mIsExternalGLControl;
 		bool mIsExternalGLControl;
 		int mDisplayFrequency;
 		int mDisplayFrequency;
+		HWND mHWnd;
 		Win32Context *mContext;
 		Win32Context *mContext;
-		RENDER_WINDOW_DESC mDesc;
+		Win32RenderWindowProperties mProperties;
     };
     };
 
 
 	/**
 	/**
@@ -156,9 +146,9 @@ namespace BansheeEngine
 		~Win32Window() { }
 		~Win32Window() { }
 
 
 		/**
 		/**
-		 * @copydoc RenderWindow::requiresTextureFlipping
+		 * @copydoc RenderWindow::screenToWindowPos
 		 */
 		 */
-		bool requiresTextureFlipping() const { return false; }
+		void getCustomAttribute(const String& name, void* pData) const;
 
 
 		/**
 		/**
 		 * @copydoc RenderWindow::screenToWindowPos
 		 * @copydoc RenderWindow::screenToWindowPos
@@ -170,11 +160,6 @@ namespace BansheeEngine
 		 */
 		 */
 		Vector2I windowToScreenPos(const Vector2I& windowPos) const;
 		Vector2I windowToScreenPos(const Vector2I& windowPos) const;
 
 
-		/**
-		 * @copydoc RenderWindow::getCustomAttribute
-		 */
-		void getCustomAttribute(const String& name, void* pData) const;
-
 		/**
 		/**
 		 * @copydoc	RenderWindow::getCore
 		 * @copydoc	RenderWindow::getCore
 		 */
 		 */
@@ -185,19 +170,20 @@ namespace BansheeEngine
 		friend class Win32GLSupport;
 		friend class Win32GLSupport;
 		friend class Win32WindowCore;
 		friend class Win32WindowCore;
 
 
-		Win32Window(Win32GLSupport& glsupport);
+		Win32Window(const RENDER_WINDOW_DESC& desc, Win32GLSupport& glsupport);
 
 
 		/**
 		/**
-		 * @copydoc	RenderWindow::createProperties
+		 * @copydoc	RenderWindowCore::getProperties
 		 */
 		 */
-		virtual RenderTargetProperties* createProperties() const;
+		const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
 
 
 		/**
 		/**
-		 * @copydoc	RenderWindow::createCore
+		 * @brief	Retrieves internal window handle.
 		 */
 		 */
-		virtual SPtr<CoreObjectCore> createCore() const;
+		HWND getHWnd() const;
 
 
 	private:
 	private:
 		Win32GLSupport& mGLSupport;
 		Win32GLSupport& mGLSupport;
+		Win32RenderWindowProperties mProperties;
 	};
 	};
 }
 }

+ 2 - 2
BansheeGLRenderSystem/Source/BsGLHardwareBufferManager.cpp

@@ -20,12 +20,12 @@ namespace BansheeEngine
 		return bs_core_ptr<GLGpuBuffer, PoolAlloc>(new (bs_alloc<GLGpuBuffer, PoolAlloc>()) GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 		return bs_core_ptr<GLGpuBuffer, PoolAlloc>(new (bs_alloc<GLGpuBuffer, PoolAlloc>()) GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 	}
 	}
 
 
-	SPtr<VertexBufferCore> GLHardwareBufferCoreManager::createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
+	SPtr<VertexBufferCore> GLHardwareBufferCoreManager::createVertexBufferInternal(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 	{
 	{
 		return bs_shared_ptr<GLVertexBufferCore>(vertexSize, numVerts, usage, streamOut);
 		return bs_shared_ptr<GLVertexBufferCore>(vertexSize, numVerts, usage, streamOut);
 	}
 	}
 
 
-	SPtr<IndexBufferCore> GLHardwareBufferCoreManager::createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+	SPtr<IndexBufferCore> GLHardwareBufferCoreManager::createIndexBufferInternal(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
 	{
 	{
 		return bs_shared_ptr<GLIndexBufferCore>(itype, numIndexes, usage);
 		return bs_shared_ptr<GLIndexBufferCore>(itype, numIndexes, usage);
 	}
 	}

+ 5 - 17
BansheeGLRenderSystem/Source/BsGLMultiRenderTexture.cpp

@@ -3,8 +3,8 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	GLMultiRenderTextureCore::GLMultiRenderTextureCore(GLMultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
-		:MultiRenderTextureCore(parent, properties, desc), mFB(nullptr)
+	GLMultiRenderTextureCore::GLMultiRenderTextureCore(const MULTI_RENDER_TEXTURE_DESC& desc)
+		:MultiRenderTextureCore(desc), mProperties(desc), mFB(nullptr)
 	{ }
 	{ }
 
 
 	GLMultiRenderTextureCore::~GLMultiRenderTextureCore()
 	GLMultiRenderTextureCore::~GLMultiRenderTextureCore()
@@ -91,19 +91,7 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	RenderTargetProperties* GLMultiRenderTexture::createProperties() const
-	{
-		return bs_new<MultiRenderTextureProperties>();
-	}
-
-	SPtr<CoreObjectCore> GLMultiRenderTexture::createCore() const
-	{
-		MultiRenderTextureProperties* coreProperties = bs_new<MultiRenderTextureProperties>();
-		MultiRenderTextureProperties* myProperties = static_cast<MultiRenderTextureProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
-
-		return bs_shared_ptr<GLMultiRenderTextureCore>(const_cast<GLMultiRenderTexture*>(this),
-			coreProperties, mDesc);
-	}
+	GLMultiRenderTexture::GLMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
+		:MultiRenderTexture(desc), mProperties(desc)
+	{ }
 }
 }

+ 44 - 32
BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp

@@ -60,7 +60,8 @@ namespace BansheeEngine
 		mDomainUBOffset(0),
 		mDomainUBOffset(0),
 		mComputeUBOffset(0),
 		mComputeUBOffset(0),
 		mDrawCallInProgress(false),
 		mDrawCallInProgress(false),
-		mCurrentDrawOperation(DOT_TRIANGLE_LIST)
+		mCurrentDrawOperation(DOT_TRIANGLE_LIST),
+		mViewportNorm(0.0f, 0.0f, 1.0f, 1.0f)
 	{
 	{
 		// Get our GLSupport
 		// Get our GLSupport
 		mGLSupport = BansheeEngine::getGLSupport();
 		mGLSupport = BansheeEngine::getGLSupport();
@@ -106,6 +107,7 @@ namespace BansheeEngine
 		mVideoModeInfo = mGLSupport->getVideoModeInfo();
 		mVideoModeInfo = mGLSupport->getVideoModeInfo();
 
 
 		RenderWindowManager::startUp<GLRenderWindowManager>(this);
 		RenderWindowManager::startUp<GLRenderWindowManager>(this);
+		RenderWindowCoreManager::startUp<GLRenderWindowCoreManager>(this);
 
 
 		RenderStateManager::startUp();
 		RenderStateManager::startUp();
 
 
@@ -185,8 +187,10 @@ namespace BansheeEngine
 
 
 		mGLSupport->stop();
 		mGLSupport->stop();
 
 
+		TextureCoreManager::shutDown();
 		TextureManager::shutDown();
 		TextureManager::shutDown();
 		QueryManager::shutDown();
 		QueryManager::shutDown();
+		RenderWindowCoreManager::shutDown();
 		RenderWindowManager::shutDown();
 		RenderWindowManager::shutDown();
 		RenderStateManager::shutDown();
 		RenderStateManager::shutDown();
 		GLVertexArrayObjectManager::shutDown(); // Note: Needs to be after QueryManager shutdown as some resources might be waiting for queries to complete
 		GLVertexArrayObjectManager::shutDown(); // Note: Needs to be after QueryManager shutdown as some resources might be waiting for queries to complete
@@ -557,35 +561,15 @@ namespace BansheeEngine
 		BS_INC_RENDER_STAT(NumDepthStencilStateChanges);
 		BS_INC_RENDER_STAT(NumDepthStencilStateChanges);
 	}
 	}
 
 
-	void GLRenderSystem::setViewport(Viewport vp)
+	void GLRenderSystem::setViewport(const Rect2& area)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		RenderTargetPtr target;
-		target = vp.getTarget();
-		setRenderTarget(target);
-
-		const RenderTargetProperties& rtProps = target->getCore()->getProperties();
-
-		// Calculate the "lower-left" corner of the viewport
-		mViewportLeft = (UINT32)(rtProps.getWidth() * vp.getNormalizedX());
-		mViewportTop = (UINT32)(rtProps.getHeight() * vp.getNormalizedY());
-		mViewportWidth = (UINT32)(rtProps.getWidth() * vp.getNormalizedWidth());
-		mViewportHeight = (UINT32)(rtProps.getHeight() * vp.getNormalizedHeight());
-
-		if (target->requiresTextureFlipping())
-		{
-			// Convert "upper-left" corner to "lower-left"
-			mViewportTop = target->getCore()->getProperties().getHeight() - (mViewportTop + mViewportHeight) - 1;
-		}
-
-		glViewport(mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight);
-
-		// Configure the viewport clipping
-		glScissor(mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight);
+		mViewportNorm = area;
+		applyViewport();
 	}
 	}
 
 
-	void GLRenderSystem::setRenderTarget(RenderTargetPtr target)
+	void GLRenderSystem::setRenderTarget(const SPtr<RenderTargetCore>& target)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
@@ -593,14 +577,14 @@ namespace BansheeEngine
 
 
 		// Switch context if different from current one
 		// Switch context if different from current one
 		GLContext *newContext = 0;
 		GLContext *newContext = 0;
-		target->getCore()->getCustomAttribute("GLCONTEXT", &newContext);
+		target->getCustomAttribute("GLCONTEXT", &newContext);
 		if(newContext && mCurrentContext != newContext) 
 		if(newContext && mCurrentContext != newContext) 
 		{
 		{
 			switchContext(newContext);
 			switchContext(newContext);
 		}
 		}
 
 
 		GLFrameBufferObject *fbo = 0;
 		GLFrameBufferObject *fbo = 0;
-		target->getCore()->getCustomAttribute("FBO", &fbo);
+		target->getCustomAttribute("FBO", &fbo);
 		if(fbo)
 		if(fbo)
 			fbo->bind();
 			fbo->bind();
 		else
 		else
@@ -610,7 +594,7 @@ namespace BansheeEngine
 		if (GLEW_EXT_framebuffer_sRGB)
 		if (GLEW_EXT_framebuffer_sRGB)
 		{
 		{
 			// Enable / disable sRGB states
 			// Enable / disable sRGB states
-			if (target->getCore()->getProperties().isHwGammaEnabled())
+			if (target->getProperties().isHwGammaEnabled())
 			{
 			{
 				glEnable(GL_FRAMEBUFFER_SRGB_EXT);
 				glEnable(GL_FRAMEBUFFER_SRGB_EXT);
 
 
@@ -624,6 +608,8 @@ namespace BansheeEngine
 			}
 			}
 		}
 		}
 
 
+		applyViewport();
+
 		BS_INC_RENDER_STAT(NumRenderTargetChanges);
 		BS_INC_RENDER_STAT(NumRenderTargetChanges);
 	}
 	}
 
 
@@ -739,7 +725,7 @@ namespace BansheeEngine
 		if(mActiveRenderTarget == nullptr)
 		if(mActiveRenderTarget == nullptr)
 			return;
 			return;
 
 
-		const RenderTargetProperties& rtProps = mActiveRenderTarget->getCore()->getProperties();
+		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
 		Rect2I clearRect(0, 0, rtProps.getWidth(), rtProps.getHeight());
 		Rect2I clearRect(0, 0, rtProps.getWidth(), rtProps.getHeight());
 
 
 		clearArea(buffers, color, depth, stencil, clearRect);
 		clearArea(buffers, color, depth, stencil, clearRect);
@@ -805,7 +791,7 @@ namespace BansheeEngine
 			glDisable(GL_SCISSOR_TEST);
 			glDisable(GL_SCISSOR_TEST);
 		}
 		}
 
 
-		const RenderTargetProperties& rtProps = mActiveRenderTarget->getCore()->getProperties();
+		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
 
 
 		bool clearEntireTarget = clearRect.width == 0 || clearRect.height == 0;
 		bool clearEntireTarget = clearRect.width == 0 || clearRect.height == 0;
 		clearEntireTarget |= (clearRect.x == 0 && clearRect.y == 0 && clearRect.width == rtProps.getWidth() && clearRect.height == rtProps.getHeight());
 		clearEntireTarget |= (clearRect.x == 0 && clearRect.y == 0 && clearRect.width == rtProps.getWidth() && clearRect.height == rtProps.getHeight());
@@ -1035,10 +1021,10 @@ namespace BansheeEngine
 
 
 	void GLRenderSystem::setScissorTestEnable(bool enable)
 	void GLRenderSystem::setScissorTestEnable(bool enable)
 	{
 	{
-		const RenderTargetProperties& rtProps = mActiveRenderTarget->getCore()->getProperties();
+		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
 
 
 		// If request texture flipping, use "upper-left", otherwise use "lower-left"
 		// If request texture flipping, use "upper-left", otherwise use "lower-left"
-		bool flipping = mActiveRenderTarget->requiresTextureFlipping();
+		bool flipping = rtProps.requiresTextureFlipping();
 		//  GL measures from the bottom, not the top
 		//  GL measures from the bottom, not the top
 		UINT32 targetHeight = rtProps.getHeight();
 		UINT32 targetHeight = rtProps.getHeight();
 		// Calculate the "lower-left" corner of the viewport
 		// Calculate the "lower-left" corner of the viewport
@@ -1770,6 +1756,7 @@ namespace BansheeEngine
 			BS_EXCEPT(InternalErrorException, "Number of combined uniform block buffers less than the number of individual per-stage buffers!?");
 			BS_EXCEPT(InternalErrorException, "Number of combined uniform block buffers less than the number of individual per-stage buffers!?");
 
 
 		TextureManager::startUp<GLTextureManager>(std::ref(*mGLSupport));
 		TextureManager::startUp<GLTextureManager>(std::ref(*mGLSupport));
+		TextureCoreManager::startUp<GLTextureCoreManager>(std::ref(*mGLSupport));
 	}
 	}
 
 
 	void GLRenderSystem::switchContext(GLContext *context)
 	void GLRenderSystem::switchContext(GLContext *context)
@@ -2093,6 +2080,31 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
+	void GLRenderSystem::applyViewport()
+	{
+		if (mActiveRenderTarget == nullptr)
+			return;
+
+		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
+
+		// Calculate the "lower-left" corner of the viewport
+		mViewportLeft = (UINT32)(rtProps.getWidth() * mViewportNorm.x);
+		mViewportTop = (UINT32)(rtProps.getHeight() * mViewportNorm.y);
+		mViewportWidth = (UINT32)(rtProps.getWidth() * mViewportNorm.width);
+		mViewportHeight = (UINT32)(rtProps.getHeight() * mViewportNorm.height);
+
+		if (rtProps.requiresTextureFlipping())
+		{
+			// Convert "upper-left" corner to "lower-left"
+			mViewportTop = rtProps.getHeight() - (mViewportTop + mViewportHeight) - 1;
+		}
+
+		glViewport(mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight);
+
+		// Configure the viewport clipping
+		glScissor(mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight);
+	}
+
 	/************************************************************************/
 	/************************************************************************/
 	/* 								UTILITY		                     		*/
 	/* 								UTILITY		                     		*/
 	/************************************************************************/
 	/************************************************************************/

+ 9 - 20
BansheeGLRenderSystem/Source/BsGLRenderTexture.cpp

@@ -23,9 +23,8 @@ namespace BansheeEngine
 
 
 #define DEPTHFORMAT_COUNT (sizeof(depthFormats)/sizeof(GLenum))
 #define DEPTHFORMAT_COUNT (sizeof(depthFormats)/sizeof(GLenum))
 
 
-	GLRenderTextureCore::GLRenderTextureCore(GLRenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
-		const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
-		:RenderTextureCore(parent, properties, colorSurfaceDesc, depthStencilSurfaceDesc), mFB(nullptr)
+	GLRenderTextureCore::GLRenderTextureCore(const RENDER_TEXTURE_DESC& desc)
+		:RenderTextureCore(desc), mProperties(desc, true), mFB(nullptr)
 	{ }
 	{ }
 
 
 	GLRenderTextureCore::~GLRenderTextureCore()
 	GLRenderTextureCore::~GLRenderTextureCore()
@@ -43,7 +42,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 = mProperties->getMultisampleCount();
+		surfaceDesc.numSamples = getProperties().getMultisampleCount();
 
 
 		if (glTexture->getTextureType() != TEX_TYPE_3D)
 		if (glTexture->getTextureType() != TEX_TYPE_3D)
 		{
 		{
@@ -90,22 +89,6 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	RenderTargetProperties* GLRenderTexture::createProperties() const
-	{
-		return bs_new<RenderTextureProperties>();
-	}
-
-	SPtr<CoreObjectCore> GLRenderTexture::createCore() const
-	{
-		RenderTextureProperties* coreProperties = bs_new<RenderTextureProperties>();
-		RenderTextureProperties* myProperties = static_cast<RenderTextureProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
-
-		return bs_shared_ptr<GLRenderTextureCore>(const_cast<GLRenderTexture*>(this),
-			coreProperties, mColorSurfaceDesc, mDepthStencilSurfaceDesc);
-	}
-
 	GLRTTManager::GLRTTManager()
 	GLRTTManager::GLRTTManager()
 		:mBlitReadFBO(0), mBlitWriteFBO(0)
 		:mBlitReadFBO(0), mBlitWriteFBO(0)
     {
     {
@@ -354,5 +337,11 @@ namespace BansheeEngine
         // If none at all, return to default
         // If none at all, return to default
         return PF_A8R8G8B8;
         return PF_A8R8G8B8;
     }
     }
+
+	GLRenderTexture::GLRenderTexture(const RENDER_TEXTURE_DESC& desc)
+		:RenderTexture(desc), mProperties(desc, true)
+	{
+
+	}
 }
 }
 
 

+ 18 - 1
BansheeGLRenderSystem/Source/BsGLRenderWindowManager.cpp

@@ -11,11 +11,28 @@ namespace BansheeEngine
 		assert(mRenderSystem != nullptr);
 		assert(mRenderSystem != nullptr);
 	}
 	}
 
 
-	RenderWindowPtr GLRenderWindowManager::createImpl(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow)
+	RenderWindowPtr GLRenderWindowManager::createImpl(RENDER_WINDOW_DESC& desc, const RenderWindowPtr& parentWindow)
 	{
 	{
 		GLSupport* glSupport = mRenderSystem->getGLSupport();
 		GLSupport* glSupport = mRenderSystem->getGLSupport();
 
 
 		// Create the window
 		// Create the window
 		return glSupport->newWindow(desc, parentWindow);
 		return glSupport->newWindow(desc, parentWindow);
 	}
 	}
+
+	GLRenderWindowCoreManager::GLRenderWindowCoreManager(GLRenderSystem* renderSystem)
+		:mRenderSystem(renderSystem)
+	{
+		assert(mRenderSystem != nullptr);
+	}
+
+	SPtr<RenderWindowCore> GLRenderWindowCoreManager::createInternal(RENDER_WINDOW_DESC& desc)
+	{
+		GLSupport* glSupport = mRenderSystem->getGLSupport();
+
+		// Create the window
+		SPtr<RenderWindowCore> window = glSupport->newWindowCore(desc);
+		windowCreated(window.get());
+
+		return window;
+	}
 }
 }

+ 18 - 4
BansheeGLRenderSystem/Source/BsGLTextureManager.cpp

@@ -24,16 +24,16 @@ namespace BansheeEngine
 		return bs_core_ptr<GLTexture, PoolAlloc>(tex);
 		return bs_core_ptr<GLTexture, PoolAlloc>(tex);
     }
     }
 
 
-	RenderTexturePtr GLTextureManager::createRenderTextureImpl()
+	RenderTexturePtr GLTextureManager::createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc)
 	{
 	{
-		GLRenderTexture* tex = new (bs_alloc<GLRenderTexture, PoolAlloc>()) GLRenderTexture();
+		GLRenderTexture* tex = new (bs_alloc<GLRenderTexture, PoolAlloc>()) GLRenderTexture(desc);
 
 
 		return bs_core_ptr<GLRenderTexture, PoolAlloc>(tex);
 		return bs_core_ptr<GLRenderTexture, PoolAlloc>(tex);
 	}
 	}
 
 
-	MultiRenderTexturePtr GLTextureManager::createMultiRenderTextureImpl()
+	MultiRenderTexturePtr GLTextureManager::createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc)
 	{
 	{
-		GLMultiRenderTexture* tex = new (bs_alloc<GLMultiRenderTexture, PoolAlloc>()) GLMultiRenderTexture();
+		GLMultiRenderTexture* tex = new (bs_alloc<GLMultiRenderTexture, PoolAlloc>()) GLMultiRenderTexture(desc);
 
 
 		return bs_core_ptr<GLMultiRenderTexture, PoolAlloc>(tex);
 		return bs_core_ptr<GLMultiRenderTexture, PoolAlloc>(tex);
 	}
 	}
@@ -66,4 +66,18 @@ namespace BansheeEngine
 
 
 		return GLPixelUtil::getClosestValidFormat(format);
 		return GLPixelUtil::getClosestValidFormat(format);
 	}
 	}
+
+	GLTextureCoreManager::GLTextureCoreManager(GLSupport& support)
+		:mGLSupport(support)
+	{ }
+
+	SPtr<RenderTextureCore> GLTextureCoreManager::createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc)
+	{
+		return bs_shared_ptr<GLRenderTextureCore>(desc);
+	}
+
+	SPtr<MultiRenderTextureCore> GLTextureCoreManager::createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_DESC& desc)
+	{
+		return bs_shared_ptr<GLMultiRenderTextureCore>(desc);
+	}
 }
 }

+ 13 - 7
BansheeGLRenderSystem/Source/BsWin32GLSupport.cpp

@@ -20,7 +20,7 @@ namespace BansheeEngine
 	}
 	}
 
 
 	Win32GLSupport::Win32GLSupport()
 	Win32GLSupport::Win32GLSupport()
-        : mInitialWindow(0), mHasPixelFormatARB(false), mHasMultisample(false), 
+        : mInitialWindow(nullptr), mHasPixelFormatARB(false), mHasMultisample(false), 
 		mHasHardwareGamma(false), mHasAdvancedContext(false)
 		mHasHardwareGamma(false), mHasAdvancedContext(false)
     {
     {
 		initialiseWGL();
 		initialiseWGL();
@@ -31,16 +31,22 @@ namespace BansheeEngine
 		if(parentWindow != nullptr)
 		if(parentWindow != nullptr)
 		{
 		{
 			HWND hWnd;
 			HWND hWnd;
-			parentWindow->getCore()->getCustomAttribute("WINDOW", &hWnd);
+			parentWindow->getCustomAttribute("WINDOW", &hWnd);
 			desc.platformSpecific["parentWindowHandle"] = toString((UINT64)hWnd);
 			desc.platformSpecific["parentWindowHandle"] = toString((UINT64)hWnd);
 		}
 		}
 
 
-		Win32Window* window = new (bs_alloc<Win32Window, PoolAlloc>()) Win32Window(*this);
-		
-		if(!mInitialWindow)
+		Win32Window* window = new (bs_alloc<Win32Window, PoolAlloc>()) Win32Window(desc, *this);
+		return RenderWindowPtr(window, &CoreObject::_deleteDelayed<Win32Window, PoolAlloc>);
+	}
+
+	SPtr<RenderWindowCore> Win32GLSupport::newWindowCore(RENDER_WINDOW_DESC& desc)
+	{
+		Win32WindowCore* window = new (bs_alloc<Win32WindowCore, GenAlloc>()) Win32WindowCore(desc, *this);
+
+		if (!mInitialWindow)
 			mInitialWindow = window;
 			mInitialWindow = window;
 
 
-		return RenderWindowPtr(window, &CoreObject::_deleteDelayed<Win32Window, PoolAlloc>);
+		return bs_shared_ptr<Win32WindowCore, GenAlloc>(window);
 	}
 	}
 
 
 	void Win32GLSupport::start()
 	void Win32GLSupport::start()
@@ -65,7 +71,7 @@ namespace BansheeEngine
 		if(_wglGetExtensionsString == nullptr)
 		if(_wglGetExtensionsString == nullptr)
 			return;
 			return;
 
 
-		const char *wgl_extensions = _wglGetExtensionsString(mInitialWindow->getCore()->_getHDC());
+		const char *wgl_extensions = _wglGetExtensionsString(mInitialWindow->_getHDC());
 
 
 		// Parse them, and add them to the main list
 		// Parse them, and add them to the main list
 		StringStream ext;
 		StringStream ext;

+ 130 - 162
BansheeGLRenderSystem/Source/BsWin32Window.cpp

@@ -19,24 +19,13 @@ 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);
-	}
+	Win32RenderWindowProperties::Win32RenderWindowProperties(const RENDER_WINDOW_DESC& desc)
+		:RenderWindowProperties(desc)
+	{ }
 
 
-	Win32WindowCore::Win32WindowCore(Win32Window* parentWnd, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, Win32GLSupport& glsupport)
-		:RenderWindowCore(parentWnd, properties), mGLSupport(glsupport), mContext(0), mWindowedStyle(0), mWindowedStyleEx(0), mIsExternal(false),
-		mIsExternalGLControl(false), mDisplayFrequency(0), mDeviceName(nullptr), mDesc(desc)
+	Win32WindowCore::Win32WindowCore(const RENDER_WINDOW_DESC& desc, Win32GLSupport& glsupport)
+		: RenderWindowCore(desc), mProperties(desc), mGLSupport(glsupport), mContext(0), mWindowedStyle(0), mWindowedStyleEx(0), mIsExternal(false),
+		mIsExternalGLControl(false), mDisplayFrequency(0), mDeviceName(nullptr), mHWnd(0)
 	{ }
 	{ }
 
 
 	Win32WindowCore::~Win32WindowCore()
 	Win32WindowCore::~Win32WindowCore()
@@ -52,12 +41,12 @@ namespace BansheeEngine
 		HINSTANCE hInst = GetModuleHandle(MODULE_NAME.c_str());
 		HINSTANCE hInst = GetModuleHandle(MODULE_NAME.c_str());
 #endif
 #endif
 
 
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
+		Win32RenderWindowProperties& props = mProperties;
 
 
-		props->mIsFullScreen = mDesc.fullscreen;
+		props.mIsFullScreen = mDesc.fullscreen;
 		mIsChild = false;
 		mIsChild = false;
 		mDisplayFrequency = Math::roundToInt(mDesc.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;
@@ -65,8 +54,8 @@ namespace BansheeEngine
 
 
 		if ((opt = mDesc.platformSpecific.find("externalWindowHandle")) != end)
 		if ((opt = mDesc.platformSpecific.find("externalWindowHandle")) != end)
 		{
 		{
-			props->mHWnd = (HWND)parseUnsignedInt(opt->second);
-			if (props->mHWnd)
+			mHWnd = (HWND)parseUnsignedInt(opt->second);
+			if (mHWnd)
 			{
 			{
 				mIsExternal = true;
 				mIsExternal = true;
 			}
 			}
@@ -86,7 +75,7 @@ namespace BansheeEngine
 		{
 		{
 			parent = (HWND)parseUnsignedInt(opt->second);
 			parent = (HWND)parseUnsignedInt(opt->second);
 			mIsChild = true;
 			mIsChild = true;
-			props->mIsFullScreen = false;
+			props.mIsFullScreen = false;
 		}
 		}
 
 
 		HMONITOR hMonitor = NULL;
 		HMONITOR hMonitor = NULL;
@@ -99,17 +88,17 @@ namespace BansheeEngine
 			hMonitor = outputInfo.getMonitorHandle();
 			hMonitor = outputInfo.getMonitorHandle();
 		}
 		}
 
 
-		if (!props->mIsFullScreen)
+		if (!props.mIsFullScreen)
 		{
 		{
 			// Make sure we don't exceed desktop color depth
 			// Make sure we don't exceed desktop color depth
-			if ((int)props->mColorDepth > GetDeviceCaps(GetDC(0), BITSPIXEL))
-				props->mColorDepth = GetDeviceCaps(GetDC(0), BITSPIXEL);
+			if ((int)props.mColorDepth > GetDeviceCaps(GetDC(0), BITSPIXEL))
+				props.mColorDepth = GetDeviceCaps(GetDC(0), BITSPIXEL);
 		}
 		}
 
 
 		mWindowedStyle = WS_VISIBLE | WS_CLIPCHILDREN;
 		mWindowedStyle = WS_VISIBLE | WS_CLIPCHILDREN;
 		mWindowedStyleEx = 0;
 		mWindowedStyleEx = 0;
 
 
-		if (!props->mIsFullScreen)
+		if (!props.mIsFullScreen)
 		{
 		{
 			if (parent)
 			if (parent)
 			{
 			{
@@ -192,18 +181,18 @@ namespace BansheeEngine
 				top += monitorInfoEx.rcWork.top;
 				top += monitorInfoEx.rcWork.top;
 			}
 			}
 
 
-			props->mWidth = mDesc.videoMode.getWidth();
-			props->mHeight = mDesc.videoMode.getHeight();
-			props->mTop = top;
-			props->mLeft = left;
+			props.mWidth = mDesc.videoMode.getWidth();
+			props.mHeight = mDesc.videoMode.getHeight();
+			props.mTop = top;
+			props.mLeft = left;
 
 
 			DWORD dwStyle = 0;
 			DWORD dwStyle = 0;
 			DWORD dwStyleEx = 0;
 			DWORD dwStyleEx = 0;
-			if (props->mIsFullScreen)
+			if (props.mIsFullScreen)
 			{
 			{
 				dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_POPUP;
 				dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_POPUP;
-				props->mTop = monitorInfoEx.rcMonitor.top;
-				props->mLeft = monitorInfoEx.rcMonitor.left;
+				props.mTop = monitorInfoEx.rcMonitor.top;
+				props.mLeft = monitorInfoEx.rcMonitor.left;
 			}
 			}
 			else
 			else
 			{
 			{
@@ -217,23 +206,23 @@ namespace BansheeEngine
 				{
 				{
 					// Calculate window dimensions required
 					// Calculate window dimensions required
 					// to get the requested client area
 					// to get the requested client area
-					SetRect(&rc, 0, 0, props->mWidth, props->mHeight);
+					SetRect(&rc, 0, 0, props.mWidth, props.mHeight);
 					AdjustWindowRect(&rc, dwStyle, false);
 					AdjustWindowRect(&rc, dwStyle, false);
-					props->mWidth = rc.right - rc.left;
-					props->mHeight = rc.bottom - rc.top;
+					props.mWidth = rc.right - rc.left;
+					props.mHeight = rc.bottom - rc.top;
 
 
 					// Clamp window rect to the nearest display monitor.
 					// Clamp window rect to the nearest display monitor.
-					if (props->mLeft < monitorInfoEx.rcWork.left)
-						props->mLeft = monitorInfoEx.rcWork.left;
+					if (props.mLeft < monitorInfoEx.rcWork.left)
+						props.mLeft = monitorInfoEx.rcWork.left;
 
 
-					if (props->mTop < monitorInfoEx.rcWork.top)
-						props->mTop = monitorInfoEx.rcWork.top;
+					if (props.mTop < monitorInfoEx.rcWork.top)
+						props.mTop = monitorInfoEx.rcWork.top;
 
 
-					if ((int)props->mWidth > monitorInfoEx.rcWork.right - props->mLeft)
-						props->mWidth = monitorInfoEx.rcWork.right - props->mLeft;
+					if ((int)props.mWidth > monitorInfoEx.rcWork.right - props.mLeft)
+						props.mWidth = monitorInfoEx.rcWork.right - props.mLeft;
 
 
-					if ((int)props->mHeight > monitorInfoEx.rcWork.bottom - props->mTop)
-						props->mHeight = monitorInfoEx.rcWork.bottom - props->mTop;
+					if ((int)props.mHeight > monitorInfoEx.rcWork.bottom - props.mTop)
+						props.mHeight = monitorInfoEx.rcWork.bottom - props.mTop;
 				}
 				}
 			}
 			}
 
 
@@ -243,15 +232,15 @@ namespace BansheeEngine
 				(HBRUSH)GetStockObject(BLACK_BRUSH), NULL, "GLWindow" };
 				(HBRUSH)GetStockObject(BLACK_BRUSH), NULL, "GLWindow" };
 			RegisterClass(&wc);
 			RegisterClass(&wc);
 
 
-			if (props->mIsFullScreen)
+			if (props.mIsFullScreen)
 			{
 			{
 				DEVMODE displayDeviceMode;
 				DEVMODE displayDeviceMode;
 
 
 				memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
 				memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
 				displayDeviceMode.dmSize = sizeof(DEVMODE);
 				displayDeviceMode.dmSize = sizeof(DEVMODE);
-				displayDeviceMode.dmBitsPerPel = props->mColorDepth;
-				displayDeviceMode.dmPelsWidth = props->mWidth;
-				displayDeviceMode.dmPelsHeight = props->mHeight;
+				displayDeviceMode.dmBitsPerPel = props.mColorDepth;
+				displayDeviceMode.dmPelsWidth = props.mWidth;
+				displayDeviceMode.dmPelsHeight = props.mHeight;
 				displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
 				displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
 
 
 				if (mDisplayFrequency)
 				if (mDisplayFrequency)
@@ -272,50 +261,50 @@ namespace BansheeEngine
 			}
 			}
 
 
 			// Pass pointer to self as WM_CREATE parameter
 			// Pass pointer to self as WM_CREATE parameter
-			props->mHWnd = CreateWindowEx(dwStyleEx, "GLWindow", mDesc.title.c_str(),
-				dwStyle, props->mLeft, props->mTop, props->mWidth, props->mHeight, parent, 0, hInst, this);
+			mHWnd = CreateWindowEx(dwStyleEx, "GLWindow", mDesc.title.c_str(),
+				dwStyle, props.mLeft, props.mTop, props.mWidth, props.mHeight, parent, 0, hInst, this);
 		}
 		}
 
 
 		RECT rc;
 		RECT rc;
 
 
-		GetWindowRect(props->mHWnd, &rc);
-		props->mTop = rc.top;
-		props->mLeft = rc.left;
+		GetWindowRect(mHWnd, &rc);
+		props.mTop = rc.top;
+		props.mLeft = rc.left;
 
 
-		GetClientRect(props->mHWnd, &rc);
-		props->mWidth = rc.right;
-		props->mHeight = rc.bottom;
+		GetClientRect(mHWnd, &rc);
+		props.mWidth = rc.right;
+		props.mHeight = rc.bottom;
 
 
-		mHDC = GetDC(props->mHWnd);
+		mHDC = GetDC(mHWnd);
 
 
 		if (!mIsExternalGLControl)
 		if (!mIsExternalGLControl)
 		{
 		{
-			int testMultisample = props->mMultisampleCount;
+			int testMultisample = props.mMultisampleCount;
 			bool testHwGamma = mDesc.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)
 			{
 			{
-				if (props->mMultisampleCount > 0)
+				if (props.mMultisampleCount > 0)
 				{
 				{
 					// Try without multisampling
 					// Try without multisampling
 					testMultisample = 0;
 					testMultisample = 0;
-					formatOk = mGLSupport.selectPixelFormat(mHDC, props->mColorDepth, testMultisample, testHwGamma);
+					formatOk = mGLSupport.selectPixelFormat(mHDC, props.mColorDepth, testMultisample, testHwGamma);
 				}
 				}
 
 
 				if (!formatOk && mDesc.gamma)
 				if (!formatOk && mDesc.gamma)
 				{
 				{
 					// Try without sRGB
 					// Try without sRGB
 					testHwGamma = false;
 					testHwGamma = false;
-					testMultisample = props->mMultisampleCount;
-					formatOk = mGLSupport.selectPixelFormat(mHDC, props->mColorDepth, testMultisample, testHwGamma);
+					testMultisample = props.mMultisampleCount;
+					formatOk = mGLSupport.selectPixelFormat(mHDC, props.mColorDepth, testMultisample, testHwGamma);
 				}
 				}
 
 
-				if (!formatOk && mDesc.gamma && (props->mMultisampleCount > 0))
+				if (!formatOk && mDesc.gamma && (props.mMultisampleCount > 0))
 				{
 				{
 					// Try without both
 					// Try without both
 					testHwGamma = false;
 					testHwGamma = false;
 					testMultisample = 0;
 					testMultisample = 0;
-					formatOk = mGLSupport.selectPixelFormat(mHDC, props->mColorDepth, testMultisample, testHwGamma);
+					formatOk = mGLSupport.selectPixelFormat(mHDC, props.mColorDepth, testMultisample, testHwGamma);
 				}
 				}
 
 
 				if (!formatOk)
 				if (!formatOk)
@@ -325,24 +314,19 @@ namespace BansheeEngine
 
 
 			// Record what gamma option we used in the end
 			// Record what gamma option we used in the end
 			// this will control enabling of sRGB state flags when used
 			// this will control enabling of sRGB state flags when used
-			props->mHwGamma = testHwGamma;
-			props->mMultisampleCount = testMultisample;
+			props.mHwGamma = testHwGamma;
+			props.mMultisampleCount = testMultisample;
 		}
 		}
 
 
-		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;
 	}
 	}
 
 
 	void Win32WindowCore::destroy()
 	void Win32WindowCore::destroy()
 	{
 	{
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
+		Win32RenderWindowProperties& props = mProperties;
 
 
-		if (!props->mHWnd)
+		if (!mHWnd)
 			return;
 			return;
 
 
 		// Unregister and destroy GLContext
 		// Unregister and destroy GLContext
@@ -350,19 +334,19 @@ namespace BansheeEngine
 
 
 		if (!mIsExternal)
 		if (!mIsExternal)
 		{
 		{
-			if (props->mIsFullScreen)
+			if (props.mIsFullScreen)
 				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
 				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
-			DestroyWindow(props->mHWnd);
+			DestroyWindow(mHWnd);
 		}
 		}
 		else
 		else
 		{
 		{
 			// just release the DC
 			// just release the DC
-			ReleaseDC(props->mHWnd, mHDC);
+			ReleaseDC(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
-		props->mHWnd = 0;
+		mHWnd = 0;
 
 
 		if (mDeviceName != NULL)
 		if (mDeviceName != NULL)
 		{
 		{
@@ -387,21 +371,21 @@ namespace BansheeEngine
 		if (numOutputs == 0)
 		if (numOutputs == 0)
 			return;
 			return;
 
 
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
+		Win32RenderWindowProperties& props = mProperties;
 
 
 		UINT32 actualMonitorIdx = std::min(monitorIdx, numOutputs - 1);
 		UINT32 actualMonitorIdx = std::min(monitorIdx, numOutputs - 1);
 		const Win32VideoOutputInfo& outputInfo = static_cast<const Win32VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
 		const Win32VideoOutputInfo& outputInfo = static_cast<const Win32VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
 
 
-		bool oldFullscreen = props->mIsFullScreen;
+		bool oldFullscreen = props.mIsFullScreen;
 
 
 		mDisplayFrequency = Math::roundToInt(refreshRate);
 		mDisplayFrequency = Math::roundToInt(refreshRate);
-		props->mIsFullScreen = true;
+		props.mIsFullScreen = true;
 
 
 		DEVMODE displayDeviceMode;
 		DEVMODE displayDeviceMode;
 
 
 		memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
 		memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
 		displayDeviceMode.dmSize = sizeof(DEVMODE);
 		displayDeviceMode.dmSize = sizeof(DEVMODE);
-		displayDeviceMode.dmBitsPerPel = props->mColorDepth;
+		displayDeviceMode.dmBitsPerPel = props.mColorDepth;
 		displayDeviceMode.dmPelsWidth = width;
 		displayDeviceMode.dmPelsWidth = width;
 		displayDeviceMode.dmPelsHeight = height;
 		displayDeviceMode.dmPelsHeight = height;
 		displayDeviceMode.dmDisplayFrequency = mDisplayFrequency;
 		displayDeviceMode.dmDisplayFrequency = mDisplayFrequency;
@@ -419,12 +403,12 @@ namespace BansheeEngine
 			BS_EXCEPT(RenderingAPIException, "ChangeDisplaySettings failed");
 			BS_EXCEPT(RenderingAPIException, "ChangeDisplaySettings failed");
 		}
 		}
 
 
-		props->mTop = monitorInfo.rcMonitor.top;
-		props->mLeft = monitorInfo.rcMonitor.left;
-		props->mWidth = width;
-		props->mHeight = height;
+		props.mTop = monitorInfo.rcMonitor.top;
+		props.mLeft = monitorInfo.rcMonitor.left;
+		props.mWidth = width;
+		props.mHeight = height;
 
 
-		SetWindowPos(props->mHWnd, HWND_TOP, props->mLeft, props->mTop, width, height, SWP_NOACTIVATE);
+		SetWindowPos(mHWnd, HWND_TOP, props.mLeft, props.mTop, width, height, SWP_NOACTIVATE);
 
 
 		markCoreDirty();
 		markCoreDirty();
 	}
 	}
@@ -440,24 +424,24 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
+		Win32RenderWindowProperties& props = mProperties;
 
 
-		if (!props->mIsFullScreen)
+		if (!props.mIsFullScreen)
 			return;
 			return;
 
 
-		props->mIsFullScreen = false;
-		props->mWidth = width;
-		props->mHeight = height;
+		props.mIsFullScreen = false;
+		props.mWidth = width;
+		props.mHeight = height;
 
 
 		// Drop out of fullscreen
 		// Drop out of fullscreen
 		ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
 		ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
 
 
 		// Calculate overall dimensions for requested client area
 		// Calculate overall dimensions for requested client area
 		UINT32 winWidth, winHeight;
 		UINT32 winWidth, winHeight;
-		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(props->mHWnd, MONITOR_DEFAULTTONEAREST);
+		HMONITOR hMonitor = MonitorFromWindow(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);
@@ -469,9 +453,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(props->mHWnd, GWL_STYLE, mWindowedStyle);
-		SetWindowLong(props->mHWnd, GWL_EXSTYLE, mWindowedStyleEx);
-		SetWindowPos(props->mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight,
+		SetWindowLong(mHWnd, GWL_STYLE, mWindowedStyle);
+		SetWindowLong(mHWnd, GWL_EXSTYLE, mWindowedStyleEx);
+		SetWindowPos(mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight,
 			SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);
 			SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);
 
 
 		_windowMovedOrResized();
 		_windowMovedOrResized();
@@ -483,13 +467,13 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
-		if (props->mHWnd && !props->mIsFullScreen)
+		Win32RenderWindowProperties& props = mProperties;
+		if (mHWnd && !props.mIsFullScreen)
 		{
 		{
-			props->mLeft = left;
-			props->mTop = top;
+			props.mLeft = left;
+			props.mTop = top;
 
 
-			SetWindowPos(props->mHWnd, 0, left, top, 0, 0,
+			SetWindowPos(mHWnd, 0, left, top, 0, 0,
 				SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 				SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 
 
 			markCoreDirty();
 			markCoreDirty();
@@ -500,17 +484,17 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
-		if (props->mHWnd && !props->mIsFullScreen)
+		Win32RenderWindowProperties& props = mProperties;
+		if (mHWnd && !props.mIsFullScreen)
 		{
 		{
-			props->mWidth = width;
-			props->mHeight = height;
+			props.mWidth = width;
+			props.mHeight = height;
 
 
 			RECT rc = { 0, 0, width, height };
 			RECT rc = { 0, 0, width, height };
-			AdjustWindowRect(&rc, GetWindowLong(props->mHWnd, GWL_STYLE), false);
+			AdjustWindowRect(&rc, GetWindowLong(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(props->mHWnd, 0, 0, 0, width, height,
+			SetWindowPos(mHWnd, 0, 0, 0, width, height,
 				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 
 
 			markCoreDirty();
 			markCoreDirty();
@@ -539,7 +523,7 @@ namespace BansheeEngine
 
 
 		if (buffer == FB_AUTO)
 		if (buffer == FB_AUTO)
 		{
 		{
-			buffer = getProperties().isFullScreen() ? FB_FRONT : FB_BACK;
+			buffer = mProperties.isFullScreen() ? FB_FRONT : FB_BACK;
 		}
 		}
 
 
 		GLenum format = BansheeEngine::GLPixelUtil::getGLOriginFormat(dst.getFormat());
 		GLenum format = BansheeEngine::GLPixelUtil::getGLOriginFormat(dst.getFormat());
@@ -582,8 +566,6 @@ 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;
@@ -592,7 +574,7 @@ namespace BansheeEngine
 		else if(name == "WINDOW")
 		else if(name == "WINDOW")
 		{
 		{
 			HWND *pHwnd = (HWND*)pData;
 			HWND *pHwnd = (HWND*)pData;
-			*pHwnd = props->mHWnd;
+			*pHwnd = mHWnd;
 			return;
 			return;
 		} 
 		} 
 	}
 	}
@@ -601,14 +583,14 @@ namespace BansheeEngine
 	{	
 	{	
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
+		Win32RenderWindowProperties& props = 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(props->mHWnd, classNameSrc, _MAX_CLASS_NAME_);
+			GetClassName(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)
@@ -617,26 +599,26 @@ namespace BansheeEngine
 			}						
 			}						
 		}
 		}
 		
 		
-		props->mActive = state;
+		props.mActive = state;
 
 
-		if(props->mIsFullScreen)
+		if(props.mIsFullScreen)
 		{
 		{
 			if( state == false )
 			if( state == false )
 			{	//Restore Desktop
 			{	//Restore Desktop
 				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
 				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
-				ShowWindow(props->mHWnd, SW_SHOWMINNOACTIVE);
+				ShowWindow(mHWnd, SW_SHOWMINNOACTIVE);
 			}
 			}
 			else
 			else
 			{	//Restore App
 			{	//Restore App
-				ShowWindow(props->mHWnd, SW_SHOWNORMAL);
+				ShowWindow(mHWnd, SW_SHOWNORMAL);
 
 
 				DEVMODE displayDeviceMode;
 				DEVMODE displayDeviceMode;
 
 
 				memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
 				memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
 				displayDeviceMode.dmSize = sizeof(DEVMODE);
 				displayDeviceMode.dmSize = sizeof(DEVMODE);
-				displayDeviceMode.dmBitsPerPel = props->mColorDepth;
-				displayDeviceMode.dmPelsWidth = props->mWidth;
-				displayDeviceMode.dmPelsHeight = props->mHeight;
+				displayDeviceMode.dmBitsPerPel = props.mColorDepth;
+				displayDeviceMode.dmPelsWidth = props.mWidth;
+				displayDeviceMode.dmPelsHeight = props.mHeight;
 				displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
 				displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
 				if (mDisplayFrequency)
 				if (mDisplayFrequency)
 				{
 				{
@@ -654,14 +636,14 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
-		props->mHidden = hidden;
+		Win32RenderWindowProperties& props = mProperties;
+		props.mHidden = hidden;
 		if (!mIsExternal)
 		if (!mIsExternal)
 		{
 		{
 			if (hidden)
 			if (hidden)
-				ShowWindow(props->mHWnd, SW_HIDE);
+				ShowWindow(mHWnd, SW_HIDE);
 			else
 			else
-				ShowWindow(props->mHWnd, SW_SHOWNORMAL);
+				ShowWindow(mHWnd, SW_SHOWNORMAL);
 		}
 		}
 
 
 		markCoreDirty();
 		markCoreDirty();
@@ -669,19 +651,19 @@ namespace BansheeEngine
 
 
 	void Win32WindowCore::_windowMovedOrResized()
 	void Win32WindowCore::_windowMovedOrResized()
 	{
 	{
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
+		Win32RenderWindowProperties& props = mProperties;
 
 
-		if (!props->mHWnd || IsIconic(props->mHWnd))
+		if (!mHWnd || IsIconic(mHWnd))
 			return;
 			return;
 
 
 		RECT rc;
 		RECT rc;
-		GetWindowRect(props->mHWnd, &rc);
-		props->mTop = rc.top;
-		props->mLeft = rc.left;
+		GetWindowRect(mHWnd, &rc);
+		props.mTop = rc.top;
+		props.mLeft = rc.left;
 
 
-		GetClientRect(props->mHWnd, &rc);
-		props->mWidth = rc.right - rc.left;
-		props->mHeight = rc.bottom - rc.top;
+		GetClientRect(mHWnd, &rc);
+		props.mWidth = rc.right - rc.left;
+		props.mHeight = rc.bottom - rc.top;
 
 
 		markCoreDirty();
 		markCoreDirty();
 
 
@@ -690,7 +672,7 @@ 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);
+		Win32RenderWindowProperties& props = mProperties;
 
 
 		RECT rc;
 		RECT rc;
 		SetRect(&rc, 0, 0, clientWidth, clientHeight);
 		SetRect(&rc, 0, 0, clientWidth, clientHeight);
@@ -699,7 +681,7 @@ namespace BansheeEngine
 		*winHeight = rc.bottom - rc.top;
 		*winHeight = rc.bottom - rc.top;
 
 
 		// Adjust to monitor
 		// Adjust to monitor
-		HMONITOR hMonitor = MonitorFromWindow(props->mHWnd, MONITOR_DEFAULTTONEAREST);
+		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
 
 
 		// Get monitor info	
 		// Get monitor info	
 		MONITORINFO monitorInfo;
 		MONITORINFO monitorInfo;
@@ -718,25 +700,20 @@ namespace BansheeEngine
 			*winHeight = maxH;
 			*winHeight = maxH;
 	}
 	}
 
 
-	Win32Window::Win32Window(Win32GLSupport &glsupport)
-		:mGLSupport(glsupport)
+	Win32Window::Win32Window(const RENDER_WINDOW_DESC& desc, Win32GLSupport &glsupport)
+		:RenderWindow(desc), mGLSupport(glsupport), mProperties(desc)
 	{
 	{
 
 
 	}
 	}
 
 
 	void Win32Window::getCustomAttribute(const String& name, void* pData) const
 	void Win32Window::getCustomAttribute(const String& name, void* pData) const
 	{
 	{
-		THROW_IF_CORE_THREAD;
-
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
 		if (name == "WINDOW")
 		if (name == "WINDOW")
 		{
 		{
-			HWND *pWnd = (HWND*)pData;
-			*pWnd = props->mHWnd;
+			HWND *pHwnd = (HWND*)pData;
+			*pHwnd = getHWnd();
 			return;
 			return;
 		}
 		}
-
-		RenderWindow::getCustomAttribute(name, pData);
 	}
 	}
 
 
 	Vector2I Win32Window::screenToWindowPos(const Vector2I& screenPos) const
 	Vector2I Win32Window::screenToWindowPos(const Vector2I& screenPos) const
@@ -745,8 +722,7 @@ namespace BansheeEngine
 		pos.x = screenPos.x;
 		pos.x = screenPos.x;
 		pos.y = screenPos.y;
 		pos.y = screenPos.y;
 
 
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
-		ScreenToClient(props->mHWnd, &pos);
+		ScreenToClient(getHWnd(), &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
@@ -756,8 +732,7 @@ namespace BansheeEngine
 		pos.x = windowPos.x;
 		pos.x = windowPos.x;
 		pos.y = windowPos.y;
 		pos.y = windowPos.y;
 
 
-		Win32RenderWindowProperties* props = static_cast<Win32RenderWindowProperties*>(mProperties);
-		ClientToScreen(props->mHWnd, &pos);
+		ClientToScreen(getHWnd(), &pos);
 		return Vector2I(pos.x, pos.y);
 		return Vector2I(pos.x, pos.y);
 	}
 	}
 
 
@@ -766,17 +741,10 @@ namespace BansheeEngine
 		return std::static_pointer_cast<Win32WindowCore>(mCoreSpecific);
 		return std::static_pointer_cast<Win32WindowCore>(mCoreSpecific);
 	}
 	}
 
 
-	RenderTargetProperties* Win32Window::createProperties() const
+	HWND Win32Window::getHWnd() const
 	{
 	{
-		return bs_new<Win32RenderWindowProperties>();
-	}
-
-	SPtr<CoreObjectCore> Win32Window::createCore() const
-	{
-		Win32RenderWindowProperties* coreProperties = bs_new<Win32RenderWindowProperties>();
-		Win32RenderWindowProperties* myProperties = static_cast<Win32RenderWindowProperties*>(mProperties);
-
-		*coreProperties = *myProperties;
-		return bs_shared_ptr<Win32WindowCore>(const_cast<Win32Window*>(this), coreProperties, mDesc, mGLSupport);
+		// HACK: I'm accessing core method from sim thread, which means an invalid handle
+		// could be returned here if requested too soon after initialization.
+		return getCore()->_getHWnd();
 	}
 	}
 }
 }

+ 1 - 1
BansheeRenderer/Include/BsBansheeRenderer.h

@@ -30,7 +30,7 @@ namespace BansheeEngine
 		 */
 		 */
 		struct RenderTargetData
 		struct RenderTargetData
 		{
 		{
-			RenderTargetPtr target;
+			SPtr<RenderTargetCore> target;
 			Vector<CameraProxyPtr> cameras;
 			Vector<CameraProxyPtr> cameras;
 		};
 		};
 
 

+ 7 - 6
BansheeRenderer/Source/BsBansheeRenderer.cpp

@@ -118,7 +118,7 @@ namespace BansheeEngine
 
 
 	void BansheeRenderer::addCameraProxy(CameraProxyPtr proxy)
 	void BansheeRenderer::addCameraProxy(CameraProxyPtr proxy)
 	{
 	{
-		RenderTargetPtr renderTarget = proxy->viewport.getTarget();
+		SPtr<RenderTargetCore> renderTarget = proxy->renderTarget;
 		auto findIter = std::find_if(mRenderTargets.begin(), mRenderTargets.end(), [&](const RenderTargetData& x) { return x.target == renderTarget; });
 		auto findIter = std::find_if(mRenderTargets.begin(), mRenderTargets.end(), [&](const RenderTargetData& x) { return x.target == renderTarget; });
 
 
 		if (findIter != mRenderTargets.end())
 		if (findIter != mRenderTargets.end())
@@ -140,7 +140,7 @@ namespace BansheeEngine
 		// Sort everything based on priority
 		// Sort everything based on priority
 		auto cameraComparer = [&](const CameraProxyPtr& a, const CameraProxyPtr& b) { return a->priority > b->priority; };
 		auto cameraComparer = [&](const CameraProxyPtr& a, const CameraProxyPtr& b) { return a->priority > b->priority; };
 		auto renderTargetInfoComparer = [&](const RenderTargetData& a, const RenderTargetData& b) 
 		auto renderTargetInfoComparer = [&](const RenderTargetData& a, const RenderTargetData& b) 
-		{ return a.target->getCore()->getProperties().getPriority() > b.target->getCore()->getProperties().getPriority(); };
+		{ return a.target->getProperties().getPriority() > b.target->getProperties().getPriority(); };
 		std::sort(begin(mRenderTargets), end(mRenderTargets), renderTargetInfoComparer);
 		std::sort(begin(mRenderTargets), end(mRenderTargets), renderTargetInfoComparer);
 
 
 		for (auto& camerasPerTarget : mRenderTargets)
 		for (auto& camerasPerTarget : mRenderTargets)
@@ -155,7 +155,7 @@ namespace BansheeEngine
 
 
 	void BansheeRenderer::removeCameraProxy(CameraProxyPtr proxy)
 	void BansheeRenderer::removeCameraProxy(CameraProxyPtr proxy)
 	{
 	{
-		RenderTargetPtr renderTarget = proxy->viewport.getTarget();
+		SPtr<RenderTargetCore> renderTarget = proxy->renderTarget;
 		auto findIter = std::find_if(mRenderTargets.begin(), mRenderTargets.end(), [&](const RenderTargetData& x) { return x.target == renderTarget; });
 		auto findIter = std::find_if(mRenderTargets.begin(), mRenderTargets.end(), [&](const RenderTargetData& x) { return x.target == renderTarget; });
 
 
 		if (findIter != mRenderTargets.end())
 		if (findIter != mRenderTargets.end())
@@ -440,15 +440,16 @@ namespace BansheeEngine
 		// Render everything, target by target
 		// Render everything, target by target
 		for (auto& renderTargetData : mRenderTargets)
 		for (auto& renderTargetData : mRenderTargets)
 		{
 		{
-			RenderTargetPtr target = renderTargetData.target;
+			SPtr<RenderTargetCore> target = renderTargetData.target;
 			Vector<CameraProxyPtr>& cameras = renderTargetData.cameras;
 			Vector<CameraProxyPtr>& cameras = renderTargetData.cameras;
 
 
 			RenderSystem::instance().beginFrame();
 			RenderSystem::instance().beginFrame();
 
 
 			for(auto& camera : cameras)
 			for(auto& camera : cameras)
 			{
 			{
-				Viewport& viewport = camera->viewport;
-				RenderSystem::instance().setViewport(viewport);
+				Viewport viewport = camera->viewport;
+				RenderSystem::instance().setRenderTarget(target);
+				RenderSystem::instance().setViewport(viewport.getNormArea());
 
 
 				UINT32 clearBuffers = 0;
 				UINT32 clearBuffers = 0;
 				if(viewport.getRequiresColorClear())
 				if(viewport.getRequiresColorClear())

+ 10 - 4
TODO.txt

@@ -25,11 +25,17 @@ Disallow CoreObject creation from core thread
  - Add asserts in CoreObject::destroy and CoreObject::initialize
  - Add asserts in CoreObject::destroy and CoreObject::initialize
  - Possibly also add asserts to CoreThread::queueCommand and CoreThread::queueReturnCommand
  - Possibly also add asserts to CoreThread::queueCommand and CoreThread::queueReturnCommand
 
 
-Make mCoreSpecific a shared ptr
- - Where needed, add create() methods to CoreObjectCore for use from the core thread
+RENDER TARGET REFACTOR:
+Need RenderWindow::create that works from core thread used for creating the primary window
+ - RenderSystem then needs to wrap the returned RenderWindowCore into a proper RenderWindow for use by the sim thread
 
 
-Refactor RenderSystem, Mesh, MeshHeap so they use only core versions of Index and VertexBuffer
- - This should also apply to any newly refactored classes, non-core stuff should be removed from core
+Move CoreAccessor methods relating to render target, to the render targets themselves
+
+Find remaining uses of getCore and try to replace them:
+ - Check Win32GLSupport
+ - When creating a window, parent window gets sent as a RenderWindow
+ - PlatfromWndProc accesses a list of non-core windows
+ - Various callbacks in PlatformImpl as well
 
 
 -----------------
 -----------------