Browse Source

Some more MeshData work

Marko Pintera 13 years ago
parent
commit
4e9fb361ca

+ 1 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -141,6 +141,7 @@
     <ClInclude Include="Include\CmComponent.h" />
     <ClInclude Include="Include\CmComponent.h" />
     <ClInclude Include="Include\stdafx.h" />
     <ClInclude Include="Include\stdafx.h" />
     <ClInclude Include="Include\targetver.h" />
     <ClInclude Include="Include\targetver.h" />
+    <ClInclude Include="Include\CmVertexDeclarationST.h" />
     <ClInclude Include="Source\CmMeshST.h" />
     <ClInclude Include="Source\CmMeshST.h" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>

+ 3 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -205,6 +205,9 @@
     <ClInclude Include="Include\CmMeshData.h">
     <ClInclude Include="Include\CmMeshData.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmVertexDeclarationST.h">
+      <Filter>Header Files\Serialization</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">
     <ClCompile Include="Source\CamelotRenderer.cpp">

+ 9 - 1
CamelotRenderer/Include/CmHardwareVertexBuffer.h

@@ -31,6 +31,7 @@ THE SOFTWARE.
 // Precompiler options
 // Precompiler options
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
 #include "CmHardwareBuffer.h"
 #include "CmHardwareBuffer.h"
+#include "CmIReflectable.h"
 #include "CmColor.h"
 #include "CmColor.h"
 
 
 namespace CamelotEngine {
 namespace CamelotEngine {
@@ -293,7 +294,7 @@ namespace CamelotEngine {
 	Like the other classes in this functional area, these declarations should be created and
 	Like the other classes in this functional area, these declarations should be created and
 	destroyed using the HardwareBufferManager.
 	destroyed using the HardwareBufferManager.
     */
     */
-	class CM_EXPORT VertexDeclaration
+	class CM_EXPORT VertexDeclaration : public IReflectable
     {
     {
     public:
     public:
 		/// Defines the list of vertex elements that makes up this declaration
 		/// Defines the list of vertex elements that makes up this declaration
@@ -443,6 +444,13 @@ namespace CamelotEngine {
             return !(*this == rhs);
             return !(*this == rhs);
         }
         }
 
 
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class VertexDeclarationST;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const;
     };
     };
 
 
 	/** Records the state of all the vertex buffer bindings required to provide a vertex declaration
 	/** Records the state of all the vertex buffer bindings required to provide a vertex declaration

+ 5 - 5
CamelotRenderer/Include/CmMeshDataST.h

@@ -78,12 +78,12 @@ namespace CamelotEngine
 	public:
 	public:
 		MeshDataST()
 		MeshDataST()
 		{
 		{
-			CM_ADD_DATABLOCKFIELD(index, 6, MeshDataST)
+			CM_ADD_DATABLOCKFIELD(index, 0, MeshDataST)
 
 
-			CM_ADD_PLAINFIELD(indexCount, 7, MeshDataST)
-			CM_ADD_PLAINFIELD(vertexCount, 8, MeshDataST)
+			CM_ADD_PLAINFIELD(indexCount, 1, MeshDataST)
+			CM_ADD_PLAINFIELD(vertexCount, 2, MeshDataST)
 
 
-			addPlainArrayField("subMeshes", 9, &MeshDataST::getSubmesh, &MeshDataST::getSubmeshArraySize, &MeshDataST::setSubmesh, &MeshDataST::setSubmeshArraySize);
+			addPlainArrayField("subMeshes", 3, &MeshDataST::getSubmesh, &MeshDataST::getSubmeshArraySize, &MeshDataST::setSubmesh, &MeshDataST::setSubmeshArraySize);
 		}
 		}
 
 
 		virtual std::shared_ptr<IReflectable> newRTTIObject() 
 		virtual std::shared_ptr<IReflectable> newRTTIObject() 
@@ -99,7 +99,7 @@ namespace CamelotEngine
 
 
 		virtual UINT32 getRTTIId() 
 		virtual UINT32 getRTTIId() 
 		{
 		{
-			return 103;
+			return TID_MeshData;
 		}
 		}
 	};
 	};
 }
 }

+ 12 - 0
CamelotRenderer/Include/CmPrerequisites.h

@@ -123,6 +123,18 @@ namespace CamelotEngine
 	typedef std::shared_ptr<GameObject> GameObjectPtr;
 	typedef std::shared_ptr<GameObject> GameObjectPtr;
 }
 }
 
 
+// All type IDs
+namespace CamelotEngine
+{
+	enum TypeID_Core
+	{
+		TID_Texture = 1001,
+		TID_Mesh = 1002,
+		TID_MeshData = 1003,
+		TID_VertexDeclaration = 1004
+	};
+}
+
 #endif // __OgrePrerequisites_H__
 #endif // __OgrePrerequisites_H__
 
 
 
 

+ 0 - 6
CamelotRenderer/Include/CmResource.h

@@ -6,12 +6,6 @@
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	enum ResourceIds
-	{
-		RID_Texture = 1001,
-		RID_Mesh = 1002
-	};
-
 	/**
 	/**
 	 * @brief	Base class for all resources used in the engine.
 	 * @brief	Base class for all resources used in the engine.
 	 */
 	 */

+ 1 - 1
CamelotRenderer/Include/CmTextureST.h

@@ -87,7 +87,7 @@ namespace CamelotEngine
 
 
 		virtual UINT32 getRTTIId()
 		virtual UINT32 getRTTIId()
 		{
 		{
-			return RID_Texture;
+			return TID_Texture;
 		}
 		}
 
 
 		virtual std::shared_ptr<IReflectable> newRTTIObject()
 		virtual std::shared_ptr<IReflectable> newRTTIObject()

+ 64 - 0
CamelotRenderer/Include/CmVertexDeclarationST.h

@@ -0,0 +1,64 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmRTTIType.h"
+#include "CmHardwareVertexBuffer.h"
+
+namespace CamelotEngine
+{
+	class VertexDeclarationST : public RTTIType<VertexDeclaration, IReflectable, VertexDeclarationST>
+	{
+	private:
+		VertexElement& getElement(VertexDeclaration* obj, UINT32 idx)
+		{
+			auto iter = obj->mElementList.begin();
+			for(int i = 0; i < idx; i++)
+				++iter;
+
+			return *iter;
+		}
+
+		void setElement(VertexDeclaration* obj, UINT32 idx, VertexElement& data)
+		{
+			auto iter = obj->mElementList.begin();
+			for(int i = 0; i < idx; i++)
+				++iter;
+
+			*iter = data;
+		}
+
+		UINT32 getElementArraySize(VertexDeclaration* obj)
+		{
+			return obj->mElementList.size();
+		}
+
+		void setElementArraySize(VertexDeclaration* obj, UINT32 size)
+		{
+			for(int i = obj->mElementList.size(); i <= size; i++)
+				obj->mElementList.push_back(VertexElement());
+		}
+
+	public:
+		VertexDeclarationST()
+		{
+			addPlainArrayField("mElementList", 0, &VertexDeclarationST::getElement, &VertexDeclarationST::getElementArraySize, 
+				&VertexDeclarationST::setElement, &VertexDeclarationST::setElementArraySize);
+		}
+
+		virtual std::shared_ptr<IReflectable> newRTTIObject() 
+		{
+			return std::shared_ptr<VertexDeclaration>(new VertexDeclaration());
+		}
+
+		virtual const String& getRTTIName() 
+		{
+			static String name = "VertexDeclaration";
+			throw name;
+		}
+
+		virtual UINT32 getRTTIId() 
+		{
+			return TID_VertexDeclaration;
+		}
+	};
+}

+ 14 - 0
CamelotRenderer/Source/CmHardwareVertexBuffer.cpp

@@ -33,6 +33,7 @@ THE SOFTWARE.
 #include "CmDefaultHardwareBufferManager.h"
 #include "CmDefaultHardwareBufferManager.h"
 #include "CmRenderSystem.h"
 #include "CmRenderSystem.h"
 #include "CmRenderSystemManager.h"
 #include "CmRenderSystemManager.h"
+#include "CmVertexDeclarationST.h"
 
 
 namespace CamelotEngine {
 namespace CamelotEngine {
 
 
@@ -500,6 +501,19 @@ namespace CamelotEngine {
         }
         }
         return ret;
         return ret;
     }
     }
+	/************************************************************************/
+	/* 								SERIALIZATION                      		*/
+	/************************************************************************/
+	RTTITypeBase* VertexDeclaration::getRTTIStatic()
+	{
+		return VertexDeclarationST::instance();
+	}
+
+	RTTITypeBase* VertexDeclaration::getRTTI() const
+	{
+		return getRTTIStatic();
+	}
+
     //-----------------------------------------------------------------------------
     //-----------------------------------------------------------------------------
 	VertexBufferBinding::VertexBufferBinding() : mHighIndex(0)
 	VertexBufferBinding::VertexBufferBinding() : mHighIndex(0)
 	{
 	{

+ 1 - 1
CamelotRenderer/Source/CmMeshST.h

@@ -27,7 +27,7 @@ namespace CamelotEngine
 
 
 		virtual UINT32 getRTTIId() 
 		virtual UINT32 getRTTIId() 
 		{
 		{
-			return RID_Mesh;
+			return TID_Mesh;
 		}
 		}
 	};
 	};
 }
 }