瀏覽代碼

Mesh importing

Marko Pintera 13 年之前
父節點
當前提交
98e7cb3402
共有 27 個文件被更改,包括 314 次插入214 次删除
  1. 1 1
      CamelotD3D9Renderer/Include/CmD3D9HardwareBufferManager.h
  2. 1 1
      CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h
  3. 0 3
      CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h
  4. 2 3
      CamelotD3D9Renderer/Source/CmD3D9HardwareBufferManager.cpp
  5. 4 4
      CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp
  6. 0 8
      CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp
  7. 15 11
      CamelotFBXImporter/Source/CmFBXImporter.cpp
  8. 1 1
      CamelotGLRenderer/Include/CmGLRenderSystem.h
  9. 0 1
      CamelotGLRenderer/Source/CmGLDefaultHardwareBufferManager.cpp
  10. 0 1
      CamelotGLRenderer/Source/CmGLHardwareBufferManager.cpp
  11. 1 1
      CamelotGLRenderer/Source/CmGLRenderSystem.cpp
  12. 1 0
      CamelotRenderer/Include/CmApplication.h
  13. 3 17
      CamelotRenderer/Include/CmHardwareBufferManager.h
  14. 1 1
      CamelotRenderer/Include/CmHardwareVertexBuffer.h
  15. 11 3
      CamelotRenderer/Include/CmMesh.h
  16. 2 2
      CamelotRenderer/Include/CmMeshData.h
  17. 3 3
      CamelotRenderer/Include/CmMeshDataRTTI.h
  18. 2 0
      CamelotRenderer/Include/CmPrerequisites.h
  19. 1 1
      CamelotRenderer/Include/CmRenderSystem.h
  20. 4 4
      CamelotRenderer/Include/CmVertexIndexData.h
  21. 22 8
      CamelotRenderer/Source/CmApplication.cpp
  22. 0 1
      CamelotRenderer/Source/CmDefaultHardwareBufferManager.cpp
  23. 4 30
      CamelotRenderer/Source/CmHardwareBufferManager.cpp
  24. 2 2
      CamelotRenderer/Source/CmHardwareVertexBuffer.cpp
  25. 226 101
      CamelotRenderer/Source/CmMesh.cpp
  26. 4 1
      CamelotRenderer/Source/CmMeshData.cpp
  27. 3 5
      CamelotRenderer/Source/CmVertexIndexData.cpp

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9HardwareBufferManager.h

@@ -38,7 +38,7 @@ namespace CamelotEngine {
     {
     {
     protected:     
     protected:     
         /// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs
         /// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs
-        VertexDeclaration* createVertexDeclarationImpl(void);
+        VertexDeclarationPtr createVertexDeclarationImpl(void);
         /// Internal method for destroys a vertex declaration, may be overridden by certain rendering APIs
         /// Internal method for destroys a vertex declaration, may be overridden by certain rendering APIs
         void destroyVertexDeclarationImpl(VertexDeclaration* decl);
         void destroyVertexDeclarationImpl(VertexDeclaration* decl);
 
 

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -263,7 +263,7 @@ namespace CamelotEngine
 		void _setPolygonMode(PolygonMode level);
 		void _setPolygonMode(PolygonMode level);
         void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
         void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
 		void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
 		void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
-		void setVertexDeclaration(VertexDeclaration* decl);
+		void setVertexDeclaration(VertexDeclarationPtr decl);
 		void setVertexBufferBinding(VertexBufferBinding* binding);
 		void setVertexBufferBinding(VertexBufferBinding* binding);
         void _render(const RenderOperation& op);
         void _render(const RenderOperation& op);
         /** See
         /** See

+ 0 - 3
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -80,9 +80,6 @@ namespace CamelotEngine
 		/// @copydoc RenderTarget::_beginUpdate
 		/// @copydoc RenderTarget::_beginUpdate
 		void _beginUpdate();
 		void _beginUpdate();
 	
 	
-		/// @copydoc RenderTarget::_updateViewport
-		void _updateViewport(Viewport* viewport, bool updateStatistics = true);
-
 		/// @copydoc RenderTarget::_endUpdate
 		/// @copydoc RenderTarget::_endUpdate
 		void _endUpdate();
 		void _endUpdate();
 
 

+ 2 - 3
CamelotD3D9Renderer/Source/CmD3D9HardwareBufferManager.cpp

@@ -39,7 +39,6 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     D3D9HardwareBufferManagerBase::~D3D9HardwareBufferManagerBase()
     D3D9HardwareBufferManagerBase::~D3D9HardwareBufferManagerBase()
     {
     {
-        destroyAllDeclarations();
         destroyAllBindings();
         destroyAllBindings();
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
@@ -110,9 +109,9 @@ namespace CamelotEngine {
             
             
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    VertexDeclaration* D3D9HardwareBufferManagerBase::createVertexDeclarationImpl(void)
+    VertexDeclarationPtr D3D9HardwareBufferManagerBase::createVertexDeclarationImpl(void)
     {
     {
-        return new D3D9VertexDeclaration();
+        return VertexDeclarationPtr(new D3D9VertexDeclaration());
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     void D3D9HardwareBufferManagerBase::destroyVertexDeclarationImpl(VertexDeclaration* decl)
     void D3D9HardwareBufferManagerBase::destroyVertexDeclarationImpl(VertexDeclaration* decl)

+ 4 - 4
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -35,6 +35,7 @@ THE SOFTWARE.
 #include "CmD3D9TextureManager.h"
 #include "CmD3D9TextureManager.h"
 #include "CmD3D9Texture.h"
 #include "CmD3D9Texture.h"
 #include "CmMath.h"
 #include "CmMath.h"
+#include "CmCamera.h"
 #include "CmD3D9HardwareBufferManager.h"
 #include "CmD3D9HardwareBufferManager.h"
 #include "CmD3D9HardwareIndexBuffer.h"
 #include "CmD3D9HardwareIndexBuffer.h"
 #include "CmD3D9HardwareVertexBuffer.h"
 #include "CmD3D9HardwareVertexBuffer.h"
@@ -43,7 +44,6 @@ THE SOFTWARE.
 #include "CmD3D9GpuProgramManager.h"
 #include "CmD3D9GpuProgramManager.h"
 #include "CmD3D9HLSLProgramFactory.h"
 #include "CmD3D9HLSLProgramFactory.h"
 #include "CmD3D9HardwareOcclusionQuery.h"
 #include "CmD3D9HardwareOcclusionQuery.h"
-#include "CmFrustum.h"
 #include "CmD3D9MultiRenderTarget.h"
 #include "CmD3D9MultiRenderTarget.h"
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9ResourceManager.h"
 #include "CmD3D9ResourceManager.h"
@@ -2498,12 +2498,12 @@ namespace CamelotEngine
 		delete context;
 		delete context;
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setVertexDeclaration(VertexDeclaration* decl)
+	void D3D9RenderSystem::setVertexDeclaration(VertexDeclarationPtr decl)
 	{
 	{
 		HRESULT hr;
 		HRESULT hr;
 
 
-		D3D9VertexDeclaration* d3ddecl = 
-			static_cast<D3D9VertexDeclaration*>(decl);
+		std::shared_ptr<D3D9VertexDeclaration> d3ddecl = 
+			std::static_pointer_cast<D3D9VertexDeclaration>(decl);
 
 
 		if (FAILED(hr = getActiveD3D9Device()->SetVertexDeclaration(d3ddecl->getD3DVertexDeclaration())))
 		if (FAILED(hr = getActiveD3D9Device()->SetVertexDeclaration(d3ddecl->getD3DVertexDeclaration())))
 		{
 		{

+ 0 - 8
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -772,14 +772,6 @@ namespace CamelotEngine
 		RenderWindow::_beginUpdate();
 		RenderWindow::_beginUpdate();
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-	void D3D9RenderWindow::_updateViewport(Viewport* viewport, bool updateStatistics)
-	{
-		if (mDeviceValid)
-		{
-			RenderWindow::_updateViewport(viewport, updateStatistics);
-		}
-	}
-	//---------------------------------------------------------------------
 	void D3D9RenderWindow::_endUpdate()
 	void D3D9RenderWindow::_endUpdate()
 	{
 	{
 		RenderWindow::_endUpdate();
 		RenderWindow::_endUpdate();

+ 15 - 11
CamelotFBXImporter/Source/CmFBXImporter.cpp

@@ -4,6 +4,7 @@
 #include "CmDataStream.h"
 #include "CmDataStream.h"
 #include "CmPath.h"
 #include "CmPath.h"
 #include "CmMeshData.h"
 #include "CmMeshData.h"
+#include "CmMesh.h"
 #include "CmVector2.h"
 #include "CmVector2.h"
 #include "CmVector3.h"
 #include "CmVector3.h"
 #include "CmVector4.h"
 #include "CmVector4.h"
@@ -44,13 +45,14 @@ namespace CamelotEngine
 		startUpSdk(fbxManager, fbxScene);
 		startUpSdk(fbxManager, fbxScene);
 		loadScene(fbxManager, fbxScene, filePath);
 		loadScene(fbxManager, fbxScene, filePath);
 
 
-		MeshDataPtr mesh = parseScene(fbxManager, fbxScene);	
+		MeshDataPtr meshData = parseScene(fbxManager, fbxScene);	
 
 
 		shutDownSdk(fbxManager);
 		shutDownSdk(fbxManager);
 
 
-		// TODO - Free FBXMeshData
+		MeshPtr mesh(new Mesh());
+		mesh->setMeshData(meshData);
 
 
-		return nullptr;
+		return mesh;
 	}
 	}
 
 
 	void FBXImporter::startUpSdk(FbxManager*& manager, FbxScene*& scene)
 	void FBXImporter::startUpSdk(FbxManager*& manager, FbxScene*& scene)
@@ -186,7 +188,7 @@ namespace CamelotEngine
 					// Count the faces of each material
 					// Count the faces of each material
 					for (int lPolygonIndex = 0; lPolygonIndex < lPolygonCount; ++lPolygonIndex)
 					for (int lPolygonIndex = 0; lPolygonIndex < lPolygonCount; ++lPolygonIndex)
 					{
 					{
-						const int lMaterialIndex = lMaterialIndice->GetAt(lPolygonIndex);
+						const UINT32 lMaterialIndex = (UINT32)lMaterialIndice->GetAt(lPolygonIndex);
 						if (meshData->subMeshes.size() < lMaterialIndex + 1)
 						if (meshData->subMeshes.size() < lMaterialIndex + 1)
 						{
 						{
 							meshData->subMeshes.resize(lMaterialIndex + 1);
 							meshData->subMeshes.resize(lMaterialIndex + 1);
@@ -561,44 +563,46 @@ namespace CamelotEngine
 		}
 		}
 
 
 		UINT32 offset = 0;
 		UINT32 offset = 0;
-		meshData->declaration.addElement(0, offset, VET_FLOAT3, VES_POSITION, 0);
+		meshData->declaration->addElement(0, offset, VET_FLOAT3, VES_POSITION, 0);
 		offset += VertexElement::getTypeSize(VET_FLOAT3);
 		offset += VertexElement::getTypeSize(VET_FLOAT3);
 
 
 		if(vertexData->color)
 		if(vertexData->color)
 		{
 		{
-			meshData->declaration.addElement(0, offset, VET_COLOUR, VES_DIFFUSE, 0);
+			meshData->declaration->addElement(0, offset, VET_COLOUR, VES_DIFFUSE, 0);
 			offset += VertexElement::getTypeSize(VET_COLOUR);
 			offset += VertexElement::getTypeSize(VET_COLOUR);
 		}
 		}
 
 
 		if(vertexData->normal)
 		if(vertexData->normal)
 		{
 		{
-			meshData->declaration.addElement(0, offset, VET_FLOAT3, VES_NORMAL, 0);
+			meshData->declaration->addElement(0, offset, VET_FLOAT3, VES_NORMAL, 0);
 			offset += VertexElement::getTypeSize(VET_FLOAT3);
 			offset += VertexElement::getTypeSize(VET_FLOAT3);
 		}
 		}
 
 
 		if(vertexData->tangent)
 		if(vertexData->tangent)
 		{
 		{
-			meshData->declaration.addElement(0, offset, VET_FLOAT3, VES_TANGENT, 0);
+			meshData->declaration->addElement(0, offset, VET_FLOAT3, VES_TANGENT, 0);
 			offset += VertexElement::getTypeSize(VET_FLOAT3);
 			offset += VertexElement::getTypeSize(VET_FLOAT3);
 		}
 		}
 
 
 		// TODO - Storing bitangents with the mesh is probably not a good idea. It's likely cheaper to recreate them in the shader
 		// TODO - Storing bitangents with the mesh is probably not a good idea. It's likely cheaper to recreate them in the shader
 		if(vertexData->bitangent)
 		if(vertexData->bitangent)
 		{
 		{
-			meshData->declaration.addElement(0, offset, VET_FLOAT3, VES_BITANGENT, 0);
+			meshData->declaration->addElement(0, offset, VET_FLOAT3, VES_BITANGENT, 0);
 			offset += VertexElement::getTypeSize(VET_FLOAT3);
 			offset += VertexElement::getTypeSize(VET_FLOAT3);
 		}
 		}
 
 
 		if(vertexData->uv0)
 		if(vertexData->uv0)
 		{
 		{
-			meshData->declaration.addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
+			meshData->declaration->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
 			offset += VertexElement::getTypeSize(VET_FLOAT2);
 			offset += VertexElement::getTypeSize(VET_FLOAT2);
 		}
 		}
 
 
 		if(vertexData->uv1)
 		if(vertexData->uv1)
 		{
 		{
-			meshData->declaration.addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 1);
+			meshData->declaration->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 1);
 			offset += VertexElement::getTypeSize(VET_FLOAT2);
 			offset += VertexElement::getTypeSize(VET_FLOAT2);
 		}
 		}
+
+		return meshData;
 	}
 	}
 }
 }

+ 1 - 1
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -391,7 +391,7 @@ namespace CamelotEngine {
         /** See
         /** See
           RenderSystem
           RenderSystem
          */
          */
-		void setVertexDeclaration(VertexDeclaration* decl);
+		void setVertexDeclaration(VertexDeclarationPtr decl);
         /** See
         /** See
           RenderSystem
           RenderSystem
          */
          */

+ 0 - 1
CamelotGLRenderer/Source/CmGLDefaultHardwareBufferManager.cpp

@@ -147,7 +147,6 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     GLDefaultHardwareBufferManagerBase::~GLDefaultHardwareBufferManagerBase()
     GLDefaultHardwareBufferManagerBase::~GLDefaultHardwareBufferManagerBase()
 	{
 	{
-        destroyAllDeclarations();
         destroyAllBindings();
         destroyAllBindings();
 	}
 	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------

+ 0 - 1
CamelotGLRenderer/Source/CmGLHardwareBufferManager.cpp

@@ -76,7 +76,6 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     GLHardwareBufferManagerBase::~GLHardwareBufferManagerBase()
     GLHardwareBufferManagerBase::~GLHardwareBufferManagerBase()
     {
     {
-        destroyAllDeclarations();
         destroyAllBindings();
         destroyAllBindings();
 
 
 		_aligned_free(mScratchBufferPool);
 		_aligned_free(mScratchBufferPool);

+ 1 - 1
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -2148,7 +2148,7 @@ namespace CamelotEngine {
 		activateGLTextureUnit(0);
 		activateGLTextureUnit(0);
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-	void GLRenderSystem::setVertexDeclaration(VertexDeclaration* decl)
+	void GLRenderSystem::setVertexDeclaration(VertexDeclarationPtr decl)
 	{
 	{
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------

+ 1 - 0
CamelotRenderer/Include/CmApplication.h

@@ -30,6 +30,7 @@ namespace CamelotEngine
 			HighLevelGpuProgramPtr mFragProg;
 			HighLevelGpuProgramPtr mFragProg;
 			HighLevelGpuProgramPtr mVertProg;
 			HighLevelGpuProgramPtr mVertProg;
 			TexturePtr mDbgTexture;
 			TexturePtr mDbgTexture;
+			MeshPtr mDbgMesh;
 			GameObjectPtr mCameraGO;
 			GameObjectPtr mCameraGO;
 	};
 	};
 
 

+ 3 - 17
CamelotRenderer/Include/CmHardwareBufferManager.h

@@ -68,26 +68,19 @@ namespace CamelotEngine {
         IndexBufferList mIndexBuffers;
         IndexBufferList mIndexBuffers;
 
 
 
 
-        typedef set<VertexDeclaration*>::type VertexDeclarationList;
 		typedef set<VertexBufferBinding*>::type VertexBufferBindingList;
 		typedef set<VertexBufferBinding*>::type VertexBufferBindingList;
-        VertexDeclarationList mVertexDeclarations;
 		VertexBufferBindingList mVertexBufferBindings;
 		VertexBufferBindingList mVertexBufferBindings;
 
 
 		// Mutexes
 		// Mutexes
 		CM_MUTEX(mVertexBuffersMutex)
 		CM_MUTEX(mVertexBuffersMutex)
 		CM_MUTEX(mIndexBuffersMutex)
 		CM_MUTEX(mIndexBuffersMutex)
-		CM_MUTEX(mVertexDeclarationsMutex)
 		CM_MUTEX(mVertexBufferBindingsMutex)
 		CM_MUTEX(mVertexBufferBindingsMutex)
 
 
-        /// Internal method for destroys all vertex declarations
-        virtual void destroyAllDeclarations(void);
         /// Internal method for destroys all vertex buffer bindings
         /// Internal method for destroys all vertex buffer bindings
         virtual void destroyAllBindings(void);
         virtual void destroyAllBindings(void);
 
 
         /// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs
         /// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs
-        virtual VertexDeclaration* createVertexDeclarationImpl(void);
-        /// Internal method for destroys a vertex declaration, may be overridden by certain rendering APIs
-        virtual void destroyVertexDeclarationImpl(VertexDeclaration* decl);
+        virtual VertexDeclarationPtr createVertexDeclarationImpl(void);
 
 
 		/// Internal method for creates a new VertexBufferBinding, may be overridden by certain rendering APIs
 		/// Internal method for creates a new VertexBufferBinding, may be overridden by certain rendering APIs
 		virtual VertexBufferBinding* createVertexBufferBindingImpl(void);
 		virtual VertexBufferBinding* createVertexBufferBindingImpl(void);
@@ -156,9 +149,7 @@ namespace CamelotEngine {
 			HardwareBuffer::Usage usage, bool useShadowBuffer = false) = 0;
 			HardwareBuffer::Usage usage, bool useShadowBuffer = false) = 0;
 
 
         /** Creates a new vertex declaration. */
         /** Creates a new vertex declaration. */
-        virtual VertexDeclaration* createVertexDeclaration(void);
-        /** Destroys a vertex declaration. */
-        virtual void destroyVertexDeclaration(VertexDeclaration* decl);
+        virtual VertexDeclarationPtr createVertexDeclaration(void);
 
 
 		/** Creates a new VertexBufferBinding. */
 		/** Creates a new VertexBufferBinding. */
 		virtual VertexBufferBinding* createVertexBufferBinding(void);
 		virtual VertexBufferBinding* createVertexBufferBinding(void);
@@ -217,15 +208,10 @@ namespace CamelotEngine {
 		}
 		}
 
 
 		/** @copydoc HardwareBufferManagerInterface::createVertexDeclaration */
 		/** @copydoc HardwareBufferManagerInterface::createVertexDeclaration */
-		virtual VertexDeclaration* createVertexDeclaration(void)
+		virtual VertexDeclarationPtr createVertexDeclaration(void)
 		{
 		{
 			return mImpl->createVertexDeclaration();
 			return mImpl->createVertexDeclaration();
 		}
 		}
-		/** @copydoc HardwareBufferManagerInterface::destroyVertexDeclaration */
-        virtual void destroyVertexDeclaration(VertexDeclaration* decl)
-		{
-			mImpl->destroyVertexDeclaration(decl);
-		}
 
 
 		/** @copydoc HardwareBufferManagerInterface::createVertexBufferBinding */
 		/** @copydoc HardwareBufferManagerInterface::createVertexBufferBinding */
 		virtual VertexBufferBinding* createVertexBufferBinding(void)
 		virtual VertexBufferBinding* createVertexBufferBinding(void)

+ 1 - 1
CamelotRenderer/Include/CmHardwareVertexBuffer.h

@@ -420,7 +420,7 @@ namespace CamelotEngine {
 		@param mgr Optional HardwareBufferManager to use for creating the clone
 		@param mgr Optional HardwareBufferManager to use for creating the clone
 			(if null, use the current default).
 			(if null, use the current default).
 		*/
 		*/
-        virtual VertexDeclaration* clone(HardwareBufferManagerBase* mgr = 0);
+        virtual VertexDeclarationPtr clone(HardwareBufferManagerBase* mgr = 0);
 
 
         inline bool operator== (const VertexDeclaration& rhs) const
         inline bool operator== (const VertexDeclaration& rhs) const
         {
         {

+ 11 - 3
CamelotRenderer/Include/CmMesh.h

@@ -4,10 +4,11 @@
 #include "CmResource.h"
 #include "CmResource.h"
 #include "CmMeshData.h"
 #include "CmMeshData.h"
 #include "CmVertexIndexData.h"
 #include "CmVertexIndexData.h"
+#include "CmRenderOperation.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	struct SubMesh
+	struct CM_EXPORT SubMesh
 	{
 	{
 		SubMesh():
 		SubMesh():
 			indexOffset(0), indexCount(0)
 			indexOffset(0), indexCount(0)
@@ -21,7 +22,7 @@ namespace CamelotEngine
 		UINT32 indexCount;
 		UINT32 indexCount;
 	};
 	};
 
 
-	class Mesh : public Resource
+	class CM_EXPORT Mesh : public Resource
 	{
 	{
 	public:
 	public:
 		Mesh();
 		Mesh();
@@ -30,7 +31,14 @@ namespace CamelotEngine
 		/**
 		/**
 		 * @brief	Mesh data that is used for initializing the mesh. Needs to be set before calling load.
 		 * @brief	Mesh data that is used for initializing the mesh. Needs to be set before calling load.
 		 */
 		 */
-		void prepare(MeshDataPtr meshData);
+		void setMeshData(MeshDataPtr meshData);
+
+		/**
+		 * @brief	Gets the mesh data from the GPU. This method is slow so be careful when you call it.
+		 */
+		MeshDataPtr getMeshData();
+
+		RenderOperation getRenderOperation(UINT32 subMeshIdx = 0) const;
 
 
 		virtual void loadImpl();
 		virtual void loadImpl();
 
 

+ 2 - 2
CamelotRenderer/Include/CmMeshData.h

@@ -19,7 +19,7 @@ namespace CamelotEngine
 			int indexCount;
 			int indexCount;
 		};
 		};
 
 
-		struct VertexData : public IReflectable
+		struct CM_EXPORT VertexData : public IReflectable
 		{
 		{
 			VertexData(UINT32 vertexCount, UINT32 streamIdx = 0);
 			VertexData(UINT32 vertexCount, UINT32 streamIdx = 0);
 			~VertexData();
 			~VertexData();
@@ -52,7 +52,7 @@ namespace CamelotEngine
 		int indexCount;
 		int indexCount;
 		int vertexCount;
 		int vertexCount;
 
 
-		VertexDeclaration declaration;
+		VertexDeclarationPtr declaration;
 		map<int, std::shared_ptr<VertexData>>::type vertexBuffers;
 		map<int, std::shared_ptr<VertexData>>::type vertexBuffers;
 		vector<SubMeshData>::type subMeshes;
 		vector<SubMeshData>::type subMeshes;
 
 

+ 3 - 3
CamelotRenderer/Include/CmMeshDataRTTI.h

@@ -87,8 +87,8 @@ namespace CamelotEngine
 		/* 								vertexDeclaration                  		*/
 		/* 								vertexDeclaration                  		*/
 		/************************************************************************/
 		/************************************************************************/
 
 
-		VertexDeclaration& getVertexDecl(MeshData* obj) { return obj->declaration; }
-		void setVertexDecl(MeshData* obj, VertexDeclaration& vertexDecl) { obj->declaration = vertexDecl; }
+		VertexDeclarationPtr getVertexDecl(MeshData* obj) { return obj->declaration; }
+		void setVertexDecl(MeshData* obj, VertexDeclarationPtr vertexDecl) { obj->declaration = vertexDecl; }
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 								vertexData                      		*/
 		/* 								vertexData                      		*/
@@ -130,7 +130,7 @@ namespace CamelotEngine
 			CM_ADD_PLAINFIELD(vertexCount, 2, MeshDataRTTI)
 			CM_ADD_PLAINFIELD(vertexCount, 2, MeshDataRTTI)
 
 
 			addPlainArrayField("subMeshes", 3, &MeshDataRTTI::getSubmesh, &MeshDataRTTI::getSubmeshArraySize, &MeshDataRTTI::setSubmesh, &MeshDataRTTI::setSubmeshArraySize);
 			addPlainArrayField("subMeshes", 3, &MeshDataRTTI::getSubmesh, &MeshDataRTTI::getSubmeshArraySize, &MeshDataRTTI::setSubmesh, &MeshDataRTTI::setSubmeshArraySize);
-			addReflectableField("vertexDeclaration", 4, &MeshDataRTTI::getVertexDecl, &MeshDataRTTI::setVertexDecl);
+			addReflectablePtrField("vertexDeclaration", 4, &MeshDataRTTI::getVertexDecl, &MeshDataRTTI::setVertexDecl);
 			addReflectablePtrArrayField("vertexBuffer", 5, &MeshDataRTTI::getVertexData, &MeshDataRTTI::getVertexDataArraySize, 
 			addReflectablePtrArrayField("vertexBuffer", 5, &MeshDataRTTI::getVertexData, &MeshDataRTTI::getVertexDataArraySize, 
 				&MeshDataRTTI::setVertexData, &MeshDataRTTI::setVertexDataArraySize);
 				&MeshDataRTTI::setVertexData, &MeshDataRTTI::setVertexDataArraySize);
 		}
 		}

+ 2 - 0
CamelotRenderer/Include/CmPrerequisites.h

@@ -116,6 +116,8 @@ namespace CamelotEngine
 	typedef std::shared_ptr<GpuProgram> GpuProgramPtr;
 	typedef std::shared_ptr<GpuProgram> GpuProgramPtr;
 	typedef std::shared_ptr<HighLevelGpuProgram> HighLevelGpuProgramPtr;
 	typedef std::shared_ptr<HighLevelGpuProgram> HighLevelGpuProgramPtr;
 	typedef std::shared_ptr<HardwarePixelBuffer> HardwarePixelBufferPtr;
 	typedef std::shared_ptr<HardwarePixelBuffer> HardwarePixelBufferPtr;
+	typedef std::shared_ptr<VertexDeclaration> VertexDeclarationPtr;
+	typedef std::shared_ptr<Mesh> MeshPtr;
 	typedef std::shared_ptr<Texture> TexturePtr;
 	typedef std::shared_ptr<Texture> TexturePtr;
 	typedef std::shared_ptr<Resource> ResourcePtr;
 	typedef std::shared_ptr<Resource> ResourcePtr;
 
 

+ 1 - 1
CamelotRenderer/Include/CmRenderSystem.h

@@ -995,7 +995,7 @@ namespace CamelotEngine
 
 
 
 
 		/** Sets the current vertex declaration, ie the source of vertex data. */
 		/** Sets the current vertex declaration, ie the source of vertex data. */
-		virtual void setVertexDeclaration(VertexDeclaration* decl) = 0;
+		virtual void setVertexDeclaration(VertexDeclarationPtr decl) = 0;
 		/** Sets the current vertex buffer binding state. */
 		/** Sets the current vertex buffer binding state. */
 		virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
 		virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
 
 

+ 4 - 4
CamelotRenderer/Include/CmVertexIndexData.h

@@ -70,13 +70,13 @@ namespace CamelotEngine {
 		@param dcl The VertexDeclaration to use
 		@param dcl The VertexDeclaration to use
 		@param bind The VertexBufferBinding to use
 		@param bind The VertexBufferBinding to use
 		*/
 		*/
-		VertexData(VertexDeclaration* dcl, VertexBufferBinding* bind);
+		VertexData(VertexDeclarationPtr dcl, VertexBufferBinding* bind);
         ~VertexData();
         ~VertexData();
 
 
 		/** Declaration of the vertex to be used in this operation. 
 		/** Declaration of the vertex to be used in this operation. 
 		@remarks Note that this is created for you on construction.
 		@remarks Note that this is created for you on construction.
 		*/
 		*/
-		VertexDeclaration* vertexDeclaration;
+		VertexDeclarationPtr vertexDeclaration;
 		/** The vertex buffer bindings to be used. 
 		/** The vertex buffer bindings to be used. 
 		@remarks Note that this is created for you on construction.
 		@remarks Note that this is created for you on construction.
 		*/
 		*/
@@ -150,7 +150,7 @@ namespace CamelotEngine {
 		@param mgr Optional pointer to the manager to use to create new declarations
 		@param mgr Optional pointer to the manager to use to create new declarations
 			and buffers etc. If not supplied, the HardwareBufferManager singleton will be used
 			and buffers etc. If not supplied, the HardwareBufferManager singleton will be used
 		*/
 		*/
-		void reorganiseBuffers(VertexDeclaration* newDeclaration, const BufferUsageList& bufferUsage, 
+		void reorganiseBuffers(VertexDeclarationPtr newDeclaration, const BufferUsageList& bufferUsage, 
 			HardwareBufferManagerBase* mgr = 0);
 			HardwareBufferManagerBase* mgr = 0);
 
 
 		/** Reorganises the data in the vertex buffers according to the 
 		/** Reorganises the data in the vertex buffers according to the 
@@ -170,7 +170,7 @@ namespace CamelotEngine {
 		@param mgr Optional pointer to the manager to use to create new declarations
 		@param mgr Optional pointer to the manager to use to create new declarations
 			and buffers etc. If not supplied, the HardwareBufferManager singleton will be used
 			and buffers etc. If not supplied, the HardwareBufferManager singleton will be used
 		*/
 		*/
-		void reorganiseBuffers(VertexDeclaration* newDeclaration, HardwareBufferManagerBase* mgr = 0);
+		void reorganiseBuffers(VertexDeclarationPtr newDeclaration, HardwareBufferManagerBase* mgr = 0);
 
 
         /** Remove any gaps in the vertex buffer bindings.
         /** Remove any gaps in the vertex buffer bindings.
         @remarks
         @remarks

+ 22 - 8
CamelotRenderer/Source/CmApplication.cpp

@@ -16,6 +16,7 @@
 #include "CmSceneManager.h"
 #include "CmSceneManager.h"
 #include "CmImporter.h"
 #include "CmImporter.h"
 #include "CmResources.h"
 #include "CmResources.h"
+#include "CmMesh.h"
 #include "CmGameObject.h"
 #include "CmGameObject.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -45,10 +46,10 @@ namespace CamelotEngine
 		mCamera = mCameraGO->addComponent<Camera>();
 		mCamera = mCameraGO->addComponent<Camera>();
 
 
 		mCamera->init(mRenderWindow, 0.0f, 0.0f, 1.0f, 1.0f, 0);
 		mCamera->init(mRenderWindow, 0.0f, 0.0f, 1.0f, 1.0f, 0);
-		mCameraGO->setPosition(Vector3(0,0,40));
-		mCameraGO->lookAt(Vector3(0,0,-300));
+		mCameraGO->setPosition(Vector3(0,50,240));
+		mCameraGO->lookAt(Vector3(0,50,-300));
 		mCamera->setNearClipDistance(5);
 		mCamera->setNearClipDistance(5);
-		mCamera->setAspectRatio(600.0f / 800.0f);
+		mCamera->setAspectRatio(800.0f / 600.0f);
 
 
 		/////////////////// HLSL SHADERS //////////////////////////
 		/////////////////// HLSL SHADERS //////////////////////////
 		//String fragShaderCode = "sampler2D diffuseMap;			\
 		//String fragShaderCode = "sampler2D diffuseMap;			\
@@ -130,18 +131,30 @@ namespace CamelotEngine
 
 
 		// IMPORTER TEST
 		// IMPORTER TEST
 		Importer::startUp(new Importer());
 		Importer::startUp(new Importer());
-		DynLib* loadedLibrary = gDynLibManager().load("CamelotFreeImgImporter.dll"); // TODO - Load this automatically somehow
+		DynLib* freeImgLibrary = gDynLibManager().load("CamelotFreeImgImporter.dll"); // TODO - Load this automatically somehow
 
 
-		if(loadedLibrary != nullptr)
+		if(freeImgLibrary != nullptr)
 		{
 		{
 			typedef const void (*LoadPluginFunc)();
 			typedef const void (*LoadPluginFunc)();
 
 
-			LoadPluginFunc loadPluginFunc = (LoadPluginFunc)loadedLibrary->getSymbol("loadPlugin");
+			LoadPluginFunc loadPluginFunc = (LoadPluginFunc)freeImgLibrary->getSymbol("loadPlugin");
+			loadPluginFunc();
+		}
+
+		DynLib* fbxLibrary = gDynLibManager().load("CamelotFBXImporter.dll"); // TODO - Load this automatically somehow
+
+		if(fbxLibrary != nullptr)
+		{
+			typedef const void (*LoadPluginFunc)();
+
+			LoadPluginFunc loadPluginFunc = (LoadPluginFunc)fbxLibrary->getSymbol("loadPlugin");
 			loadPluginFunc();
 			loadPluginFunc();
 		}
 		}
 
 
 		//mDbgTexture = std::static_pointer_cast<Texture>(Importer::instance().import("C:\\ImportTest.tga"));
 		//mDbgTexture = std::static_pointer_cast<Texture>(Importer::instance().import("C:\\ImportTest.tga"));
 		TexturePtr testTex = std::static_pointer_cast<Texture>(Importer::instance().import("C:\\ImportTest.tga"));
 		TexturePtr testTex = std::static_pointer_cast<Texture>(Importer::instance().import("C:\\ImportTest.tga"));
+		mDbgMesh = std::static_pointer_cast<Mesh>(Importer::instance().import("C:\\BarrelMesh.fbx"));
+
 		Resources::startUp(new Resources());
 		Resources::startUp(new Resources());
 
 
 		gResources().save(testTex, "C:\\ExportTest.tex");
 		gResources().save(testTex, "C:\\ExportTest.tex");
@@ -210,7 +223,7 @@ namespace CamelotEngine
 		vertexData->vertexStart = 0;
 		vertexData->vertexStart = 0;
 		vertexData->vertexCount = 8;
 		vertexData->vertexCount = 8;
 
 
-		VertexDeclaration* decl = vertexData->vertexDeclaration;
+		VertexDeclarationPtr decl = vertexData->vertexDeclaration;
 		decl->removeAllElements();
 		decl->removeAllElements();
 
 
 		size_t offset = 0;
 		size_t offset = 0;
@@ -347,7 +360,8 @@ namespace CamelotEngine
 
 
 		
 		
 		
 		
-		renderSystem->_render(ro);
+		/*renderSystem->_render(ro);*/
+		renderSystem->_render(mDbgMesh->getRenderOperation());
 
 
 		renderSystem->_endFrame();
 		renderSystem->_endFrame();
 
 

+ 0 - 1
CamelotRenderer/Source/CmDefaultHardwareBufferManager.cpp

@@ -147,7 +147,6 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     DefaultHardwareBufferManagerBase::~DefaultHardwareBufferManagerBase()
     DefaultHardwareBufferManagerBase::~DefaultHardwareBufferManagerBase()
 	{
 	{
-        destroyAllDeclarations();
         destroyAllBindings(); 
         destroyAllBindings(); 
 	}
 	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------

+ 4 - 30
CamelotRenderer/Source/CmHardwareBufferManager.cpp

@@ -55,27 +55,17 @@ namespace CamelotEngine {
 		mIndexBuffers.clear();
 		mIndexBuffers.clear();
 
 
         // Destroy everything
         // Destroy everything
-        destroyAllDeclarations();
         destroyAllBindings();
         destroyAllBindings();
         // No need to destroy main buffers - they will be destroyed by removal of bindings
         // No need to destroy main buffers - they will be destroyed by removal of bindings
 
 
         // No need to destroy temp buffers - they will be destroyed automatically.
         // No need to destroy temp buffers - they will be destroyed automatically.
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    VertexDeclaration* HardwareBufferManagerBase::createVertexDeclaration(void)
+    VertexDeclarationPtr HardwareBufferManagerBase::createVertexDeclaration(void)
     {
     {
-        VertexDeclaration* decl = createVertexDeclarationImpl();
-		CM_LOCK_MUTEX(mVertexDeclarationsMutex)
-        mVertexDeclarations.insert(decl);
+        VertexDeclarationPtr decl = createVertexDeclarationImpl();
         return decl;
         return decl;
     }
     }
-    //-----------------------------------------------------------------------
-    void HardwareBufferManagerBase::destroyVertexDeclaration(VertexDeclaration* decl)
-    {
-		CM_LOCK_MUTEX(mVertexDeclarationsMutex)
-        mVertexDeclarations.erase(decl);
-        destroyVertexDeclarationImpl(decl);
-    }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
 	VertexBufferBinding* HardwareBufferManagerBase::createVertexBufferBinding(void)
 	VertexBufferBinding* HardwareBufferManagerBase::createVertexBufferBinding(void)
 	{
 	{
@@ -92,14 +82,9 @@ namespace CamelotEngine {
 		destroyVertexBufferBindingImpl(binding);
 		destroyVertexBufferBindingImpl(binding);
 	}
 	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    VertexDeclaration* HardwareBufferManagerBase::createVertexDeclarationImpl(void)
-    {
-        return new VertexDeclaration();
-    }
-    //-----------------------------------------------------------------------
-    void HardwareBufferManagerBase::destroyVertexDeclarationImpl(VertexDeclaration* decl)
+    VertexDeclarationPtr HardwareBufferManagerBase::createVertexDeclarationImpl(void)
     {
     {
-        delete decl;
+        return VertexDeclarationPtr(new VertexDeclaration());
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
 	VertexBufferBinding* HardwareBufferManagerBase::createVertexBufferBindingImpl(void)
 	VertexBufferBinding* HardwareBufferManagerBase::createVertexBufferBindingImpl(void)
@@ -112,17 +97,6 @@ namespace CamelotEngine {
 		delete binding;
 		delete binding;
 	}
 	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    void HardwareBufferManagerBase::destroyAllDeclarations(void)
-    {
-		CM_LOCK_MUTEX(mVertexDeclarationsMutex)
-        VertexDeclarationList::iterator decl;
-        for (decl = mVertexDeclarations.begin(); decl != mVertexDeclarations.end(); ++decl)
-        {
-            destroyVertexDeclarationImpl(*decl);
-        }
-        mVertexDeclarations.clear();
-    }
-    //-----------------------------------------------------------------------
     void HardwareBufferManagerBase::destroyAllBindings(void)
     void HardwareBufferManagerBase::destroyAllBindings(void)
     {
     {
 		CM_LOCK_MUTEX(mVertexBufferBindingsMutex)
 		CM_LOCK_MUTEX(mVertexBufferBindingsMutex)

+ 2 - 2
CamelotRenderer/Source/CmHardwareVertexBuffer.cpp

@@ -410,10 +410,10 @@ namespace CamelotEngine {
 		return sz;
 		return sz;
 	}
 	}
     //-----------------------------------------------------------------------------
     //-----------------------------------------------------------------------------
-    VertexDeclaration* VertexDeclaration::clone(HardwareBufferManagerBase* mgr)
+    VertexDeclarationPtr VertexDeclaration::clone(HardwareBufferManagerBase* mgr)
     {
     {
 		HardwareBufferManagerBase* pManager = mgr ? mgr : HardwareBufferManager::instancePtr(); 
 		HardwareBufferManagerBase* pManager = mgr ? mgr : HardwareBufferManager::instancePtr(); 
-        VertexDeclaration* ret = pManager->createVertexDeclaration();
+        VertexDeclarationPtr ret = pManager->createVertexDeclaration();
 
 
 		VertexElementList::const_iterator i, iend;
 		VertexElementList::const_iterator i, iend;
 		iend = mElementList.end();
 		iend = mElementList.end();

+ 226 - 101
CamelotRenderer/Source/CmMesh.cpp

@@ -1,5 +1,9 @@
 #include "CmMesh.h"
 #include "CmMesh.h"
 #include "CmMeshRTTI.h"
 #include "CmMeshRTTI.h"
+#include "CmMeshData.h"
+#include "CmVector2.h"
+#include "CmVector3.h"
+#include "CmDebug.h"
 #include "CmHardwareBufferManager.h"
 #include "CmHardwareBufferManager.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -19,11 +23,143 @@ namespace CamelotEngine
 			delete mIndexData;
 			delete mIndexData;
 	}
 	}
 
 
-	void Mesh::prepare(MeshDataPtr meshData)
+	void Mesh::setMeshData(MeshDataPtr meshData)
 	{
 	{
 		mMeshData = meshData;
 		mMeshData = meshData;
 	}
 	}
 
 
+	MeshDataPtr Mesh::getMeshData()
+	{
+		MeshDataPtr meshData(new MeshData());
+
+		meshData->declaration = mVertexData->vertexDeclaration->clone();
+		
+		for(UINT32 i = 0; i < mSubMeshes.size(); i++)
+		{
+			MeshData::SubMeshData subMesh;
+			subMesh.indexCount = mSubMeshes[i].indexCount;
+			subMesh.indexOffset = mSubMeshes[i].indexOffset;
+
+			meshData->subMeshes.push_back(subMesh);
+		}
+
+		if(mIndexData)
+		{
+			meshData->indexCount = mIndexData->indexCount - mIndexData->indexStart;
+			meshData->index = new int[meshData->indexCount];
+
+			UINT16* idxData = static_cast<UINT16*>(mIndexData->indexBuffer->lock(HardwareBuffer::HBL_READ_ONLY));
+
+			for(UINT32 i = 0; i < mIndexData->indexCount; i++)
+				mMeshData->index[i] = (UINT32)idxData[i];
+
+			mIndexData->indexBuffer->unlock();
+		}
+
+		if(mVertexData)
+		{
+			meshData->vertexCount = mVertexData->vertexCount - mVertexData->vertexStart;
+			
+			UINT16 maxBufferIdx = mVertexData->vertexBufferBinding->getLastBoundIndex();
+			for(UINT16 i = 0; i < maxBufferIdx; i++)
+			{
+				if(!mVertexData->vertexBufferBinding->isBufferBound(i))
+					continue;
+
+				HardwareVertexBufferPtr vertexBuffer = mVertexData->vertexBufferBinding->getBuffer(i);
+				UINT32 vertexSize = vertexBuffer->getVertexSize();
+				UINT8* vertDataIter = static_cast<UINT8*>(vertexBuffer->lock(HardwareBuffer::HBL_READ_ONLY));
+
+				std::shared_ptr<MeshData::VertexData> vertexData(new MeshData::VertexData(meshData->vertexCount, i));
+				meshData->vertexBuffers[i] = vertexData;
+
+				UINT32 numElements = mVertexData->vertexDeclaration->getElementCount();
+				for(UINT32 j = 0; j < numElements; j++)
+				{
+					const VertexElement* element = mVertexData->vertexDeclaration->getElement(j);
+					VertexElementSemantic semantic = element->getSemantic();
+					UINT32 offset = element->getOffset();
+					UINT32 elemSize = element->getSize();
+
+					UINT8* dest = nullptr;
+					switch(semantic)
+					{
+					case VES_POSITION:
+						vertexData->vertex = new Vector3[mMeshData->vertexCount];
+						dest = (UINT8*)vertexData->vertex;
+
+						break;
+					case VES_DIFFUSE:
+						vertexData->color = new Color[mMeshData->vertexCount];
+						dest = (UINT8*)vertexData->color;
+
+						break;
+					case VES_NORMAL:
+						vertexData->normal = new Vector3[mMeshData->vertexCount];
+						dest = (UINT8*)vertexData->normal;	
+
+						break;
+					case VES_TANGENT:
+						vertexData->tangent = new Vector3[mMeshData->vertexCount];
+						dest = (UINT8*)vertexData->tangent;	
+
+						break;
+					case VES_BITANGENT:
+						vertexData->bitangent = new Vector3[mMeshData->vertexCount];
+						dest = (UINT8*)vertexData->bitangent;	
+
+						break;
+					case VES_TEXTURE_COORDINATES:
+						if(element->getIndex() == 0)
+						{
+							vertexData->uv0 = new Vector2[mMeshData->vertexCount];
+							dest = (UINT8*)vertexData->uv0;	
+						}
+						else if(element->getIndex() == 1)
+						{
+							vertexData->uv1 = new Vector2[mMeshData->vertexCount];
+							dest = (UINT8*)vertexData->uv1;	
+						}
+
+						break;
+					default:
+						LOGWRN("Vertex declaration contains semantic (" + toString(semantic) + ") but mesh data can't store it.");
+
+						break;
+					}
+
+					if(dest != nullptr)
+					{
+						for(UINT32 k = 0; k < mVertexData->vertexCount; k++)
+							memcpy(&dest[k * elemSize], &vertDataIter[k * vertexSize + offset], elemSize);
+					}
+				}
+
+				vertexBuffer->unlock();
+			}
+		}		
+
+		return nullptr;
+	}
+
+	RenderOperation Mesh::getRenderOperation(UINT32 subMeshIdx) const
+	{
+		if(subMeshIdx < 0 || subMeshIdx >= mSubMeshes.size())
+		{
+			CM_EXCEPT(InvalidParametersException, "Invalid sub-mesh index (" 
+				+ toString(subMeshIdx) + "). Number of sub-meshes available: " + toString(mSubMeshes.size()));
+		}
+
+		// TODO - BIG TODO - Completely ignores subMeshIdx and always renders the entire thing
+		RenderOperation ro;
+		ro.indexData = mIndexData;
+		ro.vertexData = mVertexData;
+		ro.useIndexes = true;
+		ro.operationType = RenderOperation::OT_TRIANGLE_LIST;
+
+		return ro;
+	}
+
 	void Mesh::loadImpl()
 	void Mesh::loadImpl()
 	{
 	{
 		if(mMeshData == nullptr)
 		if(mMeshData == nullptr)
@@ -32,7 +168,7 @@ namespace CamelotEngine
 		}
 		}
 
 
 		// Submeshes
 		// Submeshes
-		for(int i = 0; i < mMeshData->subMeshes.size(); i++)
+		for(UINT32 i = 0; i < mMeshData->subMeshes.size(); i++)
 			mSubMeshes.push_back(SubMesh(mMeshData->subMeshes[i].indexOffset, mMeshData->subMeshes[i].indexCount));
 			mSubMeshes.push_back(SubMesh(mMeshData->subMeshes[i].indexOffset, mMeshData->subMeshes[i].indexCount));
 
 
 		// Indices
 		// Indices
@@ -46,7 +182,7 @@ namespace CamelotEngine
 
 
 		UINT16* idxData = static_cast<UINT16*>(mIndexData->indexBuffer->lock(HardwareBuffer::HBL_NORMAL));
 		UINT16* idxData = static_cast<UINT16*>(mIndexData->indexBuffer->lock(HardwareBuffer::HBL_NORMAL));
 
 
-		for(int i = 0; i < mIndexData->indexCount; i++)
+		for(UINT32 i = 0; i < mIndexData->indexCount; i++)
 		{
 		{
 			idxData[i] = (UINT16)mMeshData->index[i];
 			idxData[i] = (UINT16)mMeshData->index[i];
 		}
 		}
@@ -59,105 +195,94 @@ namespace CamelotEngine
 		mVertexData->vertexStart = 0;
 		mVertexData->vertexStart = 0;
 		mVertexData->vertexCount = mMeshData->vertexCount;
 		mVertexData->vertexCount = mMeshData->vertexCount;
 
 
-		
-		//mVertexData->vertexDeclaration = mMeshData->declaration.clone();
-		//VertexDeclaration* decl = mVertexData->vertexDeclaration;
-		//decl->removeAllElements();
-
-		//size_t offset = 0;
-		//decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
-		//offset += VertexElement::getTypeSize(VET_FLOAT3);
-		//decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES);
-		//offset += VertexElement::getTypeSize(VET_FLOAT2);
-
-		//decl->addElement(0, offset, VET_COLOUR, VES_DIFFUSE);
-		//offset += VertexElement::getTypeSize(VET_COLOUR);
-
-		//HardwareVertexBufferPtr vertexBuffer = HardwareBufferManager::instance().createVertexBuffer(
-		//	mVertexData->vertexDeclaration->getVertexSize(0),
-		//	mVertexData->vertexCount,
-		//	HardwareBuffer::HBU_STATIC_WRITE_ONLY);
+		mVertexData->vertexDeclaration = mMeshData->declaration->clone();
 
 
-		//mVertexData->vertexBufferBinding->setBinding(0, vertexBuffer);
-
-		//size_t vertexSize = vertexBuffer->getVertexSize();
-		//char* vertBufferData = static_cast<char*>(vertexBuffer->lock(HardwareBuffer::HBL_NORMAL));
-
-		//size_t posSize = VertexElement::getTypeSize(VET_FLOAT3);
-		//size_t uvSize = VertexElement::getTypeSize(VET_FLOAT2);
-
-		//Vector3 position(-5.0f, -5.0f, -5.0f);
-		//memcpy(vertBufferData, &position, posSize);
-		//vertBufferData += posSize;
-
-		//Vector2 uv(0.0f, 0.0f);
-		//memcpy(vertBufferData, &uv, uvSize);
-		//vertBufferData += uvSize;
-
-
-		//position = 	Vector3(-5.0f, 5.0f, -5.0f);
-		//memcpy(vertBufferData, &position, posSize);
-		//vertBufferData += posSize;
-
-		//uv = Vector2(0.0f, 1.0f);
-		//memcpy(vertBufferData, &uv, uvSize);
-		//vertBufferData += uvSize;
-
-
-		//position = 	Vector3(5.0f, 5.0f, -5.0f);
-		//memcpy(vertBufferData, &position, posSize);
-		//vertBufferData += posSize;
-
-		//uv = Vector2(1.0f, 1.0f);
-		//memcpy(vertBufferData, &uv, uvSize);
-		//vertBufferData += uvSize;
-
-
-		//position = 	Vector3(5.0f, -5.0f, -5.0f);
-		//memcpy(vertBufferData, &position, posSize);
-		//vertBufferData += posSize;
-
-		//uv = Vector2(1.0f, 0.0f);
-		//memcpy(vertBufferData, &uv, uvSize);
-		//vertBufferData += uvSize;
-
-
-		//position = 	Vector3(-5.0f, -5.0f, 5.0f);
-		//memcpy(vertBufferData, &position, posSize);
-		//vertBufferData += posSize;
-
-		//uv = Vector2(0.0f, 0.0f);
-		//memcpy(vertBufferData, &uv, uvSize);
-		//vertBufferData += uvSize;
-
-
-		//position = 	Vector3(5.0f, -5.0f, 5.0f);
-		//memcpy(vertBufferData, &position, posSize);
-		//vertBufferData += posSize;
-
-		//uv = Vector2(1.0f, 0.0f);
-		//memcpy(vertBufferData, &uv, uvSize);
-		//vertBufferData += uvSize;
-
-
-		//position = 	Vector3(5.0f, 5.0f, 5.0f);
-		//memcpy(vertBufferData, &position, posSize);
-		//vertBufferData += posSize;
-
-		//uv = Vector2(1.0f, 1.0f);
-		//memcpy(vertBufferData, &uv, uvSize);
-		//vertBufferData += uvSize;
-
-
-		//position = 	Vector3(-5.0f, 5.0f, 5.0f);
-		//memcpy(vertBufferData, &position, posSize);
-		//vertBufferData += posSize;
-
-		//uv = Vector2(0.0f, 1.0f);
-		//memcpy(vertBufferData, &uv, uvSize);
-		//vertBufferData += uvSize;
-
-		//vertexBuffer->unlock();
+		for(auto iter = mMeshData->vertexBuffers.begin(); iter != mMeshData->vertexBuffers.end(); ++iter)
+		{
+			int streamIdx = iter->first; 
+
+			HardwareVertexBufferPtr vertexBuffer = HardwareBufferManager::instance().createVertexBuffer(
+				mVertexData->vertexDeclaration->getVertexSize(streamIdx),
+				mVertexData->vertexCount,
+				HardwareBuffer::HBU_STATIC_WRITE_ONLY);
+
+			mVertexData->vertexBufferBinding->setBinding(streamIdx, vertexBuffer);
+
+			UINT32 vertexSize = vertexBuffer->getVertexSize();
+			UINT8* vertBufferData = static_cast<UINT8*>(vertexBuffer->lock(HardwareBuffer::HBL_NORMAL));
+
+			UINT32 numElements = mVertexData->vertexDeclaration->getElementCount();
+
+			for(UINT32 j = 0; j < numElements; j++)
+			{
+				const VertexElement* element = mVertexData->vertexDeclaration->getElement(j);
+				VertexElementSemantic semantic = element->getSemantic();
+				UINT32 offset = element->getOffset();
+				UINT32 elemSize = element->getSize();
+
+				std::shared_ptr<MeshData::VertexData> vertexData = mMeshData->vertexBuffers[streamIdx];
+
+				UINT8* source = nullptr;
+				switch(semantic)
+				{
+				case VES_POSITION:
+					if(vertexData->vertex)
+						source = (UINT8*)vertexData->vertex;
+
+					break;
+				case VES_DIFFUSE:
+					if(vertexData->color)
+						source = (UINT8*)vertexData->color;
+
+					break;
+				case VES_NORMAL:
+					if(vertexData->normal)
+						source = (UINT8*)vertexData->normal;	
+
+					break;
+				case VES_TANGENT:
+					if(vertexData->tangent)
+						source = (UINT8*)vertexData->tangent;	
+
+					break;
+				case VES_BITANGENT:
+					if(vertexData->bitangent)
+						source = (UINT8*)vertexData->bitangent;	
+
+					break;
+				case VES_TEXTURE_COORDINATES:
+					if(element->getIndex() == 0)
+					{
+						if(vertexData->uv0)
+							source = (UINT8*)vertexData->uv0;	
+					}
+					else if(element->getIndex() == 1)
+					{
+						if(vertexData->uv1)
+							source = (UINT8*)vertexData->uv1;	
+					}
+
+					break;
+				default:
+					break;
+				}
+
+				if(source != nullptr)
+				{
+					for(UINT32 k = 0; k < mVertexData->vertexCount; k++)
+						memcpy(&vertBufferData[k * vertexSize + offset], &source[k * elemSize], elemSize);
+				}
+				else
+				{
+					LOGWRN("Vertex declaration contains semantic (" + toString(semantic) + ") but mesh doesn't have data for it. Data for the semantic will be zeroed out.");
+
+					for(UINT32 k = 0; k < mVertexData->vertexCount; k++)
+						memset(&vertBufferData[k * vertexSize + offset], 0, elemSize);
+				}
+			}
+
+			vertexBuffer->unlock();
+		}
 
 
 		mMeshData = nullptr;
 		mMeshData = nullptr;
 	}
 	}

+ 4 - 1
CamelotRenderer/Source/CmMeshData.cpp

@@ -1,6 +1,7 @@
 #include "CmMeshData.h"
 #include "CmMeshData.h"
 #include "CmVector2.h"
 #include "CmVector2.h"
 #include "CmVector3.h"
 #include "CmVector3.h"
+#include "CmHardwareBufferManager.h"
 #include "CmMeshDataRTTI.h"
 #include "CmMeshDataRTTI.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -50,7 +51,9 @@ namespace CamelotEngine
 	   :index(nullptr),
 	   :index(nullptr),
 		indexCount(0),
 		indexCount(0),
 		vertexCount(0)
 		vertexCount(0)
-	{ }
+	{
+		declaration = HardwareBufferManager::instance().createVertexDeclaration();
+	}
 
 
 	MeshData::~MeshData()
 	MeshData::~MeshData()
 	{
 	{

+ 3 - 5
CamelotRenderer/Source/CmVertexIndexData.cpp

@@ -50,7 +50,7 @@ namespace CamelotEngine {
 
 
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-	VertexData::VertexData(VertexDeclaration* dcl, VertexBufferBinding* bind)
+	VertexData::VertexData(VertexDeclarationPtr dcl, VertexBufferBinding* bind)
 	{
 	{
 		// this is a fallback rather than actively used
 		// this is a fallback rather than actively used
 		mMgr = HardwareBufferManager::instancePtr();
 		mMgr = HardwareBufferManager::instancePtr();
@@ -66,7 +66,6 @@ namespace CamelotEngine {
 		if (mDeleteDclBinding)
 		if (mDeleteDclBinding)
 		{
 		{
 			mMgr->destroyVertexBufferBinding(vertexBufferBinding);
 			mMgr->destroyVertexBufferBinding(vertexBufferBinding);
-			mMgr->destroyVertexDeclaration(vertexDeclaration);
 		}
 		}
 	}
 	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
@@ -319,7 +318,7 @@ namespace CamelotEngine {
         }
         }
     }
     }
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	void VertexData::reorganiseBuffers(VertexDeclaration* newDeclaration, 
+	void VertexData::reorganiseBuffers(VertexDeclarationPtr newDeclaration, 
 		const BufferUsageList& bufferUsages, HardwareBufferManagerBase* mgr)
 		const BufferUsageList& bufferUsages, HardwareBufferManagerBase* mgr)
 	{
 	{
 		HardwareBufferManagerBase* pManager = mgr ? mgr : mMgr;
 		HardwareBufferManagerBase* pManager = mgr ? mgr : mMgr;
@@ -435,7 +434,6 @@ namespace CamelotEngine {
 		if (mDeleteDclBinding)
 		if (mDeleteDclBinding)
 		{
 		{
 			pManager->destroyVertexBufferBinding(vertexBufferBinding);
 			pManager->destroyVertexBufferBinding(vertexBufferBinding);
-			pManager->destroyVertexDeclaration(vertexDeclaration);
 		}
 		}
 
 
 		// Assign new binding and declaration
 		// Assign new binding and declaration
@@ -447,7 +445,7 @@ namespace CamelotEngine {
 
 
 	}
 	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    void VertexData::reorganiseBuffers(VertexDeclaration* newDeclaration, HardwareBufferManagerBase* mgr)
+    void VertexData::reorganiseBuffers(VertexDeclarationPtr newDeclaration, HardwareBufferManagerBase* mgr)
     {
     {
         // Derive the buffer usages from looking at where the source has come
         // Derive the buffer usages from looking at where the source has come
         // from
         // from