Explorar el Código

Ensured that core thread uses only core versions of Index and Vertex buffer

Marko Pintera hace 11 años
padre
commit
234d75d39d
Se han modificado 52 ficheros con 404 adiciones y 535 borrados
  1. 4 4
      BansheeCore/Include/BsCoreObjectCore.h
  2. 5 0
      BansheeCore/Include/BsCorePrerequisites.h
  3. 9 3
      BansheeCore/Include/BsCoreThreadAccessor.h
  4. 33 11
      BansheeCore/Include/BsHardwareBufferManager.h
  5. 11 3
      BansheeCore/Include/BsIndexBuffer.h
  6. 3 3
      BansheeCore/Include/BsMesh.h
  7. 2 2
      BansheeCore/Include/BsMeshBase.h
  8. 4 4
      BansheeCore/Include/BsMeshHeap.h
  9. 2 15
      BansheeCore/Include/BsRenderSystem.h
  10. 2 2
      BansheeCore/Include/BsTransientMesh.h
  11. 12 3
      BansheeCore/Include/BsVertexBuffer.h
  12. 4 4
      BansheeCore/Include/BsVertexData.h
  13. 27 5
      BansheeCore/Source/BsCoreThreadAccessor.cpp
  14. 21 2
      BansheeCore/Source/BsHardwareBufferManager.cpp
  15. 24 16
      BansheeCore/Source/BsIndexBuffer.cpp
  16. 26 19
      BansheeCore/Source/BsMesh.cpp
  17. 22 13
      BansheeCore/Source/BsMeshHeap.cpp
  18. 0 61
      BansheeCore/Source/BsRenderSystem.cpp
  19. 2 2
      BansheeCore/Source/BsRenderer.cpp
  20. 2 2
      BansheeCore/Source/BsTransientMesh.cpp
  21. 17 6
      BansheeCore/Source/BsVertexBuffer.cpp
  22. 2 2
      BansheeCore/Source/BsVertexData.cpp
  23. 22 11
      BansheeD3D11RenderSystem/Include/BsD3D11HardwareBufferManager.h
  24. 2 28
      BansheeD3D11RenderSystem/Include/BsD3D11IndexBuffer.h
  25. 2 2
      BansheeD3D11RenderSystem/Include/BsD3D11RenderSystem.h
  26. 2 28
      BansheeD3D11RenderSystem/Include/BsD3D11VertexBuffer.h
  27. 17 21
      BansheeD3D11RenderSystem/Source/BsD3D11HardwareBufferManager.cpp
  28. 2 15
      BansheeD3D11RenderSystem/Source/BsD3D11IndexBuffer.cpp
  29. 7 5
      BansheeD3D11RenderSystem/Source/BsD3D11RenderSystem.cpp
  30. 2 13
      BansheeD3D11RenderSystem/Source/BsD3D11VertexBuffer.cpp
  31. 17 14
      BansheeD3D9RenderSystem/Include/BsD3D9HardwareBufferManager.h
  32. 1 20
      BansheeD3D9RenderSystem/Include/BsD3D9IndexBuffer.h
  33. 2 2
      BansheeD3D9RenderSystem/Include/BsD3D9RenderSystem.h
  34. 1 20
      BansheeD3D9RenderSystem/Include/BsD3D9VertexBuffer.h
  35. 14 24
      BansheeD3D9RenderSystem/Source/BsD3D9HardwareBufferManager.cpp
  36. 2 11
      BansheeD3D9RenderSystem/Source/BsD3D9IndexBuffer.cpp
  37. 6 4
      BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp
  38. 2 11
      BansheeD3D9RenderSystem/Source/BsD3D9VertexBuffer.cpp
  39. 2 2
      BansheeEditor/Source/BsGizmoManager.cpp
  40. 1 1
      BansheeEditorExec/BsEditorExec.cpp
  41. 0 2
      BansheeEngine/Source/BsCameraHandler.cpp
  42. 20 15
      BansheeGLRenderSystem/Include/BsGLHardwareBufferManager.h
  43. 1 20
      BansheeGLRenderSystem/Include/BsGLIndexBuffer.h
  44. 1 0
      BansheeGLRenderSystem/Include/BsGLPrerequisites.h
  45. 4 4
      BansheeGLRenderSystem/Include/BsGLRenderSystem.h
  46. 3 3
      BansheeGLRenderSystem/Include/BsGLVertexArrayObjectManager.h
  47. 1 20
      BansheeGLRenderSystem/Include/BsGLVertexBuffer.h
  48. 12 13
      BansheeGLRenderSystem/Source/BsGLHardwareBufferManager.cpp
  49. 3 12
      BansheeGLRenderSystem/Source/BsGLIndexBuffer.cpp
  50. 5 3
      BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp
  51. 13 16
      BansheeGLRenderSystem/Source/BsGLVertexArrayObjectManager.cpp
  52. 3 13
      BansheeGLRenderSystem/Source/BsGLVertexBuffer.cpp

+ 4 - 4
BansheeCore/Include/BsCoreObjectCore.h

@@ -20,10 +20,6 @@ namespace BansheeEngine
 		CoreObjectCore();
 		CoreObjectCore();
 		virtual ~CoreObjectCore();
 		virtual ~CoreObjectCore();
 
 
-	protected:
-		friend class CoreObjectManager;
-		friend class CoreObject;
-
 		/**
 		/**
 		 * @brief	Called on the core thread when the object is first created.
 		 * @brief	Called on the core thread when the object is first created.
 		 */
 		 */
@@ -34,6 +30,10 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual void destroy();
 		virtual void destroy();
 
 
+	protected:
+		friend class CoreObjectManager;
+		friend class CoreObject;
+
 		/**
 		/**
 		 * @brief	Copy internal dirty data to a memory buffer that will be used
 		 * @brief	Copy internal dirty data to a memory buffer that will be used
 		 *			for updating sim thread version of that data.
 		 *			for updating sim thread version of that data.

+ 5 - 0
BansheeCore/Include/BsCorePrerequisites.h

@@ -63,8 +63,10 @@ namespace BansheeEngine
     class GpuProgram;
     class GpuProgram;
     class GpuProgramManager;
     class GpuProgramManager;
     class IndexBuffer;
     class IndexBuffer;
+	class IndexBufferCore;
     class OcclusionQuery;
     class OcclusionQuery;
     class VertexBuffer;
     class VertexBuffer;
+	class VertexBufferCore;
 	class PixelBuffer;
 	class PixelBuffer;
 	class GpuBuffer;
 	class GpuBuffer;
 	class HighLevelGpuProgram;
 	class HighLevelGpuProgram;
@@ -78,8 +80,11 @@ namespace BansheeEngine
     class RenderSystem;
     class RenderSystem;
     class RenderSystemCapabilities;
     class RenderSystemCapabilities;
     class RenderTarget;
     class RenderTarget;
+	class RenderTargetCore;
     class RenderTexture;
     class RenderTexture;
+	class RenderTextureCore;
 	class MultiRenderTexture;
 	class MultiRenderTexture;
+	class MultiRenderTextureCore;
     class RenderWindow;
     class RenderWindow;
 	class RenderWindowCore;
 	class RenderWindowCore;
 	class RenderTargetProperties;
 	class RenderTargetProperties;

+ 9 - 3
BansheeCore/Include/BsCoreThreadAccessor.h

@@ -42,6 +42,15 @@ namespace BansheeEngine
 		/** @copydoc RenderSystem::setRasterizerState() */
 		/** @copydoc RenderSystem::setRasterizerState() */
 		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
 		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
 
 
+		/** @copydoc RenderSystem::setVertexBuffers() */
+		void setVertexBuffers(UINT32 index, const Vector<VertexBufferPtr>& buffers);
+
+		/** @copydoc RenderSystem::setIndexBuffer() */
+		void setIndexBuffer(const IndexBufferPtr& buffer);
+
+		/** @copydoc RenderSystem::setVertexDeclaration() */
+		void setVertexDeclaration(const VertexDeclarationPtr& vertexDeclaration);
+
 		/** @copydoc RenderSystem::setViewport() */
 		/** @copydoc RenderSystem::setViewport() */
 		void setViewport(Viewport vp);
 		void setViewport(Viewport vp);
 
 
@@ -87,9 +96,6 @@ namespace BansheeEngine
 		/** @copydoc RenderSystem::swapBuffers() */
 		/** @copydoc RenderSystem::swapBuffers() */
 		void swapBuffers(RenderTargetPtr target);
 		void swapBuffers(RenderTargetPtr target);
 
 
-		/** @copydoc RenderSystem::render() */
-		void render(const MeshBasePtr& mesh, UINT32 indexOffset = 0, UINT32 indexCount = 0, bool useIndices = true, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
-
 		/** @copydoc RenderSystem::draw() */
 		/** @copydoc RenderSystem::draw() */
 		void draw(UINT32 vertexOffset, UINT32 vertexCount);
 		void draw(UINT32 vertexOffset, UINT32 vertexCount);
 
 

+ 33 - 11
BansheeCore/Include/BsHardwareBufferManager.h

@@ -12,7 +12,7 @@ namespace BansheeEngine
 	/**
 	/**
 	 * @brief	Handles creation of various hardware buffers.
 	 * @brief	Handles creation of various hardware buffers.
 	 *
 	 *
-	 * @note	Thread safe.
+	 * @note	Sim thread only.
 	 */
 	 */
 	class BS_CORE_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
 	class BS_CORE_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
 	{
 	{
@@ -77,16 +77,6 @@ namespace BansheeEngine
 		virtual VertexDeclarationPtr createVertexDeclaration(const VertexDeclaration::VertexElementList& elements);
 		virtual VertexDeclarationPtr createVertexDeclaration(const VertexDeclaration::VertexElementList& elements);
 
 
 	protected:
 	protected:
-		/**
-		 * @copydoc	createVertexBuffer
-		 */
-		virtual VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
-
-		/**
-		 * @copydoc	createIndexBuffer
-		 */
-		virtual IndexBufferPtr createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
-
 		/**
 		/**
 		 * @copydoc	createGpuParamBlockBuffer
 		 * @copydoc	createGpuParamBlockBuffer
 		 */
 		 */
@@ -103,5 +93,37 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual VertexDeclarationPtr createVertexDeclarationImpl(const VertexDeclaration::VertexElementList& elements);
 		virtual VertexDeclarationPtr createVertexDeclarationImpl(const VertexDeclaration::VertexElementList& elements);
 	};
 	};
+
+	/**
+	 * @brief	Handles creation of various hardware buffers.
+	 *
+	 * @note	Core thread only.
+	 */
+	class BS_CORE_EXPORT HardwareBufferCoreManager : public Module<HardwareBufferCoreManager>
+	{
+    public:
+		virtual ~HardwareBufferCoreManager() { }
+
+		/**
+		 * @copydoc	HardwareBufferManager::createVertexBuffer
+		 */
+		virtual SPtr<VertexBufferCore> createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
+
+		/**
+		 * @copydoc	HardwareBufferManager::createIndexBuffer
+		 */
+		virtual SPtr<IndexBufferCore> createIndexBuffer(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+
+	protected:
+		/**
+		 * @copydoc	createVertexBuffer
+		 */
+		virtual SPtr<VertexBufferCore> createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
+
+		/**
+		 * @copydoc	createIndexBuffer
+		 */
+		virtual SPtr<IndexBufferCore> createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
+	};
 }
 }
 
 

+ 11 - 3
BansheeCore/Include/BsIndexBuffer.h

@@ -21,6 +21,8 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT IndexBufferProperties
 	class BS_CORE_EXPORT IndexBufferProperties
 	{
 	{
 	public:
 	public:
+		IndexBufferProperties(IndexType idxType, UINT32 numIndexes);
+
 		/**
 		/**
 		 * @brief	Returns the type of indices stored.
 		 * @brief	Returns the type of indices stored.
 		 */
 		 */
@@ -53,7 +55,7 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT IndexBufferCore : public CoreObjectCore, public HardwareBuffer
 	class BS_CORE_EXPORT IndexBufferCore : public CoreObjectCore, public HardwareBuffer
 	{
 	{
 	public:
 	public:
-		IndexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const IndexBufferProperties& properties);
+		IndexBufferCore(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage);
 		virtual ~IndexBufferCore() { }
 		virtual ~IndexBufferCore() { }
 
 
 		/**
 		/**
@@ -92,10 +94,16 @@ namespace BansheeEngine
 		static IndexBufferPtr create(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 		static IndexBufferPtr create(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 
 	protected:
 	protected:
-		IndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage, bool useSystemMemory);
+		friend class HardwareBufferManager;
+
+		IndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage);
+
+		/**
+		 * @copydoc	CoreObject::createCore
+		 */
+		virtual SPtr<CoreObjectCore> createCore() const;
 
 
 		IndexBufferProperties mProperties;
 		IndexBufferProperties mProperties;
 		GpuBufferUsage mUsage;
 		GpuBufferUsage mUsage;
-		bool mUseSystemMemory;
     };
     };
 }
 }

+ 3 - 3
BansheeCore/Include/BsMesh.h

@@ -58,12 +58,12 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc MeshBase::getVertexData
 		 * @copydoc MeshBase::getVertexData
 		 */
 		 */
-		virtual std::shared_ptr<VertexData> _getVertexData() const;
+		virtual SPtr<VertexData> _getVertexData() const;
 
 
 		/**
 		/**
 		 * @copydoc MeshBase::getIndexData
 		 * @copydoc MeshBase::getIndexData
 		 */
 		 */
-		virtual IndexBufferPtr _getIndexBuffer() const;
+		virtual SPtr<IndexBufferCore> _getIndexBuffer() const;
 
 
 		/**
 		/**
 		 * @brief	Returns a dummy mesh, containing just one triangle. Don't modify the returned mesh.
 		 * @brief	Returns a dummy mesh, containing just one triangle. Don't modify the returned mesh.
@@ -96,7 +96,7 @@ namespace BansheeEngine
 		Mesh(const MeshDataPtr& initialMeshData, const Vector<SubMesh>& subMeshes, MeshBufferType bufferType = MeshBufferType::Static);
 		Mesh(const MeshDataPtr& initialMeshData, const Vector<SubMesh>& subMeshes, MeshBufferType bufferType = MeshBufferType::Static);
 
 
 		std::shared_ptr<VertexData> mVertexData; // Core thread
 		std::shared_ptr<VertexData> mVertexData; // Core thread
-		IndexBufferPtr mIndexBuffer; // Core thread
+		SPtr<IndexBufferCore> mIndexBuffer; // Core thread
 
 
 		Bounds mBounds; // Core thread
 		Bounds mBounds; // Core thread
 		VertexDataDescPtr mVertexDesc; // Immutable
 		VertexDataDescPtr mVertexDesc; // Immutable

+ 2 - 2
BansheeCore/Include/BsMeshBase.h

@@ -97,14 +97,14 @@ namespace BansheeEngine
 		 *  
 		 *  
 		 * @note	Core thread only. Internal method.
 		 * @note	Core thread only. Internal method.
 		 */
 		 */
-		virtual std::shared_ptr<VertexData> _getVertexData() const = 0;
+		virtual SPtr<VertexData> _getVertexData() const = 0;
 
 
 		/**
 		/**
 		 * @brief	Get index data used for rendering.
 		 * @brief	Get index data used for rendering.
 		 *  
 		 *  
 		 * @note	Core thread only. Internal method.
 		 * @note	Core thread only. Internal method.
 		 */
 		 */
-		virtual IndexBufferPtr _getIndexBuffer() const = 0;
+		virtual SPtr<IndexBufferCore> _getIndexBuffer() const = 0;
 
 
 		/**
 		/**
 		 * @brief	Returns an offset into the vertex buffers that is returned
 		 * @brief	Returns an offset into the vertex buffers that is returned

+ 4 - 4
BansheeCore/Include/BsMeshHeap.h

@@ -167,12 +167,12 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Gets internal vertex data for all the meshes.
 		 * @brief	Gets internal vertex data for all the meshes.
 		 */
 		 */
-		std::shared_ptr<VertexData> _getVertexData() const;
+		SPtr<VertexData> _getVertexData() const;
 
 
 		/**
 		/**
 		 * @brief	Gets internal index data for all the meshes.
 		 * @brief	Gets internal index data for all the meshes.
 		 */
 		 */
-		IndexBufferPtr _getIndexBuffer() const;
+		SPtr<IndexBufferCore> _getIndexBuffer() const;
 
 
 		/**
 		/**
 		 * @brief	Returns the offset in vertices from the start of the buffer
 		 * @brief	Returns the offset in vertices from the start of the buffer
@@ -213,8 +213,8 @@ namespace BansheeEngine
 		Vector<UINT8*> mCPUVertexData; // Core thread
 		Vector<UINT8*> mCPUVertexData; // Core thread
 		UINT8* mCPUIndexData; // Core thread
 		UINT8* mCPUIndexData; // Core thread
 
 
-		std::shared_ptr<VertexData> mVertexData; // Core thread
-		IndexBufferPtr mIndexBuffer; // Core thread
+		SPtr<VertexData> mVertexData; // Core thread
+		SPtr<IndexBufferCore> mIndexBuffer; // Core thread
 
 
 		Map<UINT32, AllocatedData> mMeshAllocData; // Core thread
 		Map<UINT32, AllocatedData> mMeshAllocData; // Core thread
 
 

+ 2 - 15
BansheeCore/Include/BsRenderSystem.h

@@ -114,14 +114,14 @@ namespace BansheeEngine
 		 * @brief	Sets the provided vertex buffers starting at the specified source index.
 		 * @brief	Sets the provided vertex buffers starting at the specified source index.
 		 *			Set buffer to nullptr to clear the buffer at the specified index.
 		 *			Set buffer to nullptr to clear the buffer at the specified index.
 		 */
 		 */
-		virtual void setVertexBuffers(UINT32 index, VertexBufferPtr* buffers, UINT32 numBuffers) = 0;
+		virtual void setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers) = 0;
 
 
 		/**
 		/**
 		 * @brief	Sets an index buffer to use when drawing. Indices in an index buffer
 		 * @brief	Sets an index buffer to use when drawing. Indices in an index buffer
 		 * 			reference vertices in the vertex buffer, which increases cache coherency
 		 * 			reference vertices in the vertex buffer, which increases cache coherency
 		 * 			and reduces the size of vertex buffers by eliminating duplicate data.
 		 * 			and reduces the size of vertex buffers by eliminating duplicate data.
 		 */
 		 */
-		virtual void setIndexBuffer(const IndexBufferPtr& buffer) = 0;
+		virtual void setIndexBuffer(const SPtr<IndexBufferCore>& buffer) = 0;
 
 
 		/**
 		/**
 		 * @brief	Sets the vertex declaration to use when drawing. Vertex declaration
 		 * @brief	Sets the vertex declaration to use when drawing. Vertex declaration
@@ -135,19 +135,6 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual void setDrawOperation(DrawOperationType op) = 0;
 		virtual void setDrawOperation(DrawOperationType op) = 0;
 
 
-		/**
-		 * @brief	A helper method that provides a simple way of rendering a single object. It will
-		 * 			automatically set up vertex declaration, draw operation, vertex and index buffers and
-		 * 			draw them.
-		 *
-		 * @param	mesh	   	The mesh.
-		 * @param	indexOffset	(optional) Offset into the mesh buffer to start drawing from.
-		 * @param	indexCount 	(optional) Number of indexes to draw, starting at the offset. Ignored if "drawIndexed" is false. If 0 all indices in the mesh will be drawn.
-		 * @param	useIndices	(optional) If true, drawing is done using the index buffer on the mesh and the provided offset and size, otherwise all mesh vertices are drawn sequentially.
-		 * @param	drawOp	   	(optional) Draw operation to use when rendering.
-		 */
-		virtual void render(const MeshBasePtr& mesh, UINT32 indexOffset = 0, UINT32 indexCount = 0, bool useIndices = true, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
-
 		/**
 		/**
 		 * @brief	Draw an object based on currently bound GPU programs, vertex declaration and vertex buffers.
 		 * @brief	Draw an object based on currently bound GPU programs, vertex declaration and vertex buffers.
 		 * 			
 		 * 			

+ 2 - 2
BansheeCore/Include/BsTransientMesh.h

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

+ 12 - 3
BansheeCore/Include/BsVertexBuffer.h

@@ -13,6 +13,8 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT VertexBufferProperties
 	class BS_CORE_EXPORT VertexBufferProperties
 	{
 	{
 	public:
 	public:
+		VertexBufferProperties(UINT32 numVertices, UINT32 vertexSize);
+
 		/**
 		/**
 		 * @brief	Gets the size in bytes of a single vertex in this buffer.
 		 * @brief	Gets the size in bytes of a single vertex in this buffer.
 		 */
 		 */
@@ -39,7 +41,7 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT VertexBufferCore : public CoreObjectCore, public HardwareBuffer
 	class BS_CORE_EXPORT VertexBufferCore : public CoreObjectCore, public HardwareBuffer
 	{
 	{
 	public:
 	public:
-		VertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties);
+		VertexBufferCore(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool streamOut);
 		virtual ~VertexBufferCore() { }
 		virtual ~VertexBufferCore() { }
 
 
 		/**
 		/**
@@ -74,11 +76,18 @@ namespace BansheeEngine
 
 
 		static const int MAX_SEMANTIC_IDX = 8;
 		static const int MAX_SEMANTIC_IDX = 8;
 	protected:
 	protected:
-		VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMemory);
+		friend class HardwareBufferManager;
+
+		VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool streamOut = false);
+
+		/**
+		 * @copydoc	CoreObject::createCore
+		 */
+		virtual SPtr<CoreObjectCore> createCore() const;
 
 
 	protected:
 	protected:
 		VertexBufferProperties mProperties;
 		VertexBufferProperties mProperties;
 		GpuBufferUsage mUsage;
 		GpuBufferUsage mUsage;
-		bool mUseSystemMemory;
+		bool mStreamOut;
     };
     };
 }
 }

+ 4 - 4
BansheeCore/Include/BsVertexData.h

@@ -31,17 +31,17 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Assigns a new vertex buffer to the specified index.
 		 * @brief	Assigns a new vertex buffer to the specified index.
 		 */
 		 */
-		void setBuffer(UINT32 index, VertexBufferPtr buffer);
+		void setBuffer(UINT32 index, SPtr<VertexBufferCore> buffer);
 
 
 		/**
 		/**
 		 * @brief	Retrieves a vertex buffer from the specified index.
 		 * @brief	Retrieves a vertex buffer from the specified index.
 		 */
 		 */
-		VertexBufferPtr getBuffer(UINT32 index) const;
+		SPtr<VertexBufferCore> getBuffer(UINT32 index) const;
 
 
 		/**
 		/**
 		 * @brief	Returns a list of all bound vertex buffers.
 		 * @brief	Returns a list of all bound vertex buffers.
 		 */
 		 */
-		const UnorderedMap<UINT32, VertexBufferPtr>& getBuffers() const { return mVertexBuffers; }
+		const UnorderedMap<UINT32, SPtr<VertexBufferCore>>& getBuffers() const { return mVertexBuffers; }
 
 
 		/**
 		/**
 		 * @brief	Checks if there is a buffer at the specified index.
 		 * @brief	Checks if there is a buffer at the specified index.
@@ -62,7 +62,7 @@ namespace BansheeEngine
 		void recalculateMaxIndex();
 		void recalculateMaxIndex();
 
 
     private:
     private:
-		UnorderedMap<UINT32, VertexBufferPtr> mVertexBuffers;
+		UnorderedMap<UINT32, SPtr<VertexBufferCore>> mVertexBuffers;
 
 
 		UINT32 mMaxBufferIdx = 0;
 		UINT32 mMaxBufferIdx = 0;
 	};
 	};

+ 27 - 5
BansheeCore/Source/BsCoreThreadAccessor.cpp

@@ -5,6 +5,8 @@
 #include "BsRasterizerState.h"
 #include "BsRasterizerState.h"
 #include "BsDepthStencilState.h"
 #include "BsDepthStencilState.h"
 #include "BsGpuResourceData.h"
 #include "BsGpuResourceData.h"
+#include "BsIndexBuffer.h"
+#include "BsVertexBuffer.h"
 #include "BsVideoModeInfo.h"
 #include "BsVideoModeInfo.h"
 #include "BsGpuParams.h"
 #include "BsGpuParams.h"
 #include "BsPass.h"
 #include "BsPass.h"
@@ -61,6 +63,31 @@ namespace BansheeEngine
 		mCommandQueue->queue(std::bind(&RenderSystem::setDepthStencilState, RenderSystem::instancePtr(), depthStencilState, stencilRefValue));
 		mCommandQueue->queue(std::bind(&RenderSystem::setDepthStencilState, RenderSystem::instancePtr(), depthStencilState, stencilRefValue));
 	}
 	}
 
 
+	void CoreThreadAccessorBase::setVertexBuffers(UINT32 index, const Vector<VertexBufferPtr>& buffers)
+	{
+		Vector<SPtr<VertexBufferCore>> coreBuffers(buffers.size());
+		for (UINT32 i = 0; i < (UINT32)buffers.size(); i++)
+			coreBuffers[i] = buffers[i] != nullptr ? buffers[i]->getCore() : nullptr;
+
+		std::function<void(RenderSystem*, UINT32, const Vector<SPtr<VertexBufferCore>>&)> resizeFunc =
+			[](RenderSystem* rs, UINT32 idx, const Vector<SPtr<VertexBufferCore>>& _buffers)
+		{
+			rs->setVertexBuffers(idx, (SPtr<VertexBufferCore>*)_buffers.data(), (UINT32)_buffers.size());
+		};
+
+		mCommandQueue->queue(std::bind(resizeFunc, RenderSystem::instancePtr(), index, coreBuffers));
+	}
+
+	void CoreThreadAccessorBase::setIndexBuffer(const IndexBufferPtr& buffer)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setIndexBuffer, RenderSystem::instancePtr(), buffer->getCore()));
+	}
+
+	void CoreThreadAccessorBase::setVertexDeclaration(const VertexDeclarationPtr& vertexDeclaration)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setVertexDeclaration, RenderSystem::instancePtr(), vertexDeclaration));
+	}
+
 	void CoreThreadAccessorBase::setViewport(Viewport vp)
 	void CoreThreadAccessorBase::setViewport(Viewport vp)
 	{
 	{
 		mCommandQueue->queue(std::bind(&RenderSystem::setViewport, RenderSystem::instancePtr(), vp));
 		mCommandQueue->queue(std::bind(&RenderSystem::setViewport, RenderSystem::instancePtr(), vp));
@@ -136,11 +163,6 @@ namespace BansheeEngine
 		mCommandQueue->queue(std::bind(&RenderSystem::swapBuffers, RenderSystem::instancePtr(), target));
 		mCommandQueue->queue(std::bind(&RenderSystem::swapBuffers, RenderSystem::instancePtr(), target));
 	}
 	}
 
 
-	void CoreThreadAccessorBase::render(const MeshBasePtr& mesh, UINT32 indexOffset, UINT32 indexCount, bool useIndices, DrawOperationType drawOp)
-	{
-		mCommandQueue->queue(std::bind(&RenderSystem::render, RenderSystem::instancePtr(), mesh, indexOffset, indexCount, useIndices, drawOp));
-	}
-
 	void CoreThreadAccessorBase::draw(UINT32 vertexOffset, UINT32 vertexCount)
 	void CoreThreadAccessorBase::draw(UINT32 vertexOffset, UINT32 vertexCount)
 	{
 	{
 		mCommandQueue->queue(std::bind(&RenderSystem::draw, RenderSystem::instancePtr(), vertexOffset, vertexCount));
 		mCommandQueue->queue(std::bind(&RenderSystem::draw, RenderSystem::instancePtr(), vertexOffset, vertexCount));

+ 21 - 2
BansheeCore/Source/BsHardwareBufferManager.cpp

@@ -26,7 +26,7 @@ namespace BansheeEngine
 	{
 	{
 		assert (numVerts > 0);
 		assert (numVerts > 0);
 
 
-		VertexBufferPtr vbuf = createVertexBufferImpl(vertexSize, numVerts, usage, streamOut);
+		VertexBufferPtr vbuf = bs_core_ptr<VertexBuffer, GenAlloc>(new (bs_alloc<VertexBuffer>()) VertexBuffer(vertexSize, numVerts, usage, streamOut));
 		vbuf->_setThisPtr(vbuf);
 		vbuf->_setThisPtr(vbuf);
 		vbuf->initialize();
 		vbuf->initialize();
 		return vbuf;
 		return vbuf;
@@ -36,7 +36,7 @@ namespace BansheeEngine
 	{
 	{
 		assert (numIndexes > 0);
 		assert (numIndexes > 0);
 
 
-		IndexBufferPtr ibuf = createIndexBufferImpl(itype, numIndexes, usage);
+		IndexBufferPtr ibuf = bs_core_ptr<IndexBuffer, GenAlloc>(new (bs_alloc<IndexBuffer>()) IndexBuffer(itype, numIndexes, usage));
 		ibuf->_setThisPtr(ibuf);
 		ibuf->_setThisPtr(ibuf);
 		ibuf->initialize();
 		ibuf->initialize();
 		return ibuf;
 		return ibuf;
@@ -65,4 +65,23 @@ namespace BansheeEngine
 	{
 	{
 		return bs_core_ptr<VertexDeclaration, PoolAlloc>(new (bs_alloc<VertexDeclaration, PoolAlloc>()) VertexDeclaration(elements));
 		return bs_core_ptr<VertexDeclaration, PoolAlloc>(new (bs_alloc<VertexDeclaration, PoolAlloc>()) VertexDeclaration(elements));
 	}
 	}
+
+	SPtr<IndexBufferCore> HardwareBufferCoreManager::createIndexBuffer(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+	{
+		assert(numIndexes > 0);
+
+		SPtr<IndexBufferCore> ibuf = createIndexBufferImpl(itype, numIndexes, usage);
+		ibuf->initialize();
+		return ibuf;
+
+	}
+
+	SPtr<VertexBufferCore> HardwareBufferCoreManager::createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
+	{
+		assert(numVerts > 0);
+
+		SPtr<VertexBufferCore> vbuf = createVertexBufferImpl(vertexSize, numVerts, usage, streamOut);
+		vbuf->initialize();
+		return vbuf;
+	}
 }
 }

+ 24 - 16
BansheeCore/Source/BsIndexBuffer.cpp

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

+ 26 - 19
BansheeCore/Source/BsMesh.cpp

@@ -92,8 +92,7 @@ namespace BansheeEngine
 		}
 		}
 
 
 		// Indices
 		// Indices
-		SPtr<IndexBufferCore> indexBuffer = mIndexBuffer->getCore();
-		const IndexBufferProperties& ibProps = indexBuffer->getProperties();
+		const IndexBufferProperties& ibProps = mIndexBuffer->getProperties();
 
 
 		UINT32 indicesSize = meshData.getIndexBufferSize();
 		UINT32 indicesSize = meshData.getIndexBufferSize();
 		UINT8* srcIdxData = meshData.getIndexData();
 		UINT8* srcIdxData = meshData.getIndexData();
@@ -104,10 +103,10 @@ namespace BansheeEngine
 				toString(ibProps.getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
 				toString(ibProps.getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
 		}
 		}
 
 
-		if (indicesSize > indexBuffer->getSizeInBytes())
+		if (indicesSize > mIndexBuffer->getSizeInBytes())
 			BS_EXCEPT(InvalidParametersException, "Index buffer values are being written out of valid range.");
 			BS_EXCEPT(InvalidParametersException, "Index buffer values are being written out of valid range.");
 
 
-		indexBuffer->writeData(0, indicesSize, srcIdxData, discardEntireBuffer ? BufferWriteType::Discard : BufferWriteType::Normal);
+		mIndexBuffer->writeData(0, indicesSize, srcIdxData, discardEntireBuffer ? BufferWriteType::Discard : BufferWriteType::Normal);
 
 
 		// Vertices
 		// Vertices
 		for (UINT32 i = 0; i <= mVertexDesc->getMaxStreamIdx(); i++)
 		for (UINT32 i = 0; i <= mVertexDesc->getMaxStreamIdx(); i++)
@@ -127,7 +126,7 @@ namespace BansheeEngine
 					toString(myVertSize) + ". Got: " + toString(otherVertSize));
 					toString(myVertSize) + ". Got: " + toString(otherVertSize));
 			}
 			}
 
 
-			SPtr<VertexBufferCore> vertexBuffer = mVertexData->getBuffer(i)->getCore();
+			SPtr<VertexBufferCore> vertexBuffer = mVertexData->getBuffer(i);
 			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 
 
 			UINT32 bufferSize = meshData.getStreamSize(i);
 			UINT32 bufferSize = meshData.getStreamSize(i);
@@ -176,17 +175,15 @@ namespace BansheeEngine
 		if(data.getTypeId() != TID_MeshData)
 		if(data.getTypeId() != TID_MeshData)
 			BS_EXCEPT(InvalidParametersException, "Invalid GpuResourceData type. Only MeshData is supported.");
 			BS_EXCEPT(InvalidParametersException, "Invalid GpuResourceData type. Only MeshData is supported.");
 
 
-		SPtr<IndexBufferCore> indexBuffer = mIndexBuffer->getCore();
-
 		IndexType indexType = IT_32BIT;
 		IndexType indexType = IT_32BIT;
-		if (indexBuffer)
-			indexType = indexBuffer->getProperties().getType();
+		if (mIndexBuffer)
+			indexType = mIndexBuffer->getProperties().getType();
 
 
 		MeshData& meshData = static_cast<MeshData&>(data);
 		MeshData& meshData = static_cast<MeshData&>(data);
 
 
 		if(mIndexBuffer)
 		if(mIndexBuffer)
 		{
 		{
-			const IndexBufferProperties& ibProps = indexBuffer->getProperties();
+			const IndexBufferProperties& ibProps = mIndexBuffer->getProperties();
 
 
 			if (meshData.getIndexElementSize() != ibProps.getIndexSize())
 			if (meshData.getIndexElementSize() != ibProps.getIndexSize())
 			{
 			{
@@ -194,7 +191,7 @@ namespace BansheeEngine
 					toString(ibProps.getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
 					toString(ibProps.getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
 			}
 			}
 
 
-			UINT8* idxData = static_cast<UINT8*>(indexBuffer->lock(GBL_READ_ONLY));
+			UINT8* idxData = static_cast<UINT8*>(mIndexBuffer->lock(GBL_READ_ONLY));
 			UINT32 idxElemSize = ibProps.getIndexSize();
 			UINT32 idxElemSize = ibProps.getIndexSize();
 
 
 			UINT8* indices = nullptr;
 			UINT8* indices = nullptr;
@@ -212,7 +209,7 @@ namespace BansheeEngine
 
 
 			memcpy(indices, idxData, numIndicesToCopy * idxElemSize);
 			memcpy(indices, idxData, numIndicesToCopy * idxElemSize);
 
 
-			indexBuffer->unlock();
+			mIndexBuffer->unlock();
 		}
 		}
 
 
 		if(mVertexData)
 		if(mVertexData)
@@ -225,7 +222,7 @@ namespace BansheeEngine
 				if(!meshData.getVertexDesc()->hasStream(streamIdx))
 				if(!meshData.getVertexDesc()->hasStream(streamIdx))
 					continue;
 					continue;
 
 
-				SPtr<VertexBufferCore> vertexBuffer = iter->second->getCore();
+				SPtr<VertexBufferCore> vertexBuffer = iter->second;
 				const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 				const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 
 
 				// Ensure both have the same sized vertices
 				// Ensure both have the same sized vertices
@@ -257,11 +254,9 @@ namespace BansheeEngine
 
 
 	MeshDataPtr Mesh::allocateSubresourceBuffer(UINT32 subresourceIdx) const
 	MeshDataPtr Mesh::allocateSubresourceBuffer(UINT32 subresourceIdx) const
 	{
 	{
-		SPtr<IndexBufferCore> indexBuffer = mIndexBuffer->getCore();
-
 		IndexType indexType = IT_32BIT;
 		IndexType indexType = IT_32BIT;
 		if(mIndexBuffer)
 		if(mIndexBuffer)
-			indexType = indexBuffer->getProperties().getType();
+			indexType = mIndexBuffer->getProperties().getType();
 
 
 		MeshDataPtr meshData = bs_shared_ptr<MeshData>(mVertexData->vertexCount, mNumIndices, mVertexDesc, indexType);
 		MeshDataPtr meshData = bs_shared_ptr<MeshData>(mVertexData->vertexCount, mNumIndices, mVertexDesc, indexType);
 
 
@@ -275,7 +270,7 @@ namespace BansheeEngine
 		return mVertexData;
 		return mVertexData;
 	}
 	}
 
 
-	IndexBufferPtr Mesh::_getIndexBuffer() const
+	SPtr<IndexBufferCore> Mesh::_getIndexBuffer() const
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
@@ -296,7 +291,7 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 		
 		
-		mIndexBuffer = HardwareBufferManager::instance().createIndexBuffer(mIndexType,
+		mIndexBuffer = HardwareBufferCoreManager::instance().createIndexBuffer(mIndexType,
 			mNumIndices, mBufferType == MeshBufferType::Dynamic ? GBU_DYNAMIC : GBU_STATIC);
 			mNumIndices, mBufferType == MeshBufferType::Dynamic ? GBU_DYNAMIC : GBU_STATIC);
 
 
 		mVertexData = std::shared_ptr<VertexData>(bs_new<VertexData, PoolAlloc>());
 		mVertexData = std::shared_ptr<VertexData>(bs_new<VertexData, PoolAlloc>());
@@ -309,7 +304,7 @@ namespace BansheeEngine
 			if(!mVertexDesc->hasStream(i))
 			if(!mVertexDesc->hasStream(i))
 				continue;
 				continue;
 
 
-			VertexBufferPtr vertexBuffer = HardwareBufferManager::instance().createVertexBuffer(
+			SPtr<VertexBufferCore> vertexBuffer = HardwareBufferCoreManager::instance().createVertexBuffer(
 				mVertexData->vertexDeclaration->getVertexSize(i),
 				mVertexData->vertexDeclaration->getVertexSize(i),
 				mVertexData->vertexCount,
 				mVertexData->vertexCount,
 				mBufferType == MeshBufferType::Dynamic ? GBU_DYNAMIC : GBU_STATIC);
 				mBufferType == MeshBufferType::Dynamic ? GBU_DYNAMIC : GBU_STATIC);
@@ -332,6 +327,18 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
+		if (mVertexData != nullptr)
+		{
+			for (UINT32 i = 0; i < mVertexData->getBufferCount(); i++)
+			{
+				if (mVertexData->getBuffer(i) != nullptr)
+					mVertexData->getBuffer(i)->destroy();
+			}
+		}
+
+		if (mIndexBuffer != nullptr)
+			mIndexBuffer->destroy();
+
 		mVertexData = nullptr;
 		mVertexData = nullptr;
 		mIndexBuffer = nullptr;
 		mIndexBuffer = nullptr;
 		mVertexDesc = nullptr;
 		mVertexDesc = nullptr;

+ 22 - 13
BansheeCore/Source/BsMeshHeap.cpp

@@ -61,6 +61,18 @@ namespace BansheeEngine
 		if(mCPUIndexData != nullptr)
 		if(mCPUIndexData != nullptr)
 			bs_free(mCPUIndexData);
 			bs_free(mCPUIndexData);
 
 
+		if (mVertexData != nullptr)
+		{
+			for (UINT32 i = 0; i < mVertexData->getBufferCount(); i++)
+			{
+				if (mVertexData->getBuffer(i) != nullptr)
+					mVertexData->getBuffer(i)->destroy();
+			}
+		}
+
+		if (mIndexBuffer != nullptr)
+			mIndexBuffer->destroy();
+
 		mVertexData = nullptr;
 		mVertexData = nullptr;
 		mIndexBuffer = nullptr;
 		mIndexBuffer = nullptr;
 		mVertexDesc = nullptr;
 		mVertexDesc = nullptr;
@@ -270,7 +282,7 @@ namespace BansheeEngine
 					toString(vertSize) + ". Got: " + toString(otherVertSize));
 					toString(vertSize) + ". Got: " + toString(otherVertSize));
 			}
 			}
 
 
-			SPtr<VertexBufferCore> vertexBuffer = mVertexData->getBuffer(i)->getCore();
+			SPtr<VertexBufferCore> vertexBuffer = mVertexData->getBuffer(i);
 			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 
 
 			UINT8* vertDest = mCPUVertexData[i] + vertChunkStart * vertSize;
 			UINT8* vertDest = mCPUVertexData[i] + vertChunkStart * vertSize;
@@ -299,8 +311,7 @@ namespace BansheeEngine
 			vertexBuffer->writeData(vertChunkStart * vertSize, meshData->getNumVertices() * vertSize, vertDest, BufferWriteType::NoOverwrite);
 			vertexBuffer->writeData(vertChunkStart * vertSize, meshData->getNumVertices() * vertSize, vertDest, BufferWriteType::NoOverwrite);
 		}
 		}
 
 
-		SPtr<IndexBufferCore> indexBuffer = mIndexBuffer->getCore();
-		const IndexBufferProperties& ibProps = indexBuffer->getProperties();
+		const IndexBufferProperties& ibProps = mIndexBuffer->getProperties();
 
 
 		UINT32 idxSize = ibProps.getIndexSize();
 		UINT32 idxSize = ibProps.getIndexSize();
 
 
@@ -313,7 +324,7 @@ namespace BansheeEngine
 
 
 		UINT8* idxDest = mCPUIndexData + idxChunkStart * idxSize;
 		UINT8* idxDest = mCPUIndexData + idxChunkStart * idxSize;
 		memcpy(idxDest, meshData->getIndexData(), meshData->getNumIndices() * idxSize);
 		memcpy(idxDest, meshData->getIndexData(), meshData->getNumIndices() * idxSize);
-		indexBuffer->writeData(idxChunkStart * idxSize, meshData->getNumIndices() * idxSize, idxDest, BufferWriteType::NoOverwrite);
+		mIndexBuffer->writeData(idxChunkStart * idxSize, meshData->getNumIndices() * idxSize, idxDest, BufferWriteType::NoOverwrite);
 	}
 	}
 
 
 	void MeshHeap::deallocInternal(TransientMeshPtr mesh)
 	void MeshHeap::deallocInternal(TransientMeshPtr mesh)
@@ -353,10 +364,9 @@ namespace BansheeEngine
 				continue;
 				continue;
 
 
 			UINT32 vertSize = mVertexData->vertexDeclaration->getVertexSize(i);
 			UINT32 vertSize = mVertexData->vertexDeclaration->getVertexSize(i);
-			VertexBufferPtr vertexBuffer = HardwareBufferManager::instance().createVertexBuffer(
+			SPtr<VertexBufferCore> vertexBuffer = HardwareBufferCoreManager::instance().createVertexBuffer(
 				vertSize, mVertexData->vertexCount, GBU_DYNAMIC);
 				vertSize, mVertexData->vertexCount, GBU_DYNAMIC);
 
 
-			SPtr<VertexBufferCore> vertexBufferCore = vertexBuffer->getCore();
 			mVertexData->setBuffer(i, vertexBuffer);
 			mVertexData->setBuffer(i, vertexBuffer);
 
 
 			// Copy all data to the new buffer
 			// Copy all data to the new buffer
@@ -380,7 +390,7 @@ namespace BansheeEngine
 			}
 			}
 
 
 			if(destOffset > 0)
 			if(destOffset > 0)
-				vertexBufferCore->writeData(0, destOffset * vertSize, buffer, BufferWriteType::NoOverwrite);
+				vertexBuffer->writeData(0, destOffset * vertSize, buffer, BufferWriteType::NoOverwrite);
 
 
 			mCPUVertexData[i] = buffer;
 			mCPUVertexData[i] = buffer;
 		}
 		}
@@ -426,9 +436,8 @@ namespace BansheeEngine
 	{
 	{
 		mNumIndices = numIndices;
 		mNumIndices = numIndices;
 
 
-		mIndexBuffer = HardwareBufferManager::instance().createIndexBuffer(mIndexType, mNumIndices, GBU_DYNAMIC);
-		SPtr<IndexBufferCore> indexBuffer = mIndexBuffer->getCore();
-		const IndexBufferProperties& ibProps = indexBuffer->getProperties();
+		mIndexBuffer = HardwareBufferCoreManager::instance().createIndexBuffer(mIndexType, mNumIndices, GBU_DYNAMIC);
+		const IndexBufferProperties& ibProps = mIndexBuffer->getProperties();
 
 
 		// Copy all data to the new buffer
 		// Copy all data to the new buffer
 		UINT32 idxSize = ibProps.getIndexSize();
 		UINT32 idxSize = ibProps.getIndexSize();
@@ -453,7 +462,7 @@ namespace BansheeEngine
 		}
 		}
 
 
 		if(destOffset > 0)
 		if(destOffset > 0)
-			indexBuffer->writeData(0, destOffset * idxSize, buffer, BufferWriteType::NoOverwrite);
+			mIndexBuffer->writeData(0, destOffset * idxSize, buffer, BufferWriteType::NoOverwrite);
 
 
 		mCPUIndexData = buffer;
 		mCPUIndexData = buffer;
 
 
@@ -522,12 +531,12 @@ namespace BansheeEngine
 		mFreeEventQueries.push(idx);
 		mFreeEventQueries.push(idx);
 	}
 	}
 
 
-	std::shared_ptr<VertexData> MeshHeap::_getVertexData() const
+	SPtr<VertexData> MeshHeap::_getVertexData() const
 	{
 	{
 		return mVertexData;
 		return mVertexData;
 	}
 	}
 
 
-	IndexBufferPtr MeshHeap::_getIndexBuffer() const
+	SPtr<IndexBufferCore> MeshHeap::_getIndexBuffer() const
 	{
 	{
 		return mIndexBuffer;
 		return mIndexBuffer;
 	}
 	}

+ 0 - 61
BansheeCore/Source/BsRenderSystem.cpp

@@ -205,67 +205,6 @@ namespace BansheeEngine
         return false;
         return false;
 	}
 	}
 
 
-	void RenderSystem::render(const MeshBasePtr& mesh, UINT32 indexOffset, UINT32 indexCount, bool useIndices, DrawOperationType drawOp)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		gProfilerCPU().beginSample("render");
-
-		if (mClipPlanesDirty)
-		{
-			setClipPlanesImpl(mClipPlanes);
-			mClipPlanesDirty = false;
-		}
-
-		std::shared_ptr<VertexData> vertexData = mesh->_getVertexData();
-
-		setVertexDeclaration(vertexData->vertexDeclaration);
-		auto vertexBuffers = vertexData->getBuffers();
-
-		if(vertexBuffers.size() > 0)
-		{
-			VertexBufferPtr buffers[MAX_BOUND_VERTEX_BUFFERS];
-
-			UINT32 endSlot = 0;
-			UINT32 startSlot = MAX_BOUND_VERTEX_BUFFERS;
-			for(auto iter = vertexBuffers.begin(); iter != vertexBuffers.end() ; ++iter)
-			{
-				if(iter->first >= MAX_BOUND_VERTEX_BUFFERS)
-					BS_EXCEPT(InvalidParametersException, "Buffer index out of range");
-
-				startSlot = std::min(iter->first, startSlot);
-				endSlot = std::max(iter->first, endSlot);
-			}
-
-			for(auto iter = vertexBuffers.begin(); iter != vertexBuffers.end() ; ++iter)
-			{
-				buffers[iter->first - startSlot] = iter->second;
-			}
-
-			setVertexBuffers(startSlot, buffers, endSlot - startSlot + 1);
-		}
-
-		setDrawOperation(drawOp);
-
-		if (useIndices)
-		{
-			SPtr<IndexBufferCore> indexBuffer = mesh->_getIndexBuffer()->getCore();
-			const IndexBufferProperties& ibProps = indexBuffer->getProperties();
-
-			if(indexCount == 0)
-				indexCount = ibProps.getNumIndices();
-
-			setIndexBuffer(mesh->_getIndexBuffer());
-			drawIndexed(indexOffset + mesh->_getIndexOffset(), indexCount, mesh->_getVertexOffset(), vertexData->vertexCount);
-		}
-		else
-			draw(mesh->_getVertexOffset(), vertexData->vertexCount);
-
-		mesh->_notifyUsedOnGPU();
-
-		gProfilerCPU().endSample("render");
-	}
-
 	void RenderSystem::swapBuffers(RenderTargetPtr target)
 	void RenderSystem::swapBuffers(RenderTargetPtr target)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;

+ 2 - 2
BansheeCore/Source/BsRenderer.cpp

@@ -104,7 +104,7 @@ namespace BansheeEngine
 
 
 		if (vertexBuffers.size() > 0)
 		if (vertexBuffers.size() > 0)
 		{
 		{
-			VertexBufferPtr buffers[MAX_BOUND_VERTEX_BUFFERS];
+			SPtr<VertexBufferCore> buffers[MAX_BOUND_VERTEX_BUFFERS];
 
 
 			UINT32 endSlot = 0;
 			UINT32 endSlot = 0;
 			UINT32 startSlot = MAX_BOUND_VERTEX_BUFFERS;
 			UINT32 startSlot = MAX_BOUND_VERTEX_BUFFERS;
@@ -128,7 +128,7 @@ namespace BansheeEngine
 		SubMesh subMesh = meshProxy.subMesh;
 		SubMesh subMesh = meshProxy.subMesh;
 		rs.setDrawOperation(subMesh.drawOp);
 		rs.setDrawOperation(subMesh.drawOp);
 
 
-		IndexBufferPtr indexBuffer = mesh->_getIndexBuffer();
+		SPtr<IndexBufferCore> indexBuffer = mesh->_getIndexBuffer();
 
 
 		UINT32 indexCount = subMesh.indexCount;
 		UINT32 indexCount = subMesh.indexCount;
 
 

+ 2 - 2
BansheeCore/Source/BsTransientMesh.cpp

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

+ 17 - 6
BansheeCore/Source/BsVertexBuffer.cpp

@@ -7,19 +7,30 @@
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
-	VertexBufferCore::VertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties)
-		:HardwareBuffer(usage, useSystemMemory), mProperties(properties)
+	VertexBufferProperties::VertexBufferProperties(UINT32 numVertices, UINT32 vertexSize)
+		:mNumVertices(numVertices), mVertexSize(vertexSize)
+	{
+
+	}
+
+	VertexBufferCore::VertexBufferCore(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool streamOut)
+		:HardwareBuffer(usage, false), mProperties(numVertices, vertexSize)
 	{
 	{
 		mSizeInBytes = mProperties.mVertexSize * mProperties.mNumVertices;
 		mSizeInBytes = mProperties.mVertexSize * mProperties.mNumVertices;
 	}
 	}
 
 
-    VertexBuffer::VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMemory) 
-		: mUseSystemMemory(useSystemMemory), mUsage(usage)
+	VertexBuffer::VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool streamOut)
+		: mProperties(numVertices, vertexSize), mUsage(usage), mStreamOut(streamOut)
     {
     {
-		mProperties.mVertexSize = vertexSize;
-		mProperties.mNumVertices = numVertices;
+
     }
     }
 
 
+	SPtr<CoreObjectCore> VertexBuffer::createCore() const
+	{
+		return HardwareBufferCoreManager::instance().createVertexBuffer(mProperties.mVertexSize, 
+			mProperties.mNumVertices, mUsage, mStreamOut);
+	}
+
 	SPtr<VertexBufferCore> VertexBuffer::getCore() const
 	SPtr<VertexBufferCore> VertexBuffer::getCore() const
 	{
 	{
 		return std::static_pointer_cast<VertexBufferCore>(mCoreSpecific);
 		return std::static_pointer_cast<VertexBufferCore>(mCoreSpecific);

+ 2 - 2
BansheeCore/Source/BsVertexData.cpp

@@ -17,14 +17,14 @@ namespace BansheeEngine
 	{
 	{
 	}
 	}
 
 
-	void VertexData::setBuffer(UINT32 index, VertexBufferPtr buffer)
+	void VertexData::setBuffer(UINT32 index, SPtr<VertexBufferCore> buffer)
 	{
 	{
 		mVertexBuffers[index] = buffer;
 		mVertexBuffers[index] = buffer;
 
 
 		recalculateMaxIndex();
 		recalculateMaxIndex();
 	}
 	}
 
 
-	VertexBufferPtr VertexData::getBuffer(UINT32 index) const
+	SPtr<VertexBufferCore> VertexData::getBuffer(UINT32 index) const
 	{
 	{
 		auto iterFind = mVertexBuffers.find(index);
 		auto iterFind = mVertexBuffers.find(index);
 		if(iterFind != mVertexBuffers.end())
 		if(iterFind != mVertexBuffers.end())

+ 22 - 11
BansheeD3D11RenderSystem/Include/BsD3D11HardwareBufferManager.h

@@ -12,19 +12,8 @@ namespace BansheeEngine
 	{
 	{
 	public:
 	public:
 		D3D11HardwareBufferManager(D3D11Device& device);
 		D3D11HardwareBufferManager(D3D11Device& device);
-		~D3D11HardwareBufferManager();
 
 
 	protected:     
 	protected:     
-		/**
-		 * @copydoc HardwareBufferManager::createVertexBufferImpl
-		 */
-		VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
-
-		/**
-		 * @copydoc HardwareBufferManager::createIndexBufferImpl
-		 */
-		IndexBufferPtr createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
-
 		/** 
 		/** 
 		 * @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl 
 		 * @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl 
 		 */
 		 */
@@ -38,4 +27,26 @@ namespace BansheeEngine
 
 
 		D3D11Device& mDevice;
 		D3D11Device& mDevice;
 	};
 	};
+
+	/**
+	 * @brief	Handles creation of DirectX 11 hardware buffers.
+	 */
+	class BS_D3D11_EXPORT D3D11HardwareBufferCoreManager : public HardwareBufferCoreManager
+	{
+	public:
+		D3D11HardwareBufferCoreManager(D3D11Device& device);
+
+	protected:     
+		/**
+		 * @copydoc HardwareBufferCoreManager::createVertexBufferImpl
+		 */
+		SPtr<VertexBufferCore> createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
+
+		/**
+		 * @copydoc HardwareBufferCoreManager::createIndexBufferImpl
+		 */
+		SPtr<IndexBufferCore> createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+
+		D3D11Device& mDevice;
+	};
 }
 }

+ 2 - 28
BansheeD3D11RenderSystem/Include/BsD3D11IndexBuffer.h

@@ -12,8 +12,7 @@ namespace BansheeEngine
 	class BS_D3D11_EXPORT D3D11IndexBufferCore : public IndexBufferCore
 	class BS_D3D11_EXPORT D3D11IndexBufferCore : public IndexBufferCore
 	{
 	{
 	public:
 	public:
-		D3D11IndexBufferCore(D3D11Device& device, GpuBufferUsage usage, bool useSystemMemory,
-			const IndexBufferProperties& properties);
+		D3D11IndexBufferCore(D3D11Device& device, IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage);
 
 
 		~D3D11IndexBufferCore() { }
 		~D3D11IndexBufferCore() { }
 
 
@@ -46,7 +45,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc IndexBufferCore::unlockImpl
 		 * @copydoc IndexBufferCore::unlockImpl
 		 */
 		 */
-		void unlockImpl(void);
+		void unlockImpl();
 
 
 		/**
 		/**
 		 * @copydoc IndexBufferCore::initialize
 		 * @copydoc IndexBufferCore::initialize
@@ -61,29 +60,4 @@ namespace BansheeEngine
 		D3D11HardwareBuffer* mBuffer;
 		D3D11HardwareBuffer* mBuffer;
 		D3D11Device& mDevice;
 		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 SPtr<CoreObjectCore> createCore() const;
-
-		D3D11Device& mDevice;
-	};
 }
 }

+ 2 - 2
BansheeD3D11RenderSystem/Include/BsD3D11RenderSystem.h

@@ -99,12 +99,12 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc	RenderSystem::setVertexBuffers
 		 * @copydoc	RenderSystem::setVertexBuffers
 		 */
 		 */
-		void setVertexBuffers(UINT32 index, VertexBufferPtr* buffers, UINT32 numBuffers);
+		void setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers);
 
 
 		/**
 		/**
 		 * @copydoc	RenderSystem::setIndexBuffer
 		 * @copydoc	RenderSystem::setIndexBuffer
 		 */
 		 */
-		void setIndexBuffer(const IndexBufferPtr& buffer);
+		void setIndexBuffer(const SPtr<IndexBufferCore>& buffer);
 
 
 		/**
 		/**
 		 * @copydoc	RenderSystem::setVertexDeclaration
 		 * @copydoc	RenderSystem::setVertexDeclaration

+ 2 - 28
BansheeD3D11RenderSystem/Include/BsD3D11VertexBuffer.h

@@ -12,8 +12,8 @@ namespace BansheeEngine
 	class BS_D3D11_EXPORT D3D11VertexBufferCore : public VertexBufferCore
 	class BS_D3D11_EXPORT D3D11VertexBufferCore : public VertexBufferCore
 	{
 	{
 	public:
 	public:
-		D3D11VertexBufferCore(D3D11Device& device, bool streamOut, GpuBufferUsage usage, 
-			bool useSystemMemory, const VertexBufferProperties& properties);
+		D3D11VertexBufferCore(D3D11Device& device, UINT32 vertexSize, UINT32 numVertices, 
+			GpuBufferUsage usage, bool streamOut);
 
 
 		~D3D11VertexBufferCore() { }
 		~D3D11VertexBufferCore() { }
 
 
@@ -64,30 +64,4 @@ namespace BansheeEngine
 		D3D11Device& mDevice;
 		D3D11Device& mDevice;
 		bool mStreamOut;
 		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 SPtr<CoreObjectCore> createCore() const;
-
-		D3D11Device& mDevice;
-		bool mStreamOut;
-	};
 }
 }

+ 17 - 21
BansheeD3D11RenderSystem/Source/BsD3D11HardwareBufferManager.cpp

@@ -11,27 +11,6 @@ namespace BansheeEngine
 		: mDevice(device)
 		: mDevice(device)
 	{ }
 	{ }
 
 
-	D3D11HardwareBufferManager::~D3D11HardwareBufferManager()
-	{
-
-	}
-
-	VertexBufferPtr D3D11HardwareBufferManager::createVertexBufferImpl(UINT32 vertexSize, 
-		UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
-	{
-		D3D11VertexBuffer* buffer = new (bs_alloc<D3D11VertexBuffer, PoolAlloc>()) D3D11VertexBuffer(mDevice, vertexSize, numVerts, usage, false, streamOut);
-
-		return bs_core_ptr<D3D11VertexBuffer, PoolAlloc>(buffer);
-	}
-
-	IndexBufferPtr D3D11HardwareBufferManager::createIndexBufferImpl(IndexType itype, 
-		UINT32 numIndexes, GpuBufferUsage usage)
-	{
-		D3D11IndexBuffer* buffer = new (bs_alloc<D3D11IndexBuffer, PoolAlloc>()) D3D11IndexBuffer(mDevice, itype, numIndexes, usage, false);
-
-		return bs_core_ptr<D3D11IndexBuffer, PoolAlloc>(buffer);
-	}
-
 	GpuParamBlockBufferPtr D3D11HardwareBufferManager::createGpuParamBlockBufferImpl()
 	GpuParamBlockBufferPtr D3D11HardwareBufferManager::createGpuParamBlockBufferImpl()
 	{
 	{
 		D3D11GpuParamBlockBuffer* paramBlockBuffer = new (bs_alloc<D3D11GpuParamBlockBuffer, PoolAlloc>()) D3D11GpuParamBlockBuffer();
 		D3D11GpuParamBlockBuffer* paramBlockBuffer = new (bs_alloc<D3D11GpuParamBlockBuffer, PoolAlloc>()) D3D11GpuParamBlockBuffer();
@@ -46,4 +25,21 @@ namespace BansheeEngine
 
 
 		return bs_core_ptr<D3D11GpuBuffer, PoolAlloc>(buffer);
 		return bs_core_ptr<D3D11GpuBuffer, PoolAlloc>(buffer);
 	}
 	}
+
+	D3D11HardwareBufferCoreManager::D3D11HardwareBufferCoreManager(D3D11Device& device)
+		: mDevice(device)
+	{ }
+
+	SPtr<VertexBufferCore> D3D11HardwareBufferCoreManager::createVertexBufferImpl(UINT32 vertexSize,
+		UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
+	{
+		return bs_shared_ptr<D3D11VertexBufferCore>(mDevice, vertexSize, numVerts, usage, streamOut);
+	}
+
+	SPtr<IndexBufferCore> D3D11HardwareBufferCoreManager::createIndexBufferImpl(IndexType itype,
+		UINT32 numIndexes, GpuBufferUsage usage)
+	{
+		return bs_shared_ptr<D3D11IndexBufferCore>(mDevice, itype, numIndexes, usage);
+	}
+
 }
 }

+ 2 - 15
BansheeD3D11RenderSystem/Source/BsD3D11IndexBuffer.cpp

@@ -4,9 +4,8 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	D3D11IndexBufferCore::D3D11IndexBufferCore(D3D11Device& device, GpuBufferUsage usage, bool useSystemMemory, 
-		const IndexBufferProperties& properties)
-		:IndexBufferCore(usage, useSystemMemory, properties), mDevice(device), mBuffer(nullptr)
+	D3D11IndexBufferCore::D3D11IndexBufferCore(D3D11Device& device, IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage)
+		:IndexBufferCore(idxType, numIndexes, usage), mDevice(device), mBuffer(nullptr)
 	{
 	{
 
 
 	}
 	}
@@ -70,16 +69,4 @@ namespace BansheeEngine
 	{
 	{
 		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, 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)
-	{
-
-	}
-
-	SPtr<CoreObjectCore> D3D11IndexBuffer::createCore() const
-	{
-		return bs_shared_ptr<D3D11IndexBufferCore>(mDevice, mUsage, mUseSystemMemory, mProperties);
-	}
 }
 }

+ 7 - 5
BansheeD3D11RenderSystem/Source/BsD3D11RenderSystem.cpp

@@ -108,8 +108,9 @@ namespace BansheeEngine
 		// Create the texture manager for use by others		
 		// Create the texture manager for use by others		
 		TextureManager::startUp<D3D11TextureManager>();
 		TextureManager::startUp<D3D11TextureManager>();
 
 
-		// Also create hardware buffer manager		
+		// Create hardware buffer manager		
 		HardwareBufferManager::startUp<D3D11HardwareBufferManager>(std::ref(*mDevice));
 		HardwareBufferManager::startUp<D3D11HardwareBufferManager>(std::ref(*mDevice));
+		HardwareBufferCoreManager::startUp<D3D11HardwareBufferCoreManager>(std::ref(*mDevice));
 
 
 		// Create render window manager
 		// Create render window manager
 		RenderWindowManager::startUp<D3D11RenderWindowManager>(this);
 		RenderWindowManager::startUp<D3D11RenderWindowManager>(this);
@@ -168,6 +169,7 @@ namespace BansheeEngine
 
 
 		RenderStateManager::shutDown();
 		RenderStateManager::shutDown();
 		RenderWindowManager::shutDown();
 		RenderWindowManager::shutDown();
+		HardwareBufferCoreManager::shutDown();
 		HardwareBufferManager::shutDown();
 		HardwareBufferManager::shutDown();
 		TextureManager::shutDown();
 		TextureManager::shutDown();
 
 
@@ -394,7 +396,7 @@ namespace BansheeEngine
 		mDevice->getImmediateContext()->RSSetViewports(1, &mViewport);
 		mDevice->getImmediateContext()->RSSetViewports(1, &mViewport);
 	}
 	}
 
 
-	void D3D11RenderSystem::setVertexBuffers(UINT32 index, VertexBufferPtr* buffers, UINT32 numBuffers)
+	void D3D11RenderSystem::setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
@@ -408,7 +410,7 @@ namespace BansheeEngine
 
 
 		for(UINT32 i = 0; i < numBuffers; i++)
 		for(UINT32 i = 0; i < numBuffers; i++)
 		{
 		{
-			SPtr<D3D11VertexBufferCore> vertexBuffer = std::static_pointer_cast<D3D11VertexBufferCore>(buffers[i]->getCore());
+			SPtr<D3D11VertexBufferCore> vertexBuffer = std::static_pointer_cast<D3D11VertexBufferCore>(buffers[i]);
 			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 
 
 			dx11buffers[i] = vertexBuffer->getD3DVertexBuffer();
 			dx11buffers[i] = vertexBuffer->getD3DVertexBuffer();
@@ -422,11 +424,11 @@ namespace BansheeEngine
 		BS_INC_RENDER_STAT(NumVertexBufferBinds);
 		BS_INC_RENDER_STAT(NumVertexBufferBinds);
 	}
 	}
 
 
-	void D3D11RenderSystem::setIndexBuffer(const IndexBufferPtr& buffer)
+	void D3D11RenderSystem::setIndexBuffer(const SPtr<IndexBufferCore>& buffer)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		SPtr<D3D11IndexBufferCore> indexBuffer = std::static_pointer_cast<D3D11IndexBufferCore>(buffer->getCore());
+		SPtr<D3D11IndexBufferCore> indexBuffer = std::static_pointer_cast<D3D11IndexBufferCore>(buffer);
 
 
 		DXGI_FORMAT indexFormat = DXGI_FORMAT_R16_UINT;
 		DXGI_FORMAT indexFormat = DXGI_FORMAT_R16_UINT;
 		if(indexBuffer->getProperties().getType() == IT_16BIT)
 		if(indexBuffer->getProperties().getType() == IT_16BIT)

+ 2 - 13
BansheeD3D11RenderSystem/Source/BsD3D11VertexBuffer.cpp

@@ -4,9 +4,8 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	D3D11VertexBufferCore::D3D11VertexBufferCore(D3D11Device& device, bool streamOut, GpuBufferUsage usage,
-		bool useSystemMemory, const VertexBufferProperties& properties)
-		:VertexBufferCore(usage, useSystemMemory, properties), mDevice(device), mStreamOut(streamOut), mBuffer(nullptr)
+	D3D11VertexBufferCore::D3D11VertexBufferCore(D3D11Device& device, UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool streamOut)
+		:VertexBufferCore(vertexSize, numVertices, usage, streamOut), mDevice(device), mStreamOut(streamOut), mBuffer(nullptr)
 	{ }
 	{ }
 
 
 	void* D3D11VertexBufferCore::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
 	void* D3D11VertexBufferCore::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
@@ -66,14 +65,4 @@ namespace BansheeEngine
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_VertexBuffer);
 		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_VertexBuffer);
 		VertexBufferCore::destroy();
 		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)
-	{ }
-
-	SPtr<CoreObjectCore> D3D11VertexBuffer::createCore() const
-	{
-		return bs_shared_ptr<D3D11VertexBufferCore>(mDevice, mStreamOut, mUsage, mUseSystemMemory, mProperties);
-	}
 }
 }

+ 17 - 14
BansheeD3D9RenderSystem/Include/BsD3D9HardwareBufferManager.h

@@ -10,26 +10,12 @@ namespace BansheeEngine
 	 */
 	 */
     class BS_D3D9_EXPORT D3D9HardwareBufferManager : public HardwareBufferManager
     class BS_D3D9_EXPORT D3D9HardwareBufferManager : public HardwareBufferManager
     {
     {
-    public:
-        D3D9HardwareBufferManager();
-        ~D3D9HardwareBufferManager();
-
 	protected:     
 	protected:     
 		/**
 		/**
 		 * @copydoc	HardwareBufferManager::createVertexDeclarationImpl
 		 * @copydoc	HardwareBufferManager::createVertexDeclarationImpl
 		 */
 		 */
 		VertexDeclarationPtr createVertexDeclarationImpl(const VertexDeclaration::VertexElementList& elements);
 		VertexDeclarationPtr createVertexDeclarationImpl(const VertexDeclaration::VertexElementList& elements);
 
 
-		/**
-		 * @copydoc HardwareBufferManager::createVertexBufferImpl
-		 */
-		VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
-
-		/**
-		 * @copydoc HardwareBufferManager::createIndexBufferImpl
-		 */
-		IndexBufferPtr createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
-
 		/** @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl */
 		/** @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl */
 		GpuParamBlockBufferPtr createGpuParamBlockBufferImpl();
 		GpuParamBlockBufferPtr createGpuParamBlockBufferImpl();
 
 
@@ -39,4 +25,21 @@ namespace BansheeEngine
 		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
     };
     };
+
+	/**
+	 * @brief	Manages creation of DX9 hardware buffers.
+	 */
+    class BS_D3D9_EXPORT D3D9HardwareBufferCoreManager : public HardwareBufferCoreManager
+    {
+	protected:     
+		/**
+		 * @copydoc HardwareBufferCoreManager::createVertexBufferImpl
+		 */
+		SPtr<VertexBufferCore> createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
+
+		/**
+		 * @copydoc HardwareBufferCoreManager::createIndexBufferImpl
+		 */
+		SPtr<IndexBufferCore> createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+    };
 }
 }

+ 1 - 20
BansheeD3D9RenderSystem/Include/BsD3D9IndexBuffer.h

@@ -25,7 +25,7 @@ namespace BansheeEngine
 		};
 		};
 
 
     public:
     public:
-		D3D9IndexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const IndexBufferProperties& properties);
+		D3D9IndexBufferCore(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage);
 		~D3D9IndexBufferCore() { }
 		~D3D9IndexBufferCore() { }
 
 
 		/**
 		/**
@@ -99,23 +99,4 @@ namespace BansheeEngine
 		D3DINDEXBUFFER_DESC	mBufferDesc;	
 		D3DINDEXBUFFER_DESC	mBufferDesc;	
 		UINT8* mSystemMemoryBuffer;
 		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 SPtr<CoreObjectCore> createCore() const;
-    };
 }
 }

+ 2 - 2
BansheeD3D9RenderSystem/Include/BsD3D9RenderSystem.h

@@ -53,12 +53,12 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderSystem::setVertexBuffers()
 		 * @copydoc RenderSystem::setVertexBuffers()
 		 */
 		 */
-		void setVertexBuffers(UINT32 index, VertexBufferPtr* buffers, UINT32 numBuffers);
+		void setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers);
 
 
 		/**
 		/**
 		 * @copydoc RenderSystem::setIndexBuffer()
 		 * @copydoc RenderSystem::setIndexBuffer()
 		 */
 		 */
-		void setIndexBuffer(const IndexBufferPtr& buffer);
+		void setIndexBuffer(const SPtr<IndexBufferCore>& buffer);
 
 
 		/**
 		/**
 		 * @copydoc RenderSystem::setVertexDeclaration()
 		 * @copydoc RenderSystem::setVertexDeclaration()

+ 1 - 20
BansheeD3D9RenderSystem/Include/BsD3D9VertexBuffer.h

@@ -25,7 +25,7 @@ namespace BansheeEngine
 		};
 		};
 
 
     public:
     public:
-		D3D9VertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties);
+		D3D9VertexBufferCore(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool streamOut);
 		~D3D9VertexBufferCore() { }
 		~D3D9VertexBufferCore() { }
 
 
 		/**
 		/**
@@ -99,23 +99,4 @@ namespace BansheeEngine
 		D3DVERTEXBUFFER_DESC mBufferDesc;	
 		D3DVERTEXBUFFER_DESC mBufferDesc;	
 		UINT8* mSystemMemoryBuffer;
 		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 SPtr<CoreObjectCore> createCore() const;
-    };
 }
 }

+ 14 - 24
BansheeD3D9RenderSystem/Source/BsD3D9HardwareBufferManager.cpp

@@ -8,30 +8,6 @@
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
-    D3D9HardwareBufferManager::D3D9HardwareBufferManager()       
-    {
-    }
-
-    D3D9HardwareBufferManager::~D3D9HardwareBufferManager()
-    {
-    }
-
-    VertexBufferPtr D3D9HardwareBufferManager::createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
-    {
-		assert (numVerts > 0);
-
-        D3D9VertexBuffer* buffer = new (bs_alloc<D3D9VertexBuffer, PoolAlloc>()) D3D9VertexBuffer(vertexSize, numVerts, usage, false);
-		return bs_core_ptr<D3D9VertexBuffer, PoolAlloc>(buffer);
-    }
-
-	IndexBufferPtr D3D9HardwareBufferManager::createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
-    {
-		assert (numIndexes > 0);
-
-		D3D9IndexBuffer* buffer = new (bs_alloc<D3D9IndexBuffer, PoolAlloc>()) D3D9IndexBuffer(itype, numIndexes, usage, false);
-		return bs_core_ptr<D3D9IndexBuffer, PoolAlloc>(buffer);
-    }
-
 	GpuParamBlockBufferPtr D3D9HardwareBufferManager::createGpuParamBlockBufferImpl()
 	GpuParamBlockBufferPtr D3D9HardwareBufferManager::createGpuParamBlockBufferImpl()
 	{
 	{
 		GpuParamBlockBuffer* paramBlockBuffer = new (bs_alloc<GenericGpuParamBlockBuffer, PoolAlloc>()) GenericGpuParamBlockBuffer();
 		GpuParamBlockBuffer* paramBlockBuffer = new (bs_alloc<GenericGpuParamBlockBuffer, PoolAlloc>()) GenericGpuParamBlockBuffer();
@@ -50,4 +26,18 @@ namespace BansheeEngine
 		D3D9VertexDeclaration* decl = new (bs_alloc<D3D9VertexDeclaration, PoolAlloc>()) D3D9VertexDeclaration(elements);
 		D3D9VertexDeclaration* decl = new (bs_alloc<D3D9VertexDeclaration, PoolAlloc>()) D3D9VertexDeclaration(elements);
 		return bs_core_ptr<D3D9VertexDeclaration, PoolAlloc>(decl);
 		return bs_core_ptr<D3D9VertexDeclaration, PoolAlloc>(decl);
     }
     }
+
+	SPtr<VertexBufferCore> D3D9HardwareBufferCoreManager::createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
+	{
+		assert(numVerts > 0);
+
+		return bs_shared_ptr<D3D9VertexBufferCore>(vertexSize, numVerts, usage, streamOut);
+	}
+
+	SPtr<IndexBufferCore> D3D9HardwareBufferCoreManager::createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+	{
+		assert(numIndexes > 0);
+
+		return bs_shared_ptr<D3D9IndexBufferCore>(itype, numIndexes, usage);
+	}
 }
 }

+ 2 - 11
BansheeD3D9RenderSystem/Source/BsD3D9IndexBuffer.cpp

@@ -9,8 +9,8 @@
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
-	D3D9IndexBufferCore::D3D9IndexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const IndexBufferProperties& properties)
-		: IndexBufferCore(usage, useSystemMemory, properties), mSystemMemoryBuffer(nullptr)
+	D3D9IndexBufferCore::D3D9IndexBufferCore(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage)
+		: IndexBufferCore(idxType, numIndexes, usage), mSystemMemoryBuffer(nullptr)
 	{ }
 	{ }
 
 
 	void D3D9IndexBufferCore::initialize()
 	void D3D9IndexBufferCore::initialize()
@@ -303,13 +303,4 @@ namespace BansheeEngine
 
 
 		return true;			
 		return true;			
 	}
 	}
-
-	D3D9IndexBuffer::D3D9IndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage, bool useSystemMemory)
-		: IndexBuffer(idxType, numIndexes, usage, useSystemMemory)
-	{ }
-
-	SPtr<CoreObjectCore> D3D9IndexBuffer::createCore() const
-	{
-		return bs_shared_ptr<D3D9IndexBufferCore>(mUsage, mUseSystemMemory, mProperties);
-	}
 }
 }

+ 6 - 4
BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp

@@ -98,6 +98,7 @@ namespace BansheeEngine
 
 
 		// Also create hardware buffer manager		
 		// Also create hardware buffer manager		
 		HardwareBufferManager::startUp<D3D9HardwareBufferManager>();
 		HardwareBufferManager::startUp<D3D9HardwareBufferManager>();
+		HardwareBufferCoreManager::startUp<D3D9HardwareBufferCoreManager>();
 
 
 		// Create & register HLSL factory		
 		// Create & register HLSL factory		
 		mHLSLProgramFactory = bs_new<D3D9HLSLProgramFactory>();
 		mHLSLProgramFactory = bs_new<D3D9HLSLProgramFactory>();
@@ -149,6 +150,7 @@ namespace BansheeEngine
 
 
 		QueryManager::shutDown();
 		QueryManager::shutDown();
 		TextureManager::shutDown();
 		TextureManager::shutDown();
+		HardwareBufferCoreManager::shutDown();
 		HardwareBufferManager::shutDown();
 		HardwareBufferManager::shutDown();
 		RenderWindowManager::shutDown();
 		RenderWindowManager::shutDown();
 		RenderStateManager::shutDown();
 		RenderStateManager::shutDown();
@@ -1164,7 +1166,7 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	void D3D9RenderSystem::setVertexBuffers(UINT32 index, VertexBufferPtr* buffers, UINT32 numBuffers)
+	void D3D9RenderSystem::setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
@@ -1178,7 +1180,7 @@ namespace BansheeEngine
 		{
 		{
 			if(buffers[i] != nullptr)
 			if(buffers[i] != nullptr)
 			{
 			{
-				SPtr<D3D9VertexBufferCore> d3d9buf = std::static_pointer_cast<D3D9VertexBufferCore>(buffers[i]->getCore());
+				SPtr<D3D9VertexBufferCore> d3d9buf = std::static_pointer_cast<D3D9VertexBufferCore>(buffers[i]);
 				const VertexBufferProperties& vbProps = d3d9buf->getProperties();
 				const VertexBufferProperties& vbProps = d3d9buf->getProperties();
 
 
 				hr = getActiveD3D9Device()->SetStreamSource(
 				hr = getActiveD3D9Device()->SetStreamSource(
@@ -1200,11 +1202,11 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	void D3D9RenderSystem::setIndexBuffer(const IndexBufferPtr& buffer)
+	void D3D9RenderSystem::setIndexBuffer(const SPtr<IndexBufferCore>& buffer)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		SPtr<D3D9IndexBufferCore> d3dIdxBuf = std::static_pointer_cast<D3D9IndexBufferCore>(buffer->getCore());
+		SPtr<D3D9IndexBufferCore> d3dIdxBuf = std::static_pointer_cast<D3D9IndexBufferCore>(buffer);
 
 
 		HRESULT hr = getActiveD3D9Device()->SetIndices( d3dIdxBuf->getD3DIndexBuffer() );
 		HRESULT hr = getActiveD3D9Device()->SetIndices( d3dIdxBuf->getD3DIndexBuffer() );
 		if (FAILED(hr))
 		if (FAILED(hr))

+ 2 - 11
BansheeD3D9RenderSystem/Source/BsD3D9VertexBuffer.cpp

@@ -9,8 +9,8 @@
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
-	D3D9VertexBufferCore::D3D9VertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties)
-		: VertexBufferCore(usage, useSystemMemory, properties), mSystemMemoryBuffer(nullptr)
+	D3D9VertexBufferCore::D3D9VertexBufferCore(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool streamOut)
+		: VertexBufferCore(vertexSize, numVertices, usage, streamOut), mSystemMemoryBuffer(nullptr)
     { }
     { }
 
 
 	void D3D9VertexBufferCore::initialize()
 	void D3D9VertexBufferCore::initialize()
@@ -299,13 +299,4 @@ namespace BansheeEngine
 
 
 		return true;		
 		return true;		
 	}
 	}
-
-	D3D9VertexBuffer::D3D9VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMemory)
-		: VertexBuffer(vertexSize, numVertices, usage, useSystemMemory)
-	{ }
-
-	SPtr<CoreObjectCore> D3D9VertexBuffer::createCore() const
-	{
-		return bs_shared_ptr<D3D9VertexBufferCore>(mUsage, mUseSystemMemory, mProperties);
-	}
 }
 }

+ 2 - 2
BansheeEditor/Source/BsGizmoManager.cpp

@@ -778,10 +778,10 @@ namespace BansheeEngine
 		rs.setVertexDeclaration(vertexData->vertexDeclaration);
 		rs.setVertexDeclaration(vertexData->vertexDeclaration);
 		auto vertexBuffers = vertexData->getBuffers();
 		auto vertexBuffers = vertexData->getBuffers();
 
 
-		VertexBufferPtr vertBuffers[1] = { vertexBuffers.begin()->second };
+		SPtr<VertexBufferCore> vertBuffers[1] = { vertexBuffers.begin()->second };
 		rs.setVertexBuffers(0, vertBuffers, 1);
 		rs.setVertexBuffers(0, vertBuffers, 1);
 
 
-		IndexBufferPtr indexBuffer = mesh->_getIndexBuffer();
+		SPtr<IndexBufferCore> indexBuffer = mesh->_getIndexBuffer();
 		rs.setIndexBuffer(indexBuffer);
 		rs.setIndexBuffer(indexBuffer);
 
 
 		rs.setDrawOperation(DOT_TRIANGLE_LIST);
 		rs.setDrawOperation(DOT_TRIANGLE_LIST);

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

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

+ 0 - 2
BansheeEngine/Source/BsCameraHandler.cpp

@@ -5,8 +5,6 @@
 #include "BsVector2.h"
 #include "BsVector2.h"
 #include "BsAABox.h"
 #include "BsAABox.h"
 #include "BsSphere.h"
 #include "BsSphere.h"
-#include "BsVertexBuffer.h"
-#include "BsIndexBuffer.h"
 #include "BsException.h"
 #include "BsException.h"
 #include "BsRenderSystem.h"
 #include "BsRenderSystem.h"
 #include "BsSceneObject.h"
 #include "BsSceneObject.h"

+ 20 - 15
BansheeGLRenderSystem/Include/BsGLHardwareBufferManager.h

@@ -9,6 +9,22 @@ namespace BansheeEngine
 	 * @brief	Handles creation of OpenGL specific hardware buffers.
 	 * @brief	Handles creation of OpenGL specific hardware buffers.
 	 */
 	 */
     class BS_RSGL_EXPORT GLHardwareBufferManager : public HardwareBufferManager
     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.
+	 */
+    class BS_RSGL_EXPORT GLHardwareBufferCoreManager : public HardwareBufferCoreManager
     {
     {
     public:
     public:
 		/**
 		/**
@@ -23,25 +39,14 @@ namespace BansheeEngine
 
 
 	protected:
 	protected:
 		/**
 		/**
-		 * @copydoc HardwareBufferManager::createVertexBufferImpl
+		 * @copydoc HardwareBufferCoreManager::createVertexBufferImpl
 		 */
 		 */
-        VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, 
+        SPtr<VertexBufferCore> createVertexBufferImpl(UINT32 vertexSize, 
             UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
             UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
 
 
 		/**
 		/**
-		 * @copydoc HardwareBufferManager::createIndexBufferImpl
-		 */
-        IndexBufferPtr createIndexBufferImpl(
-            IndexType itype, UINT32 numIndexes, 
-            GpuBufferUsage usage);
-
-		/** @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl */
-		GpuParamBlockBufferPtr createGpuParamBlockBufferImpl();
-
-		/**
-		 * @copydoc HardwareBufferManager::createGenericBufferImpl
+		 * @copydoc HardwareBufferCoreManager::createIndexBufferImpl
 		 */
 		 */
-		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
-			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
+        SPtr<IndexBufferCore> createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
     };
     };
 }
 }

+ 1 - 20
BansheeGLRenderSystem/Include/BsGLIndexBuffer.h

@@ -11,7 +11,7 @@ namespace BansheeEngine
     class BS_RSGL_EXPORT GLIndexBufferCore : public IndexBufferCore
     class BS_RSGL_EXPORT GLIndexBufferCore : public IndexBufferCore
     {
     {
     public:
     public:
-		GLIndexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const IndexBufferProperties& properties);
+		GLIndexBufferCore(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage);
 		~GLIndexBufferCore() { }
 		~GLIndexBufferCore() { }
 
 
 		/**
 		/**
@@ -55,23 +55,4 @@ namespace BansheeEngine
 		GLuint mBufferId;
 		GLuint mBufferId;
 		bool mZeroLocked;
 		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 SPtr<CoreObjectCore> createCore() const;
-    };
 }
 }

+ 1 - 0
BansheeGLRenderSystem/Include/BsGLPrerequisites.h

@@ -10,6 +10,7 @@ namespace BansheeEngine
     class GLRenderSystem;
     class GLRenderSystem;
     class GLTexture;
     class GLTexture;
 	class GLVertexBuffer;
 	class GLVertexBuffer;
+	class GLVertexBufferCore;
     class GLTextureManager;
     class GLTextureManager;
     class GLSLGpuProgram;
     class GLSLGpuProgram;
     class GLContext;
     class GLContext;

+ 4 - 4
BansheeGLRenderSystem/Include/BsGLRenderSystem.h

@@ -36,12 +36,12 @@ namespace BansheeEngine
         /**
         /**
 		 * @copydoc RenderSystem::setVertexBuffers()
 		 * @copydoc RenderSystem::setVertexBuffers()
 		 */
 		 */
-		void setVertexBuffers(UINT32 index, VertexBufferPtr* buffers, UINT32 numBuffers);
+		void setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers);
 
 
 		/**
 		/**
 		 * @copydoc RenderSystem::setIndexBuffer()
 		 * @copydoc RenderSystem::setIndexBuffer()
 		 */
 		 */
-		void setIndexBuffer(const IndexBufferPtr& buffer);
+		void setIndexBuffer(const SPtr<IndexBufferCore>& buffer);
 
 
 		/**
 		/**
 		 * @copydoc RenderSystem::setVertexDeclaration()
 		 * @copydoc RenderSystem::setVertexDeclaration()
@@ -567,9 +567,9 @@ namespace BansheeEngine
 		UINT32 mDomainUBOffset;
 		UINT32 mDomainUBOffset;
 		UINT32 mComputeUBOffset;
 		UINT32 mComputeUBOffset;
 
 
-		Vector<VertexBufferPtr> mBoundVertexBuffers;
+		Vector<SPtr<VertexBufferCore>> mBoundVertexBuffers;
 		VertexDeclarationPtr mBoundVertexDeclaration;
 		VertexDeclarationPtr mBoundVertexDeclaration;
-		IndexBufferPtr mBoundIndexBuffer;
+		SPtr<IndexBufferCore> mBoundIndexBuffer;
 		DrawOperationType mCurrentDrawOperation;
 		DrawOperationType mCurrentDrawOperation;
 
 
 		GLContext* mMainContext;
 		GLContext* mMainContext;

+ 3 - 3
BansheeGLRenderSystem/Include/BsGLVertexArrayObjectManager.h

@@ -43,11 +43,11 @@ namespace BansheeEngine
 		friend class GLVertexArrayObjectManager;
 		friend class GLVertexArrayObjectManager;
 
 
 		GLVertexArrayObject();
 		GLVertexArrayObject();
-		GLVertexArrayObject(GLuint handle, UINT64 vertexProgramId, GLVertexBuffer** attachedBuffers, UINT32 numBuffers);
+		GLVertexArrayObject(GLuint handle, UINT64 vertexProgramId, GLVertexBufferCore** attachedBuffers, UINT32 numBuffers);
 
 
 		GLuint mHandle;
 		GLuint mHandle;
 		UINT64 mVertProgId;
 		UINT64 mVertProgId;
-		GLVertexBuffer** mAttachedBuffers;
+		GLVertexBufferCore** mAttachedBuffers;
 		UINT32 mNumBuffers;
 		UINT32 mNumBuffers;
 	};
 	};
 
 
@@ -67,7 +67,7 @@ namespace BansheeEngine
 		 *			Lifetime of returned VAO is managed by the vertex buffers that it binds.
 		 *			Lifetime of returned VAO is managed by the vertex buffers that it binds.
 		 */
 		 */
 		const GLVertexArrayObject& getVAO(const GLSLGpuProgramPtr& vertexProgram, 
 		const GLVertexArrayObject& getVAO(const GLSLGpuProgramPtr& vertexProgram, 
-			const VertexDeclarationPtr& vertexDecl, const Vector<VertexBufferPtr>& boundBuffers);
+			const VertexDeclarationPtr& vertexDecl, const Vector<SPtr<VertexBufferCore>>& boundBuffers);
 
 
 		/**
 		/**
 		 * @brief	Called when a vertex buffer containing the provided VAO is destroyed.
 		 * @brief	Called when a vertex buffer containing the provided VAO is destroyed.

+ 1 - 20
BansheeGLRenderSystem/Include/BsGLVertexBuffer.h

@@ -12,7 +12,7 @@ namespace BansheeEngine
     class BS_RSGL_EXPORT GLVertexBufferCore : public VertexBufferCore
     class BS_RSGL_EXPORT GLVertexBufferCore : public VertexBufferCore
     {
     {
     public:
     public:
-		GLVertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties);
+		GLVertexBufferCore(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool streamOut);
 		~GLVertexBufferCore() { }
 		~GLVertexBufferCore() { }
 
 
 		/**
 		/**
@@ -67,23 +67,4 @@ namespace BansheeEngine
 
 
 		Vector<GLVertexArrayObject> mVAObjects;
 		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 SPtr<CoreObjectCore> createCore() const;
-    };
 }
 }

+ 12 - 13
BansheeGLRenderSystem/Source/BsGLHardwareBufferManager.cpp

@@ -9,17 +9,6 @@
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
-    VertexBufferPtr GLHardwareBufferManager::createVertexBufferImpl(
-        UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
-    {
-		return bs_core_ptr<GLVertexBuffer, PoolAlloc>(new (bs_alloc<GLVertexBuffer, PoolAlloc>()) GLVertexBuffer(vertexSize, numVerts, 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));
-    }
-
 	GpuParamBlockBufferPtr GLHardwareBufferManager::createGpuParamBlockBufferImpl()
 	GpuParamBlockBufferPtr GLHardwareBufferManager::createGpuParamBlockBufferImpl()
 	{
 	{
 		return bs_core_ptr<GLGpuParamBlockBuffer, PoolAlloc>(new (bs_alloc<GLGpuParamBlockBuffer, PoolAlloc>()) GLGpuParamBlockBuffer());
 		return bs_core_ptr<GLGpuParamBlockBuffer, PoolAlloc>(new (bs_alloc<GLGpuParamBlockBuffer, PoolAlloc>()) GLGpuParamBlockBuffer());
@@ -31,7 +20,17 @@ namespace BansheeEngine
 		return bs_core_ptr<GLGpuBuffer, PoolAlloc>(new (bs_alloc<GLGpuBuffer, PoolAlloc>()) GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 		return bs_core_ptr<GLGpuBuffer, PoolAlloc>(new (bs_alloc<GLGpuBuffer, PoolAlloc>()) GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 	}
 	}
 
 
-    GLenum GLHardwareBufferManager::getGLUsage(GpuBufferUsage usage)
+	SPtr<VertexBufferCore> GLHardwareBufferCoreManager::createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
+	{
+		return bs_shared_ptr<GLVertexBufferCore>(vertexSize, numVerts, usage, streamOut);
+	}
+
+	SPtr<IndexBufferCore> GLHardwareBufferCoreManager::createIndexBufferImpl(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+	{
+		return bs_shared_ptr<GLIndexBufferCore>(itype, numIndexes, usage);
+	}
+
+    GLenum GLHardwareBufferCoreManager::getGLUsage(GpuBufferUsage usage)
     {
     {
         switch(usage)
         switch(usage)
         {
         {
@@ -44,7 +43,7 @@ namespace BansheeEngine
         };
         };
     }
     }
 
 
-    GLenum GLHardwareBufferManager::getGLType(VertexElementType type)
+    GLenum GLHardwareBufferCoreManager::getGLType(VertexElementType type)
     {
     {
         switch(type)
         switch(type)
         {
         {

+ 3 - 12
BansheeGLRenderSystem/Source/BsGLIndexBuffer.cpp

@@ -5,8 +5,8 @@
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
-	GLIndexBufferCore::GLIndexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const IndexBufferProperties& properties)
-		:IndexBufferCore(usage, useSystemMemory, properties), mZeroLocked(false)
+	GLIndexBufferCore::GLIndexBufferCore(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage)
+		:IndexBufferCore(idxType, numIndexes, usage), mZeroLocked(false)
 	{  }
 	{  }
 
 
 	void GLIndexBufferCore::initialize()
 	void GLIndexBufferCore::initialize()
@@ -21,7 +21,7 @@ namespace BansheeEngine
 		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBufferId);
 		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBufferId);
 
 
 		glBufferData(GL_ELEMENT_ARRAY_BUFFER, mSizeInBytes, NULL, 
 		glBufferData(GL_ELEMENT_ARRAY_BUFFER, mSizeInBytes, NULL, 
-			GLHardwareBufferManager::getGLUsage(mUsage));
+			GLHardwareBufferCoreManager::getGLUsage(mUsage));
 
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_IndexBuffer);
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_IndexBuffer);
 		IndexBufferCore::initialize();
 		IndexBufferCore::initialize();
@@ -130,13 +130,4 @@ namespace BansheeEngine
 		memcpy(bufferData, pSource, length);
 		memcpy(bufferData, pSource, length);
 		unlock();
 		unlock();
     }
     }
-
-	GLIndexBuffer::GLIndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage)
-		:IndexBuffer(idxType, numIndexes, usage, false)
-	{  }
-
-	SPtr<CoreObjectCore> GLIndexBuffer::createCore() const
-	{
-		return bs_shared_ptr<GLIndexBufferCore>(mUsage, mUseSystemMemory, mProperties);
-	}
 }
 }

+ 5 - 3
BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp

@@ -169,6 +169,7 @@ namespace BansheeEngine
 		}
 		}
 
 
 		// Deleting the hardware buffer manager.  Has to be done before the mGLSupport->stop().
 		// Deleting the hardware buffer manager.  Has to be done before the mGLSupport->stop().
+		HardwareBufferCoreManager::shutDown();
 		HardwareBufferManager::shutDown();
 		HardwareBufferManager::shutDown();
 		GLRTTManager::shutDown();
 		GLRTTManager::shutDown();
 
 
@@ -642,7 +643,7 @@ namespace BansheeEngine
 		glDisable(GL_SCISSOR_TEST);
 		glDisable(GL_SCISSOR_TEST);
 	}
 	}
 
 
-	void GLRenderSystem::setVertexBuffers(UINT32 index, VertexBufferPtr* buffers, UINT32 numBuffers)
+	void GLRenderSystem::setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
@@ -669,7 +670,7 @@ namespace BansheeEngine
 		mCurrentDrawOperation = op;
 		mCurrentDrawOperation = op;
 	}
 	}
 
 
-	void GLRenderSystem::setIndexBuffer(const IndexBufferPtr& buffer)
+	void GLRenderSystem::setIndexBuffer(const SPtr<IndexBufferCore>& buffer)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
@@ -706,7 +707,7 @@ namespace BansheeEngine
 
 
 		beginDraw();
 		beginDraw();
 
 
-		SPtr<GLIndexBufferCore> indexBuffer = std::static_pointer_cast<GLIndexBufferCore>(mBoundIndexBuffer->getCore());
+		SPtr<GLIndexBufferCore> indexBuffer = std::static_pointer_cast<GLIndexBufferCore>(mBoundIndexBuffer);
 		const IndexBufferProperties& ibProps = indexBuffer->getProperties();
 		const IndexBufferProperties& ibProps = indexBuffer->getProperties();
 		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer->getGLBufferId());
 		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer->getGLBufferId());
 
 
@@ -1706,6 +1707,7 @@ namespace BansheeEngine
 #endif
 #endif
 
 
 		HardwareBufferManager::startUp<GLHardwareBufferManager>();
 		HardwareBufferManager::startUp<GLHardwareBufferManager>();
+		HardwareBufferCoreManager::startUp<GLHardwareBufferCoreManager>();
 
 
 		// GPU Program Manager setup
 		// GPU Program Manager setup
 		if(caps->isShaderProfileSupported("glsl"))
 		if(caps->isShaderProfileSupported("glsl"))

+ 13 - 16
BansheeGLRenderSystem/Source/BsGLVertexArrayObjectManager.cpp

@@ -15,7 +15,7 @@ namespace BansheeEngine
 	{ }
 	{ }
 
 
 	GLVertexArrayObject::GLVertexArrayObject(GLuint handle, UINT64 vertexProgramId, 
 	GLVertexArrayObject::GLVertexArrayObject(GLuint handle, UINT64 vertexProgramId, 
-		GLVertexBuffer** attachedBuffers, UINT32 numBuffers)
+		GLVertexBufferCore** attachedBuffers, UINT32 numBuffers)
 		:mHandle(handle), mVertProgId(vertexProgramId), mAttachedBuffers(attachedBuffers), mNumBuffers(numBuffers)
 		:mHandle(handle), mVertProgId(vertexProgramId), mAttachedBuffers(attachedBuffers), mNumBuffers(numBuffers)
 	{ }
 	{ }
 
 
@@ -25,7 +25,7 @@ namespace BansheeEngine
 		hash_combine(seed, vao.mVertProgId);
 		hash_combine(seed, vao.mVertProgId);
 
 
 		for (UINT32 i = 0; i < vao.mNumBuffers; i++)
 		for (UINT32 i = 0; i < vao.mNumBuffers; i++)
-			hash_combine(seed, vao.mAttachedBuffers[i]->getInternalID());
+			hash_combine(seed, vao.mAttachedBuffers[i]->getGLBufferId());
 
 
 		return seed;
 		return seed;
 	}
 	}
@@ -40,7 +40,7 @@ namespace BansheeEngine
 
 
 		for (UINT32 i = 0; i < a.mNumBuffers; i++)
 		for (UINT32 i = 0; i < a.mNumBuffers; i++)
 		{
 		{
-			if (a.mAttachedBuffers[i]->getInternalID() != b.mAttachedBuffers[i]->getInternalID())
+			if (a.mAttachedBuffers[i]->getGLBufferId() != b.mAttachedBuffers[i]->getGLBufferId())
 				return false;
 				return false;
 		}
 		}
 
 
@@ -57,7 +57,7 @@ namespace BansheeEngine
 
 
 		for (UINT32 i = 0; i < mNumBuffers; i++)
 		for (UINT32 i = 0; i < mNumBuffers; i++)
 		{
 		{
-			if (mAttachedBuffers[i]->getInternalID() != obj.mAttachedBuffers[i]->getInternalID())
+			if (mAttachedBuffers[i]->getGLBufferId() != obj.mAttachedBuffers[i]->getGLBufferId())
 				return false;
 				return false;
 		}
 		}
 
 
@@ -75,7 +75,7 @@ namespace BansheeEngine
 	}
 	}
 
 
 	const GLVertexArrayObject& GLVertexArrayObjectManager::getVAO(const GLSLGpuProgramPtr& vertexProgram,
 	const GLVertexArrayObject& GLVertexArrayObjectManager::getVAO(const GLSLGpuProgramPtr& vertexProgram,
-		const VertexDeclarationPtr& vertexDecl, const Vector<VertexBufferPtr>& boundBuffers)
+		const VertexDeclarationPtr& vertexDecl, const Vector<SPtr<VertexBufferCore>>& boundBuffers)
 	{
 	{
 		UINT16 maxStreamIdx = 0;
 		UINT16 maxStreamIdx = 0;
 		const VertexDeclaration::VertexElementList& decl = vertexDecl->getElements();
 		const VertexDeclaration::VertexElementList& decl = vertexDecl->getElements();
@@ -85,7 +85,7 @@ namespace BansheeEngine
 		UINT32 numStreams = maxStreamIdx + 1;
 		UINT32 numStreams = maxStreamIdx + 1;
 		UINT32 numUsedBuffers = 0;
 		UINT32 numUsedBuffers = 0;
 		INT32* streamToSeqIdx = stackAllocN<INT32>(numStreams);
 		INT32* streamToSeqIdx = stackAllocN<INT32>(numStreams);
-		GLVertexBuffer** usedBuffers = stackAllocN<GLVertexBuffer*>((UINT32)boundBuffers.size());
+		GLVertexBufferCore** usedBuffers = stackAllocN<GLVertexBufferCore*>((UINT32)boundBuffers.size());
 		
 		
 		memset(usedBuffers, 0, (UINT32)boundBuffers.size() * sizeof(GLVertexBuffer*));
 		memset(usedBuffers, 0, (UINT32)boundBuffers.size() * sizeof(GLVertexBuffer*));
 
 
@@ -101,11 +101,11 @@ namespace BansheeEngine
 			if (streamToSeqIdx[streamIdx] != -1) // Already visited
 			if (streamToSeqIdx[streamIdx] != -1) // Already visited
 				continue;
 				continue;
 
 
-			VertexBufferPtr vertexBuffer = boundBuffers[streamIdx];
+			SPtr<VertexBufferCore> vertexBuffer = boundBuffers[streamIdx];
 			streamToSeqIdx[streamIdx] = (INT32)numUsedBuffers;
 			streamToSeqIdx[streamIdx] = (INT32)numUsedBuffers;
 
 
 			if (vertexBuffer != nullptr)
 			if (vertexBuffer != nullptr)
-				usedBuffers[numUsedBuffers] = static_cast<GLVertexBuffer*>(vertexBuffer.get()); 
+				usedBuffers[numUsedBuffers] = static_cast<GLVertexBufferCore*>(vertexBuffer.get()); 
 			else
 			else
 				usedBuffers[numUsedBuffers] = nullptr;
 				usedBuffers[numUsedBuffers] = nullptr;
 
 
@@ -154,7 +154,7 @@ 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?
 			// TODO - We might also want to check the size of input and buffer, and make sure they match? Or does OpenGL handle that internally?
 
 
-			SPtr<GLVertexBufferCore> vertexBuffer = std::static_pointer_cast<GLVertexBufferCore>(usedBuffers[seqIdx]->getCore());
+			GLVertexBufferCore* vertexBuffer = usedBuffers[seqIdx];
 			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 			const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
 
 
 			glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer->getGLBufferId());
 			glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer->getGLBufferId());
@@ -173,7 +173,7 @@ namespace BansheeEngine
 			};
 			};
 
 
 			UINT16 typeCount = VertexElement::getTypeCount(elem.getType());
 			UINT16 typeCount = VertexElement::getTypeCount(elem.getType());
-			GLenum glType = GLHardwareBufferManager::getGLType(elem.getType());
+			GLenum glType = GLHardwareBufferCoreManager::getGLType(elem.getType());
 			GLsizei vertexSize = static_cast<GLsizei>(vbProps.getVertexSize());
 			GLsizei vertexSize = static_cast<GLsizei>(vbProps.getVertexSize());
 			glVertexAttribPointer(attribLocation, typeCount, glType, normalized,
 			glVertexAttribPointer(attribLocation, typeCount, glType, normalized,
 				vertexSize, bufferData);
 				vertexSize, bufferData);
@@ -181,13 +181,11 @@ namespace BansheeEngine
 			glEnableVertexAttribArray(attribLocation);
 			glEnableVertexAttribArray(attribLocation);
 		}
 		}
 
 
-		wantedVAO.mAttachedBuffers = (GLVertexBuffer**)bs_alloc(numUsedBuffers * sizeof(GLVertexBuffer*));
+		wantedVAO.mAttachedBuffers = (GLVertexBufferCore**)bs_alloc(numUsedBuffers * sizeof(GLVertexBufferCore*));
 		for (UINT32 i = 0; i < numUsedBuffers; i++)
 		for (UINT32 i = 0; i < numUsedBuffers; i++)
 		{
 		{
 			wantedVAO.mAttachedBuffers[i] = usedBuffers[i];
 			wantedVAO.mAttachedBuffers[i] = usedBuffers[i];
-
-			SPtr<GLVertexBufferCore> curVertexBuffer = std::static_pointer_cast<GLVertexBufferCore>(usedBuffers[i]->getCore());
-			curVertexBuffer->registerVAO(wantedVAO);
+			usedBuffers[i]->registerVAO(wantedVAO);
 		}
 		}
 
 
 		stackDeallocLast(usedBuffers);
 		stackDeallocLast(usedBuffers);
@@ -206,8 +204,7 @@ namespace BansheeEngine
 
 
 		for (UINT32 i = 0; i < vao.mNumBuffers; i++)
 		for (UINT32 i = 0; i < vao.mNumBuffers; i++)
 		{
 		{
-			SPtr<GLVertexBufferCore> curVertexBuffer = std::static_pointer_cast<GLVertexBufferCore>(vao.mAttachedBuffers[i]->getCore());
-			curVertexBuffer->unregisterVAO(vao);
+			vao.mAttachedBuffers[i]->unregisterVAO(vao);
 		}
 		}
 
 
 		glDeleteVertexArrays(1, &vao.mHandle);
 		glDeleteVertexArrays(1, &vao.mHandle);

+ 3 - 13
BansheeGLRenderSystem/Source/BsGLVertexBuffer.cpp

@@ -6,8 +6,8 @@
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
-	GLVertexBufferCore::GLVertexBufferCore(GpuBufferUsage usage, bool useSystemMemory, const VertexBufferProperties& properties)
-		:VertexBufferCore(usage, useSystemMemory, properties), mZeroLocked(false)
+	GLVertexBufferCore::GLVertexBufferCore(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool streamOut)
+		:VertexBufferCore(vertexSize, numVertices, usage, streamOut), mZeroLocked(false)
     {
     {
 
 
     }
     }
@@ -25,7 +25,7 @@ namespace BansheeEngine
 		glBindBuffer(GL_ARRAY_BUFFER, mBufferId);
 		glBindBuffer(GL_ARRAY_BUFFER, mBufferId);
 
 
 		glBufferData(GL_ARRAY_BUFFER, mSizeInBytes, NULL,
 		glBufferData(GL_ARRAY_BUFFER, mSizeInBytes, NULL,
-			GLHardwareBufferManager::getGLUsage(mUsage));
+			GLHardwareBufferCoreManager::getGLUsage(mUsage));
 
 
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_VertexBuffer);
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_VertexBuffer);
 		VertexBufferCore::initialize();
 		VertexBufferCore::initialize();
@@ -150,14 +150,4 @@ namespace BansheeEngine
 		memcpy(bufferData, pSource, length);
 		memcpy(bufferData, pSource, length);
 		unlock();
 		unlock();
     }
     }
-
-	GLVertexBuffer::GLVertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage)
-		: VertexBuffer(vertexSize, numVertices, usage, false)
-	{
-	}
-
-	SPtr<CoreObjectCore> GLVertexBuffer::createCore() const
-	{
-		return bs_shared_ptr<GLVertexBufferCore>(mUsage, mUseSystemMemory, mProperties);
-	}
 }
 }