Explorar o código

Render states refactored to comply with new CoreObject design
Fixed issue with syncing and frame allocator not being used properly

Marko Pintera %!s(int64=11) %!d(string=hai) anos
pai
achega
bf970d8436
Modificáronse 47 ficheiros con 974 adicións e 492 borrados
  1. 63 10
      BansheeCore/Include/BsBlendState.h
  2. 3 12
      BansheeCore/Include/BsBlendStateRTTI.h
  3. 37 12
      BansheeCore/Include/BsCoreObjectManager.h
  4. 4 0
      BansheeCore/Include/BsCorePrerequisites.h
  5. 66 10
      BansheeCore/Include/BsDepthStencilState.h
  6. 3 11
      BansheeCore/Include/BsDepthStencilStateRTTI.h
  7. 64 10
      BansheeCore/Include/BsRasterizerState.h
  8. 3 11
      BansheeCore/Include/BsRasterizerStateRTTI.h
  9. 44 12
      BansheeCore/Include/BsRenderStateManager.h
  10. 4 4
      BansheeCore/Include/BsRenderSystem.h
  11. 69 15
      BansheeCore/Include/BsSamplerState.h
  12. 3 12
      BansheeCore/Include/BsSamplerStateRTTI.h
  13. 47 20
      BansheeCore/Source/BsBlendState.cpp
  14. 1 1
      BansheeCore/Source/BsCoreApplication.cpp
  15. 72 31
      BansheeCore/Source/BsCoreObjectManager.cpp
  16. 4 4
      BansheeCore/Source/BsCoreThreadAccessor.cpp
  17. 34 3
      BansheeCore/Source/BsDepthStencilState.cpp
  18. 5 5
      BansheeCore/Source/BsPass.cpp
  19. 32 3
      BansheeCore/Source/BsRasterizerState.cpp
  20. 64 20
      BansheeCore/Source/BsRenderStateManager.cpp
  21. 6 6
      BansheeCore/Source/BsRenderer.cpp
  22. 47 18
      BansheeCore/Source/BsSamplerState.cpp
  23. 8 8
      BansheeD3D11RenderSystem/Include/BsD3D11BlendState.h
  24. 8 8
      BansheeD3D11RenderSystem/Include/BsD3D11DepthStencilState.h
  25. 8 8
      BansheeD3D11RenderSystem/Include/BsD3D11RasterizerState.h
  26. 9 9
      BansheeD3D11RenderSystem/Include/BsD3D11RenderStateManager.h
  27. 4 4
      BansheeD3D11RenderSystem/Include/BsD3D11RenderSystem.h
  28. 7 7
      BansheeD3D11RenderSystem/Include/BsD3D11RenderUtility.h
  29. 8 8
      BansheeD3D11RenderSystem/Include/BsD3D11SamplerState.h
  30. 17 17
      BansheeD3D11RenderSystem/Source/BsD3D11BlendState.cpp
  31. 21 21
      BansheeD3D11RenderSystem/Source/BsD3D11DepthStencilState.cpp
  32. 16 16
      BansheeD3D11RenderSystem/Source/BsD3D11RasterizerState.cpp
  33. 8 12
      BansheeD3D11RenderSystem/Source/BsD3D11RenderStateManager.cpp
  34. 13 11
      BansheeD3D11RenderSystem/Source/BsD3D11RenderSystem.cpp
  35. 15 14
      BansheeD3D11RenderSystem/Source/BsD3D11RenderUtility.cpp
  36. 26 24
      BansheeD3D11RenderSystem/Source/BsD3D11SamplerState.cpp
  37. 4 4
      BansheeD3D9RenderSystem/Include/BsD3D9RenderSystem.h
  38. 45 35
      BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp
  39. 1 1
      BansheeEditor/Source/BsScenePicking.cpp
  40. 1 1
      BansheeEditorExec/BsEditorExec.cpp
  41. 4 4
      BansheeGLRenderSystem/Include/BsGLRenderSystem.h
  42. 44 34
      BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp
  43. 5 0
      BansheeUtility/Include/BsFrameAlloc.h
  44. 14 3
      BansheeUtility/Source/BsFrameAlloc.cpp
  45. 1 1
      SBansheeEngine/Include/BsManagedResource.h
  46. 2 2
      SBansheeEngine/Source/BsManagedResource.cpp
  47. 10 10
      TODO.txt

+ 63 - 10
BansheeCore/Include/BsBlendState.h

@@ -55,16 +55,12 @@ namespace BansheeEngine
 	};
 
 	/**
-	 * @brief	Render system pipeline state that allows you to modify how an object is rendered. 
-	 * 			More exactly this state allows to you to control how is a rendered
-	 * 			object blended with any previously renderer objects.
-	 * 			
-	 * @note	Blend states are immutable. Thread safe.
+	 * @brief	Information about a blend state.
 	 */
-	class BS_CORE_EXPORT BlendState : public Resource
+	class BS_CORE_EXPORT BlendProperties
 	{
 	public:
-		virtual ~BlendState() {}
+		BlendProperties(const BLEND_STATE_DESC& desc);
 
 		/**
 		 * @brief	Alpha to coverage allows you to perform blending without needing to worry about order of
@@ -137,6 +133,61 @@ namespace BansheeEngine
 		 */
 		UINT8 getRenderTargetWriteMask(UINT32 renderTargetIdx) const;
 
+	protected:
+		friend class BlendState;
+		friend class BlendStateRTTI;
+
+		BLEND_STATE_DESC mData;
+	};
+
+/**
+	 * @brief	Core thread version of a blend state.
+	 *
+	 * @see		BlendState
+	 *
+	 * @note	Core thread.
+	 */
+	class BS_CORE_EXPORT BlendStateCore : public CoreObjectCore
+	{
+	public:
+		virtual ~BlendStateCore() {}
+
+		/**
+		 * @brief	Returns information about the blend state.
+		 */
+		const BlendProperties& getProperties() const;
+
+	protected:
+		friend class RenderStateCoreManager;
+
+		BlendStateCore(const BLEND_STATE_DESC& desc);
+
+		BlendProperties mProperties;
+	};
+
+	/**
+	 * @brief	Render system pipeline state that allows you to modify how an object is rendered. 
+	 * 			More exactly this state allows to you to control how is a rendered
+	 * 			object blended with any previously renderer objects.
+	 * 			
+	 * @note	Blend states are immutable. Sim thread only.
+	 */
+	class BS_CORE_EXPORT BlendState : public Resource
+	{
+	public:
+		virtual ~BlendState() {}
+
+		/**
+		 * @brief	Returns information about a blend state.
+		 */
+		const BlendProperties& getProperties() const;
+
+		/**
+		 * @brief	Retrieves a core implementation of the sampler state usable only from the
+		 *			core thread.
+		 */
+		SPtr<BlendStateCore> getCore() const;
+
 		/**
 		 * @brief	Creates a new blend state using the specified blend state description structure.
 		 */
@@ -151,12 +202,14 @@ namespace BansheeEngine
 	protected:
 		friend class RenderStateManager;
 
+		BlendState(const BLEND_STATE_DESC& desc);
+
 		/**
-		 * @brief	Initializes the blend state. Must be called right after construction.
+		 * @copydoc	CoreObjectCore::createCore
 		 */
-		virtual void initialize(const BLEND_STATE_DESC& desc);
+		SPtr<CoreObjectCore> createCore() const;
 
-		BLEND_STATE_DESC mData;
+		BlendProperties mProperties;
 
 		/************************************************************************/
 		/* 								RTTI		                     		*/

+ 3 - 12
BansheeCore/Include/BsBlendStateRTTI.h

@@ -51,11 +51,8 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT BlendStateRTTI : public RTTIType<BlendState, IReflectable, BlendStateRTTI>
 	{
 	private:
-		BLEND_STATE_DESC& getData(BlendState* obj) { return obj->mData; }
-		void setData(BlendState* obj, BLEND_STATE_DESC& val) 
-		{ 
-			obj->mRTTIData = val;
-		} 
+		BLEND_STATE_DESC& getData(BlendState* obj) { return obj->mProperties.mData; }
+		void setData(BlendState* obj, BLEND_STATE_DESC& val) { obj->mProperties.mData = val; } 
 
 	public:
 		BlendStateRTTI()
@@ -66,13 +63,7 @@ namespace BansheeEngine
 		virtual void onDeserializationEnded(IReflectable* obj)
 		{
 			BlendState* blendState = static_cast<BlendState*>(obj);
-			if(!blendState->mRTTIData.empty())
-			{
-				BLEND_STATE_DESC desc = any_cast<BLEND_STATE_DESC>(blendState->mRTTIData);
-
-				blendState->initialize(desc);
-			}
-
+			blendState->initialize();
 		}
 
 		virtual const String& getRTTIName()

+ 37 - 12
BansheeCore/Include/BsCoreObjectManager.h

@@ -28,15 +28,15 @@ namespace BansheeEngine
 	{
 		/**
 		 * @brief	Stores dirty data that is to be transferred from core 
-		 *			thread to sim thread part of a CoreObject.
+		 *			thread to sim thread part of a CoreObject, for a single object.
 		 */
-		struct SimStoredSyncData
+		struct SimStoredSyncObjData
 		{
-			SimStoredSyncData()
+			SimStoredSyncObjData()
 				:destinationObj(nullptr)
 			{ }
 
-			SimStoredSyncData(CoreObject* destObj, const CoreSyncData& syncData)
+			SimStoredSyncObjData(CoreObject* destObj, const CoreSyncData& syncData)
 				:destinationObj(destObj), syncData(syncData)
 			{ }
 
@@ -46,15 +46,15 @@ namespace BansheeEngine
 
 		/**
 		 * @brief	Stores dirty data that is to be transferred from sim 
-		 *			thread to core thread part of a CoreObject.
+		 *			thread to core thread part of a CoreObject, for a single object.
 		 */
-		struct CoreStoredSyncData
+		struct CoreStoredSyncObjData
 		{
-			CoreStoredSyncData()
+			CoreStoredSyncObjData()
 				:destinationObj(nullptr)
 			{ }
 
-			CoreStoredSyncData(CoreObjectCore* destObj, const CoreSyncData& syncData)
+			CoreStoredSyncObjData(CoreObjectCore* destObj, const CoreSyncData& syncData)
 				:destinationObj(destObj), syncData(syncData)
 			{ }
 
@@ -62,6 +62,28 @@ namespace BansheeEngine
 			CoreSyncData syncData;
 		};
 
+		/**
+		 * @brief	Stores dirty data that is to be transferred from core 
+		 *			thread to sim thread part of a CoreObject, for all dirty 
+		 *			objects in one frame.
+		 */
+		struct SimStoredSyncData
+		{
+			FrameAlloc* alloc = nullptr;
+			Map<UINT64, SimStoredSyncObjData> entries;
+		};
+
+		/**
+		 * @brief	Stores dirty data that is to be transferred from sim 
+		 *			thread to core thread part of a CoreObject, for all dirty
+		 *			objects in one frame.
+		 */
+		struct CoreStoredSyncData
+		{
+			FrameAlloc* alloc = nullptr;
+			Map<UINT64, CoreStoredSyncObjData> entries;
+		};
+
 	public:
 		CoreObjectManager();
 		~CoreObjectManager();
@@ -115,11 +137,14 @@ namespace BansheeEngine
 		UINT64 mNextAvailableID;
 		Map<UINT64, CoreObject*> mObjects;
 
-		FrameAlloc* mSimSyncDataAlloc;
-		Map<UINT64, SimStoredSyncData> mSimSyncData;
+		Vector<SimStoredSyncData> mSimSyncData;
+		UINT32 mSimSyncIdx;
+		UINT32 mSimSyncCount;
+
+		Vector<CoreStoredSyncData> mCoreSyncData;
+		UINT32 mCoreSyncIdx;
+		UINT32 mCoreSyncCount;
 
-		FrameAlloc* mCoreSyncDataAlloc;
-		Map<UINT64, CoreStoredSyncData> mCoreSyncData;
 		BS_MUTEX(mObjectsMutex);
 	};
 }

+ 4 - 0
BansheeCore/Include/BsCorePrerequisites.h

@@ -91,6 +91,7 @@ namespace BansheeEngine
     struct RenderOpMesh;
     class StringInterface;
     class SamplerState;
+	class SamplerStateCore;
     class TextureManager;
     class Viewport;
     class VertexData;
@@ -105,9 +106,12 @@ namespace BansheeEngine
 	class HardwareBufferManager;
 	class FontManager;
 	class DepthStencilState;
+	class DepthStencilStateCore;
 	class RenderStateManager;
 	class RasterizerState;
+	class RasterizerStateCore;
 	class BlendState;
+	class BlendStateCore;
 	class GpuParamBlock;
 	class GpuParamBlockBuffer;
 	class GpuParams;

+ 66 - 10
BansheeCore/Include/BsDepthStencilState.h

@@ -51,16 +51,12 @@ namespace BansheeEngine
 	BS_ALLOW_MEMCPY_SERIALIZATION(DEPTH_STENCIL_STATE_DESC);
 
 	/**
-	* @brief	Render system pipeline state that allows you to modify how an object is rendered.
-	* 			More exactly this state allows to you to control how are depth and stencil buffers
-	*			modified upon rendering.
-	*
-	* @note		Depth stencil states are immutable. Thread safe.
-	*/
-	class BS_CORE_EXPORT DepthStencilState : public Resource
+	 * @brief	Information about a depth stencil state.
+	 */
+	class BS_CORE_EXPORT DepthStencilProperties
 	{
 	public:
-		virtual ~DepthStencilState() {}
+		DepthStencilProperties(const DEPTH_STENCIL_STATE_DESC& desc);
 
 		/**
 		 * @brief	If enabled, any pixel about to be written will be tested against the depth value
@@ -143,6 +139,61 @@ namespace BansheeEngine
 		*/
 		CompareFunction getStencilBackCompFunc() const { return mData.backStencilComparisonFunc; }
 
+	protected:
+		friend class DepthStencilState;
+		friend class DepthStencilStateRTTI;
+
+		DEPTH_STENCIL_STATE_DESC mData;
+	};
+
+	/**
+	 * @brief	Core thread version of the depth stencil state.
+	 *
+	 * @see		DepthStencilState
+	 *
+	 * @note	Core thread.
+	 */
+	class BS_CORE_EXPORT DepthStencilStateCore : public CoreObjectCore
+	{
+	public:
+		virtual ~DepthStencilStateCore() {}
+
+		/**
+		 * @brief	Returns information about the depth stencil state.
+		 */
+		const DepthStencilProperties& getProperties() const;
+
+	protected:
+		friend class RenderStateCoreManager;
+
+		DepthStencilStateCore(const DEPTH_STENCIL_STATE_DESC& desc);
+
+		DepthStencilProperties mProperties;
+	};
+
+	/**
+	 * @brief	Render system pipeline state that allows you to modify how an object is rendered.
+	 * 			More exactly this state allows to you to control how are depth and stencil buffers
+	 *			modified upon rendering.
+	 *
+	 * @note	Depth stencil states are immutable. Sim thread only.
+	 */
+	class BS_CORE_EXPORT DepthStencilState : public Resource
+	{
+	public:
+		virtual ~DepthStencilState() {}
+
+		/**
+		 * @brief	Returns information about the depth stencil state.
+		 */
+		const DepthStencilProperties& getProperties() const;
+
+		/**
+		 * @brief	Retrieves a core implementation of a sampler state usable only from the
+		 *			core thread.
+		 */
+		SPtr<DepthStencilStateCore> getCore() const;
+
 		/**
 		 * @brief	Creates a new depth stencil state using the specified depth stencil state description structure.
 		 */
@@ -155,9 +206,14 @@ namespace BansheeEngine
 	protected:
 		friend class RenderStateManager;
 
-		virtual void initialize(const DEPTH_STENCIL_STATE_DESC& desc);
+		DepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc);
 
-		DEPTH_STENCIL_STATE_DESC mData;
+		/**
+		 * @copydoc	CoreObjectCore::createCore
+		 */
+		SPtr<CoreObjectCore> createCore() const;
+
+		DepthStencilProperties mProperties;
 
 		/************************************************************************/
 		/* 								RTTI		                     		*/

+ 3 - 11
BansheeCore/Include/BsDepthStencilStateRTTI.h

@@ -10,11 +10,8 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT DepthStencilStateRTTI : public RTTIType<DepthStencilState, IReflectable, DepthStencilStateRTTI>
 	{
 	private:
-		DEPTH_STENCIL_STATE_DESC& getData(DepthStencilState* obj) { return obj->mData; }
-		void setData(DepthStencilState* obj, DEPTH_STENCIL_STATE_DESC& val) 
-		{ 
-			obj->mRTTIData = val;
-		} 
+		DEPTH_STENCIL_STATE_DESC& getData(DepthStencilState* obj) { return obj->mProperties.mData; }
+		void setData(DepthStencilState* obj, DEPTH_STENCIL_STATE_DESC& val) { obj->mProperties.mData = val; } 
 
 	public:
 		DepthStencilStateRTTI()
@@ -25,12 +22,7 @@ namespace BansheeEngine
 		virtual void onDeserializationEnded(IReflectable* obj)
 		{
 			DepthStencilState* depthStencilState = static_cast<DepthStencilState*>(obj);
-			if(!depthStencilState->mRTTIData.empty())
-			{
-				DEPTH_STENCIL_STATE_DESC desc = any_cast<DEPTH_STENCIL_STATE_DESC>(depthStencilState->mRTTIData);
-
-				depthStencilState->initialize(desc);
-			}
+			depthStencilState->initialize();
 		}
 
 		virtual const String& getRTTIName()

+ 64 - 10
BansheeCore/Include/BsRasterizerState.h

@@ -39,15 +39,12 @@ namespace BansheeEngine
 	};
 
 	/**
-	 * @brief	Render system pipeline state that allows you to modify how an object is rasterized.
-	 *			i.e. how are polygons converted to pixels.
-	 *
-	 * @note	Rasterizer states are immutable. Thread safe.
+	 * @brief	Information about a rasterizer state.
 	 */
-	class BS_CORE_EXPORT RasterizerState : public Resource
+	class BS_CORE_EXPORT RasterizerProperties
 	{
 	public:
-		virtual ~RasterizerState() {}
+		RasterizerProperties(const RASTERIZER_STATE_DESC& desc);
 
 		/**
 		 * @brief	Polygon mode allows you to draw polygons as solid objects or as wireframe by
@@ -117,6 +114,60 @@ namespace BansheeEngine
 		 */
 		bool getAntialiasedLineEnable() const { return mData.antialiasedLineEnable; }
 
+	protected:
+		friend class RasterizerState;
+		friend class RasterizerStateRTTI;
+
+		RASTERIZER_STATE_DESC mData;
+	};
+
+	/**
+	 * @brief	Core thread version of a rasterizer state.
+	 *
+	 * @see		RasterizerState
+	 *
+	 * @note	Core thread.
+	 */
+	class BS_CORE_EXPORT RasterizerStateCore : public CoreObjectCore
+	{
+	public:
+		virtual ~RasterizerStateCore() {}
+
+		/**
+		 * @brief	Returns information about the rasterizer state.
+		 */
+		const RasterizerProperties& getProperties() const;
+
+	protected:
+		friend class RenderStateCoreManager;
+
+		RasterizerStateCore(const RASTERIZER_STATE_DESC& desc);
+
+		RasterizerProperties mProperties;
+	};
+
+	/**
+	 * @brief	Render system pipeline state that allows you to modify how an object is rasterized.
+	 *			i.e. how are polygons converted to pixels.
+	 *
+	 * @note	Rasterizer states are immutable. Sim thread only.
+	 */
+	class BS_CORE_EXPORT RasterizerState : public Resource
+	{
+	public:
+		virtual ~RasterizerState() {}
+
+		/**
+		 * @brief	Returns information about the rasterizer state.
+		 */
+		const RasterizerProperties& getProperties() const;
+
+		/**
+		 * @brief	Retrieves a core implementation of the rasterizer state usable only from the
+		 *			core thread.
+		 */
+		SPtr<RasterizerStateCore> getCore() const;
+
 		/**
 		 * @brief	Creates a new rasterizer state using the specified rasterizer state descriptor structure.
 		 */
@@ -130,11 +181,14 @@ namespace BansheeEngine
 	protected:
 		friend class RenderStateManager;
 
+		RasterizerState(const RASTERIZER_STATE_DESC& desc);
+		
 		/**
-		* @brief	Initializes the rasterizer state. Must be called right after construction.
-		*/
-		virtual void initialize(const RASTERIZER_STATE_DESC& desc);
-		RASTERIZER_STATE_DESC mData;
+		 * @copydoc	CoreObjectCore::createCore
+		 */
+		SPtr<CoreObjectCore> createCore() const;
+
+		RasterizerProperties mProperties;
 
 		/************************************************************************/
 		/* 								RTTI		                     		*/

+ 3 - 11
BansheeCore/Include/BsRasterizerStateRTTI.h

@@ -12,11 +12,8 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT RasterizerStateRTTI : public RTTIType<RasterizerState, IReflectable, RasterizerStateRTTI>
 	{
 	private:
-		RASTERIZER_STATE_DESC& getData(RasterizerState* obj) { return obj->mData; }
-		void setData(RasterizerState* obj, RASTERIZER_STATE_DESC& val) 
-		{ 
-			obj->mRTTIData = val;
-		} 
+		RASTERIZER_STATE_DESC& getData(RasterizerState* obj) { return obj->mProperties.mData; }
+		void setData(RasterizerState* obj, RASTERIZER_STATE_DESC& val) { obj->mProperties.mData = val; } 
 
 	public:
 		RasterizerStateRTTI()
@@ -27,12 +24,7 @@ namespace BansheeEngine
 		virtual void onDeserializationEnded(IReflectable* obj)
 		{
 			RasterizerState* rasterizerState = static_cast<RasterizerState*>(obj);
-			if(!rasterizerState->mRTTIData.empty())
-			{
-				RASTERIZER_STATE_DESC desc = any_cast<RASTERIZER_STATE_DESC>(rasterizerState->mRTTIData);
-
-				rasterizerState->initialize(desc);
-			}
+			rasterizerState->initialize();
 		}
 
 		virtual const String& getRTTIName()

+ 44 - 12
BansheeCore/Include/BsRenderStateManager.h

@@ -8,7 +8,7 @@ namespace BansheeEngine
 	/**
 	 * @brief	Handles creation of various render states.
 	 */
-	class BS_CORE_EXPORT RenderStateManager : public Module<RenderStateManager>
+	class BS_CORE_EXPORT RenderStateManager : public Module <RenderStateManager>
 	{
 	public:
 		/**
@@ -63,7 +63,7 @@ namespace BansheeEngine
 		 * @brief	Gets a sampler state initialized with default options.
 		 */
 		const SamplerStatePtr& getDefaultSamplerState() const;
-		
+
 		/**
 		 * @brief	Gets a blend state initialized with default options.
 		 */
@@ -79,31 +79,63 @@ namespace BansheeEngine
 		 */
 		const DepthStencilStatePtr& getDefaultDepthStencilState() const;
 
+	private:
+		mutable SamplerStatePtr mDefaultSamplerState;
+		mutable BlendStatePtr mDefaultBlendState;
+		mutable RasterizerStatePtr mDefaultRasterizerState;
+		mutable DepthStencilStatePtr mDefaultDepthStencilState;
+	};
+
+	/**
+	 * @brief	Handles creation of various render states.
+	 */
+	class BS_CORE_EXPORT RenderStateCoreManager : public Module<RenderStateCoreManager>
+	{
+	public:
+		/**
+		 * @copydoc	RenderStateManager::createSamplerState
+		 */
+		SPtr<SamplerStateCore> createSamplerState(const SAMPLER_STATE_DESC& desc) const;
+
+		/**
+		 * @copydoc	RenderStateManager::createDepthStencilState
+		 */
+		SPtr<DepthStencilStateCore> createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const;
+
+		/**
+		 * @copydoc	RenderStateManager::createRasterizerState
+		 */
+		SPtr<RasterizerStateCore> createRasterizerState(const RASTERIZER_STATE_DESC& desc) const;
+
+		/**
+		 * @copydoc	RenderStateManager::createBlendState
+		 */
+		SPtr<BlendStateCore> createBlendState(const BLEND_STATE_DESC& desc) const;
+
 	protected:
+		friend class SamplerState;
+		friend class BlendState;
+		friend class RasterizerState;
+		friend class DepthStencilState;
+
 		/**
 		 * @copydoc	createSamplerState
 		 */
-		virtual SamplerStatePtr createSamplerStateImpl() const;
+		virtual SPtr<SamplerStateCore> createSamplerStateInternal(const SAMPLER_STATE_DESC& desc) const;
 
 		/**
 		 * @copydoc	createBlendState
 		 */
-		virtual BlendStatePtr createBlendStateImpl() const;
+		virtual SPtr<BlendStateCore> createBlendStateInternal(const BLEND_STATE_DESC& desc) const;
 
 		/**
 		 * @copydoc	createRasterizerState
 		 */
-		virtual RasterizerStatePtr createRasterizerStateImpl() const;
+		virtual SPtr<RasterizerStateCore> createRasterizerStateInternal(const RASTERIZER_STATE_DESC& desc) const;
 
 		/**
 		 * @copydoc	createDepthStencilState
 		 */
-		virtual DepthStencilStatePtr createDepthStencilStateImpl() const;
-
-	private:
-		mutable SamplerStatePtr mDefaultSamplerState;
-		mutable BlendStatePtr mDefaultBlendState;
-		mutable RasterizerStatePtr mDefaultRasterizerState;
-		mutable DepthStencilStatePtr mDefaultDepthStencilState;
+		virtual SPtr<DepthStencilStateCore> createDepthStencilStateInternal(const DEPTH_STENCIL_STATE_DESC& desc) const;
 	};
 }

+ 4 - 4
BansheeCore/Include/BsRenderSystem.h

@@ -51,28 +51,28 @@ namespace BansheeEngine
 		 *
 		 * @see		SamplerState
 		 */
-		virtual void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState) = 0;
+		virtual void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SPtr<SamplerStateCore>& samplerState) = 0;
 
 		/**
 		 * @brief	Sets a blend state used for all active render targets.
 		 *
 		 * @see		BlendState
 		 */
-		virtual void setBlendState(const BlendStatePtr& blendState) = 0;
+		virtual void setBlendState(const SPtr<BlendStateCore>& blendState) = 0;
 
 		/**
 		 * @brief	Sets a state that controls various rasterizer options. 
 		 *
 		 * @see		RasterizerState
 		 */
-		virtual void setRasterizerState(const RasterizerStatePtr& rasterizerState) = 0;
+		virtual void setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState) = 0;
 
 		/**
 		 * @brief	Sets a state that controls depth & stencil buffer options.
 		 *
 		 * @see		DepthStencilState
 		 */
-		virtual void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue) = 0;
+		virtual void setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue) = 0;
 
 		/**
 		 * @brief	Binds a texture to the pipeline for the specified GPU program type at the specified slot.

+ 69 - 15
BansheeCore/Include/BsSamplerState.h

@@ -35,16 +35,12 @@ namespace BansheeEngine
 	};
 
 	/**
-	* @brief	Class representing the state of a texture sampler.
-	*	
-	* @note		Sampler units are used for retrieving and filtering data from
-	*			textures set in a GPU program.
-	*			Sampler states are immutable. Thread safe.
-	*/
-	class BS_CORE_EXPORT SamplerState : public Resource
-    {
-    public:
-		virtual ~SamplerState() {}
+	 * @brief	Information about a sampler state.
+	 */
+	class BS_CORE_EXPORT SamplerProperties
+	{
+	public:
+		SamplerProperties(const SAMPLER_STATE_DESC& desc);
 
 		/**
 		 * @brief	Returns texture addressing mode for each possible texture coordinate. Addressing
@@ -91,6 +87,62 @@ namespace BansheeEngine
 		 */
 		const Color& getBorderColor() const;
 
+	protected:
+		friend class SamplerState;
+		friend class SamplerStateRTTI;
+
+		SAMPLER_STATE_DESC mData;
+	};
+
+	/**
+	 * @brief	Core thread version of a sampler state.
+	 *
+	 * @see		SamplerState
+	 *
+	 * @note	Core thread.
+	 */
+	class BS_CORE_EXPORT SamplerStateCore : public CoreObjectCore
+	{
+	public:
+		virtual ~SamplerStateCore() {}
+
+		/**
+		 * @brief	Returns information about the sampler state.
+		 */
+		const SamplerProperties& getProperties() const;
+
+	protected:
+		friend class RenderStateCoreManager;
+
+		SamplerStateCore(const SAMPLER_STATE_DESC& desc);
+
+		SamplerProperties mProperties;
+	};
+
+	/**
+	 * @brief	Class representing the state of a texture sampler.
+	 *	
+	 * @note	Sampler units are used for retrieving and filtering data from
+	 *			textures set in a GPU program. Sampler states are immutable.
+	 *
+	 *			Sim thread.
+	 */
+	class BS_CORE_EXPORT SamplerState : public Resource
+    {
+    public:
+		virtual ~SamplerState() {}
+
+		/**
+		 * @brief	Returns information about the sampler state.
+		 */
+		const SamplerProperties& getProperties() const;
+
+		/**
+		 * @brief	Retrieves a core implementation of the sampler state usable only from the
+		 *			core thread.
+		 */
+		SPtr<SamplerStateCore> getCore() const;
+
 		/**
 		 * @brief	Creates a new sampler state using the provided descriptor structure.
 		 */
@@ -102,14 +154,16 @@ namespace BansheeEngine
 		static const SamplerStatePtr& getDefault();
 
 	protected:
-		friend class RenderStateManager;
+		SamplerState(const SAMPLER_STATE_DESC& desc);
 
 		/**
-		* @brief	Initializes the sampler state. Must be called right after construction.
-		*/
-		virtual void initialize(const SAMPLER_STATE_DESC& desc);
+		 * @copydoc	CoreObjectCore::createCore
+		 */
+		SPtr<CoreObjectCore> createCore() const;
 
-        SAMPLER_STATE_DESC mData;
+		SamplerProperties mProperties;
+
+		friend class RenderStateManager;
 
 		/************************************************************************/
 		/* 								RTTI		                     		*/

+ 3 - 12
BansheeCore/Include/BsSamplerStateRTTI.h

@@ -12,11 +12,8 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT SamplerStateRTTI : public RTTIType<SamplerState, IReflectable, SamplerStateRTTI>
 	{
 	private:
-		SAMPLER_STATE_DESC& getData(SamplerState* obj) { return obj->mData; }
-		void setData(SamplerState* obj, SAMPLER_STATE_DESC& val) 
-		{ 
-			obj->mRTTIData = val;
-		} 
+		SAMPLER_STATE_DESC& getData(SamplerState* obj) { return obj->mProperties.mData; }
+		void setData(SamplerState* obj, SAMPLER_STATE_DESC& val) { obj->mProperties.mData = val; } 
 
 	public:
 		SamplerStateRTTI()
@@ -27,13 +24,7 @@ namespace BansheeEngine
 		virtual void onDeserializationEnded(IReflectable* obj)
 		{
 			SamplerState* samplerState = static_cast<SamplerState*>(obj);
-			if(!samplerState->mRTTIData.empty())
-			{
-				SAMPLER_STATE_DESC desc = any_cast<SAMPLER_STATE_DESC>(samplerState->mRTTIData);
-
-				samplerState->initialize(desc);
-			}
-
+			samplerState->initialize();
 		}
 
 		virtual const String& getRTTIName()

+ 47 - 20
BansheeCore/Source/BsBlendState.cpp

@@ -6,74 +6,101 @@
 
 namespace BansheeEngine
 {
-	void BlendState::initialize(const BLEND_STATE_DESC& desc)
-	{
-		mData = desc;
-
-		Resource::initialize();
-	}
-
-	const BlendStatePtr& BlendState::getDefault()
-	{
-		return RenderStateManager::instance().getDefaultBlendState();
-	}
+	BlendProperties::BlendProperties(const BLEND_STATE_DESC& desc)
+		:mData(desc)
+	{ }
 
-	bool BlendState::getBlendEnabled(UINT32 renderTargetIdx) const
+	bool BlendProperties::getBlendEnabled(UINT32 renderTargetIdx) const
 	{
 		assert(renderTargetIdx >= 0 && renderTargetIdx < BS_MAX_MULTIPLE_RENDER_TARGETS);
 
 		return mData.renderTargetDesc[renderTargetIdx].blendEnable;
 	}
 
-	BlendFactor BlendState::getSrcBlend(UINT32 renderTargetIdx) const
+	BlendFactor BlendProperties::getSrcBlend(UINT32 renderTargetIdx) const
 	{
 		assert(renderTargetIdx >= 0 && renderTargetIdx < BS_MAX_MULTIPLE_RENDER_TARGETS);
 
 		return mData.renderTargetDesc[renderTargetIdx].srcBlend;
 	}
 
-	BlendFactor BlendState::getDstBlend(UINT32 renderTargetIdx) const
+	BlendFactor BlendProperties::getDstBlend(UINT32 renderTargetIdx) const
 	{
 		assert(renderTargetIdx >= 0 && renderTargetIdx < BS_MAX_MULTIPLE_RENDER_TARGETS);
 
 		return mData.renderTargetDesc[renderTargetIdx].dstBlend;
 	}
 
-	BlendOperation BlendState::getBlendOperation(UINT32 renderTargetIdx) const
+	BlendOperation BlendProperties::getBlendOperation(UINT32 renderTargetIdx) const
 	{
 		assert(renderTargetIdx >= 0 && renderTargetIdx < BS_MAX_MULTIPLE_RENDER_TARGETS);
 
 		return mData.renderTargetDesc[renderTargetIdx].blendOp;
 	}
 
-	BlendFactor BlendState::getAlphaSrcBlend(UINT32 renderTargetIdx) const
+	BlendFactor BlendProperties::getAlphaSrcBlend(UINT32 renderTargetIdx) const
 	{
 		assert(renderTargetIdx >= 0 && renderTargetIdx < BS_MAX_MULTIPLE_RENDER_TARGETS);
 
 		return mData.renderTargetDesc[renderTargetIdx].srcBlendAlpha;
 	}
 
-	BlendFactor BlendState::getAlphaDstBlend(UINT32 renderTargetIdx) const
+	BlendFactor BlendProperties::getAlphaDstBlend(UINT32 renderTargetIdx) const
 	{
 		assert(renderTargetIdx >= 0 && renderTargetIdx < BS_MAX_MULTIPLE_RENDER_TARGETS);
-		
+
 		return mData.renderTargetDesc[renderTargetIdx].dstBlendAlpha;
 	}
 
-	BlendOperation BlendState::getAlphaBlendOperation(UINT32 renderTargetIdx) const
+	BlendOperation BlendProperties::getAlphaBlendOperation(UINT32 renderTargetIdx) const
 	{
 		assert(renderTargetIdx >= 0 && renderTargetIdx < BS_MAX_MULTIPLE_RENDER_TARGETS);
 
 		return mData.renderTargetDesc[renderTargetIdx].blendOpAlpha;
 	}
 
-	UINT8 BlendState::getRenderTargetWriteMask(UINT32 renderTargetIdx) const
+	UINT8 BlendProperties::getRenderTargetWriteMask(UINT32 renderTargetIdx) const
 	{
 		assert(renderTargetIdx >= 0 && renderTargetIdx < BS_MAX_MULTIPLE_RENDER_TARGETS);
 
 		return mData.renderTargetDesc[renderTargetIdx].renderTargetWriteMask;
 	}
 
+	BlendStateCore::BlendStateCore(const BLEND_STATE_DESC& desc)
+		:mProperties(desc)
+	{
+
+	}
+
+	const BlendProperties& BlendStateCore::getProperties() const
+	{
+		return mProperties;
+	}
+
+	BlendState::BlendState(const BLEND_STATE_DESC& desc)
+		:mProperties(desc)
+	{ }
+
+	SPtr<BlendStateCore> BlendState::getCore() const
+	{
+		return std::static_pointer_cast<BlendStateCore>(mCoreSpecific);
+	}
+
+	SPtr<CoreObjectCore> BlendState::createCore() const
+	{
+		return RenderStateCoreManager::instance().createBlendStateInternal(mProperties.mData);
+	}
+
+	const BlendProperties& BlendState::getProperties() const
+	{
+		return mProperties;
+	}
+
+	const BlendStatePtr& BlendState::getDefault()
+	{
+		return RenderStateManager::instance().getDefaultBlendState();
+	}
+
 	HBlendState BlendState::create(const BLEND_STATE_DESC& desc)
 	{
 		BlendStatePtr blendStatePtr = RenderStateManager::instance().createBlendState(desc);

+ 1 - 1
BansheeCore/Source/BsCoreApplication.cpp

@@ -187,7 +187,7 @@ namespace BansheeEngine
 
 			// Sync all dirty sim thread CoreObject data to core thread
 			CoreObjectManager::instance().syncDownload(CoreObjectSync::Sim, gCoreThread().getFrameAlloc());
-			gCoreThread().queueCommand(std::bind(&CoreObjectManager::syncUpload, CoreObjectManager::instancePtr(), CoreObjectSync::Sim));
+			gCoreAccessor().queueCommand(std::bind(&CoreObjectManager::syncUpload, CoreObjectManager::instancePtr(), CoreObjectSync::Sim));
 
 			PROFILE_CALL(RendererManager::instance().getActive()->renderAll(), "Render");
 

+ 72 - 31
BansheeCore/Source/BsCoreObjectManager.cpp

@@ -7,7 +7,8 @@
 namespace BansheeEngine
 {
 	CoreObjectManager::CoreObjectManager()
-		:mNextAvailableID(1), mSimSyncDataAlloc(nullptr), mCoreSyncDataAlloc(nullptr)
+		:mNextAvailableID(1), mSimSyncIdx(0), mSimSyncCount(0),
+		mCoreSyncIdx(0), mCoreSyncCount(0)
 	{
 
 	} 
@@ -50,28 +51,40 @@ namespace BansheeEngine
 		mObjects.erase(internalId);
 
 		{
-			auto iterFind = mSimSyncData.find(internalId);
-			if (iterFind != mSimSyncData.end())
+			for (UINT32 i = 0; i < mSimSyncCount; i++)
 			{
-				UINT8* data = iterFind->second.syncData.getBuffer();
+				UINT32 idx = (mSimSyncIdx + i - mSimSyncCount - 1) % mSimSyncCount;
 
-				if (data != nullptr && mSimSyncDataAlloc != nullptr)
-					mSimSyncDataAlloc->dealloc(data);
+				SimStoredSyncData& syncData = mSimSyncData[idx];
+				auto iterFind = syncData.entries.find(internalId);
+				if (iterFind != syncData.entries.end())
+				{
+					UINT8* data = iterFind->second.syncData.getBuffer();
+
+					if (data != nullptr && syncData.alloc != nullptr)
+						syncData.alloc->dealloc(data);
 
-				mSimSyncData.erase(iterFind);
+					syncData.entries.erase(iterFind);
+				}
 			}
 		}
 
 		{
-			auto iterFind = mCoreSyncData.find(internalId);
-			if (iterFind != mCoreSyncData.end())
+			for (UINT32 i = 0; i < mCoreSyncCount; i++)
 			{
-				UINT8* data = iterFind->second.syncData.getBuffer();
+				UINT32 idx = (mCoreSyncIdx + i - mCoreSyncCount - 1) % mCoreSyncCount;
 
-				if (data != nullptr && mCoreSyncDataAlloc != nullptr)
-					mCoreSyncDataAlloc->dealloc(data);
+				CoreStoredSyncData& syncData = mCoreSyncData[idx];
+				auto iterFind = syncData.entries.find(internalId);
+				if (iterFind != syncData.entries.end())
+				{
+					UINT8* data = iterFind->second.syncData.getBuffer();
 
-				mCoreSyncData.erase(iterFind);
+					if (data != nullptr && syncData.alloc != nullptr)
+						syncData.alloc->dealloc(data);
+
+					syncData.entries.erase(iterFind);
+				}
 			}
 		}
 	}
@@ -82,33 +95,47 @@ namespace BansheeEngine
 
 		if (type == CoreObjectSync::Sim)
 		{
-			mCoreSyncDataAlloc = allocator;
+			mCoreSyncCount++;
+			if (mCoreSyncCount > (UINT32)mCoreSyncData.size())
+				mCoreSyncData.push_back(CoreStoredSyncData());
+
+			mCoreSyncIdx = (mCoreSyncIdx + 1) % mCoreSyncCount;
+			CoreStoredSyncData& syncData = mCoreSyncData[mCoreSyncIdx];
+
+			syncData.alloc = allocator;
 			for (auto& objectData : mObjects)
 			{
 				CoreObject* object = objectData.second;
 				SPtr<CoreObjectCore> objectCore = object->getCore();
 				if (objectCore != nullptr && object->isCoreDirty())
 				{
-					CoreSyncData syncData = object->syncToCore(allocator);
+					CoreSyncData objSyncData = object->syncToCore(allocator);
 					object->markCoreClean();
 
-					mCoreSyncData[object->getInternalID()] = CoreStoredSyncData(objectCore.get(), syncData);
+					syncData.entries[object->getInternalID()] = CoreStoredSyncObjData(objectCore.get(), objSyncData);
 				}
 			}
 		}
 		else
 		{
-			mSimSyncDataAlloc = allocator;
+			mSimSyncCount++;
+			if (mSimSyncCount > (UINT32)mSimSyncData.size())
+				mSimSyncData.push_back(SimStoredSyncData());
+
+			mSimSyncIdx = (mSimSyncIdx + 1) % mSimSyncCount;
+			SimStoredSyncData& syncData = mSimSyncData[mSimSyncIdx];
+
+			syncData.alloc = allocator;
 			for (auto& objectData : mObjects)
 			{
 				CoreObject* object = objectData.second;
 				SPtr<CoreObjectCore> objectCore = object->getCore();
 				if (objectCore != nullptr && objectCore->isCoreDirty())
 				{
-					CoreSyncData syncData = objectCore->syncFromCore(allocator);
+					CoreSyncData objSyncData = objectCore->syncFromCore(allocator);
 					objectCore->markCoreClean();
 
-					mSimSyncData[object->getInternalID()] = SimStoredSyncData(object, syncData);
+					syncData.entries[object->getInternalID()] = SimStoredSyncObjData(object, objSyncData);
 				}
 			}
 		}
@@ -120,33 +147,47 @@ namespace BansheeEngine
 
 		if (type == CoreObjectSync::Sim)
 		{
-			for (auto& objectData : mCoreSyncData)
+			if (mCoreSyncCount == 0)
+				return;
+
+			mCoreSyncCount--;
+			UINT32 idx = mCoreSyncIdx - mCoreSyncCount;
+
+			CoreStoredSyncData& syncData = mCoreSyncData[idx];
+			for (auto& objectData : syncData.entries)
 			{
-				const CoreStoredSyncData& syncData = objectData.second;
-				syncData.destinationObj->syncToCore(syncData.syncData);
+				const CoreStoredSyncObjData& objSyncData = objectData.second;
+				objSyncData.destinationObj->syncToCore(objSyncData.syncData);
 
-				UINT8* data = syncData.syncData.getBuffer();
+				UINT8* data = objSyncData.syncData.getBuffer();
 
 				if (data != nullptr)
-					mCoreSyncDataAlloc->dealloc(data);
+					syncData.alloc->dealloc(data);
 			}
 
-			mCoreSyncData.clear();
+			syncData.entries.clear();
 		}
 		else
 		{
-			for (auto& objectData : mSimSyncData)
+			if (mSimSyncCount == 0)
+				return;
+
+			mSimSyncCount--;
+			UINT32 idx = mSimSyncIdx - mSimSyncCount;
+
+			SimStoredSyncData& syncData = mSimSyncData[idx];
+			for (auto& objectData : syncData.entries)
 			{
-				const SimStoredSyncData& syncData = objectData.second;
-				syncData.destinationObj->syncFromCore(syncData.syncData);
+				const SimStoredSyncObjData& objSyncData = objectData.second;
+				objSyncData.destinationObj->syncFromCore(objSyncData.syncData);
 
-				UINT8* data = syncData.syncData.getBuffer();
+				UINT8* data = objSyncData.syncData.getBuffer();
 
 				if (data != nullptr)
-					mSimSyncDataAlloc->dealloc(data);
+					syncData.alloc->dealloc(data);
 			}
 
-			mSimSyncData.clear();
+			syncData.entries.clear();
 		}
 	}
 }

+ 4 - 4
BansheeCore/Source/BsCoreThreadAccessor.cpp

@@ -45,22 +45,22 @@ namespace BansheeEngine
 
 	void CoreThreadAccessorBase::setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState)
 	{
-		mCommandQueue->queue(std::bind(&RenderSystem::setSamplerState, RenderSystem::instancePtr(), gptype, texUnit, samplerState));
+		mCommandQueue->queue(std::bind(&RenderSystem::setSamplerState, RenderSystem::instancePtr(), gptype, texUnit, samplerState->getCore()));
 	}
 
 	void CoreThreadAccessorBase::setBlendState(const BlendStatePtr& blendState)
 	{
-		mCommandQueue->queue(std::bind(&RenderSystem::setBlendState, RenderSystem::instancePtr(), blendState));
+		mCommandQueue->queue(std::bind(&RenderSystem::setBlendState, RenderSystem::instancePtr(), blendState->getCore()));
 	}
 
 	void CoreThreadAccessorBase::setRasterizerState(const RasterizerStatePtr& rasterizerState)
 	{
-		mCommandQueue->queue(std::bind(&RenderSystem::setRasterizerState, RenderSystem::instancePtr(), rasterizerState));
+		mCommandQueue->queue(std::bind(&RenderSystem::setRasterizerState, RenderSystem::instancePtr(), rasterizerState->getCore()));
 	}
 
 	void CoreThreadAccessorBase::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
 	{
-		mCommandQueue->queue(std::bind(&RenderSystem::setDepthStencilState, RenderSystem::instancePtr(), depthStencilState, stencilRefValue));
+		mCommandQueue->queue(std::bind(&RenderSystem::setDepthStencilState, RenderSystem::instancePtr(), depthStencilState->getCore(), stencilRefValue));
 	}
 
 	void CoreThreadAccessorBase::setVertexBuffers(UINT32 index, const Vector<VertexBufferPtr>& buffers)

+ 34 - 3
BansheeCore/Source/BsDepthStencilState.cpp

@@ -7,11 +7,37 @@
 
 namespace BansheeEngine
 {
-	void DepthStencilState::initialize(const DEPTH_STENCIL_STATE_DESC& desc)
+	DepthStencilProperties::DepthStencilProperties(const DEPTH_STENCIL_STATE_DESC& desc)
+		:mData(desc)
 	{
-		mData = desc;
 
-		Resource::initialize();
+	}
+
+	DepthStencilStateCore::DepthStencilStateCore(const DEPTH_STENCIL_STATE_DESC& desc)
+		: mProperties(desc)
+	{
+
+	}
+
+	const DepthStencilProperties& DepthStencilStateCore::getProperties() const
+	{
+		return mProperties;
+	}
+
+	DepthStencilState::DepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc)
+		:mProperties(desc)
+	{
+
+	}
+
+	SPtr<DepthStencilStateCore> DepthStencilState::getCore() const
+	{
+		return std::static_pointer_cast<DepthStencilStateCore>(mCoreSpecific);
+	}
+
+	SPtr<CoreObjectCore> DepthStencilState::createCore() const
+	{
+		return RenderStateCoreManager::instance().createDepthStencilStateInternal(mProperties.mData);
 	}
 
 	const DepthStencilStatePtr& DepthStencilState::getDefault()
@@ -19,6 +45,11 @@ namespace BansheeEngine
 		return RenderStateManager::instance().getDefaultDepthStencilState();
 	}
 
+	const DepthStencilProperties& DepthStencilState::getProperties() const
+	{
+		return mProperties;
+	}
+
 	HDepthStencilState DepthStencilState::create(const DEPTH_STENCIL_STATE_DESC& desc)
 	{
 		DepthStencilStatePtr depthStencilPtr = RenderStateManager::instance().createDepthStencilState(desc);

+ 5 - 5
BansheeCore/Source/BsPass.cpp

@@ -50,11 +50,11 @@ namespace BansheeEngine
 			for(UINT32 i = 0; i < BS_MAX_MULTIPLE_RENDER_TARGETS; i++)
 			{
 				// Transparent if destination color is taken into account
-				if (mBlendState->getDstBlend(i) != BF_ZERO ||
-					mBlendState->getSrcBlend(i) == BF_DEST_COLOR ||
-					mBlendState->getSrcBlend(i) == BF_INV_DEST_COLOR ||
-					mBlendState->getSrcBlend(i) == BF_DEST_ALPHA ||
-					mBlendState->getSrcBlend(i) == BF_INV_DEST_ALPHA)
+				if (mBlendState->getProperties().getDstBlend(i) != BF_ZERO ||
+					mBlendState->getProperties().getSrcBlend(i) == BF_DEST_COLOR ||
+					mBlendState->getProperties().getSrcBlend(i) == BF_INV_DEST_COLOR ||
+					mBlendState->getProperties().getSrcBlend(i) == BF_DEST_ALPHA ||
+					mBlendState->getProperties().getSrcBlend(i) == BF_INV_DEST_ALPHA)
 				{
 					transparent = true;
 				}

+ 32 - 3
BansheeCore/Source/BsRasterizerState.cpp

@@ -6,11 +6,40 @@
 
 namespace BansheeEngine
 {
-	void RasterizerState::initialize(const RASTERIZER_STATE_DESC& desc)
+	RasterizerProperties::RasterizerProperties(const RASTERIZER_STATE_DESC& desc)
+		:mData(desc)
+	{ }
+
+	RasterizerStateCore::RasterizerStateCore(const RASTERIZER_STATE_DESC& desc)
+		: mProperties(desc)
 	{
-		mData = desc;
 
-		Resource::initialize();
+	}
+
+	const RasterizerProperties& RasterizerStateCore::getProperties() const
+	{
+		return mProperties;
+	}
+
+	RasterizerState::RasterizerState(const RASTERIZER_STATE_DESC& desc)
+		: mProperties(desc)
+	{
+
+	}
+
+	SPtr<RasterizerStateCore> RasterizerState::getCore() const
+	{
+		return std::static_pointer_cast<RasterizerStateCore>(mCoreSpecific);
+	}
+
+	SPtr<CoreObjectCore> RasterizerState::createCore() const
+	{
+		return RenderStateCoreManager::instance().createRasterizerStateInternal(mProperties.mData);
+	}
+
+	const RasterizerProperties& RasterizerState::getProperties() const
+	{
+		return mProperties;
 	}
 
 	const RasterizerStatePtr& RasterizerState::getDefault()

+ 64 - 20
BansheeCore/Source/BsRenderStateManager.cpp

@@ -8,43 +8,44 @@ namespace BansheeEngine
 {
 	SamplerStatePtr RenderStateManager::createSamplerState(const SAMPLER_STATE_DESC& desc) const
 	{
-		SamplerStatePtr samplerState = createSamplerStateImpl();
+		SamplerStatePtr samplerState = bs_core_ptr<SamplerState, GenAlloc>(new (bs_alloc<SamplerState>()) SamplerState(desc));
 		samplerState->_setThisPtr(samplerState);
-		samplerState->initialize(desc);
+		samplerState->initialize();
 
 		return samplerState;
 	}
 
 	DepthStencilStatePtr RenderStateManager::createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
 	{
-		DepthStencilStatePtr depthStencilState = createDepthStencilStateImpl();
+		DepthStencilStatePtr depthStencilState = bs_core_ptr<DepthStencilState, GenAlloc>(new (bs_alloc<DepthStencilState>()) DepthStencilState(desc));
 		depthStencilState->_setThisPtr(depthStencilState);
-		depthStencilState->initialize(desc);
+		depthStencilState->initialize();
 
 		return depthStencilState;
 	}
 
 	RasterizerStatePtr RenderStateManager::createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
 	{
-		RasterizerStatePtr rasterizerState = createRasterizerStateImpl();
+		RasterizerStatePtr rasterizerState = bs_core_ptr<RasterizerState, GenAlloc>(new (bs_alloc<RasterizerState>()) RasterizerState(desc));
 		rasterizerState->_setThisPtr(rasterizerState);
-		rasterizerState->initialize(desc);
+		rasterizerState->initialize();
 
 		return rasterizerState;
 	}
 
 	BlendStatePtr RenderStateManager::createBlendState(const BLEND_STATE_DESC& desc) const
 	{
-		BlendStatePtr blendState = createBlendStateImpl();
+		BlendStatePtr blendState = bs_core_ptr<BlendState, GenAlloc>(new (bs_alloc<BlendState>()) BlendState(desc));
 		blendState->_setThisPtr(blendState);
-		blendState->initialize(desc);
+		blendState->initialize();
 
 		return blendState;
 	}
 
 	SamplerStatePtr RenderStateManager::createEmptySamplerState() const
 	{
-		SamplerStatePtr samplerState = createSamplerStateImpl();
+		SamplerStatePtr samplerState = bs_core_ptr<SamplerState, GenAlloc>(
+			new (bs_alloc<SamplerState>()) SamplerState(SAMPLER_STATE_DESC()));
 		samplerState->_setThisPtr(samplerState);
 
 		return samplerState;
@@ -52,7 +53,8 @@ namespace BansheeEngine
 
 	DepthStencilStatePtr RenderStateManager::createEmptyDepthStencilState() const
 	{
-		DepthStencilStatePtr depthStencilState = createDepthStencilStateImpl();
+		DepthStencilStatePtr depthStencilState = bs_core_ptr<DepthStencilState, GenAlloc>(
+			new (bs_alloc<DepthStencilState>()) DepthStencilState(DEPTH_STENCIL_STATE_DESC()));
 		depthStencilState->_setThisPtr(depthStencilState);
 
 		return depthStencilState;
@@ -60,7 +62,8 @@ namespace BansheeEngine
 
 	RasterizerStatePtr RenderStateManager::createEmptyRasterizerState() const
 	{
-		RasterizerStatePtr rasterizerState = createRasterizerStateImpl();
+		RasterizerStatePtr rasterizerState = bs_core_ptr<RasterizerState, GenAlloc>(
+			new (bs_alloc<RasterizerState>()) RasterizerState(RASTERIZER_STATE_DESC()));
 		rasterizerState->_setThisPtr(rasterizerState);
 
 		return rasterizerState;
@@ -68,7 +71,8 @@ namespace BansheeEngine
 
 	BlendStatePtr RenderStateManager::createEmptyBlendState() const
 	{
-		BlendStatePtr blendState = createBlendStateImpl();
+		BlendStatePtr blendState = bs_core_ptr<BlendState, GenAlloc>(
+			new (bs_alloc<BlendState>()) BlendState(BLEND_STATE_DESC()));
 		blendState->_setThisPtr(blendState);
 
 		return blendState;
@@ -106,23 +110,63 @@ namespace BansheeEngine
 		return mDefaultDepthStencilState; 
 	}
 
-	SamplerStatePtr RenderStateManager::createSamplerStateImpl() const
+	SPtr<SamplerStateCore> RenderStateCoreManager::createSamplerState(const SAMPLER_STATE_DESC& desc) const
 	{
-		return bs_core_ptr<SamplerState, PoolAlloc>();
+		SPtr<SamplerStateCore> samplerState = createSamplerStateInternal(desc);
+		samplerState->initialize();
+
+		return samplerState;
+	}
+
+	SPtr<DepthStencilStateCore> RenderStateCoreManager::createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
+	{
+		SPtr<DepthStencilStateCore> depthStencilState = createDepthStencilStateInternal(desc);
+		depthStencilState->initialize();
+
+		return depthStencilState;
+	}
+
+	SPtr<RasterizerStateCore> RenderStateCoreManager::createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
+	{
+		SPtr<RasterizerStateCore> rasterizerState = createRasterizerStateInternal(desc);
+		rasterizerState->initialize();
+
+		return rasterizerState;
+	}
+
+	SPtr<BlendStateCore> RenderStateCoreManager::createBlendState(const BLEND_STATE_DESC& desc) const
+	{
+		SPtr<BlendStateCore> blendState = createBlendStateInternal(desc);
+		blendState->initialize();
+
+		return blendState;
+	}
+
+	SPtr<SamplerStateCore> RenderStateCoreManager::createSamplerStateInternal(const SAMPLER_STATE_DESC& desc) const
+	{
+		SPtr<SamplerStateCore> samplerState = bs_shared_ptr<SamplerStateCore, GenAlloc>(new (bs_alloc<SamplerStateCore>()) SamplerStateCore(desc));
+
+		return samplerState;
 	}
 
-	BlendStatePtr RenderStateManager::createBlendStateImpl() const
+	SPtr<DepthStencilStateCore> RenderStateCoreManager::createDepthStencilStateInternal(const DEPTH_STENCIL_STATE_DESC& desc) const
 	{
-		return bs_core_ptr<BlendState, PoolAlloc>();
+		SPtr<DepthStencilStateCore> depthStencilState = bs_shared_ptr<DepthStencilStateCore, GenAlloc>(new (bs_alloc<DepthStencilStateCore>()) DepthStencilStateCore(desc));
+
+		return depthStencilState;
 	}
 
-	RasterizerStatePtr RenderStateManager::createRasterizerStateImpl() const
+	SPtr<RasterizerStateCore> RenderStateCoreManager::createRasterizerStateInternal(const RASTERIZER_STATE_DESC& desc) const
 	{
-		return bs_core_ptr<RasterizerState, PoolAlloc>();
+		SPtr<RasterizerStateCore> rasterizerState = bs_shared_ptr<RasterizerStateCore, GenAlloc>(new (bs_alloc<RasterizerStateCore>()) RasterizerStateCore(desc));
+
+		return rasterizerState;
 	}
 
-	DepthStencilStatePtr RenderStateManager::createDepthStencilStateImpl() const
+	SPtr<BlendStateCore> RenderStateCoreManager::createBlendStateInternal(const BLEND_STATE_DESC& desc) const
 	{
-		return bs_core_ptr<DepthStencilState, PoolAlloc>();
+		SPtr<BlendStateCore> blendState = bs_shared_ptr<BlendStateCore, GenAlloc>(new (bs_alloc<BlendStateCore>()) BlendStateCore(desc));
+
+		return blendState;
 	}
 }

+ 6 - 6
BansheeCore/Source/BsRenderer.cpp

@@ -68,19 +68,19 @@ namespace BansheeEngine
 
 		// Set up non-texture related pass settings
 		if (pass.blendState != nullptr)
-			rs.setBlendState(pass.blendState.getInternalPtr());
+			rs.setBlendState(pass.blendState->getCore());
 		else
-			rs.setBlendState(BlendState::getDefault());
+			rs.setBlendState(BlendState::getDefault()->getCore());
 
 		if (pass.depthStencilState != nullptr)
-			rs.setDepthStencilState(pass.depthStencilState.getInternalPtr(), pass.stencilRefValue);
+			rs.setDepthStencilState(pass.depthStencilState->getCore(), pass.stencilRefValue);
 		else
-			rs.setDepthStencilState(DepthStencilState::getDefault(), pass.stencilRefValue);
+			rs.setDepthStencilState(DepthStencilState::getDefault()->getCore(), pass.stencilRefValue);
 
 		if (pass.rasterizerState != nullptr)
-			rs.setRasterizerState(pass.rasterizerState.getInternalPtr());
+			rs.setRasterizerState(pass.rasterizerState->getCore());
 		else
-			rs.setRasterizerState(RasterizerState::getDefault());
+			rs.setRasterizerState(RasterizerState::getDefault()->getCore());
 	}
 
 	void Renderer::draw(const SPtr<MeshCoreBase>& mesh, const SubMesh& subMesh)

+ 47 - 18
BansheeCore/Source/BsSamplerState.cpp

@@ -7,36 +7,55 @@
 
 namespace BansheeEngine 
 {
-	void SamplerState::initialize(const SAMPLER_STATE_DESC& desc)
+	SamplerProperties::SamplerProperties(const SAMPLER_STATE_DESC& desc)
+		:mData(desc)
+	{ }
+
+	FilterOptions SamplerProperties::getTextureFiltering(FilterType ft) const
 	{
-		mData = desc;
+		switch (ft)
+		{
+		case FT_MIN:
+			return mData.minFilter;
+		case FT_MAG:
+			return mData.magFilter;
+		case FT_MIP:
+			return mData.mipFilter;
+		}
 
-		Resource::initialize();
+		return mData.minFilter;
 	}
 
-	const SamplerStatePtr& SamplerState::getDefault()
+	const Color& SamplerProperties::getBorderColor() const
 	{
-		return RenderStateManager::instance().getDefaultSamplerState();
+		return mData.borderColor;
 	}
 
-	FilterOptions SamplerState::getTextureFiltering(FilterType ft) const
+	SamplerStateCore::SamplerStateCore(const SAMPLER_STATE_DESC& desc)
+		:mProperties(desc)
 	{
-        switch (ft)
-        {
-        case FT_MIN:
-            return mData.minFilter;
-        case FT_MAG:
-            return mData.magFilter;
-        case FT_MIP:
-            return mData.mipFilter;
-        }
 
-		return mData.minFilter;
 	}
 
-	const Color& SamplerState::getBorderColor() const
+	const SamplerProperties& SamplerStateCore::getProperties() const
 	{
-		return mData.borderColor;
+		return mProperties;
+	}
+
+	SamplerState::SamplerState(const SAMPLER_STATE_DESC& desc)
+		:mProperties(desc)
+	{
+
+	}
+
+	SPtr<SamplerStateCore> SamplerState::getCore() const
+	{
+		return std::static_pointer_cast<SamplerStateCore>(mCoreSpecific);
+	}
+
+	SPtr<CoreObjectCore> SamplerState::createCore() const
+	{
+		return RenderStateCoreManager::instance().createSamplerStateInternal(mProperties.mData);
 	}
 
 	HSamplerState SamplerState::create(const SAMPLER_STATE_DESC& desc)
@@ -46,6 +65,16 @@ namespace BansheeEngine
 		return static_resource_cast<SamplerState>(gResources()._createResourceHandle(samplerPtr));
 	}
 
+	const SamplerStatePtr& SamplerState::getDefault()
+	{
+		return RenderStateManager::instance().getDefaultSamplerState();
+	}
+
+	const SamplerProperties& SamplerState::getProperties() const
+	{
+		return mProperties;
+	}
+
 	/************************************************************************/
 	/* 								RTTI		                     		*/
 	/************************************************************************/

+ 8 - 8
BansheeD3D11RenderSystem/Include/BsD3D11BlendState.h

@@ -9,10 +9,10 @@ namespace BansheeEngine
 	 * @brief	DirectX 11 implementation of a blend state. 
 	 *			Corresponds directly with a DX11 blend state object.
 	 */
-	class BS_D3D11_EXPORT D3D11BlendState : public BlendState
+	class BS_D3D11_EXPORT D3D11BlendStateCore : public BlendStateCore
 	{
 	public:
-		~D3D11BlendState();
+		~D3D11BlendStateCore();
 
 		/**
 		 * @brief	Returns the internal DX11 blend state object.
@@ -20,19 +20,19 @@ namespace BansheeEngine
 		ID3D11BlendState* getInternal() const { return mBlendState; }
 
 	protected:
-		friend class D3D11RenderStateManager;
+		friend class D3D11RenderStateCoreManager;
 
-		D3D11BlendState();
+		D3D11BlendStateCore(const BLEND_STATE_DESC& desc);
 
 		/**
-		 * @copydoc BlendState::initialize_internal().
+		 * @copydoc BlendStateCore::initialize
 		 */
-		void initialize_internal();
+		void initialize();
 
 		/**
-		 * @copydoc BlendState::destroy_internal().
+		 * @copydoc BlendStateCore::destroy
 		 */
-		void destroy_internal();
+		void destroy();
 
 		ID3D11BlendState* mBlendState;
 	};

+ 8 - 8
BansheeD3D11RenderSystem/Include/BsD3D11DepthStencilState.h

@@ -9,10 +9,10 @@ namespace BansheeEngine
 	 * @brief	DirectX 11 implementation of a depth stencil state. 
 	 *			Corresponds directly with a DX11 depth stencil state object.
 	 */
-	class BS_D3D11_EXPORT D3D11DepthStencilState : public DepthStencilState
+	class BS_D3D11_EXPORT D3D11DepthStencilStateCore : public DepthStencilStateCore
 	{
 	public:
-		~D3D11DepthStencilState();
+		~D3D11DepthStencilStateCore();
 
 		/**
 		 * @brief	Returns the internal DX11 depth stencil state object.
@@ -20,19 +20,19 @@ namespace BansheeEngine
 		ID3D11DepthStencilState* getInternal() const { return mDepthStencilState; }
 
 	protected:
-		friend class D3D11RenderStateManager;
+		friend class D3D11RenderStateCoreManager;
 
-		D3D11DepthStencilState();
+		D3D11DepthStencilStateCore(const DEPTH_STENCIL_STATE_DESC& desc);
 
 		/**
-		 * @copydoc DepthStencilState::initialize_internal().
+		 * @copydoc DepthStencilStateCore::initialize()
 		 */
-		void initialize_internal();
+		void initialize();
 
 		/**
-		 * @copydoc DepthStencilState::destroy_internal().
+		 * @copydoc DepthStencilStateCore::destroy()
 		 */
-		void destroy_internal();
+		void destroy();
 
 		ID3D11DepthStencilState* mDepthStencilState;
 	};

+ 8 - 8
BansheeD3D11RenderSystem/Include/BsD3D11RasterizerState.h

@@ -9,26 +9,26 @@ namespace BansheeEngine
 	 * @brief	DirectX 11 implementation of a rasterizer state. Wraps a DX11
 	 *			rasterizer state object.
 	 */
-	class BS_D3D11_EXPORT D3D11RasterizerState : public RasterizerState
+	class BS_D3D11_EXPORT D3D11RasterizerStateCore : public RasterizerStateCore
 	{
 	public:
-		~D3D11RasterizerState();
+		~D3D11RasterizerStateCore();
 		ID3D11RasterizerState* getInternal() const { return mRasterizerState; }
 
 	protected:
-		friend class D3D11RenderStateManager;
+		friend class D3D11RenderStateCoreManager;
 
-		D3D11RasterizerState();
+		D3D11RasterizerStateCore(const RASTERIZER_STATE_DESC& desc);
 
 		/**
-		 * @copydoc RasterizerState::initialize_internal
+		 * @copydoc RasterizerStateCore::initialize
 		 */
-		void initialize_internal();
+		void initialize();
 
 		/**
-		 * @copydoc RasterizerState::destroy_internal
+		 * @copydoc RasterizerStateCore::destroy
 		 */
-		void destroy_internal();
+		void destroy();
 
 		ID3D11RasterizerState* mRasterizerState;
 	};

+ 9 - 9
BansheeD3D11RenderSystem/Include/BsD3D11RenderStateManager.h

@@ -8,27 +8,27 @@ namespace BansheeEngine
 	/**
 	 * @brief	Handles creation of DirectX 11 pipeline states.
 	 */
-	class BS_D3D11_EXPORT D3D11RenderStateManager : public RenderStateManager
+	class BS_D3D11_EXPORT D3D11RenderStateCoreManager : public RenderStateCoreManager
 	{
 	protected:
 		/**
-		 * @copydoc	RenderStateManager::createSamplerStateImpl
+		 * @copydoc	RenderStateCoreManager::createSamplerStateInternal
 		 */
-		virtual SamplerStatePtr createSamplerStateImpl() const;
+		virtual SPtr<SamplerStateCore> createSamplerStateInternal(const SAMPLER_STATE_DESC& desc) const;
 
 		/**
-		 * @copydoc	RenderStateManager::createBlendStateImpl
+		 * @copydoc	RenderStateCoreManager::createBlendStateInternal
 		 */
-		virtual BlendStatePtr createBlendStateImpl() const;
+		virtual SPtr<BlendStateCore> createBlendStateInternal(const BLEND_STATE_DESC& desc) const;
 
 		/**
-		 * @copydoc	RenderStateManager::createRasterizerStateImpl
+		 * @copydoc	RenderStateCoreManager::createRasterizerStateInternal
 		 */
-		virtual RasterizerStatePtr createRasterizerStateImpl() const;
+		virtual SPtr<RasterizerStateCore> createRasterizerStateInternal(const RASTERIZER_STATE_DESC& desc) const;
 
 		/**
-		 * @copydoc	RenderStateManager::createDepthStencilStateImpl
+		 * @copydoc	RenderStateCoreManager::createDepthStencilStateInternal
 		 */
-		virtual DepthStencilStatePtr createDepthStencilStateImpl() const;
+		virtual SPtr<DepthStencilStateCore> createDepthStencilStateInternal(const DEPTH_STENCIL_STATE_DESC& desc) const;
 	};
 }

+ 4 - 4
BansheeD3D11RenderSystem/Include/BsD3D11RenderSystem.h

@@ -28,22 +28,22 @@ namespace BansheeEngine
 		/**
 		 * @copydoc	RenderSystem::setBlendState
 		 */
-		void setBlendState(const BlendStatePtr& blendState);
+		void setBlendState(const SPtr<BlendStateCore>& blendState);
 
 		/**
 		 * @copydoc	RenderSystem::setRasterizerState
 		 */
-		void setRasterizerState(const RasterizerStatePtr& rasterizerState);
+		void setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState);
 
 		/**
 		 * @copydoc	RenderSystem::setDepthStencilState
 		 */
-		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
+		void setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue);
 
 		/**
 		 * @copydoc	RenderSystem::setSamplerState
 		 */
-		void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState);
+		void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SPtr<SamplerStateCore>& samplerState);
 
 		/**
 		 * @copydoc	RenderSystem::setTexture

+ 7 - 7
BansheeD3D11RenderSystem/Include/BsD3D11RenderUtility.h

@@ -41,12 +41,12 @@ namespace BansheeEngine
 		ID3D11VertexShader* mClearQuadVS;
 		ID3D11PixelShader* mClearQuadPS;
 
-		HBlendState mClearQuadBlendStateYesC;
-		HBlendState mClearQuadBlendStateNoC;
-		HRasterizerState mClearQuadRasterizerState;
-		HDepthStencilState mClearQuadDSStateNoD_NoS;
-		HDepthStencilState mClearQuadDSStateYesD_NoS;
-		HDepthStencilState mClearQuadDSStateYesD_YesS;
-		HDepthStencilState mClearQuadDSStateNoD_YesS;
+		SPtr<BlendStateCore> mClearQuadBlendStateYesC;
+		SPtr<BlendStateCore> mClearQuadBlendStateNoC;
+		SPtr<RasterizerStateCore> mClearQuadRasterizerState;
+		SPtr<DepthStencilStateCore> mClearQuadDSStateNoD_NoS;
+		SPtr<DepthStencilStateCore> mClearQuadDSStateYesD_NoS;
+		SPtr<DepthStencilStateCore> mClearQuadDSStateYesD_YesS;
+		SPtr<DepthStencilStateCore> mClearQuadDSStateNoD_YesS;
 	};
 }

+ 8 - 8
BansheeD3D11RenderSystem/Include/BsD3D11SamplerState.h

@@ -9,26 +9,26 @@ namespace BansheeEngine
 	 * @brief	DirectX 11 implementation of a sampler state. Wraps a DX11
 	 *			sampler state object.
 	 */
-	class BS_D3D11_EXPORT D3D11SamplerState : public SamplerState
+	class BS_D3D11_EXPORT D3D11SamplerStateCore : public SamplerStateCore
 	{
 	public:
-		~D3D11SamplerState();
+		~D3D11SamplerStateCore();
 		ID3D11SamplerState* getInternal() const { return mSamplerState; }
 
 	protected:
-		friend class D3D11RenderStateManager;
+		friend class D3D11RenderStateCoreManager;
 
-		D3D11SamplerState();
+		D3D11SamplerStateCore(const SAMPLER_STATE_DESC& desc);
 
 		/**
-		 * @copydoc SamplerState::initialize_internal
+		 * @copydoc SamplerStateCore::initialize
 		 */
-		void initialize_internal();
+		void initialize();
 
 		/**
-		 * @copydoc SamplerState::destroy_internal
+		 * @copydoc SamplerStateCore::destroy
 		 */
-		void destroy_internal();
+		void destroy();
 
 		ID3D11SamplerState* mSamplerState;
 	};

+ 17 - 17
BansheeD3D11RenderSystem/Source/BsD3D11BlendState.cpp

@@ -6,32 +6,32 @@
 
 namespace BansheeEngine
 {
-	D3D11BlendState::D3D11BlendState()
-		:mBlendState(nullptr)
+	D3D11BlendStateCore::D3D11BlendStateCore(const BLEND_STATE_DESC& desc)
+		:BlendStateCore(desc), mBlendState(nullptr)
 	{ }
 
-	D3D11BlendState::~D3D11BlendState()
+	D3D11BlendStateCore::~D3D11BlendStateCore()
 	{
 	}
 
-	void D3D11BlendState::initialize_internal()
+	void D3D11BlendStateCore::initialize()
 	{
 		D3D11_BLEND_DESC blendStateDesc;
 		ZeroMemory(&blendStateDesc, sizeof(D3D11_BLEND_DESC));
 
-		blendStateDesc.AlphaToCoverageEnable = mData.alphaToCoverageEnable;
-		blendStateDesc.IndependentBlendEnable = mData.independantBlendEnable;
+		blendStateDesc.AlphaToCoverageEnable = mProperties.getAlphaToCoverageEnabled();
+		blendStateDesc.IndependentBlendEnable = mProperties.getIndependantBlendEnable();
 		
 		for(UINT32 i = 0; i < BS_MAX_MULTIPLE_RENDER_TARGETS; i++)
 		{
-			blendStateDesc.RenderTarget[i].BlendEnable = mData.renderTargetDesc[i].blendEnable;
-			blendStateDesc.RenderTarget[i].BlendOp = D3D11Mappings::get(mData.renderTargetDesc[i].blendOp);
-			blendStateDesc.RenderTarget[i].BlendOpAlpha = D3D11Mappings::get(mData.renderTargetDesc[i].blendOpAlpha);
-			blendStateDesc.RenderTarget[i].DestBlend = D3D11Mappings::get(mData.renderTargetDesc[i].dstBlend);
-			blendStateDesc.RenderTarget[i].DestBlendAlpha = D3D11Mappings::get(mData.renderTargetDesc[i].dstBlendAlpha);
-			blendStateDesc.RenderTarget[i].RenderTargetWriteMask = 0xf & mData.renderTargetDesc[i].renderTargetWriteMask; // Mask out all but last 4 bits
-			blendStateDesc.RenderTarget[i].SrcBlend = D3D11Mappings::get(mData.renderTargetDesc[i].srcBlend);
-			blendStateDesc.RenderTarget[i].SrcBlendAlpha = D3D11Mappings::get(mData.renderTargetDesc[i].srcBlendAlpha);
+			blendStateDesc.RenderTarget[i].BlendEnable = mProperties.getBlendEnabled(i);
+			blendStateDesc.RenderTarget[i].BlendOp = D3D11Mappings::get(mProperties.getBlendOperation(i));
+			blendStateDesc.RenderTarget[i].BlendOpAlpha = D3D11Mappings::get(mProperties.getAlphaBlendOperation(i));
+			blendStateDesc.RenderTarget[i].DestBlend = D3D11Mappings::get(mProperties.getDstBlend(i));
+			blendStateDesc.RenderTarget[i].DestBlendAlpha = D3D11Mappings::get(mProperties.getAlphaDstBlend(i));
+			blendStateDesc.RenderTarget[i].RenderTargetWriteMask = 0xf & (mProperties.getRenderTargetWriteMask(i)); // Mask out all but last 4 bits
+			blendStateDesc.RenderTarget[i].SrcBlend = D3D11Mappings::get(mProperties.getSrcBlend(i));
+			blendStateDesc.RenderTarget[i].SrcBlendAlpha = D3D11Mappings::get(mProperties.getAlphaSrcBlend(i));
 		}
 
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
@@ -46,15 +46,15 @@ namespace BansheeEngine
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_BlendState);
 
-		BlendState::initialize_internal();
+		BlendStateCore::initialize();
 	}
 
-	void D3D11BlendState::destroy_internal()
+	void D3D11BlendStateCore::destroy()
 	{
 		SAFE_RELEASE(mBlendState);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_BlendState);
 
-		BlendState::destroy_internal();
+		BlendStateCore::destroy();
 	}
 }

+ 21 - 21
BansheeD3D11RenderSystem/Source/BsD3D11DepthStencilState.cpp

@@ -6,34 +6,34 @@
 
 namespace BansheeEngine
 {
-	D3D11DepthStencilState::D3D11DepthStencilState()
-		:mDepthStencilState(nullptr)
+	D3D11DepthStencilStateCore::D3D11DepthStencilStateCore(const DEPTH_STENCIL_STATE_DESC& desc)
+		:DepthStencilStateCore(desc), mDepthStencilState(nullptr)
 	{ }
 
-	D3D11DepthStencilState::~D3D11DepthStencilState()
+	D3D11DepthStencilStateCore::~D3D11DepthStencilStateCore()
 	{
 
 	}
 
-	void D3D11DepthStencilState::initialize_internal()
+	void D3D11DepthStencilStateCore::initialize()
 	{
 		D3D11_DEPTH_STENCIL_DESC depthStencilState;
 		ZeroMemory(&depthStencilState, sizeof(D3D11_DEPTH_STENCIL_DESC));
 
-		depthStencilState.BackFace.StencilPassOp = D3D11Mappings::get(mData.backStencilPassOp);
-		depthStencilState.BackFace.StencilFailOp = D3D11Mappings::get(mData.backStencilFailOp);
-		depthStencilState.BackFace.StencilDepthFailOp = D3D11Mappings::get(mData.backStencilZFailOp);
-		depthStencilState.BackFace.StencilFunc = D3D11Mappings::get(mData.backStencilComparisonFunc);
-		depthStencilState.FrontFace.StencilPassOp = D3D11Mappings::get(mData.frontStencilPassOp);
-		depthStencilState.FrontFace.StencilFailOp = D3D11Mappings::get(mData.frontStencilFailOp);
-		depthStencilState.FrontFace.StencilDepthFailOp = D3D11Mappings::get(mData.frontStencilZFailOp);
-		depthStencilState.FrontFace.StencilFunc = D3D11Mappings::get(mData.frontStencilComparisonFunc);
-		depthStencilState.DepthEnable = mData.depthReadEnable;
-		depthStencilState.DepthWriteMask = mData.depthWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
-		depthStencilState.DepthFunc = D3D11Mappings::get(mData.depthComparisonFunc);
-		depthStencilState.StencilEnable = mData.stencilEnable;
-		depthStencilState.StencilReadMask = mData.stencilReadMask;
-		depthStencilState.StencilWriteMask = mData.stencilWriteMask;
+		depthStencilState.BackFace.StencilPassOp = D3D11Mappings::get(mProperties.getStencilBackPassOp());
+		depthStencilState.BackFace.StencilFailOp = D3D11Mappings::get(mProperties.getStencilBackFailOp());
+		depthStencilState.BackFace.StencilDepthFailOp = D3D11Mappings::get(mProperties.getStencilBackZFailOp());
+		depthStencilState.BackFace.StencilFunc = D3D11Mappings::get(mProperties.getStencilBackCompFunc());
+		depthStencilState.FrontFace.StencilPassOp = D3D11Mappings::get(mProperties.getStencilFrontPassOp());
+		depthStencilState.FrontFace.StencilFailOp = D3D11Mappings::get(mProperties.getStencilFrontFailOp());
+		depthStencilState.FrontFace.StencilDepthFailOp = D3D11Mappings::get(mProperties.getStencilFrontZFailOp());
+		depthStencilState.FrontFace.StencilFunc = D3D11Mappings::get(mProperties.getStencilFrontCompFunc());
+		depthStencilState.DepthEnable = mProperties.getDepthReadEnable();
+		depthStencilState.DepthWriteMask = mProperties.getDepthWriteEnable() ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
+		depthStencilState.DepthFunc = D3D11Mappings::get(mProperties.getDepthComparisonFunc());
+		depthStencilState.StencilEnable = mProperties.getStencilEnable();
+		depthStencilState.StencilReadMask = mProperties.getStencilReadMask();
+		depthStencilState.StencilWriteMask = mProperties.getStencilWriteMask();
 
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 		D3D11Device& device = rs->getPrimaryDevice();
@@ -47,15 +47,15 @@ namespace BansheeEngine
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_DepthStencilState);
 
-		DepthStencilState::initialize_internal();
+		DepthStencilStateCore::initialize();
 	}
 
-	void D3D11DepthStencilState::destroy_internal()
+	void D3D11DepthStencilStateCore::destroy()
 	{
 		SAFE_RELEASE(mDepthStencilState);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_DepthStencilState);
 
-		DepthStencilState::destroy_internal();
+		DepthStencilStateCore::destroy();
 	}
 }

+ 16 - 16
BansheeD3D11RenderSystem/Source/BsD3D11RasterizerState.cpp

@@ -6,28 +6,28 @@
 
 namespace BansheeEngine
 {
-	D3D11RasterizerState::D3D11RasterizerState()
-		:mRasterizerState(nullptr)
+	D3D11RasterizerStateCore::D3D11RasterizerStateCore(const RASTERIZER_STATE_DESC& desc)
+		:RasterizerStateCore(desc), mRasterizerState(nullptr)
 	{ }
 
-	D3D11RasterizerState::~D3D11RasterizerState()
+	D3D11RasterizerStateCore::~D3D11RasterizerStateCore()
 	{
 	}
 
-	void D3D11RasterizerState::initialize_internal()
+	void D3D11RasterizerStateCore::initialize()
 	{
 		D3D11_RASTERIZER_DESC rasterizerStateDesc;
 		ZeroMemory(&rasterizerStateDesc, sizeof(D3D11_RASTERIZER_DESC));
 
-		rasterizerStateDesc.AntialiasedLineEnable = mData.antialiasedLineEnable;
-		rasterizerStateDesc.CullMode = D3D11Mappings::get(mData.cullMode);
-		rasterizerStateDesc.DepthBias = mData.depthBias;
-		rasterizerStateDesc.DepthBiasClamp = mData.depthBiasClamp;
-		rasterizerStateDesc.DepthClipEnable = mData.depthClipEnable;
-		rasterizerStateDesc.FillMode = D3D11Mappings::get(mData.polygonMode);
-		rasterizerStateDesc.MultisampleEnable = mData.multisampleEnable;
-		rasterizerStateDesc.ScissorEnable = mData.scissorEnable;
-		rasterizerStateDesc.SlopeScaledDepthBias = mData.slopeScaledDepthBias;
+		rasterizerStateDesc.AntialiasedLineEnable = mProperties.getAntialiasedLineEnable();
+		rasterizerStateDesc.CullMode = D3D11Mappings::get(mProperties.getCullMode());
+		rasterizerStateDesc.DepthBias = mProperties.getDepthBias();
+		rasterizerStateDesc.DepthBiasClamp = mProperties.getDepthBiasClamp();
+		rasterizerStateDesc.DepthClipEnable = mProperties.getDepthClipEnable();
+		rasterizerStateDesc.FillMode = D3D11Mappings::get(mProperties.getPolygonMode());
+		rasterizerStateDesc.MultisampleEnable = mProperties.getMultisampleEnable();
+		rasterizerStateDesc.ScissorEnable = mProperties.getScissorEnable();
+		rasterizerStateDesc.SlopeScaledDepthBias = mProperties.getSlopeScaledDepthBias();
 		rasterizerStateDesc.FrontCounterClockwise = false;
 
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
@@ -41,14 +41,14 @@ namespace BansheeEngine
 		}
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_RasterizerState);
-		RasterizerState::initialize_internal();
+		RasterizerStateCore::initialize();
 	}
 
-	void D3D11RasterizerState::destroy_internal()
+	void D3D11RasterizerStateCore::destroy()
 	{
 		SAFE_RELEASE(mRasterizerState);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_RasterizerState);
-		RasterizerState::destroy_internal();
+		RasterizerStateCore::destroy();
 	}
 }

+ 8 - 12
BansheeD3D11RenderSystem/Source/BsD3D11RenderStateManager.cpp

@@ -6,27 +6,23 @@
 
 namespace BansheeEngine
 {
-	SamplerStatePtr D3D11RenderStateManager::createSamplerStateImpl() const
+	SPtr<SamplerStateCore> D3D11RenderStateCoreManager::createSamplerStateInternal(const SAMPLER_STATE_DESC& desc) const
 	{
-		SamplerStatePtr samplerState = bs_core_ptr<D3D11SamplerState, PoolAlloc>(new (bs_alloc<D3D11SamplerState, PoolAlloc>()) D3D11SamplerState());
-		return samplerState;
+		return bs_shared_ptr<D3D11SamplerStateCore, GenAlloc>(new (bs_alloc<D3D11SamplerStateCore>()) D3D11SamplerStateCore(desc));
 	}
 
-	BlendStatePtr D3D11RenderStateManager::createBlendStateImpl() const
+	SPtr<BlendStateCore> D3D11RenderStateCoreManager::createBlendStateInternal(const BLEND_STATE_DESC& desc) const
 	{
-		BlendStatePtr blendState = bs_core_ptr<D3D11BlendState, PoolAlloc>(new (bs_alloc<D3D11BlendState, PoolAlloc>()) D3D11BlendState());
-		return blendState;
+		return bs_shared_ptr<D3D11BlendStateCore, GenAlloc>(new (bs_alloc<D3D11BlendStateCore>()) D3D11BlendStateCore(desc));
 	}
 
-	RasterizerStatePtr D3D11RenderStateManager::createRasterizerStateImpl() const
+	SPtr<RasterizerStateCore> D3D11RenderStateCoreManager::createRasterizerStateInternal(const RASTERIZER_STATE_DESC& desc) const
 	{
-		RasterizerStatePtr rasterizerState = bs_core_ptr<D3D11RasterizerState, PoolAlloc>(new (bs_alloc<D3D11RasterizerState, PoolAlloc>()) D3D11RasterizerState());
-		return rasterizerState;
+		return bs_shared_ptr<D3D11RasterizerStateCore, GenAlloc>(new (bs_alloc<D3D11RasterizerStateCore>()) D3D11RasterizerStateCore(desc));
 	}
 
-	DepthStencilStatePtr D3D11RenderStateManager::createDepthStencilStateImpl() const
+	SPtr<DepthStencilStateCore> D3D11RenderStateCoreManager::createDepthStencilStateInternal(const DEPTH_STENCIL_STATE_DESC& desc) const
 	{
-		DepthStencilStatePtr depthStencilState = bs_core_ptr<D3D11DepthStencilState, PoolAlloc>(new (bs_alloc<D3D11DepthStencilState, PoolAlloc>()) D3D11DepthStencilState());
-		return depthStencilState;
+		return bs_shared_ptr<D3D11DepthStencilStateCore, GenAlloc>(new (bs_alloc<D3D11DepthStencilStateCore>()) D3D11DepthStencilStateCore(desc));
 	}
 }

+ 13 - 11
BansheeD3D11RenderSystem/Source/BsD3D11RenderSystem.cpp

@@ -122,7 +122,8 @@ namespace BansheeEngine
 		mHLSLFactory = bs_new<D3D11HLSLProgramFactory>();
 
 		// Create render state manager
-		RenderStateManager::startUp<D3D11RenderStateManager>();
+		RenderStateManager::startUp();
+		RenderStateCoreManager::startUp<D3D11RenderStateCoreManager>();
 
 		mCurrentCapabilities = createRenderSystemCapabilities();
 
@@ -170,6 +171,7 @@ namespace BansheeEngine
 		mActiveVertexDeclaration = nullptr;
 		mActiveVertexShader = nullptr;
 
+		RenderStateCoreManager::shutDown();
 		RenderStateManager::shutDown();
 		RenderWindowCoreManager::shutDown();
 		RenderWindowManager::shutDown();
@@ -197,7 +199,7 @@ namespace BansheeEngine
 		RenderSystem::destroy_internal();
 	}
 
-	void D3D11RenderSystem::setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState)
+	void D3D11RenderSystem::setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SPtr<SamplerStateCore>& samplerState)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -205,7 +207,7 @@ namespace BansheeEngine
 		//  and then set them all up at once before rendering? Needs testing
 
 		ID3D11SamplerState* samplerArray[1];
-		D3D11SamplerState* d3d11SamplerState = static_cast<D3D11SamplerState*>(const_cast<SamplerState*>(samplerState.get()));
+		D3D11SamplerStateCore* d3d11SamplerState = static_cast<D3D11SamplerStateCore*>(const_cast<SamplerStateCore*>(samplerState.get()));
 		samplerArray[0] = d3d11SamplerState->getInternal();
 
 		switch(gptype)
@@ -235,31 +237,31 @@ namespace BansheeEngine
 		BS_INC_RENDER_STAT(NumSamplerBinds);
 	}
 
-	void D3D11RenderSystem::setBlendState(const BlendStatePtr& blendState)
+	void D3D11RenderSystem::setBlendState(const SPtr<BlendStateCore>& blendState)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		D3D11BlendState* d3d11BlendState = static_cast<D3D11BlendState*>(const_cast<BlendState*>(blendState.get()));
+		D3D11BlendStateCore* d3d11BlendState = static_cast<D3D11BlendStateCore*>(const_cast<BlendStateCore*>(blendState.get()));
 		mDevice->getImmediateContext()->OMSetBlendState(d3d11BlendState->getInternal(), nullptr, 0xFFFFFFFF);
 
 		BS_INC_RENDER_STAT(NumBlendStateChanges);
 	}
 
-	void D3D11RenderSystem::setRasterizerState(const RasterizerStatePtr& rasterizerState)
+	void D3D11RenderSystem::setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		D3D11RasterizerState* d3d11RasterizerState = static_cast<D3D11RasterizerState*>(const_cast<RasterizerState*>(rasterizerState.get()));
+		D3D11RasterizerStateCore* d3d11RasterizerState = static_cast<D3D11RasterizerStateCore*>(const_cast<RasterizerStateCore*>(rasterizerState.get()));
 		mDevice->getImmediateContext()->RSSetState(d3d11RasterizerState->getInternal());
 
 		BS_INC_RENDER_STAT(NumRasterizerStateChanges);
 	}
 
-	void D3D11RenderSystem::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
+	void D3D11RenderSystem::setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		D3D11DepthStencilState* d3d11RasterizerState = static_cast<D3D11DepthStencilState*>(const_cast<DepthStencilState*>(depthStencilState.get()));
+		D3D11DepthStencilStateCore* d3d11RasterizerState = static_cast<D3D11DepthStencilStateCore*>(const_cast<DepthStencilStateCore*>(depthStencilState.get()));
 		mDevice->getImmediateContext()->OMSetDepthStencilState(d3d11RasterizerState->getInternal(), stencilRefValue);
 
 		BS_INC_RENDER_STAT(NumDepthStencilStateChanges);
@@ -568,9 +570,9 @@ namespace BansheeEngine
 			HSamplerState& samplerState = bindableParams->getSamplerState(iter->second.slot);
 
 			if(samplerState == nullptr)
-				setSamplerState(gptype, iter->second.slot, SamplerState::getDefault());
+				setSamplerState(gptype, iter->second.slot, SamplerState::getDefault()->getCore());
 			else
-				setSamplerState(gptype, iter->second.slot, samplerState.getInternalPtr());
+				setSamplerState(gptype, iter->second.slot, samplerState->getCore());
 		}
 
 		for(auto iter = paramDesc.textures.begin(); iter != paramDesc.textures.end(); ++iter)

+ 15 - 14
BansheeD3D11RenderSystem/Source/BsD3D11RenderUtility.cpp

@@ -6,6 +6,7 @@
 #include "BsD3D11BlendState.h"
 #include "BsD3D11RasterizerState.h"
 #include "BsD3D11DepthStencilState.h"
+#include "BsRenderStateManager.h"
 
 namespace BansheeEngine
 {
@@ -36,28 +37,28 @@ namespace BansheeEngine
 		// Set states
 		if((clearBuffers & FBT_COLOR) != 0)
 		{
-			D3D11BlendState* d3d11BlendState = static_cast<D3D11BlendState*>(const_cast<BlendState*>(mClearQuadBlendStateYesC.get()));
+			D3D11BlendStateCore* d3d11BlendState = static_cast<D3D11BlendStateCore*>(const_cast<BlendStateCore*>(mClearQuadBlendStateYesC.get()));
 			mDevice->getImmediateContext()->OMSetBlendState(d3d11BlendState->getInternal(), nullptr, 0xFFFFFFFF);
 		}
 		else
 		{
-			D3D11BlendState* d3d11BlendState = static_cast<D3D11BlendState*>(const_cast<BlendState*>(mClearQuadBlendStateNoC.get()));
+			D3D11BlendStateCore* d3d11BlendState = static_cast<D3D11BlendStateCore*>(const_cast<BlendStateCore*>(mClearQuadBlendStateNoC.get()));
 			mDevice->getImmediateContext()->OMSetBlendState(d3d11BlendState->getInternal(), nullptr, 0xFFFFFFFF);
 		}
 
-		D3D11RasterizerState* d3d11RasterizerState = static_cast<D3D11RasterizerState*>(const_cast<RasterizerState*>(mClearQuadRasterizerState.get()));
+		D3D11RasterizerStateCore* d3d11RasterizerState = static_cast<D3D11RasterizerStateCore*>(const_cast<RasterizerStateCore*>(mClearQuadRasterizerState.get()));
 		mDevice->getImmediateContext()->RSSetState(d3d11RasterizerState->getInternal());
 
 		if((clearBuffers & FBT_DEPTH) != 0)
 		{
 			if((clearBuffers & FBT_STENCIL) != 0)
 			{
-				D3D11DepthStencilState* d3d11RasterizerState = static_cast<D3D11DepthStencilState*>(const_cast<DepthStencilState*>(mClearQuadDSStateYesD_YesS.get()));
+				D3D11DepthStencilStateCore* d3d11RasterizerState = static_cast<D3D11DepthStencilStateCore*>(const_cast<DepthStencilStateCore*>(mClearQuadDSStateYesD_YesS.get()));
 				mDevice->getImmediateContext()->OMSetDepthStencilState(d3d11RasterizerState->getInternal(), stencil);
 			}
 			else
 			{
-				D3D11DepthStencilState* d3d11RasterizerState = static_cast<D3D11DepthStencilState*>(const_cast<DepthStencilState*>(mClearQuadDSStateYesD_NoS.get()));
+				D3D11DepthStencilStateCore* d3d11RasterizerState = static_cast<D3D11DepthStencilStateCore*>(const_cast<DepthStencilStateCore*>(mClearQuadDSStateYesD_NoS.get()));
 				mDevice->getImmediateContext()->OMSetDepthStencilState(d3d11RasterizerState->getInternal(), stencil);
 			}
 		}
@@ -65,12 +66,12 @@ namespace BansheeEngine
 		{
 			if((clearBuffers & FBT_STENCIL) != 0)
 			{
-				D3D11DepthStencilState* d3d11RasterizerState = static_cast<D3D11DepthStencilState*>(const_cast<DepthStencilState*>(mClearQuadDSStateNoD_YesS.get()));
+				D3D11DepthStencilStateCore* d3d11RasterizerState = static_cast<D3D11DepthStencilStateCore*>(const_cast<DepthStencilStateCore*>(mClearQuadDSStateNoD_YesS.get()));
 				mDevice->getImmediateContext()->OMSetDepthStencilState(d3d11RasterizerState->getInternal(), stencil);
 			}
 			else
 			{
-				D3D11DepthStencilState* d3d11RasterizerState = static_cast<D3D11DepthStencilState*>(const_cast<DepthStencilState*>(mClearQuadDSStateNoD_NoS.get()));
+				D3D11DepthStencilStateCore* d3d11RasterizerState = static_cast<D3D11DepthStencilStateCore*>(const_cast<DepthStencilStateCore*>(mClearQuadDSStateNoD_NoS.get()));
 				mDevice->getImmediateContext()->OMSetDepthStencilState(d3d11RasterizerState->getInternal(), stencil);
 			}
 		}
@@ -109,25 +110,25 @@ namespace BansheeEngine
 	void D3D11RenderUtility::initClearQuadResources()
 	{
 		BLEND_STATE_DESC blendStateDescYesC;
-		mClearQuadBlendStateYesC = BlendState::create(blendStateDescYesC);
+		mClearQuadBlendStateYesC = RenderStateCoreManager::instance().createBlendState(blendStateDescYesC);
 
 		BLEND_STATE_DESC blendStateDescNoC;
 		for(int i = 0; i < BS_MAX_MULTIPLE_RENDER_TARGETS; i++)
 			blendStateDescNoC.renderTargetDesc[i].renderTargetWriteMask = 0;
 
-		mClearQuadBlendStateNoC = BlendState::create(blendStateDescNoC);
+		mClearQuadBlendStateNoC = RenderStateCoreManager::instance().createBlendState(blendStateDescNoC);
 
 		DEPTH_STENCIL_STATE_DESC depthStateDescNoD_NoS;
 		depthStateDescNoD_NoS.depthReadEnable = false;
 		depthStateDescNoD_NoS.depthWriteEnable = false;
 		depthStateDescNoD_NoS.depthComparisonFunc = CMPF_ALWAYS_PASS;
-		mClearQuadDSStateNoD_NoS = DepthStencilState::create(depthStateDescNoD_NoS);
+		mClearQuadDSStateNoD_NoS = RenderStateCoreManager::instance().createDepthStencilState(depthStateDescNoD_NoS);
 
 		DEPTH_STENCIL_STATE_DESC depthStateDescYesD_NoS;
 		depthStateDescYesD_NoS.depthReadEnable = false;
 		depthStateDescYesD_NoS.depthWriteEnable = false; // TODO - Set to true
 		//depthStateDescYesD_NoS.depthComparisonFunc = CMPF_ALWAYS_PASS;
-		mClearQuadDSStateYesD_NoS = DepthStencilState::create(depthStateDescYesD_NoS);
+		mClearQuadDSStateYesD_NoS = RenderStateCoreManager::instance().createDepthStencilState(depthStateDescYesD_NoS);
 
 		DEPTH_STENCIL_STATE_DESC depthStateDescYesD_YesS;
 		depthStateDescYesD_YesS.depthReadEnable = false;
@@ -136,7 +137,7 @@ namespace BansheeEngine
 		depthStateDescYesD_YesS.stencilEnable = true;
 		depthStateDescYesD_YesS.frontStencilComparisonFunc = CMPF_ALWAYS_PASS;
 		depthStateDescYesD_YesS.frontStencilPassOp = SOP_REPLACE;
-		mClearQuadDSStateYesD_YesS = DepthStencilState::create(depthStateDescYesD_YesS);
+		mClearQuadDSStateYesD_YesS = RenderStateCoreManager::instance().createDepthStencilState(depthStateDescYesD_YesS);
 
 		DEPTH_STENCIL_STATE_DESC depthStateDescNoD_YesS;
 		depthStateDescNoD_YesS.depthReadEnable = false;
@@ -144,10 +145,10 @@ namespace BansheeEngine
 		depthStateDescNoD_YesS.depthComparisonFunc = CMPF_ALWAYS_PASS;
 		depthStateDescNoD_YesS.stencilEnable = true;
 		depthStateDescNoD_YesS.frontStencilComparisonFunc = CMPF_ALWAYS_PASS;
-		mClearQuadDSStateNoD_YesS = DepthStencilState::create(depthStateDescNoD_YesS);
+		mClearQuadDSStateNoD_YesS = RenderStateCoreManager::instance().createDepthStencilState(depthStateDescNoD_YesS);
 
 		RASTERIZER_STATE_DESC rasterizerStateDesc;
-		mClearQuadRasterizerState = RasterizerState::create(rasterizerStateDesc);
+		mClearQuadRasterizerState = RenderStateCoreManager::instance().createRasterizerState(rasterizerStateDesc);
 
 		String vsShaderCode = "										\
 						void main(									\

+ 26 - 24
BansheeD3D11RenderSystem/Source/BsD3D11SamplerState.cpp

@@ -6,39 +6,41 @@
 
 namespace BansheeEngine
 {
-	D3D11SamplerState::D3D11SamplerState()
-		:mSamplerState(nullptr)
+	D3D11SamplerStateCore::D3D11SamplerStateCore(const SAMPLER_STATE_DESC& desc)
+		:SamplerStateCore(desc), mSamplerState(nullptr)
 	{ }
 
-	D3D11SamplerState::~D3D11SamplerState()
+	D3D11SamplerStateCore::~D3D11SamplerStateCore()
 	{
 	}
 
-	void D3D11SamplerState::initialize_internal()
+	void D3D11SamplerStateCore::initialize()
 	{
 		D3D11_SAMPLER_DESC samplerState;
 		ZeroMemory(&samplerState, sizeof(D3D11_SAMPLER_DESC));
 
-		samplerState.AddressU = D3D11Mappings::get(mData.addressMode.u);
-		samplerState.AddressV = D3D11Mappings::get(mData.addressMode.v);
-		samplerState.AddressW = D3D11Mappings::get(mData.addressMode.w);
-		samplerState.BorderColor[0] = mData.borderColor[0];
-		samplerState.BorderColor[1] = mData.borderColor[1];
-		samplerState.BorderColor[2] = mData.borderColor[2];
-		samplerState.BorderColor[3] = mData.borderColor[3];
-		samplerState.ComparisonFunc = D3D11Mappings::get(mData.comparisonFunc);
-		samplerState.MaxAnisotropy = mData.maxAniso;
-		samplerState.MaxLOD = mData.mipMax;
-		samplerState.MinLOD = mData.mipMin;
-		samplerState.MipLODBias =mData.mipmapBias;
+		samplerState.AddressU = D3D11Mappings::get(mProperties.getTextureAddressingMode().u);
+		samplerState.AddressV = D3D11Mappings::get(mProperties.getTextureAddressingMode().v);
+		samplerState.AddressW = D3D11Mappings::get(mProperties.getTextureAddressingMode().w);
+		samplerState.BorderColor[0] = mProperties.getBorderColor()[0];
+		samplerState.BorderColor[1] = mProperties.getBorderColor()[1];
+		samplerState.BorderColor[2] = mProperties.getBorderColor()[2];
+		samplerState.BorderColor[3] = mProperties.getBorderColor()[3];
+		samplerState.ComparisonFunc = D3D11Mappings::get(mProperties.getComparisonFunction());
+		samplerState.MaxAnisotropy = mProperties.getTextureAnisotropy();
+		samplerState.MaxLOD = mProperties.getMaximumMip();
+		samplerState.MinLOD = mProperties.getMinimumMip();
+		samplerState.MipLODBias = mProperties.getTextureMipmapBias();
 
-		bool isComparison = ((mData.minFilter & FO_USE_COMPARISON) & (mData.magFilter & FO_USE_COMPARISON) & (mData.mipFilter & FO_USE_COMPARISON)) != 0;
+		bool isComparison = ((mProperties.getTextureFiltering(FT_MIN) & FO_USE_COMPARISON) & 
+			(mProperties.getTextureFiltering(FT_MAG) & FO_USE_COMPARISON) &
+			(mProperties.getTextureFiltering(FT_MIP) & FO_USE_COMPARISON)) != 0;
 
-		FilterOptions minFilter = (FilterOptions)(mData.minFilter & ~FO_USE_COMPARISON);
-		FilterOptions magFilter = (FilterOptions)(mData.magFilter & ~FO_USE_COMPARISON);
-		FilterOptions mipFilter = (FilterOptions)(mData.mipFilter & ~FO_USE_COMPARISON);
+		FilterOptions minFilter = (FilterOptions)(mProperties.getTextureFiltering(FT_MIN) & ~FO_USE_COMPARISON);
+		FilterOptions magFilter = (FilterOptions)(mProperties.getTextureFiltering(FT_MAG) & ~FO_USE_COMPARISON);
+		FilterOptions mipFilter = (FilterOptions)(mProperties.getTextureFiltering(FT_MIP) & ~FO_USE_COMPARISON);
 
-		if(minFilter == FO_ANISOTROPIC && mData.magFilter == FO_ANISOTROPIC && mData.mipFilter == FO_ANISOTROPIC)
+		if (minFilter == FO_ANISOTROPIC && magFilter == FO_ANISOTROPIC && mipFilter == FO_ANISOTROPIC)
 		{
 			samplerState.Filter = D3D11_FILTER_ANISOTROPIC;
 		}
@@ -99,15 +101,15 @@ namespace BansheeEngine
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_SamplerState);
 
-		SamplerState::initialize_internal();
+		SamplerStateCore::initialize();
 	}
 
-	void D3D11SamplerState::destroy_internal()
+	void D3D11SamplerStateCore::destroy()
 	{
 		SAFE_RELEASE(mSamplerState);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_SamplerState);
 
-		SamplerState::destroy_internal();
+		SamplerStateCore::destroy();
 	}
 }

+ 4 - 4
BansheeD3D9RenderSystem/Include/BsD3D9RenderSystem.h

@@ -84,22 +84,22 @@ namespace BansheeEngine
 		/**
 		 * @copydoc RenderSystem::setSamplerState()
 		 */
-		void setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerStatePtr& state);
+		void setSamplerState(GpuProgramType gptype, UINT16 unit, const SPtr<SamplerStateCore>& state);
 
 		/**
 		 * @copydoc RenderSystem::setBlendState()
 		 */
-		void setBlendState(const BlendStatePtr& blendState);
+		void setBlendState(const SPtr<BlendStateCore>& blendState);
 
 		/**
 		 * @copydoc RenderSystem::setRasterizerState()
 		 */
-		void setRasterizerState(const RasterizerStatePtr& rasterizerState);
+		void setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState);
 
 		/**
 		 * @copydoc RenderSystem::setDepthStencilState()
 		 */
-		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
+		void setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue);
 
 		/**
 		 * @copydoc RenderSystem::setViewport()

+ 45 - 35
BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp

@@ -107,6 +107,7 @@ namespace BansheeEngine
 
 		// Create render state manager
 		RenderStateManager::startUp();
+		RenderStateCoreManager::startUp();
 
 		RenderSystem::initializePrepare();
 	}
@@ -155,6 +156,7 @@ namespace BansheeEngine
 		HardwareBufferManager::shutDown();
 		RenderWindowCoreManager::shutDown();
 		RenderWindowManager::shutDown();
+		RenderStateCoreManager::shutDown();
 		RenderStateManager::shutDown();
 
 		// Deleting the HLSL program factory
@@ -284,9 +286,9 @@ namespace BansheeEngine
 			HSamplerState& samplerState = bindableParams->getSamplerState(iter->second.slot);
 
 			if(samplerState == nullptr)
-				setSamplerState(gptype, iter->second.slot, SamplerState::getDefault());
+				setSamplerState(gptype, iter->second.slot, SamplerState::getDefault()->getCore());
 			else
-				setSamplerState(gptype, iter->second.slot, samplerState.getInternalPtr());
+				setSamplerState(gptype, iter->second.slot, samplerState->getCore());
 		}
 
 		for(auto iter = paramDesc.textures.begin(); iter != paramDesc.textures.end(); ++iter)
@@ -524,7 +526,7 @@ namespace BansheeEngine
 		LOGWRN("Texture random load/store not supported on DX9.");
 	}
 
-	void D3D9RenderSystem::setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerStatePtr& state)
+	void D3D9RenderSystem::setSamplerState(GpuProgramType gptype, UINT16 unit, const SPtr<SamplerStateCore>& state)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -539,41 +541,45 @@ namespace BansheeEngine
 			unit = D3DVERTEXTEXTURESAMPLER0 + unit; // Vertex stage uses special samplers
 		}
 
+		const SamplerProperties& sampProps = state->getProperties();
+
 		// Set texture layer filtering
-		setTextureFiltering(unit, FT_MIN, state->getTextureFiltering(FT_MIN));
-		setTextureFiltering(unit, FT_MAG, state->getTextureFiltering(FT_MAG));
-		setTextureFiltering(unit, FT_MIP, state->getTextureFiltering(FT_MIP));
+		setTextureFiltering(unit, FT_MIN, sampProps.getTextureFiltering(FT_MIN));
+		setTextureFiltering(unit, FT_MAG, sampProps.getTextureFiltering(FT_MAG));
+		setTextureFiltering(unit, FT_MIP, sampProps.getTextureFiltering(FT_MIP));
 
 		// Set texture layer filtering
-		if (state->getTextureAnisotropy() > 0)
-			setTextureAnisotropy(unit, state->getTextureAnisotropy());
+		if (sampProps.getTextureAnisotropy() > 0)
+			setTextureAnisotropy(unit, sampProps.getTextureAnisotropy());
 
 		// Set mipmap biasing
-		setTextureMipmapBias(unit, state->getTextureMipmapBias());
+		setTextureMipmapBias(unit, sampProps.getTextureMipmapBias());
 
 		// Texture addressing mode
-		const UVWAddressingMode& uvw = state->getTextureAddressingMode();
+		const UVWAddressingMode& uvw = sampProps.getTextureAddressingMode();
 		setTextureAddressingMode(unit, uvw);
 
 		// Set border color
-		setTextureBorderColor(unit, state->getBorderColor());
+		setTextureBorderColor(unit, sampProps.getBorderColor());
 
 		BS_INC_RENDER_STAT(NumSamplerBinds);
 	}
 
-	void D3D9RenderSystem::setBlendState(const BlendStatePtr& blendState)
+	void D3D9RenderSystem::setBlendState(const SPtr<BlendStateCore>& blendState)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
+		const BlendProperties& stateProps = blendState->getProperties();
+
 		// Alpha to coverage
-		setAlphaToCoverage(blendState->getAlphaToCoverageEnabled());
+		setAlphaToCoverage(stateProps.getAlphaToCoverageEnabled());
 
 		// Blend states
 		// DirectX 9 doesn't allow us to specify blend state per render target, so we just use the first one.
-		if(blendState->getBlendEnabled(0))
+		if (stateProps.getBlendEnabled(0))
 		{
-			setSceneBlending(blendState->getSrcBlend(0), blendState->getDstBlend(0), blendState->getAlphaSrcBlend(0), blendState->getAlphaDstBlend(0)
-				, blendState->getBlendOperation(0), blendState->getAlphaBlendOperation(0));
+			setSceneBlending(stateProps.getSrcBlend(0), stateProps.getDstBlend(0), stateProps.getAlphaSrcBlend(0), stateProps.getAlphaDstBlend(0)
+				, stateProps.getBlendOperation(0), stateProps.getAlphaBlendOperation(0));
 		}
 		else
 		{
@@ -581,51 +587,55 @@ namespace BansheeEngine
 		}
 
 		// Color write mask
-		UINT8 writeMask = blendState->getRenderTargetWriteMask(0);
+		UINT8 writeMask = stateProps.getRenderTargetWriteMask(0);
 		setColorBufferWriteEnabled((writeMask & 0x1) != 0, (writeMask & 0x2) != 0, (writeMask & 0x4) != 0, (writeMask & 0x8) != 0);
 
 		BS_INC_RENDER_STAT(NumBlendStateChanges);
 	}
 
-	void D3D9RenderSystem::setRasterizerState(const RasterizerStatePtr& rasterizerState)
+	void D3D9RenderSystem::setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		setDepthBias((float)rasterizerState->getDepthBias(), rasterizerState->getSlopeScaledDepthBias());
+		const RasterizerProperties& stateProps = rasterizerState->getProperties();
 
-		setCullingMode(rasterizerState->getCullMode());
+		setDepthBias((float)stateProps.getDepthBias(), stateProps.getSlopeScaledDepthBias());
 
-		setPolygonMode(rasterizerState->getPolygonMode());
+		setCullingMode(stateProps.getCullMode());
 
-		setScissorTestEnable(rasterizerState->getScissorEnable());
+		setPolygonMode(stateProps.getPolygonMode());
 
-		setMultisampleAntialiasEnable(rasterizerState->getMultisampleEnable());
+		setScissorTestEnable(stateProps.getScissorEnable());
 
-		setAntialiasedLineEnable(rasterizerState->getAntialiasedLineEnable());
+		setMultisampleAntialiasEnable(stateProps.getMultisampleEnable());
+
+		setAntialiasedLineEnable(stateProps.getAntialiasedLineEnable());
 
 		BS_INC_RENDER_STAT(NumRasterizerStateChanges);
 	}
 
-	void D3D9RenderSystem::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
+	void D3D9RenderSystem::setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
+		const DepthStencilProperties& stateProps = depthStencilState->getProperties();
+
 		// Set stencil buffer options
-		setStencilCheckEnabled(depthStencilState->getStencilEnable());
+		setStencilCheckEnabled(stateProps.getStencilEnable());
 
-		setStencilBufferOperations(depthStencilState->getStencilFrontFailOp(), depthStencilState->getStencilFrontZFailOp(), depthStencilState->getStencilFrontPassOp(), true);
-		setStencilBufferFunc(depthStencilState->getStencilFrontCompFunc(), true);
+		setStencilBufferOperations(stateProps.getStencilFrontFailOp(), stateProps.getStencilFrontZFailOp(), stateProps.getStencilFrontPassOp(), true);
+		setStencilBufferFunc(stateProps.getStencilFrontCompFunc(), true);
 
-		setStencilBufferOperations(depthStencilState->getStencilBackFailOp(), depthStencilState->getStencilBackZFailOp(), depthStencilState->getStencilBackPassOp(), false);
-		setStencilBufferFunc(depthStencilState->getStencilBackCompFunc(), false);
+		setStencilBufferOperations(stateProps.getStencilBackFailOp(), stateProps.getStencilBackZFailOp(), stateProps.getStencilBackPassOp(), false);
+		setStencilBufferFunc(stateProps.getStencilBackCompFunc(), false);
 
-		setStencilBufferReadMask(depthStencilState->getStencilReadMask());
-		setStencilBufferWriteMask(depthStencilState->getStencilWriteMask());
+		setStencilBufferReadMask(stateProps.getStencilReadMask());
+		setStencilBufferWriteMask(stateProps.getStencilWriteMask());
 
 		// Set depth buffer options
-		setDepthBufferCheckEnabled(depthStencilState->getDepthReadEnable());
-		setDepthBufferWriteEnabled(depthStencilState->getDepthWriteEnable());
-		setDepthBufferFunction(depthStencilState->getDepthComparisonFunc());		
+		setDepthBufferCheckEnabled(stateProps.getDepthReadEnable());
+		setDepthBufferWriteEnabled(stateProps.getDepthWriteEnable());
+		setDepthBufferFunction(stateProps.getDepthComparisonFunc());
 
 		// Set stencil ref value
 		setStencilRefValue(stencilRefValue);

+ 1 - 1
BansheeEditor/Source/BsScenePicking.cpp

@@ -155,7 +155,7 @@ namespace BansheeEngine
 						else
 							rasterizerState = firstPass->getRasterizerState().getInternalPtr();
 
-						CullingMode cullMode = rasterizerState->getCullMode();
+						CullingMode cullMode = rasterizerState->getProperties().getCullMode();
 
 						HTexture mainTexture;
 						if (useAlphaShader)

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

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

+ 4 - 4
BansheeGLRenderSystem/Include/BsGLRenderSystem.h

@@ -72,22 +72,22 @@ namespace BansheeEngine
 		/**
 		 * @copydoc RenderSystem::setSamplerState()
 		 */
-		void setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerStatePtr& state);
+		void setSamplerState(GpuProgramType gptype, UINT16 unit, const SPtr<SamplerStateCore>& state);
 
 		/**
 		 * @copydoc RenderSystem::setBlendState()
 		 */
-		void setBlendState(const BlendStatePtr& blendState);
+		void setBlendState(const SPtr<BlendStateCore>& blendState);
 
 		/**
 		 * @copydoc RenderSystem::setRasterizerState()
 		 */
-		void setRasterizerState(const RasterizerStatePtr& rasterizerState);
+		void setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState);
 
 		/**
 		 * @copydoc RenderSystem::setDepthStencilState()
 		 */
-		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
+		void setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue);
 
 		/**
 		 * @copydoc RenderSystem::setViewport()

+ 44 - 34
BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp

@@ -110,6 +110,7 @@ namespace BansheeEngine
 		RenderWindowCoreManager::startUp<GLRenderWindowCoreManager>(this);
 
 		RenderStateManager::startUp();
+		RenderStateCoreManager::startUp();
 
 		QueryManager::startUp<GLQueryManager>();
 
@@ -192,6 +193,7 @@ namespace BansheeEngine
 		QueryManager::shutDown();
 		RenderWindowCoreManager::shutDown();
 		RenderWindowManager::shutDown();
+		RenderStateCoreManager::shutDown();
 		RenderStateManager::shutDown();
 		GLVertexArrayObjectManager::shutDown(); // Note: Needs to be after QueryManager shutdown as some resources might be waiting for queries to complete
 
@@ -281,9 +283,9 @@ namespace BansheeEngine
 			HSamplerState& samplerState = bindableParams->getSamplerState(iter->second.slot);
 
 			if(samplerState == nullptr)
-				setSamplerState(gptype, iter->second.slot, SamplerState::getDefault());
+				setSamplerState(gptype, iter->second.slot, SamplerState::getDefault()->getCore());
 			else
-				setSamplerState(gptype, iter->second.slot, samplerState.getInternalPtr());
+				setSamplerState(gptype, iter->second.slot, samplerState->getCore());
 
 			glProgramUniform1i(glProgram, iter->second.slot, getGLTextureUnit(gptype, iter->second.slot));
 		}
@@ -443,29 +445,31 @@ namespace BansheeEngine
 		BS_INC_RENDER_STAT(NumTextureBinds);
 	}
 
-	void GLRenderSystem::setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerStatePtr& state)
+	void GLRenderSystem::setSamplerState(GpuProgramType gptype, UINT16 unit, const SPtr<SamplerStateCore>& state)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
+		const SamplerProperties& stateProps = state->getProperties();
+
 		unit = getGLTextureUnit(gptype, unit);
 
 		// Set texture layer filtering
-		setTextureFiltering(unit, FT_MIN, state->getTextureFiltering(FT_MIN));
-		setTextureFiltering(unit, FT_MAG, state->getTextureFiltering(FT_MAG));
-		setTextureFiltering(unit, FT_MIP, state->getTextureFiltering(FT_MIP));
+		setTextureFiltering(unit, FT_MIN, stateProps.getTextureFiltering(FT_MIN));
+		setTextureFiltering(unit, FT_MAG, stateProps.getTextureFiltering(FT_MAG));
+		setTextureFiltering(unit, FT_MIP, stateProps.getTextureFiltering(FT_MIP));
 
 		// Set texture anisotropy
-		setTextureAnisotropy(unit, state->getTextureAnisotropy());
+		setTextureAnisotropy(unit, stateProps.getTextureAnisotropy());
 
 		// Set mipmap biasing
-		setTextureMipmapBias(unit, state->getTextureMipmapBias());
+		setTextureMipmapBias(unit, stateProps.getTextureMipmapBias());
 
 		// Texture addressing mode
-		const UVWAddressingMode& uvw = state->getTextureAddressingMode();
+		const UVWAddressingMode& uvw = stateProps.getTextureAddressingMode();
 		setTextureAddressingMode(unit, uvw);
 
 		// Set border color
-		setTextureBorderColor(unit, state->getBorderColor());
+		setTextureBorderColor(unit, stateProps.getBorderColor());
 
 		BS_INC_RENDER_STAT(NumSamplerBinds);
 	}
@@ -488,19 +492,21 @@ namespace BansheeEngine
 		BS_INC_RENDER_STAT(NumTextureBinds);
 	}
 
-	void GLRenderSystem::setBlendState(const BlendStatePtr& blendState)
+	void GLRenderSystem::setBlendState(const SPtr<BlendStateCore>& blendState)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
+		const BlendProperties& stateProps = blendState->getProperties();
+
 		// Alpha to coverage
-		setAlphaToCoverage(blendState->getAlphaToCoverageEnabled());
+		setAlphaToCoverage(stateProps.getAlphaToCoverageEnabled());
 
 		// Blend states
 		// OpenGL doesn't allow us to specify blend state per render target, so we just use the first one.
-		if(blendState->getBlendEnabled(0))
+		if (stateProps.getBlendEnabled(0))
 		{
-			setSceneBlending(blendState->getSrcBlend(0), blendState->getDstBlend(0), blendState->getAlphaSrcBlend(0), 
-				blendState->getAlphaDstBlend(0), blendState->getBlendOperation(0), blendState->getAlphaBlendOperation(0));
+			setSceneBlending(stateProps.getSrcBlend(0), stateProps.getDstBlend(0), stateProps.getAlphaSrcBlend(0),
+				stateProps.getAlphaDstBlend(0), stateProps.getBlendOperation(0), stateProps.getAlphaBlendOperation(0));
 		}
 		else
 		{
@@ -508,52 +514,56 @@ namespace BansheeEngine
 		}
 
 		// Color write mask
-		UINT8 writeMask = blendState->getRenderTargetWriteMask(0);
+		UINT8 writeMask = stateProps.getRenderTargetWriteMask(0);
 		setColorBufferWriteEnabled((writeMask & 0x1) != 0, (writeMask & 0x2) != 0, (writeMask & 0x4) != 0, (writeMask & 0x8) != 0);
 
 		BS_INC_RENDER_STAT(NumBlendStateChanges);
 	}
 
-	void GLRenderSystem::setRasterizerState(const RasterizerStatePtr& rasterizerState)
+	void GLRenderSystem::setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		setDepthBias((float)rasterizerState->getDepthBias(), rasterizerState->getSlopeScaledDepthBias());
+		const RasterizerProperties& stateProps = rasterizerState->getProperties();
 
-		setCullingMode(rasterizerState->getCullMode());
+		setDepthBias((float)stateProps.getDepthBias(), stateProps.getSlopeScaledDepthBias());
 
-		setPolygonMode(rasterizerState->getPolygonMode());
+		setCullingMode(stateProps.getCullMode());
 
-		setScissorTestEnable(rasterizerState->getScissorEnable());
+		setPolygonMode(stateProps.getPolygonMode());
 
-		setMultisamplingEnable(rasterizerState->getMultisampleEnable());
+		setScissorTestEnable(stateProps.getScissorEnable());
 
-		setDepthClipEnable(rasterizerState->getDepthClipEnable());
+		setMultisamplingEnable(stateProps.getMultisampleEnable());
 
-		setAntialiasedLineEnable(rasterizerState->getAntialiasedLineEnable());
+		setDepthClipEnable(stateProps.getDepthClipEnable());
+
+		setAntialiasedLineEnable(stateProps.getAntialiasedLineEnable());
 
 		BS_INC_RENDER_STAT(NumRasterizerStateChanges);
 	}
 
-	void GLRenderSystem::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
+	void GLRenderSystem::setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
+		const DepthStencilProperties& stateProps = depthStencilState->getProperties();
+
 		// Set stencil buffer options
-		setStencilCheckEnabled(depthStencilState->getStencilEnable());
+		setStencilCheckEnabled(stateProps.getStencilEnable());
 
-		setStencilBufferOperations(depthStencilState->getStencilFrontFailOp(), depthStencilState->getStencilFrontZFailOp(), depthStencilState->getStencilFrontPassOp(), true);
-		setStencilBufferFunc(depthStencilState->getStencilFrontCompFunc(), depthStencilState->getStencilReadMask(), true);
+		setStencilBufferOperations(stateProps.getStencilFrontFailOp(), stateProps.getStencilFrontZFailOp(), stateProps.getStencilFrontPassOp(), true);
+		setStencilBufferFunc(stateProps.getStencilFrontCompFunc(), stateProps.getStencilReadMask(), true);
 
-		setStencilBufferOperations(depthStencilState->getStencilBackFailOp(), depthStencilState->getStencilBackZFailOp(), depthStencilState->getStencilBackPassOp(), false);
-		setStencilBufferFunc(depthStencilState->getStencilBackCompFunc(), depthStencilState->getStencilReadMask(), false);
+		setStencilBufferOperations(stateProps.getStencilBackFailOp(), stateProps.getStencilBackZFailOp(), stateProps.getStencilBackPassOp(), false);
+		setStencilBufferFunc(stateProps.getStencilBackCompFunc(), stateProps.getStencilReadMask(), false);
 
-		setStencilBufferWriteMask(depthStencilState->getStencilWriteMask());
+		setStencilBufferWriteMask(stateProps.getStencilWriteMask());
 
 		// Set depth buffer options
-		setDepthBufferCheckEnabled(depthStencilState->getDepthReadEnable());
-		setDepthBufferWriteEnabled(depthStencilState->getDepthWriteEnable());
-		setDepthBufferFunction(depthStencilState->getDepthComparisonFunc());	
+		setDepthBufferCheckEnabled(stateProps.getDepthReadEnable());
+		setDepthBufferWriteEnabled(stateProps.getDepthWriteEnable());
+		setDepthBufferFunction(stateProps.getDepthComparisonFunc());
 
 		// Set stencil ref value
 		setStencilRefValue(stencilRefValue);

+ 5 - 0
BansheeUtility/Include/BsFrameAlloc.h

@@ -64,6 +64,11 @@ namespace BansheeEngine
 		MemBlock* mFreeBlock;
 		std::atomic<UINT32> mTotalAllocBytes;
 
+#if BS_DEBUG_MODE
+		UINT32 mAllocId;
+		Set<UINT32> mActiveAllocs;
+#endif
+
 		MemBlock* allocBlock(UINT32 wantedSize);
 		void deallocBlock(MemBlock* block);
 	};

+ 14 - 3
BansheeUtility/Source/BsFrameAlloc.cpp

@@ -38,7 +38,7 @@ namespace BansheeEngine
 	UINT8* FrameAlloc::alloc(UINT32 amount)
 	{
 #if BS_DEBUG_MODE
-		amount += sizeof(UINT32);
+		amount += sizeof(UINT32) * 2;
 #endif
 
 		UINT32 freeMem = mFreeBlock->mSize - mFreeBlock->mFreePtr;
@@ -53,7 +53,13 @@ namespace BansheeEngine
 		UINT32* storedSize = reinterpret_cast<UINT32*>(data);
 		*storedSize = amount;
 
-		return data + sizeof(UINT32);
+		UINT32* storedId = reinterpret_cast<UINT32*>(data + sizeof(UINT32));
+		*storedId = mAllocId;
+
+		mActiveAllocs.insert(mAllocId);
+		mAllocId++;
+
+		return data + sizeof(UINT32) * 2;
 #else
 		return data;
 #endif
@@ -65,9 +71,11 @@ namespace BansheeEngine
 		// happens in "clear"
 			
 #if BS_DEBUG_MODE
-		data -= sizeof(UINT32);
+		data -= sizeof(UINT32) * 2;
 		UINT32* storedSize = reinterpret_cast<UINT32*>(data);
+		UINT32* storedId = reinterpret_cast<UINT32*>(data + sizeof(UINT32));
 		mTotalAllocBytes -= *storedSize;
+		mActiveAllocs.erase(*storedId);
 #endif
 	}
 
@@ -76,6 +84,9 @@ namespace BansheeEngine
 #if BS_DEBUG_MODE
 		if(mTotalAllocBytes.load() > 0)
 			BS_EXCEPT(InvalidStateException, "Not all frame allocated bytes were properly released.");
+
+		mAllocId = 0;
+		mActiveAllocs.clear();
 #endif
 
 		// Merge all blocks into one

+ 1 - 1
SBansheeEngine/Include/BsManagedResource.h

@@ -21,7 +21,7 @@ namespace BansheeEngine
 		friend class ScriptManagedResource;
 
 		ManagedResource(MonoObject* managedInstance);
-		void destroy_internal();
+		void destroy();
 
 		MonoObject* mManagedInstance;
 		uint32_t mManagedHandle;

+ 2 - 2
SBansheeEngine/Source/BsManagedResource.cpp

@@ -62,9 +62,9 @@ namespace BansheeEngine
 		ManagedResourceManager::instance().registerManagedResource(mMyHandle);
 	}
 
-	void ManagedResource::destroy_internal()
+	void ManagedResource::destroy()
 	{
-		Resource::destroy_internal();
+		Resource::destroy();
 
 		if (mManagedInstance != nullptr)
 		{

+ 10 - 10
TODO.txt

@@ -5,28 +5,28 @@ Resource
  - RasterizerState
  - DepthStencilState
  - BlendState
- - GpuProgInclude
  - SamplerState
- - Font
- - Texture
  - GpuProgram
- - Material
- - Shader
- - SpriteTexture
- - ManagedResource
+ - Material -> Remove MaterialProxy
+ - Shader -> Remove ShaderProxy
 MeshHeap
 TextureView
 VertexDeclaration
 GpuBuffer
 GpuParamBlockBuffer
 
+Also:
+ - Make CameraHandler a Coreobject and remove CameraProxy
+ - Make RenderableHandler a CoreObject and remove CameraProxy
+ - Rename CoreObject initialize_internal and destroy_internal to initializeCore/destroyCore and make them private
+
 Disallow CoreObject creation from core thread
  - Add asserts in CoreObject::destroy and CoreObject::initialize
  - Possibly also add asserts to CoreThread::queueCommand and CoreThread::queueReturnCommand
 
-Since Mesh refactor when I select/deselect a gizmo the entire render texture flashes white for one frame (might be related to RT refactor instead)
-
-There seems to be a threading issue with frame alloc freeing due to CoreObject syncing. Sometimes I get crashes in frame alloc relating to unfreed memory
+ New issues:
+  - Since Mesh refactor when I select/deselect a gizmo the entire render texture flashes white for one frame (might be related to RT refactor instead)
+  - There seems to be a threading issue with frame alloc freeing due to CoreObject syncing. Sometimes I get crashes in frame alloc relating to unfreed memory
 
 -----------------