Răsfoiți Sursa

Refactored Index and Vertex buffers to work with new CoreObject system

Marko Pintera 11 ani în urmă
părinte
comite
dbdd6a60f8
48 a modificat fișierele cu 691 adăugiri și 354 ștergeri
  1. 3 2
      BansheeCore/Include/BsCoreObjectCore.h
  2. 2 2
      BansheeCore/Include/BsHardwareBufferManager.h
  3. 66 19
      BansheeCore/Include/BsIndexBuffer.h
  4. 9 9
      BansheeCore/Include/BsMesh.h
  5. 3 3
      BansheeCore/Include/BsMeshData.h
  6. 3 3
      BansheeCore/Include/BsMeshDataRTTI.h
  7. 3 3
      BansheeCore/Include/BsMeshHeap.h
  8. 4 4
      BansheeCore/Include/BsMeshManager.h
  9. 7 0
      BansheeCore/Include/BsRenderSystem.h
  10. 47 10
      BansheeCore/Include/BsVertexBuffer.h
  11. 18 1
      BansheeCore/Source/BsCoreObjectCore.cpp
  12. 8 2
      BansheeCore/Source/BsCoreObjectManager.cpp
  13. 1 1
      BansheeCore/Source/BsHardwareBufferManager.cpp
  14. 18 11
      BansheeCore/Source/BsIndexBuffer.cpp
  15. 38 27
      BansheeCore/Source/BsMesh.cpp
  16. 5 5
      BansheeCore/Source/BsMeshData.cpp
  17. 16 9
      BansheeCore/Source/BsMeshHeap.cpp
  18. 2 2
      BansheeCore/Source/BsMeshManager.cpp
  19. 2 2
      BansheeCore/Source/BsMeshRTTI.h
  20. 4 3
      BansheeCore/Source/BsRenderSystem.cpp
  21. 15 3
      BansheeCore/Source/BsVertexBuffer.cpp
  22. 1 1
      BansheeD3D11RenderSystem/Include/BsD3D11HardwareBufferManager.h
  23. 39 19
      BansheeD3D11RenderSystem/Include/BsD3D11IndexBuffer.h
  24. 40 17
      BansheeD3D11RenderSystem/Include/BsD3D11VertexBuffer.h
  25. 1 1
      BansheeD3D11RenderSystem/Source/BsD3D11HardwareBufferManager.cpp
  26. 24 17
      BansheeD3D11RenderSystem/Source/BsD3D11IndexBuffer.cpp
  27. 8 6
      BansheeD3D11RenderSystem/Source/BsD3D11RenderSystem.cpp
  28. 22 15
      BansheeD3D11RenderSystem/Source/BsD3D11VertexBuffer.cpp
  29. 1 1
      BansheeD3D9RenderSystem/Include/BsD3D9HardwareBufferManager.h
  30. 30 14
      BansheeD3D9RenderSystem/Include/BsD3D9IndexBuffer.h
  31. 1 1
      BansheeD3D9RenderSystem/Include/BsD3D9Mappings.h
  32. 5 0
      BansheeD3D9RenderSystem/Include/BsD3D9RenderSystem.h
  33. 30 19
      BansheeD3D9RenderSystem/Include/BsD3D9VertexBuffer.h
  34. 1 1
      BansheeD3D9RenderSystem/Source/BsD3D9HardwareBufferManager.cpp
  35. 28 22
      BansheeD3D9RenderSystem/Source/BsD3D9IndexBuffer.cpp
  36. 2 2
      BansheeD3D9RenderSystem/Source/BsD3D9Mappings.cpp
  37. 4 3
      BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp
  38. 26 20
      BansheeD3D9RenderSystem/Source/BsD3D9VertexBuffer.cpp
  39. 1 1
      BansheeEditorExec/BsEditorExec.cpp
  40. 1 1
      BansheeGLRenderSystem/Include/BsGLHardwareBufferManager.h
  41. 30 15
      BansheeGLRenderSystem/Include/BsGLIndexBuffer.h
  42. 30 14
      BansheeGLRenderSystem/Include/BsGLVertexBuffer.h
  43. 1 1
      BansheeGLRenderSystem/Source/BsGLHardwareBufferManager.cpp
  44. 21 16
      BansheeGLRenderSystem/Source/BsGLIndexBuffer.cpp
  45. 6 4
      BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp
  46. 9 4
      BansheeGLRenderSystem/Source/BsGLVertexArrayObjectManager.cpp
  47. 22 16
      BansheeGLRenderSystem/Source/BsGLVertexBuffer.cpp
  48. 33 2
      TODO.txt

+ 3 - 2
BansheeCore/Include/BsCoreObjectCore.h

@@ -18,7 +18,7 @@ namespace BansheeEngine
 	{
 	public:
 		CoreObjectCore();
-		virtual ~CoreObjectCore() {}
+		virtual ~CoreObjectCore();
 
 	protected:
 		friend class CoreObjectManager;
@@ -32,7 +32,7 @@ namespace BansheeEngine
 		/**
 		 * @brief	Called on the core thread just before the object is destroyed.
 		 */
-		virtual void destroy() { }
+		virtual void destroy();
 
 		/**
 		 * @brief	Copy internal dirty data to a memory buffer that will be used
@@ -69,5 +69,6 @@ namespace BansheeEngine
 		bool isCoreDirty() const { return mCoreDirtyFlags != 0; }
 
 		UINT32 mCoreDirtyFlags;
+		bool mIsDestroyed;
 	};
 }

+ 2 - 2
BansheeCore/Include/BsHardwareBufferManager.h

@@ -41,7 +41,7 @@ namespace BansheeEngine
 		 * @param	numIndexes	Number of indexes can buffer can hold.
 		 * @param	usage		Usage that tells the hardware how will be buffer be used. 
 		 */
-		virtual IndexBufferPtr createIndexBuffer(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+		virtual IndexBufferPtr createIndexBuffer(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 		/**
 		 * @brief	Creates an GPU parameter block that you can use for setting parameters for GPU programs.
@@ -85,7 +85,7 @@ namespace BansheeEngine
 		/**
 		 * @copydoc	createIndexBuffer
 		 */
-		virtual IndexBufferPtr createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
+		virtual IndexBufferPtr createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
 
 		/**
 		 * @copydoc	createGpuParamBlockBuffer

+ 66 - 19
BansheeCore/Include/BsIndexBuffer.h

@@ -7,22 +7,20 @@
 namespace BansheeEngine 
 {
 	/**
-	 * @brief	Hardware buffer that hold indices that reference vertices in a vertex buffer.
+	 * @brief	Type of the indices used, used for determining size.
 	 */
-    class BS_CORE_EXPORT IndexBuffer : public HardwareBuffer, public CoreObject
-    {
-	public:
-		/**
-		 * @brief	Type of the indices used, used for determining size.
-		 */
-		enum IndexType 
-		{
-			IT_16BIT,
-			IT_32BIT
-		};
-
-		~IndexBuffer();
+	enum IndexType 
+	{
+		IT_16BIT,
+		IT_32BIT
+	};
 
+	/**
+	 * @brief	Contains information about an index buffer.
+	 */
+	class BS_CORE_EXPORT IndexBufferProperties
+	{
+	public:
 		/**
 		 * @brief	Returns the type of indices stored.
 		 */
@@ -38,17 +36,66 @@ namespace BansheeEngine
 		 */
 		UINT32 getIndexSize() const { return mIndexSize; }
 
+	protected:
+		friend class IndexBuffer;
+		friend class IndexBufferCore;
+
+		IndexType mIndexType;
+		UINT32 mNumIndexes;
+		UINT32 mIndexSize;
+	};
+
+	/**
+	 * @brief	Core thread specific implementation of an index buffer.
+	 *
+	 * @see		IndexBuffer
+	 */
+	class BS_CORE_EXPORT IndexBufferCore : public CoreObjectCore, public HardwareBuffer
+	{
+	public:
+		IndexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const IndexBufferProperties& properties);
+		virtual ~IndexBufferCore() { }
+
+		/**
+		 * @brief	Returns information about the index buffer.
+		 */
+		const IndexBufferProperties& getProperties() const { return mProperties; }
+
+	protected:
+		IndexBufferProperties mProperties;
+	};
+
+	/**
+	 * @brief	Hardware buffer that hold indices that reference vertices in a vertex buffer.
+	 */
+    class BS_CORE_EXPORT IndexBuffer : public CoreObject
+    {
+	public:
+		virtual ~IndexBuffer() { }
+
+		/**
+		 * @brief	Returns information about the index buffer.
+		 */
+		const IndexBufferProperties& getProperties() const { return mProperties; }
+
+		/**
+		 * @brief	Retrieves a core implementation of an index buffer
+		 *			usable only from the core thread.
+		 *
+		 * @note	Core thread only.
+		 */
+		IndexBufferCore* getCore() const;
+
 		/**
 		 * @copydoc	HardwareBufferManager::createIndexBuffer
 		 */
-		static IndexBufferPtr create(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+		static IndexBufferPtr create(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 	protected:
 		IndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage, bool useSystemMemory);
 
-	protected:
-		IndexType mIndexType;
-		UINT32 mNumIndexes;
-		UINT32 mIndexSize;
+		IndexBufferProperties mProperties;
+		GpuBufferUsage mUsage;
+		bool mUseSystemMemory;
     };
 }

+ 9 - 9
BansheeCore/Include/BsMesh.h

@@ -84,11 +84,11 @@ namespace BansheeEngine
 
 		Mesh(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 
 			MeshBufferType bufferType = MeshBufferType::Static, DrawOperationType drawOp = DOT_TRIANGLE_LIST,
-			IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
+			IndexType indexType = IT_32BIT);
 
 		Mesh(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc,
 			const Vector<SubMesh>& subMeshes, MeshBufferType bufferType = MeshBufferType::Static,
-			IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
+			IndexType indexType = IT_32BIT);
 
 		Mesh(const MeshDataPtr& initialMeshData, MeshBufferType bufferType = MeshBufferType::Static, 
 			DrawOperationType drawOp = DOT_TRIANGLE_LIST);
@@ -101,7 +101,7 @@ namespace BansheeEngine
 		Bounds mBounds; // Core thread
 		VertexDataDescPtr mVertexDesc; // Immutable
 		MeshBufferType mBufferType; // Immutable
-		IndexBuffer::IndexType mIndexType; // Immutable
+		IndexType mIndexType; // Immutable
 
 		MeshDataPtr mTempInitialMeshData; // Immutable
 
@@ -161,7 +161,7 @@ namespace BansheeEngine
 		 *							the number of vertices limited by the size.
 		 */
 		static HMesh create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, MeshBufferType bufferType = MeshBufferType::Static,
-			DrawOperationType drawOp = DOT_TRIANGLE_LIST, IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
+			DrawOperationType drawOp = DOT_TRIANGLE_LIST, IndexType indexType = IT_32BIT);
 
 		/**
 		 * @brief	Creates a new empty mesh. Created mesh will have specified sub-meshes you may render independently.
@@ -179,7 +179,7 @@ namespace BansheeEngine
 		 *							the number of vertices limited by the size.
 		 */
 		static HMesh create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, const Vector<SubMesh>& subMeshes,
-			MeshBufferType bufferType = MeshBufferType::Static, IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
+			MeshBufferType bufferType = MeshBufferType::Static, IndexType indexType = IT_32BIT);
 
 		/**
 		 * @brief	Creates a new mesh from an existing mesh data. Created mesh will match the vertex and index buffers described
@@ -207,22 +207,22 @@ namespace BansheeEngine
 		static HMesh create(const MeshDataPtr& initialMeshData, const Vector<SubMesh>& subMeshes, MeshBufferType bufferType = MeshBufferType::Static);
 
 		/**
-		 * @copydoc	create(UINT32, UINT32, const VertexDataDescPtr&, MeshBufferType, DrawOperationType, IndexBuffer::IndexType)
+		 * @copydoc	create(UINT32, UINT32, const VertexDataDescPtr&, MeshBufferType, DrawOperationType, IndexType)
 		 *
 		 * @note	Internal method. Use "create" for normal use.
 		 */
 		static MeshPtr _createPtr(UINT32 numVertices, UINT32 numIndices, 
 			const VertexDataDescPtr& vertexDesc, MeshBufferType bufferType = MeshBufferType::Static,
-			DrawOperationType drawOp = DOT_TRIANGLE_LIST, IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
+			DrawOperationType drawOp = DOT_TRIANGLE_LIST, IndexType indexType = IT_32BIT);
 
 		/**
-		 * @copydoc	create(UINT32, UINT32, const VertexDataDescPtr&, const Vector<SubMesh>&, MeshBufferType, IndexBuffer::IndexType)
+		 * @copydoc	create(UINT32, UINT32, const VertexDataDescPtr&, const Vector<SubMesh>&, MeshBufferType, IndexType)
 		 *
 		 * @note	Internal method. Use "create" for normal use.
 		 */
 		static MeshPtr _createPtr(UINT32 numVertices, UINT32 numIndices, 
 			const VertexDataDescPtr& vertexDesc, const Vector<SubMesh>& subMeshes,
-			MeshBufferType bufferType = MeshBufferType::Static, IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
+			MeshBufferType bufferType = MeshBufferType::Static, IndexType indexType = IT_32BIT);
 
 		/**
 		 * @copydoc	create(const MeshDataPtr&, MeshBufferType, DrawOperationType)

+ 3 - 3
BansheeCore/Include/BsMeshData.h

@@ -97,7 +97,7 @@ namespace BansheeEngine
 		 * @brief	Constructs a new object that can hold number of vertices described by the provided vertex data description. As well
 		 *			as a number of indices of the provided type.
 		 */
-		MeshData(UINT32 numVertices, UINT32 numIndexes, const VertexDataDescPtr& vertexData, IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
+		MeshData(UINT32 numVertices, UINT32 numIndexes, const VertexDataDescPtr& vertexData, IndexType indexType = IT_32BIT);
 		~MeshData();
 
 		/**
@@ -171,7 +171,7 @@ namespace BansheeEngine
 		/**
 		 * @brief	Returns the type of an index element.
 		 */
-		IndexBuffer::IndexType getIndexType() const { return mIndexType; }
+		IndexType getIndexType() const { return mIndexType; }
 
 		/**
 		 * @brief	Returns the pointer to the first element of the specified type. If you want to
@@ -279,7 +279,7 @@ namespace BansheeEngine
 
 		UINT32 mNumVertices;
 		UINT32 mNumIndices;
-		IndexBuffer::IndexType mIndexType;
+		IndexType mIndexType;
 
 		VertexDataDescPtr mVertexData;
 

+ 3 - 3
BansheeCore/Include/BsMeshDataRTTI.h

@@ -8,7 +8,7 @@
 
 namespace BansheeEngine
 {
-	BS_ALLOW_MEMCPY_SERIALIZATION(IndexBuffer::IndexType);
+	BS_ALLOW_MEMCPY_SERIALIZATION(IndexType);
 
 	class BS_CORE_EXPORT MeshDataRTTI : public RTTIType<MeshData, GpuResourceData, MeshDataRTTI>
 	{
@@ -16,8 +16,8 @@ namespace BansheeEngine
 		VertexDataDescPtr getVertexData(MeshData* obj) { return obj->mVertexData; }
 		void setVertexData(MeshData* obj, VertexDataDescPtr value) { obj->mVertexData = value; }
 
-		IndexBuffer::IndexType& getIndexType(MeshData* obj) { return obj->mIndexType; }
-		void setIndexType(MeshData* obj, IndexBuffer::IndexType& value) { obj->mIndexType = value; }
+		IndexType& getIndexType(MeshData* obj) { return obj->mIndexType; }
+		void setIndexType(MeshData* obj, IndexType& value) { obj->mIndexType = value; }
 
 		UINT32& getNumVertices(MeshData* obj) { return obj->mNumVertices; }
 		void setNumVertices(MeshData* obj, UINT32& value) { obj->mNumVertices = value; }

+ 3 - 3
BansheeCore/Include/BsMeshHeap.h

@@ -93,7 +93,7 @@ namespace BansheeEngine
 		 * @param	indexType	Type of the stored indices.
 		 */
 		static MeshHeapPtr create(UINT32 numVertices, UINT32 numIndices, 
-			const VertexDataDescPtr& vertexDesc, IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
+			const VertexDataDescPtr& vertexDesc, IndexType indexType = IT_32BIT);
 
 	private:
 		friend class TransientMesh;
@@ -102,7 +102,7 @@ namespace BansheeEngine
 		 * @copydoc	create
 		 */
 		MeshHeap(UINT32 numVertices, UINT32 numIndices, 
-			const VertexDataDescPtr& vertexDesc, IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
+			const VertexDataDescPtr& vertexDesc, IndexType indexType = IT_32BIT);
 
 		/**
 		 * @copydoc CoreObject::initialize_internal()
@@ -219,7 +219,7 @@ namespace BansheeEngine
 		Map<UINT32, AllocatedData> mMeshAllocData; // Core thread
 
 		VertexDataDescPtr mVertexDesc; // Immutable
-		IndexBuffer::IndexType mIndexType; // Immutable
+		IndexType mIndexType; // Immutable
 
 		Map<UINT32, TransientMeshPtr> mMeshes; // Sim thread
 		UINT32 mNextFreeId; // Sim thread

+ 4 - 4
BansheeCore/Include/BsMeshManager.h

@@ -16,16 +16,16 @@ namespace BansheeEngine
 		~MeshManager();
 
 		/**
-		 * @copydoc	Mesh::create(UINT32, UINT32, const VertexDataDescPtr&, MeshBufferType, DrawOperationType, IndexBuffer::IndexType)
+		 * @copydoc	Mesh::create(UINT32, UINT32, const VertexDataDescPtr&, MeshBufferType, DrawOperationType, IndexType)
 		 */
 		MeshPtr create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, MeshBufferType bufferType = MeshBufferType::Static, 
-			DrawOperationType drawOp = DOT_TRIANGLE_LIST, IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
+			DrawOperationType drawOp = DOT_TRIANGLE_LIST, IndexType indexType = IT_32BIT);
 
 		/**
-		 * @copydoc	Mesh::create(UINT32, UINT32, const VertexDataDescPtr&, const Vector<SubMesh>&, MeshBufferType, IndexBuffer::IndexType)
+		 * @copydoc	Mesh::create(UINT32, UINT32, const VertexDataDescPtr&, const Vector<SubMesh>&, MeshBufferType, IndexType)
 		 */
 		MeshPtr create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, const Vector<SubMesh>& subMeshes, 
-			MeshBufferType bufferType = MeshBufferType::Static, IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
+			MeshBufferType bufferType = MeshBufferType::Static, IndexType indexType = IT_32BIT);
 
 		/**
 		 * @copyodc	Mesh::create(const MeshDataPtr&, MeshBufferType, DrawOperationType)

+ 7 - 0
BansheeCore/Include/BsRenderSystem.h

@@ -325,6 +325,13 @@ namespace BansheeEngine
 		 */
 		virtual float getMaximumDepthInputValue() = 0;
 
+		/**
+		 * @brief	Checks if vertex color needs to be flipped before sent to the shader.
+		 *
+		 * @note	Thread safe.
+		 */
+		virtual bool getVertexColorFlipRequired() const { return false; }
+
 		/************************************************************************/
 		/* 							INTERNAL METHODS				        	*/
 		/************************************************************************/

+ 47 - 10
BansheeCore/Include/BsVertexBuffer.h

@@ -8,13 +8,11 @@
 namespace BansheeEngine 
 {
 	/**
-	 * @brief	Specialization of a hardware buffer used for holding vertex data.
+	 * @brief	Contains information about a vertex buffer buffer.
 	 */
-    class BS_CORE_EXPORT VertexBuffer : public HardwareBuffer, public CoreObject
-    {
+	class BS_CORE_EXPORT VertexBufferProperties
+	{
 	public:
-		virtual ~VertexBuffer() { }
-
 		/**
 		 * @brief	Gets the size in bytes of a single vertex in this buffer.
 		 */
@@ -25,11 +23,49 @@ namespace BansheeEngine
 		 */
         UINT32 getNumVertices() const { return mNumVertices; }
 
+	protected:
+		friend class VertexBuffer;
+		friend class VertexBufferCore;
+
+		UINT32 mNumVertices;
+		UINT32 mVertexSize;
+	};
+
+	/**
+	 * @brief	Core thread specific implementation of a vertex buffer.
+	 *
+	 * @see		VertexBuffer
+	 */
+	class BS_CORE_EXPORT VertexBufferCore : public CoreObjectCore, public HardwareBuffer
+	{
+	public:
+		VertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties);
+		virtual ~VertexBufferCore() { }
+
 		/**
-		 * @brief	Some render systems expect vertex color bits in an order different than
-		 * 			RGBA, in which case override this to flip the RGBA order.
+		 * @brief	Returns information about the vertex buffer.
 		 */
-		virtual bool vertexColorReqRGBFlip() { return false; }
+		const VertexBufferProperties& getProperties() const { return mProperties; }
+
+	protected:
+		VertexBufferProperties mProperties;
+	};
+
+	/**
+	 * @brief	Specialization of a hardware buffer used for holding vertex data.
+	 */
+    class BS_CORE_EXPORT VertexBuffer : public CoreObject
+    {
+	public:
+		virtual ~VertexBuffer() { }
+
+		/**
+		 * @brief	Retrieves a core implementation of a vertex buffer
+		 *			usable only from the core thread.
+		 *
+		 * @note	Core thread only.
+		 */
+		VertexBufferCore* getCore() const;
 
 		/**
 		 * @copydoc	HardwareBufferManager::createVertexBuffer
@@ -41,7 +77,8 @@ namespace BansheeEngine
 		VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMemory);
 
 	protected:
-		UINT32 mNumVertices;
-		UINT32 mVertexSize;
+		VertexBufferProperties mProperties;
+		GpuBufferUsage mUsage;
+		bool mUseSystemMemory;
     };
 }

+ 18 - 1
BansheeCore/Source/BsCoreObjectCore.cpp

@@ -1,8 +1,25 @@
 #include "BsCoreObjectCore.h"
+#include "BsCoreThread.h"
 
 namespace BansheeEngine
 {
 	CoreObjectCore::CoreObjectCore()
-		:mCoreDirtyFlags(0xFFFFFFFF)
+		:mCoreDirtyFlags(0xFFFFFFFF), mIsDestroyed(false)
 	{ }
+
+	CoreObjectCore::~CoreObjectCore()
+	{
+		// This should only trigger for objects created directly by core thread.
+		// If you are not sure this will get called by the core thread, make sure 
+		// to destroy() the object manually before it goes out of scope.
+		if (!mIsDestroyed)
+			destroy();
+	}
+
+	void CoreObjectCore::destroy() 
+	{ 
+		throwIfNotCoreThread();
+
+		mIsDestroyed = true;
+	}
 }

+ 8 - 2
BansheeCore/Source/BsCoreObjectManager.cpp

@@ -101,7 +101,10 @@ namespace BansheeEngine
 				const CoreStoredSyncData& syncData = objectData.second;
 				syncData.destinationObj->syncToCore(syncData.syncData);
 
-				mCoreSyncDataAlloc->dealloc(syncData.syncData.getBuffer());
+				UINT8* data = syncData.syncData.getBuffer();
+
+				if (data != nullptr)
+					mCoreSyncDataAlloc->dealloc(data);
 			}
 
 			mCoreSyncData.clear();
@@ -113,7 +116,10 @@ namespace BansheeEngine
 				const SimStoredSyncData& syncData = objectData.second;
 				syncData.destinationObj->syncFromCore(syncData.syncData);
 
-				mSimSyncDataAlloc->dealloc(syncData.syncData.getBuffer());
+				UINT8* data = syncData.syncData.getBuffer();
+
+				if (data != nullptr)
+					mSimSyncDataAlloc->dealloc(data);
 			}
 
 			mSimSyncData.clear();

+ 1 - 1
BansheeCore/Source/BsHardwareBufferManager.cpp

@@ -32,7 +32,7 @@ namespace BansheeEngine
 		return vbuf;
 	}
 
-	IndexBufferPtr HardwareBufferManager::createIndexBuffer(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+	IndexBufferPtr HardwareBufferManager::createIndexBuffer(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
 	{
 		assert (numIndexes > 0);
 

+ 18 - 11
BansheeCore/Source/BsIndexBuffer.cpp

@@ -4,28 +4,35 @@
 
 namespace BansheeEngine 
 {
+	IndexBufferCore::IndexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const IndexBufferProperties& properties)
+		:HardwareBuffer(usage, useSystemMemory), mProperties(properties)
+	{ 
+		mSizeInBytes = mProperties.mIndexSize * mProperties.mNumIndexes;
+	}
+
     IndexBuffer::IndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage, bool useSystemMemory) 
-        : HardwareBuffer(usage, useSystemMemory), mIndexType(idxType), mNumIndexes(numIndexes)
+		:mUsage(usage), mUseSystemMemory(useSystemMemory)
     {
-        switch (mIndexType)
+		mProperties.mIndexType = idxType;
+		mProperties.mNumIndexes = numIndexes;
+
+		switch (mProperties.mIndexType)
         {
         case IT_16BIT:
-            mIndexSize = sizeof(unsigned short);
+			mProperties.mIndexSize = sizeof(unsigned short);
             break;
         case IT_32BIT:
-            mIndexSize = sizeof(unsigned int);
+			mProperties.mIndexSize = sizeof(unsigned int);
             break;
         }
-
-        mSizeInBytes = mIndexSize * mNumIndexes;
     }
 
-    IndexBuffer::~IndexBuffer()
-    {
-
-    }
+	IndexBufferCore* IndexBuffer::getCore() const
+	{
+		return static_cast<IndexBufferCore*>(mCoreSpecific);
+	}
 
-	IndexBufferPtr IndexBuffer::create(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+	IndexBufferPtr IndexBuffer::create(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
 	{
 		return HardwareBufferManager::instance().createIndexBuffer(itype, numIndexes, usage);
 	}

+ 38 - 27
BansheeCore/Source/BsMesh.cpp

@@ -16,7 +16,7 @@
 namespace BansheeEngine
 {
 	Mesh::Mesh(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 
-		MeshBufferType bufferType, DrawOperationType drawOp, IndexBuffer::IndexType indexType)
+		MeshBufferType bufferType, DrawOperationType drawOp, IndexType indexType)
 		:MeshBase(numVertices, numIndices, drawOp), mVertexData(nullptr), mIndexBuffer(nullptr),
 		mVertexDesc(vertexDesc), mBufferType(bufferType), mIndexType(indexType)
 	{
@@ -24,7 +24,7 @@ namespace BansheeEngine
 	}
 
 	Mesh::Mesh(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc,
-		const Vector<SubMesh>& subMeshes, MeshBufferType bufferType, IndexBuffer::IndexType indexType)
+		const Vector<SubMesh>& subMeshes, MeshBufferType bufferType, IndexType indexType)
 		:MeshBase(numVertices, numIndices, subMeshes), mVertexData(nullptr), mIndexBuffer(nullptr),
 		mVertexDesc(vertexDesc), mBufferType(bufferType), mIndexType(indexType)
 	{
@@ -49,7 +49,7 @@ namespace BansheeEngine
 
 	Mesh::Mesh()
 		:MeshBase(0, 0, DOT_TRIANGLE_LIST), mVertexData(nullptr), mIndexBuffer(nullptr), 
-		mBufferType(MeshBufferType::Static), mIndexType(IndexBuffer::IT_32BIT)
+		mBufferType(MeshBufferType::Static), mIndexType(IT_32BIT)
 	{
 
 	}
@@ -92,19 +92,22 @@ namespace BansheeEngine
 		}
 
 		// Indices
+		IndexBufferCore* indexBuffer = mIndexBuffer->getCore();
+		const IndexBufferProperties& ibProps = indexBuffer->getProperties();
+
 		UINT32 indicesSize = meshData.getIndexBufferSize();
 		UINT8* srcIdxData = meshData.getIndexData();
 
-		if (meshData.getIndexElementSize() != mIndexBuffer->getIndexSize())
+		if (meshData.getIndexElementSize() != ibProps.getIndexSize())
 		{
 			BS_EXCEPT(InvalidParametersException, "Provided index size doesn't match meshes index size. Needed: " +
-				toString(mIndexBuffer->getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
+				toString(ibProps.getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
 		}
 
-		if (indicesSize > mIndexBuffer->getSizeInBytes())
+		if (indicesSize > indexBuffer->getSizeInBytes())
 			BS_EXCEPT(InvalidParametersException, "Index buffer values are being written out of valid range.");
 
-		mIndexBuffer->writeData(0, indicesSize, srcIdxData, discardEntireBuffer ? BufferWriteType::Discard : BufferWriteType::Normal);
+		indexBuffer->writeData(0, indicesSize, srcIdxData, discardEntireBuffer ? BufferWriteType::Discard : BufferWriteType::Normal);
 
 		// Vertices
 		for (UINT32 i = 0; i <= mVertexDesc->getMaxStreamIdx(); i++)
@@ -124,7 +127,8 @@ namespace BansheeEngine
 					toString(myVertSize) + ". Got: " + toString(otherVertSize));
 			}
 
-			VertexBufferPtr vertexBuffer = mVertexData->getBuffer(i);
+			VertexBufferCore* vertexBuffer = mVertexData->getBuffer(i)->getCore();
+			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 
 			UINT32 bufferSize = meshData.getStreamSize(i);
 			UINT8* srcVertBufferData = meshData.getStreamData(i);
@@ -132,7 +136,7 @@ namespace BansheeEngine
 			if (bufferSize > vertexBuffer->getSizeInBytes())
 				BS_EXCEPT(InvalidParametersException, "Vertex buffer values for stream \"" + toString(i) + "\" are being written out of valid range.");
 
-			if (vertexBuffer->vertexColorReqRGBFlip())
+			if (RenderSystem::instance().getVertexColorFlipRequired())
 			{
 				UINT8* bufferCopy = (UINT8*)bs_alloc(bufferSize);
 				memcpy(bufferCopy, srcVertBufferData, bufferSize); // TODO Low priority - Attempt to avoid this copy
@@ -172,26 +176,30 @@ namespace BansheeEngine
 		if(data.getTypeId() != TID_MeshData)
 			BS_EXCEPT(InvalidParametersException, "Invalid GpuResourceData type. Only MeshData is supported.");
 
-		IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT;
-		if(mIndexBuffer)
-			indexType = mIndexBuffer->getType();
+		IndexBufferCore* indexBuffer = mIndexBuffer->getCore();
+
+		IndexType indexType = IT_32BIT;
+		if (indexBuffer)
+			indexType = indexBuffer->getProperties().getType();
 
 		MeshData& meshData = static_cast<MeshData&>(data);
 
 		if(mIndexBuffer)
 		{
-			if(meshData.getIndexElementSize() != mIndexBuffer->getIndexSize())
+			const IndexBufferProperties& ibProps = indexBuffer->getProperties();
+
+			if (meshData.getIndexElementSize() != ibProps.getIndexSize())
 			{
 				BS_EXCEPT(InvalidParametersException, "Provided index size doesn't match meshes index size. Needed: " + 
-					toString(mIndexBuffer->getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
+					toString(ibProps.getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
 			}
 
-			UINT8* idxData = static_cast<UINT8*>(mIndexBuffer->lock(GBL_READ_ONLY));
-			UINT32 idxElemSize = mIndexBuffer->getIndexSize();
+			UINT8* idxData = static_cast<UINT8*>(indexBuffer->lock(GBL_READ_ONLY));
+			UINT32 idxElemSize = ibProps.getIndexSize();
 
 			UINT8* indices = nullptr;
 
-			if(indexType == IndexBuffer::IT_16BIT)
+			if(indexType == IT_16BIT)
 				indices = (UINT8*)meshData.getIndices16();
 			else
 				indices = (UINT8*)meshData.getIndices32();
@@ -204,7 +212,7 @@ namespace BansheeEngine
 
 			memcpy(indices, idxData, numIndicesToCopy * idxElemSize);
 
-			mIndexBuffer->unlock();
+			indexBuffer->unlock();
 		}
 
 		if(mVertexData)
@@ -217,6 +225,9 @@ namespace BansheeEngine
 				if(!meshData.getVertexDesc()->hasStream(streamIdx))
 					continue;
 
+				VertexBufferCore* vertexBuffer = iter->second->getCore();
+				const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
+
 				// Ensure both have the same sized vertices
 				UINT32 myVertSize = mVertexDesc->getVertexStride(streamIdx);
 				UINT32 otherVertSize = meshData.getVertexDesc()->getVertexStride(streamIdx);
@@ -227,9 +238,7 @@ namespace BansheeEngine
 				}
 
 				UINT32 numVerticesToCopy = meshData.getNumVertices();
-
-				VertexBufferPtr vertexBuffer = iter->second;
-				UINT32 bufferSize = vertexBuffer->getVertexSize() * numVerticesToCopy;
+				UINT32 bufferSize = vbProps.getVertexSize() * numVerticesToCopy;
 				
 				if(bufferSize > vertexBuffer->getSizeInBytes())
 					BS_EXCEPT(InvalidParametersException, "Vertex buffer values for stream \"" + toString(streamIdx) + "\" are being read out of valid range.");
@@ -248,9 +257,11 @@ namespace BansheeEngine
 
 	MeshDataPtr Mesh::allocateSubresourceBuffer(UINT32 subresourceIdx) const
 	{
-		IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT;
+		IndexBufferCore* indexBuffer = mIndexBuffer->getCore();
+
+		IndexType indexType = IT_32BIT;
 		if(mIndexBuffer)
-			indexType = mIndexBuffer->getType();
+			indexType = indexBuffer->getProperties().getType();
 
 		MeshDataPtr meshData = bs_shared_ptr<MeshData>(mVertexData->vertexCount, mNumIndices, mVertexDesc, indexType);
 
@@ -427,7 +438,7 @@ namespace BansheeEngine
 	/************************************************************************/
 
 	HMesh Mesh::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 
-		MeshBufferType bufferType, DrawOperationType drawOp, IndexBuffer::IndexType indexType)
+		MeshBufferType bufferType, DrawOperationType drawOp, IndexType indexType)
 	{
 		MeshPtr meshPtr = _createPtr(numVertices, numIndices, vertexDesc, bufferType, drawOp, indexType);
 
@@ -435,7 +446,7 @@ namespace BansheeEngine
 	}
 
 	HMesh Mesh::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc,
-		const Vector<SubMesh>& subMeshes, MeshBufferType bufferType, IndexBuffer::IndexType indexType)
+		const Vector<SubMesh>& subMeshes, MeshBufferType bufferType, IndexType indexType)
 	{
 		MeshPtr meshPtr = _createPtr(numVertices, numIndices, vertexDesc, subMeshes, bufferType, indexType);
 
@@ -457,13 +468,13 @@ namespace BansheeEngine
 	}
 
 	MeshPtr Mesh::_createPtr(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 
-		MeshBufferType bufferType, DrawOperationType drawOp, IndexBuffer::IndexType indexType)
+		MeshBufferType bufferType, DrawOperationType drawOp, IndexType indexType)
 	{
 		return MeshManager::instance().create(numVertices, numIndices, vertexDesc, bufferType, drawOp, indexType);
 	}
 
 	MeshPtr Mesh::_createPtr(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc,
-		const Vector<SubMesh>& subMeshes, MeshBufferType bufferType, IndexBuffer::IndexType indexType)
+		const Vector<SubMesh>& subMeshes, MeshBufferType bufferType, IndexType indexType)
 	{
 		return MeshManager::instance().create(numVertices, numIndices, vertexDesc, subMeshes, bufferType, indexType);
 	}

+ 5 - 5
BansheeCore/Source/BsMeshData.cpp

@@ -11,14 +11,14 @@
 
 namespace BansheeEngine
 {
-	MeshData::MeshData(UINT32 numVertices, UINT32 numIndexes, const VertexDataDescPtr& vertexData, IndexBuffer::IndexType indexType)
+	MeshData::MeshData(UINT32 numVertices, UINT32 numIndexes, const VertexDataDescPtr& vertexData, IndexType indexType)
 	   :mNumVertices(numVertices), mNumIndices(numIndexes), mVertexData(vertexData), mIndexType(indexType)
 	{
 		allocateInternalBuffer();
 	}
 
 	MeshData::MeshData()
-		:mNumVertices(0), mNumIndices(0), mIndexType(IndexBuffer::IT_32BIT)
+		:mNumVertices(0), mNumIndices(0), mIndexType(IT_32BIT)
 	{ }
 
 	MeshData::~MeshData()
@@ -31,7 +31,7 @@ namespace BansheeEngine
 
 	UINT16* MeshData::getIndices16() const
 	{
-		if(mIndexType != IndexBuffer::IT_16BIT)
+		if(mIndexType != IT_16BIT)
 			BS_EXCEPT(InternalErrorException, "Attempting to get 16bit index buffer, but internally allocated buffer is 32 bit.");
 
 		UINT32 indexBufferOffset = getIndexBufferOffset();
@@ -41,7 +41,7 @@ namespace BansheeEngine
 
 	UINT32* MeshData::getIndices32() const
 	{
-		if(mIndexType != IndexBuffer::IT_32BIT)
+		if(mIndexType != IT_32BIT)
 			BS_EXCEPT(InternalErrorException, "Attempting to get 32bit index buffer, but internally allocated buffer is 16 bit.");
 
 		UINT32 indexBufferOffset = getIndexBufferOffset();
@@ -289,7 +289,7 @@ namespace BansheeEngine
 
 	UINT32 MeshData::getIndexElementSize() const
 	{
-		return mIndexType == IndexBuffer::IT_32BIT ? sizeof(UINT32) : sizeof(UINT16);
+		return mIndexType == IT_32BIT ? sizeof(UINT32) : sizeof(UINT16);
 	}
 
 	UINT32 MeshData::getElementOffset(VertexElementSemantic semantic, UINT32 semanticIdx, UINT32 streamIdx) const

+ 16 - 9
BansheeCore/Source/BsMeshHeap.cpp

@@ -13,7 +13,7 @@ namespace BansheeEngine
 	const float MeshHeap::GrowPercent = 1.5f;
 
 	MeshHeap::MeshHeap(UINT32 numVertices, UINT32 numIndices, 
-		const VertexDataDescPtr& vertexDesc, IndexBuffer::IndexType indexType)
+		const VertexDataDescPtr& vertexDesc, IndexType indexType)
 		:mNumVertices(numVertices), mNumIndices(numIndices), mNextFreeId(0), 
 		mIndexType(indexType), mVertexDesc(vertexDesc), mCPUIndexData(nullptr),
 		mNextQueryId(0)
@@ -30,7 +30,7 @@ namespace BansheeEngine
 	}
 
 	MeshHeapPtr MeshHeap::create(UINT32 numVertices, UINT32 numIndices, 
-		const VertexDataDescPtr& vertexDesc, IndexBuffer::IndexType indexType)
+		const VertexDataDescPtr& vertexDesc, IndexType indexType)
 	{
 		MeshHeap* meshHeap = new (bs_alloc<MeshHeap>()) MeshHeap(numVertices, numIndices, vertexDesc, indexType); 
 		MeshHeapPtr meshHeapPtr = bs_core_ptr<MeshHeap, GenAlloc>(meshHeap);
@@ -270,12 +270,13 @@ namespace BansheeEngine
 					toString(vertSize) + ". Got: " + toString(otherVertSize));
 			}
 
-			VertexBufferPtr vertexBuffer = mVertexData->getBuffer(i);
+			VertexBufferCore* vertexBuffer = mVertexData->getBuffer(i)->getCore();
+			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 
 			UINT8* vertDest = mCPUVertexData[i] + vertChunkStart * vertSize;
 			memcpy(vertDest, meshData->getStreamData(i), meshData->getNumVertices() * vertSize);
 
-			if(vertexBuffer->vertexColorReqRGBFlip())
+			if (RenderSystem::instance().getVertexColorFlipRequired())
 			{
 				UINT32 vertexStride = mVertexDesc->getVertexStride(i);
 				for(INT32 semanticIdx = 0; semanticIdx < VertexBuffer::MAX_SEMANTIC_IDX; semanticIdx++)
@@ -298,7 +299,10 @@ namespace BansheeEngine
 			vertexBuffer->writeData(vertChunkStart * vertSize, meshData->getNumVertices() * vertSize, vertDest, BufferWriteType::NoOverwrite);
 		}
 
-		UINT32 idxSize = mIndexBuffer->getIndexSize();
+		IndexBufferCore* indexBuffer = mIndexBuffer->getCore();
+		const IndexBufferProperties& ibProps = indexBuffer->getProperties();
+
+		UINT32 idxSize = ibProps.getIndexSize();
 
 		// Ensure index sizes match
 		if(meshData->getIndexElementSize() != idxSize)
@@ -309,7 +313,7 @@ namespace BansheeEngine
 
 		UINT8* idxDest = mCPUIndexData + idxChunkStart * idxSize;
 		memcpy(idxDest, meshData->getIndexData(), meshData->getNumIndices() * idxSize);
-		mIndexBuffer->writeData(idxChunkStart * idxSize, meshData->getNumIndices() * idxSize, idxDest, BufferWriteType::NoOverwrite);
+		indexBuffer->writeData(idxChunkStart * idxSize, meshData->getNumIndices() * idxSize, idxDest, BufferWriteType::NoOverwrite);
 	}
 
 	void MeshHeap::deallocInternal(TransientMeshPtr mesh)
@@ -352,6 +356,7 @@ namespace BansheeEngine
 			VertexBufferPtr vertexBuffer = HardwareBufferManager::instance().createVertexBuffer(
 				vertSize, mVertexData->vertexCount, GBU_DYNAMIC);
 
+			VertexBufferCore* vertexBufferCore = vertexBuffer->getCore();
 			mVertexData->setBuffer(i, vertexBuffer);
 
 			// Copy all data to the new buffer
@@ -375,7 +380,7 @@ namespace BansheeEngine
 			}
 
 			if(destOffset > 0)
-				vertexBuffer->writeData(0, destOffset * vertSize, buffer, BufferWriteType::NoOverwrite);
+				vertexBufferCore->writeData(0, destOffset * vertSize, buffer, BufferWriteType::NoOverwrite);
 
 			mCPUVertexData[i] = buffer;
 		}
@@ -422,9 +427,11 @@ namespace BansheeEngine
 		mNumIndices = numIndices;
 
 		mIndexBuffer = HardwareBufferManager::instance().createIndexBuffer(mIndexType, mNumIndices, GBU_DYNAMIC);
+		IndexBufferCore* indexBuffer = mIndexBuffer->getCore();
+		const IndexBufferProperties& ibProps = indexBuffer->getProperties();
 
 		// Copy all data to the new buffer
-		UINT32 idxSize = mIndexBuffer->getIndexSize();
+		UINT32 idxSize = ibProps.getIndexSize();
 
 		UINT8* oldBuffer = mCPUIndexData;
 		UINT8* buffer = (UINT8*)bs_alloc(idxSize * numIndices);
@@ -446,7 +453,7 @@ namespace BansheeEngine
 		}
 
 		if(destOffset > 0)
-			mIndexBuffer->writeData(0, destOffset * idxSize, buffer, BufferWriteType::NoOverwrite);
+			indexBuffer->writeData(0, destOffset * idxSize, buffer, BufferWriteType::NoOverwrite);
 
 		mCPUIndexData = buffer;
 

+ 2 - 2
BansheeCore/Source/BsMeshManager.cpp

@@ -18,7 +18,7 @@ namespace BansheeEngine
 	}
 
 	MeshPtr MeshManager::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 
-		MeshBufferType bufferType, DrawOperationType drawOp, IndexBuffer::IndexType indexType)
+		MeshBufferType bufferType, DrawOperationType drawOp, IndexType indexType)
 	{
 		MeshPtr mesh = bs_core_ptr<Mesh, PoolAlloc>(new (bs_alloc<Mesh, PoolAlloc>()) 
 			Mesh(numVertices, numIndices, vertexDesc, bufferType, drawOp, indexType));
@@ -29,7 +29,7 @@ namespace BansheeEngine
 	}
 
 	MeshPtr MeshManager::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 
-		const Vector<SubMesh>& subMeshes, MeshBufferType bufferType, IndexBuffer::IndexType indexType)
+		const Vector<SubMesh>& subMeshes, MeshBufferType bufferType, IndexType indexType)
 	{
 		MeshPtr mesh = bs_core_ptr<Mesh, PoolAlloc>(new (bs_alloc<Mesh, PoolAlloc>())
 			Mesh(numVertices, numIndices, vertexDesc, subMeshes, bufferType, indexType));

+ 2 - 2
BansheeCore/Source/BsMeshRTTI.h

@@ -14,8 +14,8 @@ namespace BansheeEngine
 		VertexDataDescPtr getVertexDesc(Mesh* obj) { return obj->mVertexDesc; }
 		void setVertexDesc(Mesh* obj, VertexDataDescPtr value) { obj->mVertexDesc = value; }
 
-		IndexBuffer::IndexType& getIndexType(Mesh* obj) { return obj->mIndexType; }
-		void setIndexType(Mesh* obj, IndexBuffer::IndexType& value) { obj->mIndexType = value; }
+		IndexType& getIndexType(Mesh* obj) { return obj->mIndexType; }
+		void setIndexType(Mesh* obj, IndexType& value) { obj->mIndexType = value; }
 
 		UINT32& getBufferType(Mesh* obj) { return (UINT32&)obj->mBufferType; }
 		void setBufferType(Mesh* obj, UINT32& value) { obj->mBufferType = (MeshBufferType)value; }

+ 4 - 3
BansheeCore/Source/BsRenderSystem.cpp

@@ -249,12 +249,13 @@ namespace BansheeEngine
 
 		if (useIndices)
 		{
-			IndexBufferPtr indexBuffer = mesh->_getIndexBuffer();
+			IndexBufferCore* indexBuffer = mesh->_getIndexBuffer()->getCore();
+			const IndexBufferProperties& ibProps = indexBuffer->getProperties();
 
 			if(indexCount == 0)
-				indexCount = indexBuffer->getNumIndices();
+				indexCount = ibProps.getNumIndices();
 
-			setIndexBuffer(indexBuffer);
+			setIndexBuffer(mesh->_getIndexBuffer());
 			drawIndexed(indexOffset + mesh->_getIndexOffset(), indexCount, mesh->_getVertexOffset(), vertexData->vertexCount);
 		}
 		else

+ 15 - 3
BansheeCore/Source/BsVertexBuffer.cpp

@@ -7,12 +7,24 @@
 
 namespace BansheeEngine 
 {
-    VertexBuffer::VertexBuffer(UINT32 vertexSize,  UINT32 numVertices, GpuBufferUsage usage, bool useSystemMemory) 
-        : HardwareBuffer(usage, useSystemMemory), mNumVertices(numVertices), mVertexSize(vertexSize)
+	VertexBufferCore::VertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties)
+		:HardwareBuffer(usage, useSystemMemory), mProperties(properties)
+	{
+		mSizeInBytes = mProperties.mVertexSize * mProperties.mNumVertices;
+	}
+
+    VertexBuffer::VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMemory) 
+		: mUseSystemMemory(useSystemMemory), mUsage(usage)
     {
-        mSizeInBytes = mVertexSize * numVertices;
+		mProperties.mVertexSize = vertexSize;
+		mProperties.mNumVertices = numVertices;
     }
 
+	VertexBufferCore* VertexBuffer::getCore() const
+	{
+		return static_cast<VertexBufferCore*>(mCoreSpecific);
+	}
+
 	VertexBufferPtr VertexBuffer::create(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 	{
 		return HardwareBufferManager::instance().createVertexBuffer(vertexSize, numVerts, usage, streamOut);

+ 1 - 1
BansheeD3D11RenderSystem/Include/BsD3D11HardwareBufferManager.h

@@ -23,7 +23,7 @@ namespace BansheeEngine
 		/**
 		 * @copydoc HardwareBufferManager::createIndexBufferImpl
 		 */
-		IndexBufferPtr createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+		IndexBufferPtr createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 		/** 
 		 * @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl 

+ 39 - 19
BansheeD3D11RenderSystem/Include/BsD3D11IndexBuffer.h

@@ -9,23 +9,26 @@ namespace BansheeEngine
 	/**
 	 * @brief	DirectX 11 implementation of an index buffer.
 	 */
-	class BS_D3D11_EXPORT D3D11IndexBuffer : public IndexBuffer
+	class BS_D3D11_EXPORT D3D11IndexBufferCore : public IndexBufferCore
 	{
 	public:
-		~D3D11IndexBuffer();
+		D3D11IndexBufferCore(D3D11Device& device, GpuBufferUsage usage, bool useSystemMemory,
+			const IndexBufferProperties& properties);
+
+		~D3D11IndexBufferCore() { }
 
 		/**
-		 * @copydoc HardwareBuffer::readData
+		 * @copydoc IndexBufferCore::readData
 		 */
 		void readData(UINT32 offset, UINT32 length, void* pDest);
 
 		/**
-		 * @copydoc HardwareBuffer::writeData
+		 * @copydoc IndexBufferCore::writeData
 		 */
 		void writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal);
 
 		/**
-		 * @copydoc HardwareBuffer::copyData
+		 * @copydoc IndexBufferCore::copyData
 		 */
 		void copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 
@@ -35,35 +38,52 @@ namespace BansheeEngine
 		ID3D11Buffer* getD3DIndexBuffer() const { return mBuffer->getD3DBuffer(); }		
 
 	protected:
-		friend class D3D11HardwareBufferManager;
-
-		/**
-		 * @copydoc	IndexBuffer::IndexBuffer.
-		 */
-		D3D11IndexBuffer(D3D11Device& device, IndexType idxType, UINT32 numIndexes, 
-			GpuBufferUsage usage, bool useSystemMem);
-
 		/**
-		 * @copydoc HardwareBuffer::lockImpl
+		 * @copydoc IndexBufferCore::lockImpl
 		 */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 
 		/**
-		 * @copydoc HardwareBuffer::unlockImpl
+		 * @copydoc IndexBufferCore::unlockImpl
 		 */
 		void unlockImpl(void);
 
 		/**
-		 * @copydoc IndexBuffer::initialize_internal()
+		 * @copydoc IndexBufferCore::initialize
 		 */
-		void initialize_internal();	
+		void initialize();	
 		
 		/**
-		 * @copydoc IndexBuffer::destroy_internal()
+		 * @copydoc IndexBufferCore::destroy
 		 */
-		void destroy_internal();
+		void destroy();
 
 		D3D11HardwareBuffer* mBuffer;
 		D3D11Device& mDevice;
 	};
+
+	/**
+	 * @brief	DirectX 11 implementation of an index buffer.
+	 */
+	class BS_D3D11_EXPORT D3D11IndexBuffer : public IndexBuffer
+	{
+	public:
+		~D3D11IndexBuffer() { }
+
+	protected:
+		friend class D3D11HardwareBufferManager;
+
+		/**
+		 * @copydoc	IndexBuffer::IndexBuffer.
+		 */
+		D3D11IndexBuffer(D3D11Device& device, IndexType idxType, UINT32 numIndexes, 
+			GpuBufferUsage usage, bool useSystemMem);
+
+		/**
+		 * @copydoc	CoreObject::createCore
+		 */
+		virtual CoreObjectCore* createCore() const;
+
+		D3D11Device& mDevice;
+	};
 }

+ 40 - 17
BansheeD3D11RenderSystem/Include/BsD3D11VertexBuffer.h

@@ -9,23 +9,26 @@ namespace BansheeEngine
 	/**
 	 * @brief	DirectX 11 implementation of a vertex buffer.
 	 */
-	class BS_D3D11_EXPORT D3D11VertexBuffer : public VertexBuffer
+	class BS_D3D11_EXPORT D3D11VertexBufferCore : public VertexBufferCore
 	{
 	public:
-		~D3D11VertexBuffer();
+		D3D11VertexBufferCore(D3D11Device& device, bool streamOut, GpuBufferUsage usage, 
+			bool useSystemMemory, const VertexBufferProperties& properties);
+
+		~D3D11VertexBufferCore() { }
 
 		/**
-		 * @copydoc HardwareBuffer::readData
+		 * @copydoc VertexBufferCore::readData
 		 */
 		void readData(UINT32 offset, UINT32 length, void* pDest);
 
 		/**
-		 * @copydoc HardwareBuffer::writeData
+		 * @copydoc VertexBufferCore::writeData
 		 */
 		void writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal);
 
 		/**
-		 * @copydoc HardwareBuffer::copyData
+		 * @copydoc VertexBufferCore::copyData
 		 */
 		void copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 
@@ -38,33 +41,53 @@ namespace BansheeEngine
 		friend class D3D11HardwareBufferManager;
 
 		/**
-		 * @copydoc	VertexBuffer::VertexBuffer
-		 */
-		D3D11VertexBuffer(D3D11Device& device, UINT32 vertexSize, UINT32 numVertices, 
-			GpuBufferUsage usage, bool useSystemMem, bool streamOut);
-
-		/**
-		* @copydoc HardwareBuffer::lockImpl
+		* @copydoc VertexBufferCore::lockImpl
 		 */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 
 		/**
-		 * @copydoc HardwareBuffer::unlockImpl
+		 * @copydoc VertexBufferCore::unlockImpl
 		 */
 		void unlockImpl(void);
 
 		/**
-		 * @copydoc VertexBuffer::initialize_internal()
+		 * @copydoc VertexBufferCore::initialize
 		 */
-		void initialize_internal();	
+		void initialize();	
 		
 		/**
-		 * @copydoc VertexBuffer::destroy_internal()
+		 * @copydoc VertexBufferCore::destroy
 		 */
-		void destroy_internal();
+		void destroy();
 
 		D3D11HardwareBuffer* mBuffer;
+		D3D11Device& mDevice;
 		bool mStreamOut;
+	};
+
+	/**
+	 * @brief	DirectX 11 implementation of a vertex buffer.
+	 */
+	class BS_D3D11_EXPORT D3D11VertexBuffer : public VertexBuffer
+	{
+	public:
+		~D3D11VertexBuffer() { }
+
+	protected: 
+		friend class D3D11HardwareBufferManager;
+
+		/**
+		 * @copydoc	VertexBuffer::VertexBuffer
+		 */
+		D3D11VertexBuffer(D3D11Device& device, UINT32 vertexSize, UINT32 numVertices, 
+			GpuBufferUsage usage, bool useSystemMem, bool streamOut);
+
+		/**
+		 * @copydoc	CoreObject::createCore
+		 */
+		virtual CoreObjectCore* createCore() const;
+
 		D3D11Device& mDevice;
+		bool mStreamOut;
 	};
 }

+ 1 - 1
BansheeD3D11RenderSystem/Source/BsD3D11HardwareBufferManager.cpp

@@ -24,7 +24,7 @@ namespace BansheeEngine
 		return bs_core_ptr<D3D11VertexBuffer, PoolAlloc>(buffer);
 	}
 
-	IndexBufferPtr D3D11HardwareBufferManager::createIndexBufferImpl(IndexBuffer::IndexType itype, 
+	IndexBufferPtr D3D11HardwareBufferManager::createIndexBufferImpl(IndexType itype, 
 		UINT32 numIndexes, GpuBufferUsage usage)
 	{
 		D3D11IndexBuffer* buffer = new (bs_alloc<D3D11IndexBuffer, PoolAlloc>()) D3D11IndexBuffer(mDevice, itype, numIndexes, usage, false);

+ 24 - 17
BansheeD3D11RenderSystem/Source/BsD3D11IndexBuffer.cpp

@@ -4,37 +4,32 @@
 
 namespace BansheeEngine
 {
-	D3D11IndexBuffer::D3D11IndexBuffer(D3D11Device& device, IndexType idxType, UINT32 numIndexes, 
-		GpuBufferUsage usage, bool useSystemMem)
-		:IndexBuffer(idxType, numIndexes, usage, useSystemMem), mDevice(device), mBuffer(nullptr)
+	D3D11IndexBufferCore::D3D11IndexBufferCore(D3D11Device& device, GpuBufferUsage usage, bool useSystemMemory, 
+		const IndexBufferProperties& properties)
+		:IndexBufferCore(usage, useSystemMemory, properties), mDevice(device), mBuffer(nullptr)
 	{
 
 	}
 
-	D3D11IndexBuffer::~D3D11IndexBuffer()
-	{
-		
-	}
-
-	void D3D11IndexBuffer::initialize_internal()
+	void D3D11IndexBufferCore::initialize()
 	{
 		mBuffer = bs_new<D3D11HardwareBuffer, PoolAlloc>(D3D11HardwareBuffer::BT_INDEX, mUsage, 1, mSizeInBytes, std::ref(mDevice), mSystemMemory);
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_IndexBuffer);
-		IndexBuffer::initialize_internal();
+		IndexBufferCore::initialize();
 	}
 
-	void D3D11IndexBuffer::destroy_internal()
+	void D3D11IndexBufferCore::destroy()
 	{
 		if(mBuffer != nullptr)
 			bs_delete<PoolAlloc>(mBuffer) ;
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_IndexBuffer);
 
-		IndexBuffer::destroy_internal();
+		IndexBufferCore::destroy();
 	}
 
-	void* D3D11IndexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
+	void* D3D11IndexBufferCore::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
 #if BS_PROFILING_ENABLED
 		if (options == GBL_READ_ONLY || options == GBL_READ_WRITE)
@@ -51,28 +46,40 @@ namespace BansheeEngine
 		return mBuffer->lock(offset, length, options);
 	}
 
-	void D3D11IndexBuffer::unlockImpl()
+	void D3D11IndexBufferCore::unlockImpl()
 	{
 		mBuffer->unlock();
 	}
 
-	void D3D11IndexBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
+	void D3D11IndexBufferCore::readData(UINT32 offset, UINT32 length, void* pDest)
 	{
 		mBuffer->readData(offset, length, pDest);
 
 		BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_IndexBuffer);
 	}
 
-	void D3D11IndexBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
+	void D3D11IndexBufferCore::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
 	{
 		mBuffer->writeData(offset, length, pSource, writeFlags);
 
 		BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_IndexBuffer);
 	}
 
-	void D3D11IndexBuffer::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, 
+	void D3D11IndexBufferCore::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset,
 		UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
 	{
 		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 	}
+
+	D3D11IndexBuffer::D3D11IndexBuffer(D3D11Device& device, IndexType idxType, UINT32 numIndexes,
+		GpuBufferUsage usage, bool useSystemMem)
+		:IndexBuffer(idxType, numIndexes, usage, useSystemMem), mDevice(device)
+	{
+
+	}
+
+	CoreObjectCore* D3D11IndexBuffer::createCore() const
+	{
+		return bs_new<D3D11IndexBufferCore>(mDevice, mUsage, mUseSystemMemory, mProperties);
+	}
 }

+ 8 - 6
BansheeD3D11RenderSystem/Source/BsD3D11RenderSystem.cpp

@@ -408,10 +408,12 @@ namespace BansheeEngine
 
 		for(UINT32 i = 0; i < numBuffers; i++)
 		{
-			D3D11VertexBuffer* vertexBuffer = static_cast<D3D11VertexBuffer*>(buffers[i].get());
+			D3D11VertexBufferCore* vertexBuffer = static_cast<D3D11VertexBufferCore*>(buffers[i]->getCore());
+			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
+
 			dx11buffers[i] = vertexBuffer->getD3DVertexBuffer();
 
-			strides[i] = buffers[i]->getVertexSize();
+			strides[i] = vbProps.getVertexSize();
 			offsets[i] = 0;
 		}
 
@@ -424,15 +426,15 @@ namespace BansheeEngine
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		D3D11IndexBuffer* indexBuffer = static_cast<D3D11IndexBuffer*>(buffer.get());
+		D3D11IndexBufferCore* indexBuffer = static_cast<D3D11IndexBufferCore*>(buffer->getCore());
 
 		DXGI_FORMAT indexFormat = DXGI_FORMAT_R16_UINT;
-		if(indexBuffer->getType() == IndexBuffer::IT_16BIT)
+		if(indexBuffer->getProperties().getType() == IT_16BIT)
 			indexFormat = DXGI_FORMAT_R16_UINT;
-		else if(indexBuffer->getType() == IndexBuffer::IT_32BIT)
+		else if (indexBuffer->getProperties().getType() == IT_32BIT)
 			indexFormat = DXGI_FORMAT_R32_UINT;
 		else
-			BS_EXCEPT(InternalErrorException, "Unsupported index format: " + toString(indexBuffer->getType()));
+			BS_EXCEPT(InternalErrorException, "Unsupported index format: " + toString(indexBuffer->getProperties().getType()));
 
 		mDevice->getImmediateContext()->IASetIndexBuffer(indexBuffer->getD3DIndexBuffer(), indexFormat, 0);
 

+ 22 - 15
BansheeD3D11RenderSystem/Source/BsD3D11VertexBuffer.cpp

@@ -4,15 +4,12 @@
 
 namespace BansheeEngine
 {
-	D3D11VertexBuffer::D3D11VertexBuffer(D3D11Device& device, UINT32 vertexSize, UINT32 numVertices, 
-		GpuBufferUsage usage, bool useSystemMem, bool streamOut)
-		:VertexBuffer(vertexSize, numVertices, usage, useSystemMem), mDevice(device), mStreamOut(streamOut)
-	{ }
-
-	D3D11VertexBuffer::~D3D11VertexBuffer()
+	D3D11VertexBufferCore::D3D11VertexBufferCore(D3D11Device& device, bool streamOut, GpuBufferUsage usage,
+		bool useSystemMemory, const VertexBufferProperties& properties)
+		:VertexBufferCore(usage, useSystemMemory, properties), mDevice(device), mStreamOut(streamOut), mBuffer(nullptr)
 	{ }
 
-	void* D3D11VertexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
+	void* D3D11VertexBufferCore::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
 #if BS_PROFILING_ENABLED
 		if (options == GBL_READ_ONLY || options == GBL_READ_WRITE)
@@ -29,44 +26,54 @@ namespace BansheeEngine
 		return mBuffer->lock(offset, length, options);
 	}
 
-	void D3D11VertexBuffer::unlockImpl()
+	void D3D11VertexBufferCore::unlockImpl()
 	{
 		mBuffer->unlock();
 	}
 
-	void D3D11VertexBuffer::readData(UINT32 offset, UINT32 length, void* dest)
+	void D3D11VertexBufferCore::readData(UINT32 offset, UINT32 length, void* dest)
 	{
 		mBuffer->readData(offset, length, dest);
 		BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_VertexBuffer);
 	}
 
-	void D3D11VertexBuffer::writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags)
+	void D3D11VertexBufferCore::writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags)
 	{
 		mBuffer->writeData(offset, length, source, writeFlags);
 		BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_VertexBuffer);
 	}
 
-	void D3D11VertexBuffer::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, 
+	void D3D11VertexBufferCore::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset,
 		UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
 	{
 		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 	}
 
-	void D3D11VertexBuffer::initialize_internal()
+	void D3D11VertexBufferCore::initialize()
 	{
 		mBuffer = bs_new<D3D11HardwareBuffer, PoolAlloc>(D3D11HardwareBuffer::BT_VERTEX, 
 			mUsage, 1, mSizeInBytes, std::ref(mDevice), mSystemMemory, mStreamOut);
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_VertexBuffer);
-		VertexBuffer::initialize_internal();
+		VertexBufferCore::initialize();
 	}
 
-	void D3D11VertexBuffer::destroy_internal()
+	void D3D11VertexBufferCore::destroy()
 	{
 		if(mBuffer != nullptr)
 			bs_delete<PoolAlloc>(mBuffer);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_VertexBuffer);
-		VertexBuffer::destroy_internal();
+		VertexBufferCore::destroy();
+	}
+
+	D3D11VertexBuffer::D3D11VertexBuffer(D3D11Device& device, UINT32 vertexSize, UINT32 numVertices,
+		GpuBufferUsage usage, bool useSystemMem, bool streamOut)
+		:VertexBuffer(vertexSize, numVertices, usage, useSystemMem), mDevice(device), mStreamOut(streamOut)
+	{ }
+
+	CoreObjectCore* D3D11VertexBuffer::createCore() const
+	{
+		return bs_new<D3D11VertexBufferCore>(mDevice, mStreamOut, mUsage, mUseSystemMemory, mProperties);
 	}
 }

+ 1 - 1
BansheeD3D9RenderSystem/Include/BsD3D9HardwareBufferManager.h

@@ -28,7 +28,7 @@ namespace BansheeEngine
 		/**
 		 * @copydoc HardwareBufferManager::createIndexBufferImpl
 		 */
-		IndexBufferPtr createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+		IndexBufferPtr createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 		/** @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl */
 		GpuParamBlockBufferPtr createGpuParamBlockBufferImpl();

+ 30 - 14
BansheeD3D9RenderSystem/Include/BsD3D9IndexBuffer.h

@@ -9,7 +9,7 @@ namespace BansheeEngine
 	/**
 	 * @brief	DirectX 9 implementation of an index buffer.
 	 */
-    class BS_D3D9_EXPORT D3D9IndexBuffer : public IndexBuffer, public D3D9Resource
+    class BS_D3D9_EXPORT D3D9IndexBufferCore : public IndexBufferCore, public D3D9Resource
     {
 	protected:
 		/**
@@ -25,15 +25,16 @@ namespace BansheeEngine
 		};
 
     public:
-        ~D3D9IndexBuffer();
+		D3D9IndexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const IndexBufferProperties& properties);
+		~D3D9IndexBufferCore() { }
 
 		/**
-		 * @copydoc	IndexBuffer::readData
+		 * @copydoc	IndexBufferCore::readData
 		 */
         void readData(UINT32 offset, UINT32 length, void* dest);
 
 		/**
-		 * @copydoc	IndexBuffer::writeData
+		 * @copydoc	IndexBufferCore::writeData
 		 */
 		void writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags = BufferWriteType::Normal);
 
@@ -68,17 +69,13 @@ namespace BansheeEngine
         IDirect3DIndexBuffer9* getD3DIndexBuffer();		
 
 	protected:
-		friend class D3D9HardwareBufferManager;
-
-		D3D9IndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage, bool useSystemMem);
-		
 		/**
-		 * @copydoc	IndexBuffer::lockImpl
+		 * @copydoc	IndexBufferCore::lockImpl
 		 */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 
 		/**
-		 * @copydoc	IndexBuffer::unlockImpl
+		 * @copydoc	IndexBufferCore::unlockImpl
 		 */
 		void unlockImpl();
 
@@ -88,18 +85,37 @@ namespace BansheeEngine
 		bool updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources);
 
 		/**
-		 * @copydoc IndexBuffer::initialize_internal
+		 * @copydoc IndexBufferCore::initialize
 		 */
-		void initialize_internal();	
+		void initialize();	
 		
 		/**
-		 * @copydoc IndexBuffer::destroy_internal
+		 * @copydoc IndexBufferCore::destroy
 		 */
-		void destroy_internal();
+		void destroy();
 
 	protected:		
 		Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
 		D3DINDEXBUFFER_DESC	mBufferDesc;	
 		UINT8* mSystemMemoryBuffer;
     };
+
+	/**
+	 * @brief	DirectX 9 implementation of an index buffer.
+	 */
+    class BS_D3D9_EXPORT D3D9IndexBuffer : public IndexBuffer
+    {
+    public:
+		~D3D9IndexBuffer() { }
+
+	protected:
+		friend class D3D9HardwareBufferManager;
+
+		D3D9IndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage, bool useSystemMem);
+
+		/**
+		 * @copydoc	CoreObject::createCore
+		 */
+		virtual CoreObjectCore* createCore() const;
+    };
 }

+ 1 - 1
BansheeD3D9RenderSystem/Include/BsD3D9Mappings.h

@@ -91,7 +91,7 @@ namespace BansheeEngine
 		/**
 		 * @brief	Returns DirectX 9 index buffer type.
 		 */
-        static D3DFORMAT get(IndexBuffer::IndexType itype);
+        static D3DFORMAT get(IndexType itype);
 		
 		/**
 		 * @brief	Returns DirectX 9 vertex element type.

+ 5 - 0
BansheeD3D9RenderSystem/Include/BsD3D9RenderSystem.h

@@ -171,6 +171,11 @@ namespace BansheeEngine
 		 */
 		VertexElementType getColorVertexElementType() const;
 
+		/**
+		 * @copydoc	RenderSystem::getColorVertexElementType
+		 */
+		bool getVertexColorFlipRequired() const { return true; }
+
 		/************************************************************************/
 		/* 				Internal use by DX9 RenderSystem only                   */
 		/************************************************************************/

+ 30 - 19
BansheeD3D9RenderSystem/Include/BsD3D9VertexBuffer.h

@@ -9,7 +9,7 @@ namespace BansheeEngine
 	/**
 	 * @brief	DirectX 9 implementation of a vertex buffer.
 	 */
-    class BS_D3D9_EXPORT D3D9VertexBuffer : public VertexBuffer, public D3D9Resource
+    class BS_D3D9_EXPORT D3D9VertexBufferCore : public VertexBufferCore, public D3D9Resource
     {   
 	protected:
 		/**
@@ -25,15 +25,16 @@ namespace BansheeEngine
 		};
 
     public:
-        ~D3D9VertexBuffer();
+		D3D9VertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties);
+		~D3D9VertexBufferCore() { }
 
 		/**
-		 * @copydoc	VertexBuffer::readData
+		 * @copydoc	VertexBufferCore::readData
 		 */
         void readData(UINT32 offset, UINT32 length, void* dest);
 
 		/**
-		 * @copydoc	VertexBuffer::writeData
+		 * @copydoc	VertexBufferCore::writeData
 		 */
         void writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags = BufferWriteType::Normal);
 	
@@ -67,33 +68,24 @@ namespace BansheeEngine
 		 */
         IDirect3DVertexBuffer9* getD3D9VertexBuffer();
 
-		/**
-		 * @copydoc	VertexBuffer::vertexColorReqRGBFlip
-		 */
-		virtual bool vertexColorReqRGBFlip() { return true; }
-
 	protected:	
-		friend class D3D9HardwareBufferManager;
-
-		D3D9VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMem);
-	
 		/**
-		 * @copydoc VertexBuffer::initialize_internal
+		 * @copydoc VertexBufferCore::initialize
 		 */
-		void initialize_internal();	
+		void initialize();	
 		
 		/**
-		 * @copydoc VertexBuffer::destroy_internal
+		 * @copydoc VertexBufferCore::destroy
 		 */
-		void destroy_internal();
+		void destroy();
 
 		/**
-		 * @copydoc	VertexBuffer::lockImpl
+		 * @copydoc	VertexBufferCore::lockImpl
 		 */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 
 		/**
-		 * @copydoc	VertexBuffer::unlockImpl
+		 * @copydoc	VertexBufferCore::unlockImpl
 		 */
 		void unlockImpl();
 
@@ -107,4 +99,23 @@ namespace BansheeEngine
 		D3DVERTEXBUFFER_DESC mBufferDesc;	
 		UINT8* mSystemMemoryBuffer;
     };
+
+/**
+	 * @brief	DirectX 9 implementation of a vertex buffer.
+	 */
+    class BS_D3D9_EXPORT D3D9VertexBuffer : public VertexBuffer
+    {   
+    public:
+		~D3D9VertexBuffer() { }
+
+	protected:	
+		friend class D3D9HardwareBufferManager;
+
+		D3D9VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMem);
+
+		/**
+		 * @copydoc	CoreObject::createCore
+		 */
+		virtual CoreObjectCore* createCore() const;
+    };
 }

+ 1 - 1
BansheeD3D9RenderSystem/Source/BsD3D9HardwareBufferManager.cpp

@@ -24,7 +24,7 @@ namespace BansheeEngine
 		return bs_core_ptr<D3D9VertexBuffer, PoolAlloc>(buffer);
     }
 
-	IndexBufferPtr D3D9HardwareBufferManager::createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+	IndexBufferPtr D3D9HardwareBufferManager::createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
     {
 		assert (numIndexes > 0);
 

+ 28 - 22
BansheeD3D9RenderSystem/Source/BsD3D9IndexBuffer.cpp

@@ -9,14 +9,11 @@
 
 namespace BansheeEngine 
 {
-    D3D9IndexBuffer::D3D9IndexBuffer(IndexBuffer::IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage, bool useSystemMemory)
-        : IndexBuffer(idxType, numIndexes, usage, useSystemMemory)
-    { }
+	D3D9IndexBufferCore::D3D9IndexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const IndexBufferProperties& properties)
+		: IndexBufferCore(usage, useSystemMemory, properties), mSystemMemoryBuffer(nullptr)
+	{ }
 
-    D3D9IndexBuffer::~D3D9IndexBuffer()
-    { }
-
-	void D3D9IndexBuffer::initialize_internal()
+	void D3D9IndexBufferCore::initialize()
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
 
@@ -39,10 +36,10 @@ namespace BansheeEngine
 		}	
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_IndexBuffer);
-		IndexBuffer::initialize_internal();
+		IndexBufferCore::initialize();
 	}
 
-	void D3D9IndexBuffer::destroy_internal()
+	void D3D9IndexBufferCore::destroy()
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
 
@@ -62,10 +59,10 @@ namespace BansheeEngine
 			bs_free(mSystemMemoryBuffer);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_IndexBuffer);
-		IndexBuffer::destroy_internal();
+		IndexBufferCore::destroy();
 	}
 
-    void* D3D9IndexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
+	void* D3D9IndexBufferCore::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
     {		
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -111,7 +108,7 @@ namespace BansheeEngine
 		return mSystemMemoryBuffer + offset;		
     }
 
-	void D3D9IndexBuffer::unlockImpl()
+	void D3D9IndexBufferCore::unlockImpl()
     {	
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -124,14 +121,14 @@ namespace BansheeEngine
 		}			
     }
 
-    void D3D9IndexBuffer::readData(UINT32 offset, UINT32 length, void* dest)
+	void D3D9IndexBufferCore::readData(UINT32 offset, UINT32 length, void* dest)
     {
         void* pSrc = this->lock(offset, length, GBL_READ_ONLY);
         memcpy(dest, pSrc, length);
         this->unlock();
     }
 
-    void D3D9IndexBuffer::writeData(UINT32 offset, UINT32 length,  const void* source, BufferWriteType writeFlags)
+	void D3D9IndexBufferCore::writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags)
     {
 		GpuLockOptions lockOption = GBL_WRITE_ONLY;
 		if(writeFlags == BufferWriteType::Discard)
@@ -144,7 +141,7 @@ namespace BansheeEngine
         this->unlock();    
 	}
 
-	void D3D9IndexBuffer::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
+	void D3D9IndexBufferCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
 	{			
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -153,7 +150,7 @@ namespace BansheeEngine
 
 	}
 
-	void D3D9IndexBuffer::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
+	void D3D9IndexBufferCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
 	{		
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -169,7 +166,7 @@ namespace BansheeEngine
 		}
 	}
 
-	void D3D9IndexBuffer::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
+	void D3D9IndexBufferCore::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
 	{		
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -183,7 +180,7 @@ namespace BansheeEngine
 		}
 	}
 
-	void D3D9IndexBuffer::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
+	void D3D9IndexBufferCore::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
 	{		
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -194,7 +191,7 @@ namespace BansheeEngine
 		}
 	}
 
-	void D3D9IndexBuffer::createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL pool)
+	void D3D9IndexBufferCore::createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL pool)
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -224,7 +221,7 @@ namespace BansheeEngine
 		hr = d3d9Device->CreateIndexBuffer(
 			static_cast<UINT>(mSizeInBytes),
 			D3D9Mappings::get(mUsage),
-			D3D9Mappings::get(mIndexType),
+			D3D9Mappings::get(mProperties.getType()),
 			pool,
 			&bufferResources->mBuffer,
 			nullptr
@@ -244,7 +241,7 @@ namespace BansheeEngine
 		}		
 	}
 
-	IDirect3DIndexBuffer9* D3D9IndexBuffer::getD3DIndexBuffer()
+	IDirect3DIndexBuffer9* D3D9IndexBufferCore::getD3DIndexBuffer()
 	{		
 		IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getActiveD3D9Device();
 
@@ -264,7 +261,7 @@ namespace BansheeEngine
 		return iterFind->second->mBuffer;
 	}
 
-	bool D3D9IndexBuffer::updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources)
+	bool D3D9IndexBufferCore::updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources)
 	{
 		assert(bufferResources != nullptr);
 		assert(bufferResources->mBuffer != nullptr);
@@ -306,4 +303,13 @@ namespace BansheeEngine
 
 		return true;			
 	}
+
+	D3D9IndexBuffer::D3D9IndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage, bool useSystemMemory)
+		: IndexBuffer(idxType, numIndexes, usage, useSystemMemory)
+	{ }
+
+	CoreObjectCore* D3D9IndexBuffer::createCore() const
+	{
+		return bs_new<D3D9IndexBufferCore>(mUsage, mUseSystemMemory, mProperties);
+	}
 }

+ 2 - 2
BansheeD3D9RenderSystem/Source/BsD3D9Mappings.cpp

@@ -315,9 +315,9 @@ namespace BansheeEngine
         return ret;
     }
 
-    D3DFORMAT D3D9Mappings::get(IndexBuffer::IndexType itype)
+    D3DFORMAT D3D9Mappings::get(IndexType itype)
     {
-        if (itype == IndexBuffer::IT_32BIT)
+        if (itype == IT_32BIT)
         {
             return D3DFMT_INDEX32;
         }

+ 4 - 3
BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp

@@ -1178,13 +1178,14 @@ namespace BansheeEngine
 		{
 			if(buffers[i] != nullptr)
 			{
-				D3D9VertexBuffer* d3d9buf = static_cast<D3D9VertexBuffer*>(buffers[i].get());
+				D3D9VertexBufferCore* d3d9buf = static_cast<D3D9VertexBufferCore*>(buffers[i]->getCore());
+				const VertexBufferProperties& vbProps = d3d9buf->getProperties();
 
 				hr = getActiveD3D9Device()->SetStreamSource(
 					static_cast<UINT>(index + i),
 					d3d9buf->getD3D9VertexBuffer(),
 					0,
-					static_cast<UINT>(d3d9buf->getVertexSize()) // stride
+					static_cast<UINT>(vbProps.getVertexSize()) // stride
 					);
 			}
 			else
@@ -1203,7 +1204,7 @@ namespace BansheeEngine
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		D3D9IndexBuffer* d3dIdxBuf = static_cast<D3D9IndexBuffer*>(buffer.get());
+		D3D9IndexBufferCore* d3dIdxBuf = static_cast<D3D9IndexBufferCore*>(buffer->getCore());
 
 		HRESULT hr = getActiveD3D9Device()->SetIndices( d3dIdxBuf->getD3DIndexBuffer() );
 		if (FAILED(hr))

+ 26 - 20
BansheeD3D9RenderSystem/Source/BsD3D9VertexBuffer.cpp

@@ -9,14 +9,11 @@
 
 namespace BansheeEngine 
 {
-    D3D9VertexBuffer::D3D9VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMemory)
-		: VertexBuffer(vertexSize, numVertices, usage, useSystemMemory)
-    { }
-
-    D3D9VertexBuffer::~D3D9VertexBuffer()
+	D3D9VertexBufferCore::D3D9VertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties)
+		: VertexBufferCore(usage, useSystemMemory, properties), mSystemMemoryBuffer(nullptr)
     { }
 
-	void D3D9VertexBuffer::initialize_internal()
+	void D3D9VertexBufferCore::initialize()
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
 
@@ -39,10 +36,10 @@ namespace BansheeEngine
 		}
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_VertexBuffer);
-		VertexBuffer::initialize_internal();
+		VertexBufferCore::initialize();
 	}
 
-	void D3D9VertexBuffer::destroy_internal()
+	void D3D9VertexBufferCore::destroy()
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
 
@@ -62,10 +59,10 @@ namespace BansheeEngine
 			bs_free(mSystemMemoryBuffer);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_VertexBuffer);
-		VertexBuffer::destroy_internal();
+		VertexBufferCore::destroy();
 	}
 
-    void* D3D9VertexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
+	void* D3D9VertexBufferCore::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
     {		
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -111,7 +108,7 @@ namespace BansheeEngine
 		return mSystemMemoryBuffer + offset;		
     }
 
-	void D3D9VertexBuffer::unlockImpl()
+	void D3D9VertexBufferCore::unlockImpl()
     {
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -124,14 +121,14 @@ namespace BansheeEngine
 		}
     }
 
-    void D3D9VertexBuffer::readData(UINT32 offset, UINT32 length, void* dest)
+	void D3D9VertexBufferCore::readData(UINT32 offset, UINT32 length, void* dest)
     {
         void* pSrc = this->lock(offset, length, GBL_READ_ONLY);
         memcpy(dest, pSrc, length);
         this->unlock();
     }
 
-	void D3D9VertexBuffer::writeData(UINT32 offset, UINT32 length, const void* source, 
+	void D3D9VertexBufferCore::writeData(UINT32 offset, UINT32 length, const void* source,
 		BufferWriteType writeFlags)
 	{
 		GpuLockOptions lockOption = GBL_WRITE_ONLY;
@@ -145,7 +142,7 @@ namespace BansheeEngine
 		this->unlock();
 	}
 
-	void D3D9VertexBuffer::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
+	void D3D9VertexBufferCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
 	{			
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -153,7 +150,7 @@ namespace BansheeEngine
 			createBuffer(d3d9Device, mBufferDesc.Pool);
 	}
 
-	void D3D9VertexBuffer::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
+	void D3D9VertexBufferCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
 	{	
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -170,7 +167,7 @@ namespace BansheeEngine
 		}	
 	}
 
-	void D3D9VertexBuffer::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
+	void D3D9VertexBufferCore::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
 	{	
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -185,7 +182,7 @@ namespace BansheeEngine
 		}
 	}
 
-	void D3D9VertexBuffer::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
+	void D3D9VertexBufferCore::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
 	{		
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -193,7 +190,7 @@ namespace BansheeEngine
 			createBuffer(d3d9Device, mBufferDesc.Pool);
 	}
 
-	void D3D9VertexBuffer::createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool)
+	void D3D9VertexBufferCore::createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool)
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
@@ -242,7 +239,7 @@ namespace BansheeEngine
 		}		
 	}
 
-	IDirect3DVertexBuffer9* D3D9VertexBuffer::getD3D9VertexBuffer()
+	IDirect3DVertexBuffer9* D3D9VertexBufferCore::getD3D9VertexBuffer()
 	{
 		IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getActiveD3D9Device();
 		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
@@ -260,7 +257,7 @@ namespace BansheeEngine
 		return iterFind->second->mBuffer;
 	}	
 
-	bool D3D9VertexBuffer::updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources)
+	bool D3D9VertexBufferCore::updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources)
 	{		
 		assert(bufferResources != nullptr);
 		assert(bufferResources->mBuffer != nullptr);
@@ -302,4 +299,13 @@ namespace BansheeEngine
 
 		return true;		
 	}
+
+	D3D9VertexBuffer::D3D9VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMemory)
+		: VertexBuffer(vertexSize, numVertices, usage, useSystemMemory)
+	{ }
+
+	CoreObjectCore* D3D9VertexBuffer::createCore() const
+	{
+		return bs_new<D3D9VertexBufferCore>(mUsage, mUseSystemMemory, mProperties);
+	}
 }

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

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

+ 1 - 1
BansheeGLRenderSystem/Include/BsGLHardwareBufferManager.h

@@ -32,7 +32,7 @@ namespace BansheeEngine
 		 * @copydoc HardwareBufferManager::createIndexBufferImpl
 		 */
         IndexBufferPtr createIndexBufferImpl(
-            IndexBuffer::IndexType itype, UINT32 numIndexes, 
+            IndexType itype, UINT32 numIndexes, 
             GpuBufferUsage usage);
 
 		/** @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl */

+ 30 - 15
BansheeGLRenderSystem/Include/BsGLIndexBuffer.h

@@ -8,18 +8,19 @@ namespace BansheeEngine
 	/**
 	 * @brief	OpenGL implementation of an index buffer.
 	 */
-    class BS_RSGL_EXPORT GLIndexBuffer : public IndexBuffer
+    class BS_RSGL_EXPORT GLIndexBufferCore : public IndexBufferCore
     {
     public:
-        ~GLIndexBuffer();
+		GLIndexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const IndexBufferProperties& properties);
+		~GLIndexBufferCore() { }
 
 		/**
-		 * @copydoc IndexBuffer::readData
+		 * @copydoc IndexBufferCore::readData
 		 */
         void readData(UINT32 offset, UINT32 length, void* pDest);
 
 		/**
-		 * @copydoc IndexBuffer::writeData
+		 * @copydoc IndexBufferCore::writeData
 		 */
         void writeData(UINT32 offset, UINT32 length, const void* pSource, 
 			BufferWriteType writeFlags = BufferWriteType::Normal);
@@ -30,28 +31,23 @@ namespace BansheeEngine
         GLuint getGLBufferId() const { return mBufferId; }
 
 	protected:
-		friend class GLHardwareBufferManager;
-
-		GLIndexBuffer(IndexType idxType, UINT32 numIndexes, 
-			GpuBufferUsage usage); 
-
 		/**
-		 * @copydoc IndexBuffer::initialize_internal
+		 * @copydoc IndexBufferCore::initialize
 		 */
-		void initialize_internal();	
+		void initialize();	
 		
 		/**
-		 * @copydoc IndexBuffer::destroy_internal
+		 * @copydoc IndexBufferCore::destroy
 		 */
-		void destroy_internal();
+		void destroy();
 
 		/**
-		 * @copydoc IndexBuffer::lockImpl
+		 * @copydoc IndexBufferCore::lockImpl
 		 */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 
 		/**
-		 * @copydoc IndexBuffer::unlockImpl
+		 * @copydoc IndexBufferCore::unlockImpl
 		 */
 		void unlockImpl();
 
@@ -59,4 +55,23 @@ namespace BansheeEngine
 		GLuint mBufferId;
 		bool mZeroLocked;
     };
+
+	/**
+	 * @brief	OpenGL implementation of an index buffer.
+	 */
+    class BS_RSGL_EXPORT GLIndexBuffer : public IndexBuffer
+    {
+    public:
+		~GLIndexBuffer() { }
+
+	protected:
+		friend class GLHardwareBufferManager;
+
+		GLIndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage); 
+
+		/**
+		 * @copydoc	CoreObject::createCore
+		 */
+		virtual CoreObjectCore* createCore() const;
+    };
 }

+ 30 - 14
BansheeGLRenderSystem/Include/BsGLVertexBuffer.h

@@ -9,18 +9,19 @@ namespace BansheeEngine
 	/**
 	 * @brief	OpenGL implementation of a vertex buffer.
 	 */
-    class BS_RSGL_EXPORT GLVertexBuffer : public VertexBuffer 
+    class BS_RSGL_EXPORT GLVertexBufferCore : public VertexBufferCore
     {
     public:
-        ~GLVertexBuffer();
+		GLVertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties);
+		~GLVertexBufferCore() { }
 
 		/**
-		 * @copydoc	HardwareBuffer::readData
+		 * @copydoc	VertexBufferCore::readData
 		 */
         void readData(UINT32 offset, UINT32 length, void* pDest);
 
 		/**
-		* @copydoc	HardwareBuffer::writeData
+		* @copydoc	VertexBufferCore::writeData
 		*/
         void writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal);
 
@@ -40,27 +41,23 @@ namespace BansheeEngine
 		void unregisterVAO(const GLVertexArrayObject& vao);
 
 	protected:
-		friend class GLHardwareBufferManager;
-
-		GLVertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage); 
-
 		/**
-		 * @copydoc VertexBuffer::initialize_internal()
+		 * @copydoc VertexBufferCore::initialize
 		 */
-		void initialize_internal();
+		void initialize();
 
 		/**
-		 * @copydoc VertexBuffer::destroy_internal()
+		 * @copydoc VertexBufferCore::destroy
 		 */
-		void destroy_internal();
+		void destroy();
 
 		/**
-		 * @copydoc	HardwareBuffer::lockImpl()
+		 * @copydoc	VertexBufferCore::lockImpl
 		 */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 
 		/**
-		 * @copydoc	HardwareBuffer::unlockImpl()
+		 * @copydoc	VertexBufferCore::unlockImpl
 		 */
 		void unlockImpl();
 
@@ -70,4 +67,23 @@ namespace BansheeEngine
 
 		Vector<GLVertexArrayObject> mVAObjects;
     };
+
+	/**
+	 * @brief	OpenGL implementation of a vertex buffer.
+	 */
+    class BS_RSGL_EXPORT GLVertexBuffer : public VertexBuffer 
+    {
+    public:
+		~GLVertexBuffer() { }
+
+	protected:
+		friend class GLHardwareBufferManager;
+
+		GLVertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage); 
+
+		/**
+		 * @copydoc	CoreObject::createCore
+		 */
+		virtual CoreObjectCore* createCore() const;
+    };
 }

+ 1 - 1
BansheeGLRenderSystem/Source/BsGLHardwareBufferManager.cpp

@@ -15,7 +15,7 @@ namespace BansheeEngine
 		return bs_core_ptr<GLVertexBuffer, PoolAlloc>(new (bs_alloc<GLVertexBuffer, PoolAlloc>()) GLVertexBuffer(vertexSize, numVerts, usage));
     }
 
-    IndexBufferPtr GLHardwareBufferManager::createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+    IndexBufferPtr GLHardwareBufferManager::createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
     {
 		return bs_core_ptr<GLIndexBuffer, PoolAlloc>(new (bs_alloc<GLIndexBuffer, PoolAlloc>()) GLIndexBuffer(itype, numIndexes, usage));
     }

+ 21 - 16
BansheeGLRenderSystem/Source/BsGLIndexBuffer.cpp

@@ -5,21 +5,17 @@
 
 namespace BansheeEngine 
 {
-    GLIndexBuffer::GLIndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage)
-		: IndexBuffer(idxType, numIndexes, usage, false), mZeroLocked(false)
-    {  }
+	GLIndexBufferCore::GLIndexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const IndexBufferProperties& properties)
+		:IndexBufferCore(usage, useSystemMemory, properties), mZeroLocked(false)
+	{  }
 
-    GLIndexBuffer::~GLIndexBuffer()
-    {    }
-
-	void GLIndexBuffer::initialize_internal()
+	void GLIndexBufferCore::initialize()
 	{
 		glGenBuffers(1, &mBufferId );
 
 		if (!mBufferId)
 		{
-			BS_EXCEPT(InternalErrorException, 
-				"Cannot create GL index buffer");
+			BS_EXCEPT(InternalErrorException, "Cannot create GL index buffer");
 		}
 
 		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBufferId);
@@ -28,18 +24,18 @@ namespace BansheeEngine
 			GLHardwareBufferManager::getGLUsage(mUsage));
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_IndexBuffer);
-		IndexBuffer::initialize_internal();
+		IndexBufferCore::initialize();
 	}
 
-	void GLIndexBuffer::destroy_internal()
+	void GLIndexBufferCore::destroy()
 	{
 		glDeleteBuffers(1, &mBufferId);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_IndexBuffer);
-		IndexBuffer::destroy_internal();
+		IndexBufferCore::destroy();
 	}
 
-    void* GLIndexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
+	void* GLIndexBufferCore::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
     {
         GLenum access = 0;
         if(mIsLocked)
@@ -98,7 +94,7 @@ namespace BansheeEngine
 		return retPtr;
     }
 
-	void GLIndexBuffer::unlockImpl()
+	void GLIndexBufferCore::unlockImpl()
     {
 		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBufferId);
 
@@ -113,7 +109,7 @@ namespace BansheeEngine
 		mIsLocked = false;
     }
 
-    void GLIndexBuffer::readData(UINT32 offset, UINT32 length, 
+	void GLIndexBufferCore::readData(UINT32 offset, UINT32 length,
         void* pDest)
     {
 		void* bufferData = lock(offset, length, GBL_READ_ONLY);
@@ -121,7 +117,7 @@ namespace BansheeEngine
 		unlock();
     }
 
-    void GLIndexBuffer::writeData(UINT32 offset, UINT32 length, 
+    void GLIndexBufferCore::writeData(UINT32 offset, UINT32 length, 
 		const void* pSource, BufferWriteType writeFlags)
     {
 		GpuLockOptions lockOption = GBL_WRITE_ONLY;
@@ -134,4 +130,13 @@ namespace BansheeEngine
 		memcpy(bufferData, pSource, length);
 		unlock();
     }
+
+	GLIndexBuffer::GLIndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage)
+		:IndexBuffer(idxType, numIndexes, usage, false)
+	{  }
+
+	CoreObjectCore* GLIndexBuffer::createCore() const
+	{
+		return bs_new<GLIndexBufferCore>(mUsage, mUseSystemMemory, mProperties);
+	}
 }

+ 6 - 4
BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp

@@ -705,11 +705,13 @@ namespace BansheeEngine
 		GLint primType = getGLDrawMode();
 
 		beginDraw();
-		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 
-			static_cast<GLIndexBuffer*>(mBoundIndexBuffer.get())->getGLBufferId());
 
-		GLenum indexType = (mBoundIndexBuffer->getType() == IndexBuffer::IT_16BIT) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
-		glDrawElementsBaseVertex(primType, indexCount, indexType, (GLvoid*)(mBoundIndexBuffer->getIndexSize() * startIndex), vertexOffset);
+		GLIndexBufferCore* indexBuffer = static_cast<GLIndexBufferCore*>(mBoundIndexBuffer->getCore());
+		const IndexBufferProperties& ibProps = indexBuffer->getProperties();
+		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer->getGLBufferId());
+
+		GLenum indexType = (ibProps.getType() == IT_16BIT) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
+		glDrawElementsBaseVertex(primType, indexCount, indexType, (GLvoid*)(ibProps.getIndexSize() * startIndex), vertexOffset);
 
 		endDraw();
 		UINT32 primCount = vertexCountToPrimCount(mCurrentDrawOperation, vertexCount);

+ 9 - 4
BansheeGLRenderSystem/Source/BsGLVertexArrayObjectManager.cpp

@@ -154,7 +154,9 @@ namespace BansheeEngine
 
 			// TODO - We might also want to check the size of input and buffer, and make sure they match? Or does OpenGL handle that internally?
 
-			GLVertexBuffer* vertexBuffer = usedBuffers[seqIdx];
+			GLVertexBufferCore* vertexBuffer = static_cast<GLVertexBufferCore*>(usedBuffers[seqIdx]->getCore());
+			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
+
 			glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer->getGLBufferId());
 			void* bufferData = VBO_BUFFER_OFFSET(elem.getOffset());
 
@@ -172,7 +174,7 @@ namespace BansheeEngine
 
 			UINT16 typeCount = VertexElement::getTypeCount(elem.getType());
 			GLenum glType = GLHardwareBufferManager::getGLType(elem.getType());
-			GLsizei vertexSize = static_cast<GLsizei>(vertexBuffer->getVertexSize());
+			GLsizei vertexSize = static_cast<GLsizei>(vbProps.getVertexSize());
 			glVertexAttribPointer(attribLocation, typeCount, glType, normalized,
 				vertexSize, bufferData);
 
@@ -183,7 +185,9 @@ namespace BansheeEngine
 		for (UINT32 i = 0; i < numUsedBuffers; i++)
 		{
 			wantedVAO.mAttachedBuffers[i] = usedBuffers[i];
-			wantedVAO.mAttachedBuffers[i]->registerVAO(wantedVAO);
+
+			GLVertexBufferCore* curVertexBuffer = static_cast<GLVertexBufferCore*>(usedBuffers[i]->getCore());
+			curVertexBuffer->registerVAO(wantedVAO);
 		}
 
 		stackDeallocLast(usedBuffers);
@@ -202,7 +206,8 @@ namespace BansheeEngine
 
 		for (UINT32 i = 0; i < vao.mNumBuffers; i++)
 		{
-			vao.mAttachedBuffers[i]->unregisterVAO(vao);
+			GLVertexBufferCore* curVertexBuffer = static_cast<GLVertexBufferCore*>(vao.mAttachedBuffers[i]->getCore());
+			curVertexBuffer->unregisterVAO(vao);
 		}
 
 		glDeleteVertexArrays(1, &vao.mHandle);

+ 22 - 16
BansheeGLRenderSystem/Source/BsGLVertexBuffer.cpp

@@ -6,17 +6,13 @@
 
 namespace BansheeEngine 
 {
-    GLVertexBuffer::GLVertexBuffer(UINT32 vertexSize, 
-        UINT32 numVertices, GpuBufferUsage usage)
-		: VertexBuffer(vertexSize, numVertices, usage, false), mZeroLocked(false)
+	GLVertexBufferCore::GLVertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties)
+		:VertexBufferCore(usage, useSystemMemory, properties), mZeroLocked(false)
     {
-    }
 
-    GLVertexBuffer::~GLVertexBuffer()
-    {
     }
 
-	void GLVertexBuffer::initialize_internal()
+	void GLVertexBufferCore::initialize()
 	{
 		glGenBuffers(1, &mBufferId);
 
@@ -32,10 +28,10 @@ namespace BansheeEngine
 			GLHardwareBufferManager::getGLUsage(mUsage));
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_VertexBuffer);
-		VertexBuffer::initialize_internal();
+		VertexBufferCore::initialize();
 	}
 
-	void GLVertexBuffer::destroy_internal()
+	void GLVertexBufferCore::destroy()
 	{
 		glDeleteBuffers(1, &mBufferId);
 
@@ -43,15 +39,15 @@ namespace BansheeEngine
 			GLVertexArrayObjectManager::instance().notifyBufferDestroyed(mVAObjects[0]);
 
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_VertexBuffer);
-		VertexBuffer::destroy_internal();
+		VertexBufferCore::destroy();
 	}
 
-	void GLVertexBuffer::registerVAO(const GLVertexArrayObject& vao)
+	void GLVertexBufferCore::registerVAO(const GLVertexArrayObject& vao)
 	{
 		mVAObjects.push_back(vao);
 	}
 
-	void GLVertexBuffer::unregisterVAO(const GLVertexArrayObject& vao)
+	void GLVertexBufferCore::unregisterVAO(const GLVertexArrayObject& vao)
 	{
 		auto iterFind = std::find(mVAObjects.begin(), mVAObjects.end(), vao);
 
@@ -59,7 +55,7 @@ namespace BansheeEngine
 			mVAObjects.erase(iterFind);
 	}
 
-    void* GLVertexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
+	void* GLVertexBufferCore::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
     {
         GLenum access = 0;
 
@@ -119,7 +115,7 @@ namespace BansheeEngine
 		return retPtr;
     }
 
-	void GLVertexBuffer::unlockImpl()
+	void GLVertexBufferCore::unlockImpl()
     {
 		glBindBuffer(GL_ARRAY_BUFFER, mBufferId);
 
@@ -134,14 +130,14 @@ namespace BansheeEngine
         mIsLocked = false;
     }
 
-    void GLVertexBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
+	void GLVertexBufferCore::readData(UINT32 offset, UINT32 length, void* pDest)
     {
 		void* bufferData = lock(offset, length, GBL_READ_ONLY);
 		memcpy(pDest, bufferData, length);
 		unlock();
     }
 
-    void GLVertexBuffer::writeData(UINT32 offset, UINT32 length, 
+	void GLVertexBufferCore::writeData(UINT32 offset, UINT32 length,
 		const void* pSource, BufferWriteType writeFlags)
     {
 		GpuLockOptions lockOption = GBL_WRITE_ONLY;
@@ -154,4 +150,14 @@ namespace BansheeEngine
 		memcpy(bufferData, pSource, length);
 		unlock();
     }
+
+	GLVertexBuffer::GLVertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage)
+		: VertexBuffer(vertexSize, numVertices, usage, false)
+	{
+	}
+
+	CoreObjectCore* GLVertexBuffer::createCore() const
+	{
+		return bs_new<GLVertexBufferCore>(mUsage, mUseSystemMemory, mProperties);
+	}
 }

+ 33 - 2
TODO.txt

@@ -1,7 +1,38 @@
 --------- ALL LONG TERM TASKS / FIXES BELONG TO GOOGLE DOCS: ImplementationTODO OR PossibleImprovements ----------
 
-Write documentation for the new CoreObject refactor
-
+TODO - CoreObject refactor:
+IndexBuffer
+VertexBuffer
+Resource
+ - RasterizerState
+ - DepthStencilState
+ - BlendState
+ - GpuProgInclude
+ - SamplerState
+ - Font
+ - Texture
+ - Mesh
+ - GpuProgram
+ - Material
+ - Shader
+ - SpriteTexture
+ - ManagedResource
+MeshHeap
+TextureView
+VertexDeclaration
+GpuBuffer
+GpuParamBlockBuffer
+
+Go through stuff that doesn't require syncing first, e.g. IndexBuffer
+  - Rename IndexBuffer to IndexBufferCore, and make it inheir from CoreObjectCore
+  - Add a new class IndexBuffer and use that on sim thread (if it's even used on sim thread)
+  - IndexBuffer should then only need to create an IndexBufferCore and needs no other functionality
+  - Potentially I'll want to move common immutable data (buffer size, type, etc.) into IndexBufferProperties, similar to RenderTarget
+    and have it accessible from both IndexBuffer and IndexBufferCore. This saves me from having to duplicate all methods on both types.
+
+Possibly also disallow CoreObject creation from core thread. Instead force them to create CoreObjectCore versions.
+
+-----------------
 
 
 Refactor GizmoManager and HandleManager so they accept a CameraHandler