Jelajahi Sumber

GpuBuffer and GpuParamBlockBuffer refactored to comply with new CoreObject design

Marko Pintera 11 tahun lalu
induk
melakukan
928c215c48
38 mengubah file dengan 557 tambahan dan 394 penghapusan
  1. 2 0
      BansheeCore/Include/BsCorePrerequisites.h
  2. 117 58
      BansheeCore/Include/BsGpuBuffer.h
  3. 3 3
      BansheeCore/Include/BsGpuBufferView.h
  4. 50 27
      BansheeCore/Include/BsGpuParamBlockBuffer.h
  5. 24 12
      BansheeCore/Include/BsHardwareBufferManager.h
  6. 1 1
      BansheeCore/Include/BsMesh.h
  7. 40 13
      BansheeCore/Source/BsGpuBuffer.cpp
  8. 1 1
      BansheeCore/Source/BsGpuBufferView.cpp
  9. 1 1
      BansheeCore/Source/BsGpuParamBlock.cpp
  10. 19 19
      BansheeCore/Source/BsGpuParamBlockBuffer.cpp
  11. 21 4
      BansheeCore/Source/BsHardwareBufferManager.cpp
  12. 17 17
      BansheeD3D11RenderSystem/Include/BsD3D11GpuBuffer.h
  13. 3 3
      BansheeD3D11RenderSystem/Include/BsD3D11GpuBufferView.h
  14. 8 8
      BansheeD3D11RenderSystem/Include/BsD3D11GpuParamBlockBuffer.h
  15. 11 23
      BansheeD3D11RenderSystem/Include/BsD3D11HardwareBufferManager.h
  16. 1 2
      BansheeD3D11RenderSystem/Include/BsD3D11Prerequisites.h
  17. 0 2
      BansheeD3D11RenderSystem/Include/BsD3D11VertexBuffer.h
  18. 23 20
      BansheeD3D11RenderSystem/Source/BsD3D11GpuBuffer.cpp
  19. 16 12
      BansheeD3D11RenderSystem/Source/BsD3D11GpuBufferView.cpp
  20. 9 9
      BansheeD3D11RenderSystem/Source/BsD3D11GpuParamBlockBuffer.cpp
  21. 20 19
      BansheeD3D11RenderSystem/Source/BsD3D11HardwareBufferManager.cpp
  22. 3 2
      BansheeD3D11RenderSystem/Source/BsD3D11RenderSystem.cpp
  23. 18 17
      BansheeD3D9RenderSystem/Include/BsD3D9GpuBuffer.h
  24. 10 16
      BansheeD3D9RenderSystem/Include/BsD3D9HardwareBufferManager.h
  25. 0 1
      BansheeD3D9RenderSystem/Include/BsD3D9Prerequisites.h
  26. 13 12
      BansheeD3D9RenderSystem/Source/BsD3D9GpuBuffer.cpp
  27. 21 13
      BansheeD3D9RenderSystem/Source/BsD3D9HardwareBufferManager.cpp
  28. 2 2
      BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp
  29. 17 16
      BansheeGLRenderSystem/Include/BsGLGpuBuffer.h
  30. 8 8
      BansheeGLRenderSystem/Include/BsGLGpuParamBlockBuffer.h
  31. 9 16
      BansheeGLRenderSystem/Include/BsGLHardwareBufferManager.h
  32. 14 14
      BansheeGLRenderSystem/Source/BsGLGpuBuffer.cpp
  33. 8 8
      BansheeGLRenderSystem/Source/BsGLGpuParamBlockBuffer.cpp
  34. 21 11
      BansheeGLRenderSystem/Source/BsGLHardwareBufferManager.cpp
  35. 4 3
      BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp
  36. 17 0
      BansheeUtility/Include/BsRTTIType.h
  37. 5 0
      BansheeUtility/Source/BsRTTIType.cpp
  38. 0 1
      TODO.txt

+ 2 - 0
BansheeCore/Include/BsCorePrerequisites.h

@@ -153,6 +153,8 @@ namespace BansheeEngine
 	class TextureCore;
 	class MeshHeapCore;
 	class VertexDeclarationCore;
+	class GpuBufferCore;
+	class GpuParamBlockBufferCore;
 	// Asset import
 	class SpecificImporter;
 	class Importer;

+ 117 - 58
BansheeCore/Include/BsGpuBuffer.h

@@ -7,26 +7,65 @@
 namespace BansheeEngine 
 {
 	/**
-	 * @brief	Handles a generic GPU buffer that you may use for storing any kind of data you wish to be accessible
-	 *			to the GPU. These buffers may be bounds to GPU program binding slots and accessed from a GPU program,
-	 *			or may be used by fixed pipeline in some way.
+	 * @brief	Information about a GPU buffer.
+	 */
+	class BS_CORE_EXPORT GpuBufferProperties
+	{
+	public:
+		GpuBufferProperties(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, 
+			GpuBufferUsage usage, bool randomGpuWrite, bool useCounter);
+
+		/**
+		 * @brief	Returns the type of the GPU buffer. Type determines which kind of views (if any) can be created
+		 *			for the buffer, and how is data read or modified in it.
+		 */
+		GpuBufferType getType() const { return mType; }
+
+		/**
+		 * @brief	Returns buffer usage which determines how are planning on updating the buffer contents.
+		 */
+		GpuBufferUsage getUsage() const { return mUsage; }
+
+		/**
+		 * @brief	Return whether the buffer supports random reads and writes within the GPU programs.
+		 */
+		bool getRandomGpuWrite() const { return mRandomGpuWrite; }
+
+		/**
+		 * @brief	Returns whether the buffer supports counter use within GPU programs.
+		 */
+		bool getUseCounter() const { return mUseCounter; }
+
+		/**
+		 * @brief	Returns number of elements in the buffer.
+		 */
+		UINT32 getElementCount() const { return mElementCount; }
+
+		/**
+		 * @brief	Returns size of a single element in the buffer in bytes.
+		 */
+		UINT32 getElementSize() const { return mElementSize; }
+
+	protected:
+		GpuBufferType mType;
+		GpuBufferUsage mUsage;
+		bool mRandomGpuWrite;
+		bool mUseCounter;
+		UINT32 mElementCount;
+		UINT32 mElementSize;
+	};
+
+	/**
+	 * @brief	Core thread version of a GpuBuffer.
 	 *
-	 *			Buffer types:
-	 *			  - Raw buffers containing a block of bytes that are up to the GPU program to interpret.
-	 *			  - Structured buffer containing an array of structures compliant to a certain layout. Similar to raw
-	 *				buffer but easier to interpret the data.
-	 *			  - Random read/write buffers that allow you to write to random parts of the buffer from within
-	 *				the GPU program, and then read it later. These can only be bound to pixel and compute stages.
-	 *			  - Append/Consume buffers also allow you to write to them, but in a stack-like fashion, usually where one set
-	 *				of programs produces data while other set consumes it from the same buffer. Append/Consume buffers are structured
-	 *				by default.
+	 * @see		GpuBuffer
 	 *
 	 * @note	Core thread only.
 	 */
-	class BS_CORE_EXPORT GpuBuffer : public CoreObject
-    {
-    public:
-        virtual ~GpuBuffer();
+	class BS_CORE_EXPORT GpuBufferCore : public CoreObjectCore
+	{
+	public:
+		virtual ~GpuBufferCore();
 
 		/**
 		 * @brief	Locks the buffer returning a pointer to the internal buffer data that you may then
@@ -74,9 +113,14 @@ namespace BansheeEngine
 		 * @param	discardWholeBuffer	If true, the contents of the current buffer will be entirely discarded. This can improve
 		 *								performance if you know you wont be needing that data any more.
 		 */
-		virtual void copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
+		virtual void copyData(GpuBufferCore& srcBuffer, UINT32 srcOffset,
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false) = 0;
 
+		/**
+		 * @brief	Returns properties describing the buffer.
+		 */
+		const GpuBufferProperties& getProperties() const { return mProperties; }
+
 		/**
 		 * @brief	Creates a buffer view that may be used for binding a buffer to a slot in the pipeline. Views allow you to specify
 		 *			how is data in the buffer organized to make it easier for the pipeline to interpret.
@@ -94,7 +138,7 @@ namespace BansheeEngine
 		 *			TODO Low Priority: Perhaps reflect this limitation by having an enum with only
 		 *			those two options?
 		 */
-		static GpuBufferView* requestView(GpuBufferPtr buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements, bool useCounter, GpuViewUsage usage);
+		static GpuBufferView* requestView(const SPtr<GpuBufferCore>& buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements, bool useCounter, GpuViewUsage usage);
 
 		/**
 		 * @brief	Releases a view created with requestView. 
@@ -103,39 +147,9 @@ namespace BansheeEngine
 		 */
 		static void releaseView(GpuBufferView* view);
 
-		/**
-		 * @brief	Returns the type of the GPU buffer. Type determines which kind of views (if any) can be created
-		 *			for the buffer, and how is data read or modified in it.
-		 */
-		GpuBufferType getType() const { return mType; }
-
-		/**
-		 * @brief	Returns buffer usage which determines how are planning on updating the buffer contents.
-		 */
-		GpuBufferUsage getUsage() const { return mUsage; }
-
-		/**
-		 * @brief	Return whether the buffer supports random reads and writes within the GPU programs.
-		 */
-		bool getRandomGpuWrite() const { return mRandomGpuWrite; }
-
-		/**
-		 * @brief	Returns whether the buffer supports counter use within GPU programs.
-		 */
-		bool getUseCounter() const { return mUseCounter; }
-
-		/**
-		 * @brief	Returns number of elements in the buffer.
-		 */
-		UINT32 getElementCount() const { return mElementCount; }
-
-		/**
-		 * @brief	Returns size of a single element in the buffer in bytes.
-		 */
-		UINT32 getElementSize() const { return mElementSize; }
-
 	protected:
-		GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
+		GpuBufferCore(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, 
+			GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 
 		/**
 		 * @brief	Creates an empty view for the current buffer.
@@ -154,9 +168,9 @@ namespace BansheeEngine
 		void clearBufferViews();
 
 		/**
-		 * @copydoc CoreObject::destroy_internal()
+		 * @copydoc CoreObject::destroy()
 		 */
-		virtual void destroy_internal();
+		virtual void destroy();
 
 		/**
 		 * @brief	Helper class to help with reference counting for GPU buffer views.
@@ -172,13 +186,58 @@ namespace BansheeEngine
 		};
 
 		UnorderedMap<GPU_BUFFER_DESC, GpuBufferReference*, GpuBufferView::HashFunction, GpuBufferView::EqualFunction> mBufferViews;
+		GpuBufferProperties mProperties;
+	};
+
+	/**
+	 * @brief	Handles a generic GPU buffer that you may use for storing any kind of data you wish to be accessible
+	 *			to the GPU. These buffers may be bounds to GPU program binding slots and accessed from a GPU program,
+	 *			or may be used by fixed pipeline in some way.
+	 *
+	 *			Buffer types:
+	 *			  - Raw buffers containing a block of bytes that are up to the GPU program to interpret.
+	 *			  - Structured buffer containing an array of structures compliant to a certain layout. Similar to raw
+	 *				buffer but easier to interpret the data.
+	 *			  - Random read/write buffers that allow you to write to random parts of the buffer from within
+	 *				the GPU program, and then read it later. These can only be bound to pixel and compute stages.
+	 *			  - Append/Consume buffers also allow you to write to them, but in a stack-like fashion, usually where one set
+	 *				of programs produces data while other set consumes it from the same buffer. Append/Consume buffers are structured
+	 *				by default.
+	 *
+	 * @note	Sim thread only.
+	 */
+	class BS_CORE_EXPORT GpuBuffer : public CoreObject
+    {
+    public:
+		virtual ~GpuBuffer() { }
+
+		/**
+		 * @brief	Returns properties describing the buffer.
+		 */
+		const GpuBufferProperties& getProperties() const { return mProperties; }
+
+		/**
+		 * @brief	Retrieves a core implementation of a GPU buffer usable only from the
+		 *			core thread.
+		 */
+		SPtr<GpuBufferCore> getCore() const;
 
 	protected:
-		GpuBufferType mType;
-		GpuBufferUsage mUsage;
-		bool mRandomGpuWrite;
-		bool mUseCounter;
-		UINT32 mElementCount;
-		UINT32 mElementSize;
+		friend class HardwareBufferManager;
+
+		GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, 
+			bool randomGpuWrite = false, bool useCounter = false);
+
+		/**
+		 * @copydoc	CoreObject::createCore
+		 */
+		SPtr<CoreObjectCore> createCore() const;
+
+		/**
+		 * @copydoc	HardwareBufferManager::createGpuParamBlockBuffer
+		 */
+		static GpuParamBlockBufferPtr create(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
+
+		GpuBufferProperties mProperties;
     };
 }

+ 3 - 3
BansheeCore/Include/BsGpuBufferView.h

@@ -51,7 +51,7 @@ namespace BansheeEngine
 		 *			a set of parameters describing the view to create.
 		 *			Must be called right after construction.
 		 */
-		virtual void initialize(GpuBufferPtr buffer, GPU_BUFFER_DESC& desc);
+		virtual void initialize(const SPtr<GpuBufferCore>& buffer, GPU_BUFFER_DESC& desc);
 
 		/**
 		 * @brief	Returns a descriptor structure used for creating the view.
@@ -61,7 +61,7 @@ namespace BansheeEngine
 		/**
 		 * @brief	Returns the buffer this view was created for.
 		 */
-		GpuBufferPtr getBuffer() const { return mBuffer; }
+		SPtr<GpuBufferCore> getBuffer() const { return mBuffer; }
 
 		/**
 		 * @brief	Returns index of first element in the buffer that this view
@@ -94,6 +94,6 @@ namespace BansheeEngine
 
 	protected:
 		GPU_BUFFER_DESC mDesc;
-		GpuBufferPtr mBuffer;
+		SPtr<GpuBufferCore> mBuffer;
 	};
 }

+ 50 - 27
BansheeCore/Include/BsGpuParamBlockBuffer.h

@@ -6,30 +6,17 @@
 namespace BansheeEngine
 {
 	/**
-	 * @brief	Represents a GPU parameter block buffer. Parameter block buffers
-	 *			are bound to GPU programs which then fetch parameters from those buffers.
+	 * @brief	Core thread version of a GPU param block buffer.
+	 *
+	 * @see		GpuParamBlockBuffer
 	 *
-	 *			Writing or reading from this buffer will translate directly to API calls
-	 *			that update the GPU.
-	 * 			
 	 * @note	Core thread only.
 	 */
-	class BS_CORE_EXPORT GpuParamBlockBuffer : public CoreObject
+	class BS_CORE_EXPORT GpuParamBlockBufferCore : public CoreObjectCore
 	{
 	public:
-		GpuParamBlockBuffer();
-		virtual ~GpuParamBlockBuffer();
-
-		/**
-		 * @brief	Initializes a buffer with the specified size in bytes and usage.
-		 *			Specify dynamic usage if you plan on modifying the buffer often,
-		 *			otherwise specify static usage.
-		 *
-		 * @see		CoreObject::initialize
-		 * 
-		 * @note	Must be called right after construction.
-		 */
-		void initialize(UINT32 size, GpuParamBlockUsage usage);
+		GpuParamBlockBufferCore(UINT32 size, GpuParamBlockUsage usage);
+		virtual ~GpuParamBlockBufferCore() { }
 
 		/**
 		 * @brief	Writes all of the specified data to the buffer.
@@ -52,6 +39,31 @@ namespace BansheeEngine
 		 */
 		UINT32 getSize() const { return mSize; }
 
+	protected:
+		GpuParamBlockUsage mUsage;
+		UINT32 mSize;
+	};
+
+	/**
+	 * @brief	Represents a GPU parameter block buffer. Parameter block buffers
+	 *			are bound to GPU programs which then fetch parameters from those buffers.
+	 *
+	 *			Writing or reading from this buffer will translate directly to API calls
+	 *			that update the GPU.
+	 * 			
+	 * @note	Sim thread only.
+	 */
+	class BS_CORE_EXPORT GpuParamBlockBuffer : public CoreObject
+	{
+	public:
+		GpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage);
+		virtual ~GpuParamBlockBuffer() { }
+
+		/**
+		 * @brief	Returns the size of the buffer in bytes.
+		 */
+		UINT32 getSize() const { return mSize; }
+
 		/**
 		 * @brief	Returns	a parameter block buffer which is used for caching 
 		 *			the parameter information. Essentially a CPU copy of the GPU buffer.
@@ -61,12 +73,23 @@ namespace BansheeEngine
 		 */
 		GpuParamBlockPtr getParamBlock() const { return mParamBlock; }
 
+		/**
+		 * @brief	Retrieves a core implementation of a GPU param block buffer usable only from the
+		 *			core thread.
+		 */
+		SPtr<GpuParamBlockBufferCore> getCore() const;
+
 		/**
 		 * @copydoc	HardwareBufferManager::createGpuParamBlockBuffer
 		 */
 		static GpuParamBlockBufferPtr create(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
 
 	protected:
+		/**
+		 * @copydoc	CoreObject::createCore
+		 */
+		SPtr<CoreObjectCore> createCore() const;
+
 		GpuParamBlockUsage mUsage;
 		UINT32 mSize;
 
@@ -77,18 +100,18 @@ namespace BansheeEngine
 	 * @brief	Implementation of a GpuParamBlock buffer that doesn't use a GPU buffer
 	 *			for storage. Used with APIs that do not support GPU parameter buffers.
 	 */
-	class BS_CORE_EXPORT GenericGpuParamBlockBuffer : public GpuParamBlockBuffer
+	class BS_CORE_EXPORT GenericGpuParamBlockBufferCore : public GpuParamBlockBufferCore
 	{
 	public:
-		GenericGpuParamBlockBuffer();
+		GenericGpuParamBlockBufferCore(UINT32 size, GpuParamBlockUsage usage);
 
 		/**
-		 * @copydoc	GpuParamBlockBuffer::writeData
+		 * @copydoc	GpuParamBlockBufferCore::writeData
 		 */
 		void writeData(const UINT8* data);
 
 		/**
-		 * @copydoc GpuParamBlockBuffer::readData.
+		 * @copydoc GpuParamBlockBufferCore::readData.
 		 */
 		void readData(UINT8* data) const;
 
@@ -96,13 +119,13 @@ namespace BansheeEngine
 		UINT8* mData;
 
 		/**
-		 * @copydoc CoreObject::initialize_internal.
+		 * @copydoc CoreObjectCore::initialize
 		 */
-		virtual void initialize_internal();
+		virtual void initialize();
 
 		/**
-		 * @copydoc CoreObject::destroy_internal.
+		 * @copydoc CoreObjectCore::destroy
 		 */
-		virtual void destroy_internal();
+		virtual void destroy();
 	};
 }

+ 24 - 12
BansheeCore/Include/BsHardwareBufferManager.h

@@ -75,18 +75,6 @@ namespace BansheeEngine
 		 * @brief	Creates a new vertex declaration from a list of vertex elements.
 		 */
 		virtual VertexDeclarationPtr createVertexDeclaration(const List<VertexElement>& elements);
-
-	protected:
-		/**
-		 * @copydoc	createGpuParamBlockBuffer
-		 */
-		virtual GpuParamBlockBufferPtr createGpuParamBlockBufferImpl() = 0;
-
-		/**
-		 * @copydoc	createGpuBuffer
-		 */
-		virtual GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, 
-			bool randomGpuWrite = false, bool useCounter = false) = 0;
 	};
 
 	/**
@@ -114,10 +102,23 @@ namespace BansheeEngine
 		 */
 		virtual SPtr<VertexDeclarationCore> createVertexDeclaration(const List<VertexElement>& elements);
 
+		/**
+		 * @copydoc	HardwareBufferManager::createGpuParamBlockBuffer
+		 */
+		virtual SPtr<GpuParamBlockBufferCore> createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
+
+		/**
+		 * @copydoc	HardwareBufferManager::createGpuBuffer
+		 */
+		virtual SPtr<GpuBufferCore> createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
+
 	protected:
 		friend class IndexBuffer;
 		friend class VertexBuffer;
 		friend class VertexDeclaration;
+		friend class GpuParamBlockBuffer;
+		friend class GpuBuffer;
 
 		/**
 		 * @copydoc	createVertexBuffer
@@ -129,6 +130,17 @@ namespace BansheeEngine
 		 */
 		virtual SPtr<IndexBufferCore> createIndexBufferInternal(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
 
+		/**
+		 * @copydoc	createGpuParamBlockBuffer
+		 */
+		virtual SPtr<GpuParamBlockBufferCore> createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC) = 0;
+
+		/**
+		 * @copydoc	createGpuBuffer
+		 */
+		virtual SPtr<GpuBufferCore> createGpuBufferInternal(UINT32 elementCount, UINT32 elementSize,
+			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false) = 0;
+
 		/**
 		 * @copydoc	createVertexDeclaration
 		 */

+ 1 - 1
BansheeCore/Include/BsMesh.h

@@ -168,7 +168,7 @@ namespace BansheeEngine
 		void updateBounds(const MeshData& meshData);
 
 		/**
-		 * @copydoc	RenderTarget::createCore
+		 * @copydoc	CoreObject::createCore
 		 */
 		SPtr<CoreObjectCore> createCore() const;
 

+ 40 - 13
BansheeCore/Source/BsGpuBuffer.cpp

@@ -1,30 +1,39 @@
 #include "BsGpuBuffer.h"
 #include "BsException.h"
 #include "BsRenderSystem.h"
+#include "BsHardwareBufferManager.h"
 
 namespace BansheeEngine
 {
-	GpuBuffer::GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
+	GpuBufferProperties::GpuBufferProperties(UINT32 elementCount, UINT32 elementSize, GpuBufferType type,
+		GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 		:mElementCount(elementCount), mElementSize(elementSize), mType(type), mUsage(usage), mRandomGpuWrite(randomGpuWrite), mUseCounter(useCounter)
-	{  
+	{
+
+	}
+
+	GpuBufferCore::GpuBufferCore(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage,
+		bool randomGpuWrite, bool useCounter)
+		: mProperties(elementCount, elementSize, type, usage, randomGpuWrite, useCounter)
+	{
 	}
 
-	GpuBuffer::~GpuBuffer() 
+	GpuBufferCore::~GpuBufferCore()
 	{
 		// Make sure that derived classes call clearBufferViews
 		// I can't call it here since it needs a virtual method call
 	}
 
-	void GpuBuffer::destroy_internal()
+	void GpuBufferCore::destroy()
 	{
 		clearBufferViews();
 
-		CoreObject::destroy_internal();
+		CoreObjectCore::destroy();
 	}
 
-	void GpuBuffer::clearBufferViews()
+	void GpuBufferCore::clearBufferViews()
 	{
-		for(auto iter = mBufferViews.begin(); iter != mBufferViews.end(); ++iter)
+		for (auto iter = mBufferViews.begin(); iter != mBufferViews.end(); ++iter)
 		{
 			destroyView(iter->second->view);
 			bs_delete<PoolAlloc>(iter->second);
@@ -33,7 +42,8 @@ namespace BansheeEngine
 		mBufferViews.clear();
 	}
 
-	GpuBufferView* GpuBuffer::requestView(GpuBufferPtr buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements, bool useCounter, GpuViewUsage usage)
+	GpuBufferView* GpuBufferCore::requestView(const SPtr<GpuBufferCore>& buffer, UINT32 firstElement,
+		UINT32 elementWidth, UINT32 numElements, bool useCounter, GpuViewUsage usage)
 	{
 		GPU_BUFFER_DESC key;
 		key.firstElement = firstElement;
@@ -43,7 +53,7 @@ namespace BansheeEngine
 		key.usage = usage;
 
 		auto iterFind = buffer->mBufferViews.find(key);
-		if(iterFind == buffer->mBufferViews.end())
+		if (iterFind == buffer->mBufferViews.end())
 		{
 			GpuBufferView* newView = buffer->createView();
 			newView->initialize(buffer, key);
@@ -56,19 +66,19 @@ namespace BansheeEngine
 		return iterFind->second->view;
 	}
 
-	void GpuBuffer::releaseView(GpuBufferView* view)
+	void GpuBufferCore::releaseView(GpuBufferView* view)
 	{
-		GpuBufferPtr buffer = view->getBuffer();
+		SPtr<GpuBufferCore> buffer = view->getBuffer();
 
 		auto iterFind = buffer->mBufferViews.find(view->getDesc());
-		if(iterFind == buffer->mBufferViews.end())
+		if (iterFind == buffer->mBufferViews.end())
 		{
 			BS_EXCEPT(InternalErrorException, "Trying to release a buffer view that doesn't exist!");
 		}
 
 		iterFind->second->refCount--;
 
-		if(iterFind->second->refCount == 0)
+		if (iterFind->second->refCount == 0)
 		{
 			GpuBufferReference* toRemove = iterFind->second;
 
@@ -78,4 +88,21 @@ namespace BansheeEngine
 			bs_delete<PoolAlloc>(toRemove);
 		}
 	}
+
+	GpuBuffer::GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, 
+		bool randomGpuWrite, bool useCounter)
+		:mProperties(elementCount, elementSize, type, usage, randomGpuWrite, useCounter)
+	{  
+	}
+
+	SPtr<GpuBufferCore> GpuBuffer::getCore() const
+	{
+		return std::static_pointer_cast<GpuBufferCore>(mCoreSpecific);
+	}
+
+	SPtr<CoreObjectCore> GpuBuffer::createCore() const
+	{
+		return HardwareBufferCoreManager::instance().createGpuBufferInternal(mProperties.getElementCount(), 
+			mProperties.getElementSize(), mProperties.getType(), mProperties.getUsage(), mProperties.getRandomGpuWrite(), mProperties.getUseCounter());
+	}
 }

+ 1 - 1
BansheeCore/Source/BsGpuBufferView.cpp

@@ -32,7 +32,7 @@ namespace BansheeEngine
 
 	}
 
-	void GpuBufferView::initialize(GpuBufferPtr buffer, GPU_BUFFER_DESC& desc)
+	void GpuBufferView::initialize(const SPtr<GpuBufferCore>& buffer, GPU_BUFFER_DESC& desc)
 	{
 		mBuffer = buffer;
 		mDesc = desc;

+ 1 - 1
BansheeCore/Source/BsGpuParamBlock.cpp

@@ -84,7 +84,7 @@ namespace BansheeEngine
 
 	void GpuParamBlock::uploadToBuffer(const GpuParamBlockBufferPtr& buffer)
 	{
-		buffer->writeData(mData);
+		buffer->getCore()->writeData(mData);
 		mDirty = false;
 	}
 }

+ 19 - 19
BansheeCore/Source/BsGpuParamBlockBuffer.cpp

@@ -4,42 +4,42 @@
 
 namespace BansheeEngine
 {
-	GpuParamBlockBuffer::GpuParamBlockBuffer()
-		:mSize(0), mUsage(GPBU_DYNAMIC)
+	GpuParamBlockBufferCore::GpuParamBlockBufferCore(UINT32 size, GpuParamBlockUsage usage)
+		:mSize(size), mUsage(usage)
 	{
-
 	}
 
-	GpuParamBlockBuffer::~GpuParamBlockBuffer()
+	GpuParamBlockBuffer::GpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage)
+		:mSize(size), mUsage(usage)
 	{
-
+		mParamBlock = bs_shared_ptr<GpuParamBlock>(size);
 	}
 
-	void GpuParamBlockBuffer::initialize(UINT32 size, GpuParamBlockUsage usage)
+	SPtr<GpuParamBlockBufferCore> GpuParamBlockBuffer::getCore() const
 	{
-		mSize = size;
-		mUsage = usage;
-
-		mParamBlock = bs_shared_ptr<GpuParamBlock>(size);
+		return std::static_pointer_cast<GpuParamBlockBufferCore>(mCoreSpecific);
+	}
 
-		CoreObject::initialize();
+	SPtr<CoreObjectCore> GpuParamBlockBuffer::createCore() const
+	{
+		return HardwareBufferCoreManager::instance().createGpuParamBlockBufferInternal(mSize, mUsage);
 	}
 
-	GenericGpuParamBlockBuffer::GenericGpuParamBlockBuffer()
-		:mData(nullptr)
+	GenericGpuParamBlockBufferCore::GenericGpuParamBlockBufferCore(UINT32 size, GpuParamBlockUsage usage)
+		:GpuParamBlockBufferCore(size, usage), mData(nullptr)
 	{ }
 
-	void GenericGpuParamBlockBuffer::writeData(const UINT8* data)
+	void GenericGpuParamBlockBufferCore::writeData(const UINT8* data)
 	{
 		memcpy(mData, data, mSize);
 	}
 
-	void GenericGpuParamBlockBuffer::readData(UINT8* data) const
+	void GenericGpuParamBlockBufferCore::readData(UINT8* data) const
 	{
 		memcpy(data, mData, mSize);
 	}
 
-	void GenericGpuParamBlockBuffer::initialize_internal()
+	void GenericGpuParamBlockBufferCore::initialize()
 	{
 		if (mSize > 0)
 			mData = (UINT8*)bs_alloc<ScratchAlloc>(mSize);
@@ -48,15 +48,15 @@ namespace BansheeEngine
 
 		memset(mData, 0, mSize);
 
-		GpuParamBlockBuffer::initialize_internal();
+		GpuParamBlockBufferCore::initialize();
 	}
 
-	void GenericGpuParamBlockBuffer::destroy_internal()
+	void GenericGpuParamBlockBufferCore::destroy()
 	{
 		if(mData != nullptr)
 			bs_free<ScratchAlloc>(mData);
 
-		GpuParamBlockBuffer::destroy_internal();
+		GpuParamBlockBufferCore::destroy();
 	}
 
 	static GpuParamBlockBufferPtr create(UINT32 size, GpuParamBlockUsage usage)

+ 21 - 4
BansheeCore/Source/BsHardwareBufferManager.cpp

@@ -48,19 +48,19 @@ namespace BansheeEngine
 
 	GpuParamBlockBufferPtr HardwareBufferManager::createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage)
 	{
-		GpuParamBlockBufferPtr paramBlockPtr = createGpuParamBlockBufferImpl();
+		GpuParamBlockBufferPtr paramBlockPtr = bs_core_ptr<GpuParamBlockBuffer, GenAlloc>(new (bs_alloc<GpuParamBlockBuffer>()) GpuParamBlockBuffer(size, usage));
 		paramBlockPtr->_setThisPtr(paramBlockPtr);
-		paramBlockPtr->initialize(size, usage);
-
+		paramBlockPtr->initialize();
 		return paramBlockPtr;
 	}
 
 	GpuBufferPtr HardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
-		GpuBufferPtr gbuf = createGpuBufferImpl(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
+		GpuBufferPtr gbuf = bs_core_ptr<GpuBuffer, GenAlloc>(new (bs_alloc<GpuBuffer>()) GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 		gbuf->_setThisPtr(gbuf);
 		gbuf->initialize();
+
 		return gbuf;
 	}
 
@@ -91,6 +91,23 @@ namespace BansheeEngine
 		return declPtr;
 	}
 
+	SPtr<GpuParamBlockBufferCore> HardwareBufferCoreManager::createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage)
+	{
+		SPtr<GpuParamBlockBufferCore> paramBlockPtr = createGpuParamBlockBufferInternal(size, usage);
+		paramBlockPtr->initialize();
+
+		return paramBlockPtr;
+	}
+
+	SPtr<GpuBufferCore> HardwareBufferCoreManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize,
+		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
+	{
+		SPtr<GpuBufferCore> gbuf = createGpuBufferInternal(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
+		gbuf->initialize();
+
+		return gbuf;
+	}
+
 	SPtr<VertexDeclarationCore> HardwareBufferCoreManager::createVertexDeclarationInternal(const List<VertexElement>& elements)
 	{
 		VertexDeclarationCore* decl = new (bs_alloc<VertexDeclarationCore, GenAlloc>()) VertexDeclarationCore(elements);

+ 17 - 17
BansheeD3D11RenderSystem/Include/BsD3D11GpuBuffer.h

@@ -8,36 +8,36 @@ namespace BansheeEngine
 	/**
 	 * @brief	DirectX 11 implementation of a generic GPU buffer.
 	 */
-	class BS_D3D11_EXPORT D3D11GpuBuffer : public GpuBuffer
+	class BS_D3D11_EXPORT D3D11GpuBufferCore : public GpuBufferCore
     {
     public:
-        ~D3D11GpuBuffer();
+		~D3D11GpuBufferCore();
 
 		/**
-		 * @copydoc GenericBuffer::lockImpl
+		 * @copydoc GpuBufferCore::lock
 		 */
 		virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options);
 
 		/**
-		 * @copydoc GenericBuffer::unlockImpl
+		 * @copydoc GpuBufferCore::unlock
 		 */
 		virtual void unlock();
 
 		/**
-		 * @copydoc GenericBuffer::readData
+		 * @copydoc GpuBufferCore::readData
 		 */
         virtual void readData(UINT32 offset, UINT32 length, void* pDest);
 
 		/**
-		 * @copydoc GenericBuffer::writeData
+		 * @copydoc GpuBufferCore::writeData
 		 */
         virtual void writeData(UINT32 offset, UINT32 length, const void* pSource,
 			BufferWriteType writeFlags = BufferWriteType::Normal);
 
 		/**
-		 * @copydoc GenericBuffer::copyData
+		 * @copydoc GpuBufferCore::copyData
 		 */
-		void copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
+		void copyData(GpuBufferCore& srcBuffer, UINT32 srcOffset, 
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 
 		/**
@@ -46,33 +46,33 @@ namespace BansheeEngine
 		ID3D11Buffer* getDX11Buffer() const;
 
 	protected:
-		friend class D3D11HardwareBufferManager;
+		friend class D3D11HardwareBufferCoreManager;
 
 		/**
-		 * @copydoc	GpuBuffer::GpuBuffer
+		 * @copydoc	GpuBufferCore::GpuBufferCore
 		 */
-		D3D11GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, 
+		D3D11GpuBufferCore(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage,
 			bool randomGpuWrite = false, bool useCounter = false);
 
 		/**
-		 * @copydoc GpuBuffer::createView
+		 * @copydoc GpuBufferCore::createView
 		 */
 		virtual GpuBufferView* createView();
 
 		/**
-		 * @copydoc GpuBuffer::destroyView
+		 * @copydoc GpuBufferCore::destroyView
 		 */
 		virtual void destroyView(GpuBufferView* view);
 
 		/**
-		 * @copydoc GpuBuffer::initialize_internal
+		 * @copydoc GpuBufferCore::initialize
 		 */
-		void initialize_internal();	
+		void initialize();	
 		
 		/**
-		 * @copydoc GpuBuffer::destroy_internal
+		 * @copydoc GpuBufferCore::destroy
 		 */
-		void destroy_internal();
+		void destroy();
 
 	private:
 		D3D11HardwareBuffer* mBuffer;

+ 3 - 3
BansheeD3D11RenderSystem/Include/BsD3D11GpuBufferView.h

@@ -18,7 +18,7 @@ namespace BansheeEngine
 		/**
 		 * @copydoc	GpuBufferView::initialize
 		 */
-		void initialize(GpuBufferPtr buffer, GPU_BUFFER_DESC& desc);
+		void initialize(const SPtr<GpuBufferCore>& buffer, GPU_BUFFER_DESC& desc);
 
 	private:
 		/**
@@ -36,7 +36,7 @@ namespace BansheeEngine
 		 *
 		 * @returns	Constructed DX11 shader resource view object.
 		 */
-		ID3D11ShaderResourceView* createSRV(D3D11GpuBuffer* buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements);
+		ID3D11ShaderResourceView* createSRV(D3D11GpuBufferCore* buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements);
 
 		/**
 		 * @brief	Creates a DX11 unordered access view that allows a buffer to be bound to a shader for random reading or writing.
@@ -50,7 +50,7 @@ namespace BansheeEngine
 		 *
 		 * @returns	Constructed DX11 unordered access view object.
 		 */
-		ID3D11UnorderedAccessView* createUAV(D3D11GpuBuffer* buffer, UINT32 firstElement, UINT32 numElements, bool useCounter);
+		ID3D11UnorderedAccessView* createUAV(D3D11GpuBufferCore* buffer, UINT32 firstElement, UINT32 numElements, bool useCounter);
 
 		ID3D11ShaderResourceView* mSRV;
 		ID3D11UnorderedAccessView* mUAV;

+ 8 - 8
BansheeD3D11RenderSystem/Include/BsD3D11GpuParamBlockBuffer.h

@@ -8,18 +8,18 @@ namespace BansheeEngine
 	/**
 	 * @brief	DirectX 11 implementation of a parameter block buffer (constant buffer in DX11 lingo).
 	 */
-	class BS_D3D11_EXPORT D3D11GpuParamBlockBuffer : public GpuParamBlockBuffer
+	class BS_D3D11_EXPORT D3D11GpuParamBlockBufferCore : public GpuParamBlockBufferCore
 	{
 	public:
-		D3D11GpuParamBlockBuffer();
+		D3D11GpuParamBlockBufferCore(UINT32 size, GpuParamBlockUsage usage);
 
 		/**
-		 * @copydoc GpuParamBlockBuffer::writeData.
+		 * @copydoc GpuParamBlockBufferCore::writeData.
 		 */
 		void writeData(const UINT8* data);
 
 		/**
-		 * @copydoc GpuParamBlockBuffer::readData.
+		 * @copydoc GpuParamBlockBufferCore::readData.
 		 */
 		void readData(UINT8* data) const;
 
@@ -29,14 +29,14 @@ namespace BansheeEngine
 		ID3D11Buffer* getD3D11Buffer() const;
 	protected:
 		/**
-		 * @copydoc CoreGpuObject::initialize_internal.
+		 * @copydoc GpuParamBlockBufferCore::initialize
 		 */
-		virtual void initialize_internal();
+		virtual void initialize();
 
 		/**
-		 * @copydoc CoreGpuObject::destroy_internal.
+		 * @copydoc GpuParamBlockBufferCore::destroy
 		 */
-		virtual void destroy_internal();
+		virtual void destroy();
 
 	private:
 		D3D11HardwareBuffer* mBuffer;

+ 11 - 23
BansheeD3D11RenderSystem/Include/BsD3D11HardwareBufferManager.h

@@ -5,29 +5,6 @@
 
 namespace BansheeEngine
 {
-	/**
-	 * @brief	Handles creation of DirectX 11 hardware buffers.
-	 */
-	class BS_D3D11_EXPORT D3D11HardwareBufferManager : public HardwareBufferManager
-	{
-	public:
-		D3D11HardwareBufferManager(D3D11Device& device);
-
-	protected:     
-		/** 
-		 * @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl 
-		 */
-		GpuParamBlockBufferPtr createGpuParamBlockBufferImpl();
-
-		/**
-		 * @copydoc HardwareBufferManager::createGenericBufferImpl
-		 */
-		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
-			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
-
-		D3D11Device& mDevice;
-	};
-
 	/**
 	 * @brief	Handles creation of DirectX 11 hardware buffers.
 	 */
@@ -47,6 +24,17 @@ namespace BansheeEngine
 		 */
 		SPtr<IndexBufferCore> createIndexBufferInternal(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
+		/** 
+		 * @copydoc HardwareBufferCoreManager::createGpuParamBlockBufferInternal 
+		 */
+		SPtr<GpuParamBlockBufferCore> createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
+
+		/**
+		 * @copydoc HardwareBufferCoreManager::createGpuBufferInternal
+		 */
+		SPtr<GpuBufferCore> createGpuBufferInternal(UINT32 elementCount, UINT32 elementSize,
+			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
+
 		D3D11Device& mDevice;
 	};
 }

+ 1 - 2
BansheeD3D11RenderSystem/Include/BsD3D11Prerequisites.h

@@ -29,7 +29,6 @@ namespace BansheeEngine
 	class D3D11VideoMode;
 	class D3D11VideoModeList;
 	class D3D11GpuProgramManager;
-	class D3D11HardwareBufferManager;
 	class D3D11IndexBuffer;
 	class D3D11HardwareConstantBuffer;
 	class D3D11HLSLProgramFactory;
@@ -47,7 +46,7 @@ namespace BansheeEngine
 	class D3D11SamplerState;
 	class D3D11DepthStencilState;
 	class D3D11InputLayoutManager;
-	class D3D11GpuBuffer;
+	class D3D11GpuBufferCore;
 	class D3D11RenderUtility;
 	class D3D11GpuProgramCore;
 

+ 0 - 2
BansheeD3D11RenderSystem/Include/BsD3D11VertexBuffer.h

@@ -38,8 +38,6 @@ namespace BansheeEngine
 		ID3D11Buffer* getD3DVertexBuffer() const { return mBuffer->getD3DBuffer(); }		
 
 	protected: 
-		friend class D3D11HardwareBufferManager;
-
 		/**
 		* @copydoc VertexBufferCore::lockImpl
 		 */

+ 23 - 20
BansheeD3D11RenderSystem/Source/BsD3D11GpuBuffer.cpp

@@ -9,19 +9,22 @@
 
 namespace BansheeEngine
 {
-	D3D11GpuBuffer::D3D11GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter) 
-		: GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter), mBuffer(nullptr)
+	D3D11GpuBufferCore::D3D11GpuBufferCore(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, 
+		GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
+		: GpuBufferCore(elementCount, elementSize, type, usage, randomGpuWrite, useCounter), mBuffer(nullptr)
 	{ }
 
-	D3D11GpuBuffer::~D3D11GpuBuffer()
+	D3D11GpuBufferCore::~D3D11GpuBufferCore()
 	{ }
 
-	void D3D11GpuBuffer::initialize_internal()
+	void D3D11GpuBufferCore::initialize()
 	{
 		D3D11HardwareBuffer::BufferType bufferType;
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(D3D11RenderSystem::instancePtr());
 
-		switch(mType)
+		const GpuBufferProperties& props = getProperties();
+
+		switch (props.getType())
 		{
 		case GBT_STRUCTURED:
 			bufferType = D3D11HardwareBuffer::BT_STRUCTURED;
@@ -36,27 +39,27 @@ namespace BansheeEngine
 			bufferType = D3D11HardwareBuffer::BT_APPENDCONSUME;
 			break;
 		default:
-			BS_EXCEPT(InvalidParametersException, "Unsupported buffer type " + toString(mType));
+			BS_EXCEPT(InvalidParametersException, "Unsupported buffer type " + toString(props.getType()));
 		}
 
-		mBuffer = bs_new<D3D11HardwareBuffer, PoolAlloc>(bufferType, mUsage, mElementCount, mElementSize, 
-			d3d11rs->getPrimaryDevice(), false, false, mRandomGpuWrite, mUseCounter);
+		mBuffer = bs_new<D3D11HardwareBuffer, PoolAlloc>(bufferType, props.getUsage(), props.getElementCount(), props.getElementSize(),
+			d3d11rs->getPrimaryDevice(), false, false, props.getRandomGpuWrite(), props.getUseCounter());
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_GpuBuffer);
 
-		GpuBuffer::initialize_internal();
+		GpuBufferCore::initialize();
 	}
 
-	void D3D11GpuBuffer::destroy_internal()
+	void D3D11GpuBufferCore::destroy()
 	{
 		bs_delete<PoolAlloc>(mBuffer);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_GpuBuffer);
 
-		GpuBuffer::destroy_internal();
+		GpuBufferCore::destroy();
 	}
 
-	void* D3D11GpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
+	void* D3D11GpuBufferCore::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
 #if BS_PROFILING_ENABLED
 		if (options == GBL_READ_ONLY || options == GBL_READ_WRITE)
@@ -73,44 +76,44 @@ namespace BansheeEngine
 		return mBuffer->lock(offset, length, options);
 	}
 
-	void D3D11GpuBuffer::unlock()
+	void D3D11GpuBufferCore::unlock()
 	{
 		mBuffer->unlock();
 	}
 
-	void D3D11GpuBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
+	void D3D11GpuBufferCore::readData(UINT32 offset, UINT32 length, void* pDest)
 	{
 		BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_GpuBuffer);
 
 		mBuffer->readData(offset, length, pDest);
 	}
 
-	void D3D11GpuBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
+	void D3D11GpuBufferCore::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
 	{
 		BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_GpuBuffer);
 
 		mBuffer->writeData(offset, length, pSource, writeFlags);
 	}
 
-	void D3D11GpuBuffer::copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
+	void D3D11GpuBufferCore::copyData(GpuBufferCore& srcBuffer, UINT32 srcOffset,
 		UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
 	{
-		D3D11GpuBuffer* d3d11SrcBuffer = static_cast<D3D11GpuBuffer*>(&srcBuffer);
+		D3D11GpuBufferCore* d3d11SrcBuffer = static_cast<D3D11GpuBufferCore*>(&srcBuffer);
 
 		mBuffer->copyData(*d3d11SrcBuffer->mBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 	}
 
-	ID3D11Buffer* D3D11GpuBuffer::getDX11Buffer() const 
+	ID3D11Buffer* D3D11GpuBufferCore::getDX11Buffer() const
 	{ 
 		return mBuffer->getD3DBuffer(); 
 	}
 
-	GpuBufferView* D3D11GpuBuffer::createView()
+	GpuBufferView* D3D11GpuBufferCore::createView()
 	{
 		return bs_new<D3D11GpuBufferView, PoolAlloc>();
 	}
 
-	void D3D11GpuBuffer::destroyView(GpuBufferView* view)
+	void D3D11GpuBufferCore::destroyView(GpuBufferView* view)
 	{
 		if(view != nullptr)
 			bs_delete<PoolAlloc>(view);

+ 16 - 12
BansheeD3D11RenderSystem/Source/BsD3D11GpuBufferView.cpp

@@ -22,11 +22,11 @@ namespace BansheeEngine
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_ResourceView);
 	}
 
-	void D3D11GpuBufferView::initialize(GpuBufferPtr buffer, GPU_BUFFER_DESC& desc)
+	void D3D11GpuBufferView::initialize(const SPtr<GpuBufferCore>& buffer, GPU_BUFFER_DESC& desc)
 	{
 		GpuBufferView::initialize(buffer, desc);
 
-		D3D11GpuBuffer* d3d11GpuBuffer = static_cast<D3D11GpuBuffer*>(buffer.get());
+		D3D11GpuBufferCore* d3d11GpuBuffer = static_cast<D3D11GpuBufferCore*>(buffer.get());
 
 		if((desc.usage & GVU_RANDOMWRITE) != 0)
 			mUAV = createUAV(d3d11GpuBuffer, desc.firstElement, desc.numElements, desc.useCounter);
@@ -40,22 +40,24 @@ namespace BansheeEngine
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_ResourceView);
 	}
 
-	ID3D11ShaderResourceView* D3D11GpuBufferView::createSRV(D3D11GpuBuffer* buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements)
+	ID3D11ShaderResourceView* D3D11GpuBufferView::createSRV(D3D11GpuBufferCore* buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements)
 	{
-		if(buffer->getType() == GBT_APPENDCONSUME)
+		const GpuBufferProperties& props = buffer->getProperties();
+
+		if (props.getType() == GBT_APPENDCONSUME)
 			BS_EXCEPT(InvalidParametersException, "Cannot create ShaderResourceView for an append/consume buffer.");
 
 		D3D11_SHADER_RESOURCE_VIEW_DESC desc;
 		ZeroMemory(&desc, sizeof(desc));
 
-		if(buffer->getType() == GBT_STRUCTURED)
+		if (props.getType() == GBT_STRUCTURED)
 		{
 			desc.Format = DXGI_FORMAT_UNKNOWN;
 			desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
 			desc.Buffer.ElementOffset = firstElement * elementWidth;
 			desc.Buffer.ElementWidth = elementWidth;
 		}
-		else if(buffer->getType() == GBT_RAW)
+		else if (props.getType() == GBT_RAW)
 		{
 			desc.Format = DXGI_FORMAT_R32_TYPELESS;
 			desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
@@ -63,7 +65,7 @@ namespace BansheeEngine
 			desc.BufferEx.FirstElement = firstElement;
 			desc.BufferEx.NumElements = numElements;
 		}
-		else if(buffer->getType() == GBT_INDIRECTARGUMENT)
+		else if (props.getType() == GBT_INDIRECTARGUMENT)
 		{
 			desc.Format = DXGI_FORMAT_R32_UINT;
 			desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
@@ -85,14 +87,16 @@ namespace BansheeEngine
 		return srv;
 	}
 
-	ID3D11UnorderedAccessView* D3D11GpuBufferView::createUAV(D3D11GpuBuffer* buffer, UINT32 firstElement, UINT32 numElements, bool useCounter)
+	ID3D11UnorderedAccessView* D3D11GpuBufferView::createUAV(D3D11GpuBufferCore* buffer, UINT32 firstElement, UINT32 numElements, bool useCounter)
 	{
+		const GpuBufferProperties& props = buffer->getProperties();
+
 		D3D11_UNORDERED_ACCESS_VIEW_DESC desc;
 		ZeroMemory(&desc, sizeof(desc));
 
 		desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
 
-		if(buffer->getType() == GBT_STRUCTURED)
+		if (props.getType() == GBT_STRUCTURED)
 		{
 			desc.Format = DXGI_FORMAT_UNKNOWN;
 			desc.Buffer.FirstElement = firstElement;
@@ -103,21 +107,21 @@ namespace BansheeEngine
 			else
 				desc.Buffer.Flags = 0;
 		}
-		else if(buffer->getType() == GBT_RAW)
+		else if (props.getType() == GBT_RAW)
 		{
 			desc.Format = DXGI_FORMAT_R32_TYPELESS;
 			desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
 			desc.Buffer.FirstElement = firstElement;
 			desc.Buffer.NumElements = numElements;
 		}
-		else if(buffer->getType() == GBT_INDIRECTARGUMENT)
+		else if (props.getType() == GBT_INDIRECTARGUMENT)
 		{
 			desc.Format = DXGI_FORMAT_R32_UINT;
 			desc.Buffer.Flags = 0;
 			desc.Buffer.FirstElement = firstElement;
 			desc.Buffer.NumElements = numElements;
 		}
-		else if(buffer->getType() == GBT_APPENDCONSUME)
+		else if (props.getType() == GBT_APPENDCONSUME)
 		{
 			desc.Format = DXGI_FORMAT_UNKNOWN;
 			desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;

+ 9 - 9
BansheeD3D11RenderSystem/Source/BsD3D11GpuParamBlockBuffer.cpp

@@ -6,13 +6,13 @@
 
 namespace BansheeEngine
 {
-	D3D11GpuParamBlockBuffer::D3D11GpuParamBlockBuffer()
-		:mBuffer(nullptr)
+	D3D11GpuParamBlockBufferCore::D3D11GpuParamBlockBufferCore(UINT32 size, GpuParamBlockUsage usage)
+		:GpuParamBlockBufferCore(size, usage), mBuffer(nullptr)
 	{
 
 	}
 
-	void D3D11GpuParamBlockBuffer::initialize_internal()
+	void D3D11GpuParamBlockBufferCore::initialize()
 	{
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 		D3D11Device& device = d3d11rs->getPrimaryDevice();
@@ -26,32 +26,32 @@ namespace BansheeEngine
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_GpuParamBuffer);
 
-		GpuParamBlockBuffer::initialize_internal();
+		GpuParamBlockBufferCore::initialize();
 	}
 
-	void D3D11GpuParamBlockBuffer::destroy_internal()
+	void D3D11GpuParamBlockBufferCore::destroy()
 	{
 		if(mBuffer != nullptr)
 			bs_delete<PoolAlloc>(mBuffer);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_GpuParamBuffer);
 
-		GpuParamBlockBuffer::destroy_internal();
+		GpuParamBlockBufferCore::destroy();
 	}
 
-	ID3D11Buffer* D3D11GpuParamBlockBuffer::getD3D11Buffer() const
+	ID3D11Buffer* D3D11GpuParamBlockBufferCore::getD3D11Buffer() const
 	{
 		return mBuffer->getD3DBuffer();
 	}
 
-	void D3D11GpuParamBlockBuffer::writeData(const UINT8* data)
+	void D3D11GpuParamBlockBufferCore::writeData(const UINT8* data)
 	{
 		mBuffer->writeData(0, mSize, data, BufferWriteType::Discard);
 
 		BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_GpuParamBuffer);
 	}
 
-	void D3D11GpuParamBlockBuffer::readData(UINT8* data) const
+	void D3D11GpuParamBlockBufferCore::readData(UINT8* data) const
 	{
 		mBuffer->readData(0, mSize, data);
 

+ 20 - 19
BansheeD3D11RenderSystem/Source/BsD3D11HardwareBufferManager.cpp

@@ -7,25 +7,6 @@
 
 namespace BansheeEngine
 {
-	D3D11HardwareBufferManager::D3D11HardwareBufferManager(D3D11Device& device)
-		: mDevice(device)
-	{ }
-
-	GpuParamBlockBufferPtr D3D11HardwareBufferManager::createGpuParamBlockBufferImpl()
-	{
-		D3D11GpuParamBlockBuffer* paramBlockBuffer = new (bs_alloc<D3D11GpuParamBlockBuffer, PoolAlloc>()) D3D11GpuParamBlockBuffer();
-
-		return bs_core_ptr<D3D11GpuParamBlockBuffer, PoolAlloc>(paramBlockBuffer);
-	}
-
-	GpuBufferPtr D3D11HardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
-		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
-	{
-		D3D11GpuBuffer* buffer = new (bs_alloc<D3D11GpuBuffer, PoolAlloc>()) D3D11GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
-
-		return bs_core_ptr<D3D11GpuBuffer, PoolAlloc>(buffer);
-	}
-
 	D3D11HardwareBufferCoreManager::D3D11HardwareBufferCoreManager(D3D11Device& device)
 		: mDevice(device)
 	{ }
@@ -48,4 +29,24 @@ namespace BansheeEngine
 		return ret;
 	}
 
+	SPtr<GpuParamBlockBufferCore> D3D11HardwareBufferCoreManager::createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage)
+	{
+		D3D11GpuParamBlockBufferCore* paramBlockBuffer = new (bs_alloc<D3D11GpuParamBlockBufferCore, GenAlloc>()) D3D11GpuParamBlockBufferCore(size, usage);
+
+		SPtr<GpuParamBlockBufferCore> paramBlockBufferPtr = bs_shared_ptr<D3D11GpuParamBlockBufferCore, GenAlloc>(paramBlockBuffer);
+		paramBlockBufferPtr->_setThisPtr(paramBlockBufferPtr);
+
+		return paramBlockBufferPtr;
+	}
+
+	SPtr<GpuBufferCore> D3D11HardwareBufferCoreManager::createGpuBufferInternal(UINT32 elementCount, UINT32 elementSize,
+		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
+	{
+		D3D11GpuBufferCore* buffer = new (bs_alloc<D3D11GpuBufferCore, GenAlloc>()) D3D11GpuBufferCore(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
+
+		SPtr<D3D11GpuBufferCore> bufferPtr = bs_shared_ptr<D3D11GpuBufferCore, GenAlloc>(buffer);
+		bufferPtr->_setThisPtr(bufferPtr);
+
+		return bufferPtr;
+	}
 }

+ 3 - 2
BansheeD3D11RenderSystem/Source/BsD3D11RenderSystem.cpp

@@ -111,7 +111,7 @@ namespace BansheeEngine
 		TextureCoreManager::startUp<D3D11TextureCoreManager>();
 
 		// Create hardware buffer manager		
-		HardwareBufferManager::startUp<D3D11HardwareBufferManager>(std::ref(*mDevice));
+		HardwareBufferManager::startUp();
 		HardwareBufferCoreManager::startUp<D3D11HardwareBufferCoreManager>(std::ref(*mDevice));
 
 		// Create render window manager
@@ -604,7 +604,8 @@ namespace BansheeEngine
 
 			if(currentBlockBuffer != nullptr)
 			{
-				const D3D11GpuParamBlockBuffer* d3d11paramBlockBuffer = static_cast<const D3D11GpuParamBlockBuffer*>(currentBlockBuffer.get());
+				const D3D11GpuParamBlockBufferCore* d3d11paramBlockBuffer = 
+					static_cast<const D3D11GpuParamBlockBufferCore*>(currentBlockBuffer->getCore().get());
 				bufferArray[0] = d3d11paramBlockBuffer->getD3D11Buffer();
 			}
 			else

+ 18 - 17
BansheeD3D9RenderSystem/Include/BsD3D9GpuBuffer.h

@@ -10,56 +10,57 @@ namespace BansheeEngine
 	 *			is just a dummy in order to conform to the interface
 	 *			as DX9 supports no such buffers.
 	 */
-	class BS_D3D9_EXPORT D3D9GpuBuffer : public GpuBuffer
+	class BS_D3D9_EXPORT D3D9GpuBufferCore : public GpuBufferCore
 	{
 	public:
-        ~D3D9GpuBuffer();
+		~D3D9GpuBufferCore();
 
 		/**
-		 * @copydoc GenericBuffer::lockImpl
+		 * @copydoc GpuBufferCore::lock
 		 */
 		virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options);
 
 		/**
-		 * @copydoc GenericBuffer::unlockImpl
+		 * @copydoc GpuBufferCore::unlock
 		 */
 		virtual void unlock();
 
 		/**
-		* @copydoc GenericBuffer::readData
-		*/
+		 * @copydoc GpuBufferCore::readData
+		 */
         virtual void readData(UINT32 offset, UINT32 length, void* pDest);
 
 		/**
-		* @copydoc GenericBuffer::writeData
-		*/
+		 * @copydoc GpuBufferCore::writeData
+		 */
         virtual void writeData(UINT32 offset, UINT32 length, const void* pSource,
 				BufferWriteType writeFlags = BufferWriteType::Normal);
 
 		/**
-		* @copydoc GenericBuffer::copyData
-		*/
-		void copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
+		 * @copydoc GpuBufferCore::copyData
+		 */
+		void copyData(GpuBufferCore& srcBuffer, UINT32 srcOffset,
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 
 	protected:
-		friend class D3D9HardwareBufferManager;
+		friend class D3D9HardwareBufferCoreManager;
 
-		D3D9GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
+		D3D9GpuBufferCore(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage,
+			bool randomGpuWrite = false, bool useCounter = false);
 
 		/**
-		 * @copydoc	GpuBuffer::createView
+		 * @copydoc	GpuBufferCore::createView
 		 */
 		virtual GpuBufferView* createView();
 
 		/**
-		 * @copydoc	GpuBuffer::destroyView
+		 * @copydoc	GpuBufferCore::destroyView
 		 */
 		virtual void destroyView(GpuBufferView* view);
 
 		/**
-		 * @copydoc GpuBuffer::initialize_internal()
+		 * @copydoc GpuBufferCore::initialize
 		 */
-		void initialize_internal();	
+		void initialize();	
 	};
 }

+ 10 - 16
BansheeD3D9RenderSystem/Include/BsD3D9HardwareBufferManager.h

@@ -5,22 +5,6 @@
 
 namespace BansheeEngine 
 {
-	/**
-	 * @brief	Manages creation of DX9 hardware buffers.
-	 */
-    class BS_D3D9_EXPORT D3D9HardwareBufferManager : public HardwareBufferManager
-    {
-	protected:     
-		/** @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl */
-		GpuParamBlockBufferPtr createGpuParamBlockBufferImpl();
-
-		/**
-		 * @copydoc HardwareBufferManager::createGenericBufferImpl
-		 */
-		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
-			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
-    };
-
 	/**
 	 * @brief	Manages creation of DX9 hardware buffers.
 	 */
@@ -42,5 +26,15 @@ namespace BansheeEngine
 		 */
 		SPtr<VertexDeclarationCore> createVertexDeclarationInternal(const List<VertexElement>& elements);
 
+		/** 
+		 * @copydoc HardwareBufferCoreManager::createGpuParamBlockBufferInternal 
+		 */
+		SPtr<GpuParamBlockBufferCore> createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
+
+		/**
+		 * @copydoc HardwareBufferCoreManager::createGenericBufferInternal
+		 */
+		SPtr<GpuBufferCore> createGpuBufferInternal(UINT32 elementCount, UINT32 elementSize, 
+			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
     };
 }

+ 0 - 1
BansheeD3D9RenderSystem/Include/BsD3D9Prerequisites.h

@@ -40,7 +40,6 @@ namespace BansheeEngine
 	class D3D9ResourceManager;
 	class D3D9GpuProgram;
 	class D3D9GpuProgramManager;
-    class D3D9HardwareBufferManager;
     class D3D9IndexBuffer;
     class D3D9HLSLProgramFactory;
     class D3D9HLSLProgramCore;

+ 13 - 12
BansheeD3D9RenderSystem/Source/BsD3D9GpuBuffer.cpp

@@ -3,49 +3,50 @@
 
 namespace BansheeEngine
 {
-	D3D9GpuBuffer::D3D9GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter) 
-		: GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter)
+	D3D9GpuBufferCore::D3D9GpuBufferCore(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, 
+		GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
+		: GpuBufferCore(elementCount, elementSize, type, usage, randomGpuWrite, useCounter)
 	{
 	}
 
-	D3D9GpuBuffer::~D3D9GpuBuffer()
+	D3D9GpuBufferCore::~D3D9GpuBufferCore()
 	{ }
 
-	void D3D9GpuBuffer::initialize_internal()
+	void D3D9GpuBufferCore::initialize()
 	{
 		LOGWRN("Generic buffers are not supported in DirectX 9. Creating a dummy buffer. All operations on it will either be no-op or return a nullptr.");
 
-		GpuBuffer::initialize_internal();
+		GpuBufferCore::initialize();
 	}
 
-	void* D3D9GpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
+	void* D3D9GpuBufferCore::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
 		return nullptr;
 	}
 
-	void D3D9GpuBuffer::unlock()
+	void D3D9GpuBufferCore::unlock()
 	{
 	}
 
-	void D3D9GpuBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
+	void D3D9GpuBufferCore::readData(UINT32 offset, UINT32 length, void* pDest)
 	{
 	}
 
-	void D3D9GpuBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
+	void D3D9GpuBufferCore::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
 	{
 	}
 
-	void D3D9GpuBuffer::copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
+	void D3D9GpuBufferCore::copyData(GpuBufferCore& srcBuffer, UINT32 srcOffset,
 		UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
 	{
 	}
 
-	GpuBufferView* D3D9GpuBuffer::createView()
+	GpuBufferView* D3D9GpuBufferCore::createView()
 	{
 		return nullptr;
 	}
 
-	void D3D9GpuBuffer::destroyView(GpuBufferView* view)
+	void D3D9GpuBufferCore::destroyView(GpuBufferView* view)
 	{
 	}
 }

+ 21 - 13
BansheeD3D9RenderSystem/Source/BsD3D9HardwareBufferManager.cpp

@@ -8,19 +8,6 @@
 
 namespace BansheeEngine 
 {
-	GpuParamBlockBufferPtr D3D9HardwareBufferManager::createGpuParamBlockBufferImpl()
-	{
-		GpuParamBlockBuffer* paramBlockBuffer = new (bs_alloc<GenericGpuParamBlockBuffer, PoolAlloc>()) GenericGpuParamBlockBuffer();
-		return bs_core_ptr<GpuParamBlockBuffer, PoolAlloc>(paramBlockBuffer);
-	}
-
-	GpuBufferPtr D3D9HardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
-		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
-	{
-		D3D9GpuBuffer* buffer = new (bs_alloc<D3D9GpuBuffer, PoolAlloc>()) D3D9GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
-		return bs_core_ptr<D3D9GpuBuffer, PoolAlloc>(buffer);
-	}
-
 	SPtr<VertexBufferCore> D3D9HardwareBufferCoreManager::createVertexBufferInternal(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 	{
 		assert(numVerts > 0);
@@ -50,4 +37,25 @@ namespace BansheeEngine
 
 		return declPtr;
 	}
+
+	SPtr<GpuParamBlockBufferCore> D3D9HardwareBufferCoreManager::createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage)
+	{
+		GenericGpuParamBlockBufferCore* paramBlockBuffer = new (bs_alloc<GenericGpuParamBlockBufferCore, GenAlloc>()) GenericGpuParamBlockBufferCore(size, usage);
+
+		SPtr<GpuParamBlockBufferCore> paramBlockBufferPtr = bs_shared_ptr<GenericGpuParamBlockBufferCore, GenAlloc>(paramBlockBuffer);
+		paramBlockBufferPtr->_setThisPtr(paramBlockBufferPtr);
+
+		return paramBlockBufferPtr;
+	}
+
+	SPtr<GpuBufferCore> D3D9HardwareBufferCoreManager::createGpuBufferInternal(UINT32 elementCount, UINT32 elementSize,
+		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
+	{
+		D3D9GpuBufferCore* buffer = new (bs_alloc<D3D9GpuBufferCore, GenAlloc>()) D3D9GpuBufferCore(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
+
+		SPtr<GpuBufferCore> bufferPtr = bs_shared_ptr<D3D9GpuBufferCore, GenAlloc>(buffer);
+		bufferPtr->_setThisPtr(bufferPtr);
+
+		return bufferPtr;
+	}
 }

+ 2 - 2
BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp

@@ -95,7 +95,7 @@ namespace BansheeEngine
 		mDeviceManager = bs_new<D3D9DeviceManager>();
 
 		// Also create hardware buffer manager		
-		HardwareBufferManager::startUp<D3D9HardwareBufferManager>();
+		HardwareBufferManager::startUp();
 		HardwareBufferCoreManager::startUp<D3D9HardwareBufferCoreManager>();
 
 		// Create & register HLSL factory		
@@ -313,7 +313,7 @@ namespace BansheeEngine
 				GpuParamBlockBufferPtr paramBlock = bindableParams->getParamBlockBuffer(paramBlockSlot);
 
 				UINT8* data = (UINT8*)bs_alloc<ScratchAlloc>(paramBlock->getSize());
-				paramBlock->readData(data);
+				paramBlock->getCore()->readData(data);
 
 				bufferData[paramBlockSlot] = data;
 			}

+ 17 - 16
BansheeGLRenderSystem/Include/BsGLGpuBuffer.h

@@ -9,60 +9,61 @@ namespace BansheeEngine
 	 * @brief	OpenGL implementation of a generic GPU buffer.
 	 */
 	// TODO - Not implemented, just a dummy class for now
-	class BS_RSGL_EXPORT GLGpuBuffer : public GpuBuffer
+	class BS_RSGL_EXPORT GLGpuBufferCore : public GpuBufferCore
 	{
 	public:
-        ~GLGpuBuffer();
+		~GLGpuBufferCore();
 
 		/**
-		 * @copydoc GpuBuffer::lockImpl
+		 * @copydoc GpuBufferCore::lock
 		 */
 		virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options);
 
 		/**
-		 * @copydoc GpuBuffer::unlockImpl
+		 * @copydoc GpuBufferCore::unlock
 		 */
 		virtual void unlock();
 
 		/**
-		 * @copydoc GpuBuffer::readData
+		 * @copydoc GpuBufferCore::readData
 		 */
         virtual void readData(UINT32 offset, UINT32 length, void* pDest);
 
 		/**
-		 * @copydoc GpuBuffer::writeData
+		 * @copydoc GpuBufferCore::writeData
 		 */
         virtual void writeData(UINT32 offset, UINT32 length, const void* pSource,
 				BufferWriteType writeFlags = BufferWriteType::Normal);
 
 		/**
-		 * @copydoc GpuBuffer::copyData
+		 * @copydoc GpuBufferCore::copyData
 		 */
-		void copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
+		void copyData(GpuBufferCore& srcBuffer, UINT32 srcOffset,
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 
 	protected:
-		friend class GLHardwareBufferManager;
+		friend class GLHardwareBufferCoreManager;
 
-		GLGpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
+		GLGpuBufferCore(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, 
+			GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 
 		/**
-		 * @copydoc GpuBuffer::initialize_internal
+		 * @copydoc GpuBufferCore::initialize
 		 */
-		void initialize_internal();	
+		void initialize();	
 
 		/**
-		 * @copydoc GpuBuffer::destroy_internal
+		 * @copydoc GpuBufferCore::destroy
 		 */
-		void destroy_internal();	
+		void destroy();	
 
 		/**
-		 * @copydoc GpuBuffer::createView
+		 * @copydoc GpuBufferCore::createView
 		 */
 		virtual GpuBufferView* createView();
 
 		/**
-		 * @copydoc GpuBuffer::destroyView
+		 * @copydoc GpuBufferCore::destroyView
 		 */
 		virtual void destroyView(GpuBufferView* view);
 	};

+ 8 - 8
BansheeGLRenderSystem/Include/BsGLGpuParamBlockBuffer.h

@@ -8,18 +8,18 @@ namespace BansheeEngine
 	/**
 	 * @brief	OpenGL implementation of a GPU parameter buffer (Uniform buffer).
 	 */
-	class BS_RSGL_EXPORT GLGpuParamBlockBuffer : public GpuParamBlockBuffer
+	class BS_RSGL_EXPORT GLGpuParamBlockBufferCore : public GpuParamBlockBufferCore
 	{
 	public:
-		GLGpuParamBlockBuffer();
+		GLGpuParamBlockBufferCore(UINT32 size, GpuParamBlockUsage usage);
 
 		/**
-		 * @copydoc GpuParamBlockBuffer::writeAll.
+		 * @copydoc GpuParamBlockBufferCore::writeData
 		 */
 		void writeData(const UINT8* data);
 
 		/**
-		 * @copydoc GpuParamBlockBuffer::readAll.
+		 * @copydoc GpuParamBlockBufferCore::readData
 		 */
 		void readData(UINT8* data) const;
 
@@ -29,14 +29,14 @@ namespace BansheeEngine
 		GLuint getGLHandle() const { return mGLHandle; }
 	protected:
 		/**
-		 * @copydoc CoreGpuObject::initialize_internal.
+		 * @copydoc GpuParamBlockBufferCore::initialize
 		 */
-		virtual void initialize_internal();
+		virtual void initialize();
 
 		/**
-		 * @copydoc CoreGpuObject::destroy_internal.
+		 * @copydoc GpuParamBlockBufferCore::destroy
 		 */
-		virtual void destroy_internal();
+		virtual void destroy();
 
 	private:
 		GLuint mGLHandle;

+ 9 - 16
BansheeGLRenderSystem/Include/BsGLHardwareBufferManager.h

@@ -5,22 +5,6 @@
 
 namespace BansheeEngine 
 {
-	/**
-	 * @brief	Handles creation of OpenGL specific hardware buffers.
-	 */
-    class BS_RSGL_EXPORT GLHardwareBufferManager : public HardwareBufferManager
-    {
-	protected:
-		/** @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl */
-		GpuParamBlockBufferPtr createGpuParamBlockBufferImpl();
-
-		/**
-		 * @copydoc HardwareBufferManager::createGenericBufferImpl
-		 */
-		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
-			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
-    };
-
 	/**
 	 * @brief	Handles creation of OpenGL specific hardware buffers.
 	 */
@@ -48,5 +32,14 @@ namespace BansheeEngine
 		 * @copydoc HardwareBufferCoreManager::createIndexBufferImpl
 		 */
         SPtr<IndexBufferCore> createIndexBufferInternal(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+
+		/** @copydoc HardwareBufferCoreManager::createGpuParamBlockBufferInternal */
+		SPtr<GpuParamBlockBufferCore> createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
+
+		/**
+		 * @copydoc HardwareBufferCoreManager::createGenericBufferInternal
+		 */
+		SPtr<GpuBufferCore> createGpuBufferInternal(UINT32 elementCount, UINT32 elementSize, 
+			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
     };
 }

+ 14 - 14
BansheeGLRenderSystem/Source/BsGLGpuBuffer.cpp

@@ -4,30 +4,30 @@
 
 namespace BansheeEngine
 {
-	GLGpuBuffer::GLGpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter) 
-		: GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter)
+	GLGpuBufferCore::GLGpuBufferCore(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
+		: GpuBufferCore(elementCount, elementSize, type, usage, randomGpuWrite, useCounter)
 	{
 	}
 
-	GLGpuBuffer::~GLGpuBuffer()
+	GLGpuBufferCore::~GLGpuBufferCore()
 	{
 	}
 
-	void GLGpuBuffer::initialize_internal()
+	void GLGpuBufferCore::initialize()
 	{
 		LOGWRN("Generic buffers are not supported in OpenGL. Creating a dummy buffer. All operations on it will either be no-op or return a nullptr.");
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_GpuBuffer);
-		GpuBuffer::initialize_internal();
+		GpuBufferCore::initialize();
 	}
 
-	void GLGpuBuffer::destroy_internal()
+	void GLGpuBufferCore::destroy()
 	{
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_GpuBuffer);
-		GpuBuffer::destroy_internal();
+		GpuBufferCore::destroy();
 	}
 
-	void* GLGpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
+	void* GLGpuBufferCore::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
 #if BS_PROFILING_ENABLED
 		if (options == GBL_READ_ONLY || options == GBL_READ_WRITE)
@@ -44,31 +44,31 @@ namespace BansheeEngine
 		return nullptr;
 	}
 
-	void GLGpuBuffer::unlock()
+	void GLGpuBufferCore::unlock()
 	{
 	}
 
-	void GLGpuBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
+	void GLGpuBufferCore::readData(UINT32 offset, UINT32 length, void* pDest)
 	{
 		BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_GpuBuffer);
 	}
 
-	void GLGpuBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
+	void GLGpuBufferCore::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
 	{
 		BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_GpuBuffer);
 	}
 
-	void GLGpuBuffer::copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
+	void GLGpuBufferCore::copyData(GpuBufferCore& srcBuffer, UINT32 srcOffset,
 		UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
 	{
 	}
 
-	GpuBufferView* GLGpuBuffer::createView()
+	GpuBufferView* GLGpuBufferCore::createView()
 	{
 		return nullptr;
 	}
 
-	void GLGpuBuffer::destroyView(GpuBufferView* view)
+	void GLGpuBufferCore::destroyView(GpuBufferView* view)
 	{
 	}
 }

+ 8 - 8
BansheeGLRenderSystem/Source/BsGLGpuParamBlockBuffer.cpp

@@ -4,12 +4,12 @@
 
 namespace BansheeEngine
 {
-	GLGpuParamBlockBuffer::GLGpuParamBlockBuffer()
-		:mGLHandle(0)
+	GLGpuParamBlockBufferCore::GLGpuParamBlockBufferCore(UINT32 size, GpuParamBlockUsage usage)
+		:GpuParamBlockBufferCore(size, usage), mGLHandle(0)
 	{
 	}
 
-	void GLGpuParamBlockBuffer::initialize_internal()
+	void GLGpuParamBlockBufferCore::initialize()
 	{
 		glGenBuffers(1, &mGLHandle);
 		glBindBuffer(GL_UNIFORM_BUFFER, mGLHandle);
@@ -23,18 +23,18 @@ namespace BansheeEngine
 		glBindBuffer(GL_UNIFORM_BUFFER, 0);
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_GpuParamBuffer);
-		GpuParamBlockBuffer::initialize_internal();
+		GpuParamBlockBufferCore::initialize();
 	}
 
-	void GLGpuParamBlockBuffer::destroy_internal()
+	void GLGpuParamBlockBufferCore::destroy()
 	{
 		glDeleteBuffers(1, &mGLHandle);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_GpuParamBuffer);
-		GpuParamBlockBuffer::destroy_internal();
+		GpuParamBlockBufferCore::destroy();
 	}
 
-	void GLGpuParamBlockBuffer::writeData(const UINT8* data)
+	void GLGpuParamBlockBufferCore::writeData(const UINT8* data)
 	{
 		glBindBuffer(GL_UNIFORM_BUFFER, mGLHandle);
 		glBufferSubData(GL_UNIFORM_BUFFER, 0 , mSize, data);
@@ -43,7 +43,7 @@ namespace BansheeEngine
 		BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_GpuParamBuffer);
 	}
 
-	void GLGpuParamBlockBuffer::readData(UINT8* data) const
+	void GLGpuParamBlockBufferCore::readData(UINT8* data) const
 	{
 		glBindBuffer(GL_UNIFORM_BUFFER, mGLHandle);
 		glGetBufferSubData(GL_UNIFORM_BUFFER, 0 , mSize, (GLvoid*)data);

+ 21 - 11
BansheeGLRenderSystem/Source/BsGLHardwareBufferManager.cpp

@@ -9,17 +9,6 @@
 
 namespace BansheeEngine 
 {
-	GpuParamBlockBufferPtr GLHardwareBufferManager::createGpuParamBlockBufferImpl()
-	{
-		return bs_core_ptr<GLGpuParamBlockBuffer, PoolAlloc>(new (bs_alloc<GLGpuParamBlockBuffer, PoolAlloc>()) GLGpuParamBlockBuffer());
-	}
-
-	GpuBufferPtr GLHardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
-		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
-	{
-		return bs_core_ptr<GLGpuBuffer, PoolAlloc>(new (bs_alloc<GLGpuBuffer, PoolAlloc>()) GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
-	}
-
 	SPtr<VertexBufferCore> GLHardwareBufferCoreManager::createVertexBufferInternal(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 	{
 		SPtr<GLVertexBufferCore> ret = bs_shared_ptr<GLVertexBufferCore>(vertexSize, numVerts, usage, streamOut);
@@ -36,6 +25,27 @@ namespace BansheeEngine
 		return ret;
 	}
 
+	SPtr<GpuParamBlockBufferCore> GLHardwareBufferCoreManager::createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage)
+	{
+		GLGpuParamBlockBufferCore* paramBlockBuffer = new (bs_alloc<GLGpuParamBlockBufferCore, GenAlloc>()) GLGpuParamBlockBufferCore(size, usage);
+
+		SPtr<GpuParamBlockBufferCore> paramBlockBufferPtr = bs_shared_ptr<GLGpuParamBlockBufferCore, GenAlloc>(paramBlockBuffer);
+		paramBlockBufferPtr->_setThisPtr(paramBlockBufferPtr);
+
+		return paramBlockBufferPtr;
+	}
+
+	SPtr<GpuBufferCore> GLHardwareBufferCoreManager::createGpuBufferInternal(UINT32 elementCount, UINT32 elementSize,
+		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
+	{
+		GLGpuBufferCore* buffer = new (bs_alloc<GLGpuBufferCore, GenAlloc>()) GLGpuBufferCore(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
+
+		SPtr<GpuBufferCore> bufferPtr = bs_shared_ptr<GLGpuBufferCore, GenAlloc>(buffer);
+		bufferPtr->_setThisPtr(bufferPtr);
+
+		return bufferPtr;
+	}
+
     GLenum GLHardwareBufferCoreManager::getGLUsage(GpuBufferUsage usage)
     {
         switch(usage)

+ 4 - 3
BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp

@@ -298,19 +298,20 @@ namespace BansheeEngine
 			if(paramBlockBuffer == nullptr)
 				continue;
 
+			SPtr<GpuParamBlockBufferCore> paramBlockBufferCore = paramBlockBuffer->getCore();
 			if(iter->second.slot == 0)
 			{
 				// 0 means uniforms are not in block, in which case we handle it specially
 				if (uniformBufferData == nullptr && paramBlockBuffer->getSize() > 0)
 				{
 					uniformBufferData = (UINT8*)bs_alloc<ScratchAlloc>(paramBlockBuffer->getSize());
-					paramBlockBuffer->readData(uniformBufferData);
+					paramBlockBufferCore->readData(uniformBufferData);
 				}
 
 				continue;
 			}
 
-			const GLGpuParamBlockBuffer* glParamBlockBuffer = static_cast<const GLGpuParamBlockBuffer*>(paramBlockBuffer.get());
+			const GLGpuParamBlockBufferCore* glParamBlockBuffer = static_cast<const GLGpuParamBlockBufferCore*>(paramBlockBufferCore.get());
 
 			UINT32 globalBlockBinding = getGLUniformBlockBinding(gptype, blockBinding);
 			glUniformBlockBinding(glProgram, iter->second.slot - 1, globalBlockBinding);
@@ -1701,7 +1702,7 @@ namespace BansheeEngine
 		}
 #endif
 
-		HardwareBufferManager::startUp<GLHardwareBufferManager>();
+		HardwareBufferManager::startUp();
 		HardwareBufferCoreManager::startUp<GLHardwareBufferCoreManager>();
 
 		// GPU Program Manager setup

+ 17 - 0
BansheeUtility/Include/BsRTTIType.h

@@ -1042,4 +1042,21 @@ namespace BansheeEngine
 
 		return object->getTypeId() == T::getRTTIStatic()->getRTTIId();
 	}
+
+	/**
+	 * @brief	Creates a new object just from its type ID.
+	 */
+	std::shared_ptr<IReflectable> rtti_create(UINT32 rttiId);
+
+	/**
+	 * @brief	Checks is the current object a subclass of some type.
+	 */
+	template<class T>
+	bool rtti_is_subclass(IReflectable* object)
+	{
+		static_assert((std::is_base_of<BansheeEngine::IReflectable, T>::value),
+			"Invalid data type for type checking. It needs to derive from BansheeEngine::IReflectable.");
+
+		return object->isDerivedFrom(T::getRTTIStatic());
+	}
 }

+ 5 - 0
BansheeUtility/Source/BsRTTIType.cpp

@@ -71,4 +71,9 @@ namespace BansheeEngine
 		BS_EXCEPT(InternalErrorException, "Found circular reference on RTTI type: " + myType + " to type: " + otherType + "."
 			+ " Either remove one of the references or mark it as a weak reference when defining the RTTI field.");
 	}
+
+	std::shared_ptr<IReflectable> rtti_create(UINT32 rttiId)
+	{
+		return IReflectable::createInstanceFromTypeId(rttiId);
+	}
 }

+ 0 - 1
TODO.txt

@@ -4,7 +4,6 @@ TODO - CoreObject refactor:
 Resource
  - Material -> Remove MaterialProxy
  - Shader -> Remove ShaderProxy
-VertexDeclaration
 GpuBuffer
 GpuParamBlockBuffer