فهرست منبع

Added GpuProgram importer
Added support for ImportOptions

Marko Pintera 13 سال پیش
والد
کامیت
ba5f1c9453
26فایلهای تغییر یافته به همراه474 افزوده شده و 37 حذف شده
  1. 14 0
      CamelotClient/CamelotClient.cpp
  2. 1 1
      CamelotFBXImporter/Include/CmFBXImporter.h
  3. 1 1
      CamelotFBXImporter/Source/CmFBXImporter.cpp
  4. 1 1
      CamelotFreeImgImporter/Include/CmFreeImgImporter.h
  5. 1 1
      CamelotFreeImgImporter/Source/CmFreeImgImporter.cpp
  6. 8 0
      CamelotRenderer/CamelotRenderer.vcxproj
  7. 24 0
      CamelotRenderer/CamelotRenderer.vcxproj.filters
  8. 1 1
      CamelotRenderer/Include/CmGpuProgIncludeImporter.h
  9. 38 0
      CamelotRenderer/Include/CmGpuProgramImportOptions.h
  10. 49 0
      CamelotRenderer/Include/CmGpuProgramImportOptionsRTTI.h
  11. 31 0
      CamelotRenderer/Include/CmGpuProgramImporter.h
  12. 21 0
      CamelotRenderer/Include/CmImportOptions.h
  13. 32 0
      CamelotRenderer/Include/CmImportOptionsRTTI.h
  14. 23 3
      CamelotRenderer/Include/CmImporter.h
  15. 37 3
      CamelotRenderer/Include/CmPrerequisites.h
  16. 18 1
      CamelotRenderer/Include/CmSpecificImporter.h
  17. 1 1
      CamelotRenderer/Source/CmGpuProgIncludeImporter.cpp
  18. 24 0
      CamelotRenderer/Source/CmGpuProgramImportOptions.cpp
  19. 49 0
      CamelotRenderer/Source/CmGpuProgramImporter.cpp
  20. 18 0
      CamelotRenderer/Source/CmImportOptions.cpp
  21. 51 13
      CamelotRenderer/Source/CmImporter.cpp
  22. 13 0
      CamelotRenderer/Source/CmSpecificImporter.cpp
  23. 3 4
      CamelotRenderer/TODO.txt
  24. 3 3
      CamelotUtility/Include/CmIReflectable.h
  25. 6 3
      CamelotUtility/Include/CmRTTIType.h
  26. 6 1
      CamelotUtility/Source/CmIReflectable.cpp

+ 14 - 0
CamelotClient/CamelotClient.cpp

@@ -21,6 +21,7 @@
 #include "CmImporter.h"
 #include "CmMesh.h"
 #include "CmGpuProgInclude.h" // DEBUG ONLY
+#include "CmGpuProgramImportOptions.h"
 
 #include "CmDebugCamera.h"
 
@@ -57,6 +58,19 @@ int CALLBACK WinMain(
 	GpuProgIncludeHandle gpuProgInclude = Importer::instance().import("C:\\testInclude.gpuproginc");
 	const String& debugString = gpuProgInclude->getString();
 
+	ImportOptionsPtr gpuProgImportOptions = Importer::instance().createImportOptions("C:\\testGpuProg.gpuprog");
+	if(rtti_is_of_type<GpuProgramImportOptions>(gpuProgImportOptions))
+	{
+		GpuProgramImportOptions* importOptions = static_cast<GpuProgramImportOptions*>(gpuProgImportOptions.get());
+
+		importOptions->setEntryPoint("ps_main");
+		importOptions->setLanguage("hlsl");
+		importOptions->setProfile(GPP_PS_4_0);
+		importOptions->setType(GPT_FRAGMENT_PROGRAM);
+	}
+
+	HighLevelGpuProgramHandle importedGpuProgram = Importer::instance().import("C:\\testGpuProg.gpuprog", gpuProgImportOptions);
+
 	/////////////////// HLSL 9 SHADERS //////////////////////////
 	//String fragShaderCode = "sampler2D tex;			\
 	//						float4 ps_main(float2 uv : TEXCOORD0) : COLOR0		\

+ 1 - 1
CamelotFBXImporter/Include/CmFBXImporter.h

@@ -35,7 +35,7 @@ namespace CamelotEngine
 		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const; 
 
 		/** Inherited from SpecificImporter */
-		virtual BaseResourceHandle import(const String& filePath);
+		virtual BaseResourceHandle import(const String& filePath, ConstImportOptionsPtr importOptions);
 	private:
 		vector<String>::type mExtensions;
 

+ 1 - 1
CamelotFBXImporter/Source/CmFBXImporter.cpp

@@ -35,7 +35,7 @@ namespace CamelotEngine
 		return true; // FBX files can be plain-text so I don't even check for magic number
 	}
 
-	BaseResourceHandle FBXImporter::import(const String& filePath)
+	BaseResourceHandle FBXImporter::import(const String& filePath, ConstImportOptionsPtr importOptions)
 	{
 		FbxManager* fbxManager = nullptr;
 		FbxScene* fbxScene = nullptr;

+ 1 - 1
CamelotFreeImgImporter/Include/CmFreeImgImporter.h

@@ -34,7 +34,7 @@ namespace CamelotEngine
 		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const; 
 
 		/** Inherited from SpecificImporter */
-		virtual BaseResourceHandle import(const String& filePath);
+		virtual BaseResourceHandle import(const String& filePath, ConstImportOptionsPtr importOptions);
 	private:
 		vector<String>::type mExtensions;
 		std::unordered_map<String, int> mExtensionToFID;

+ 1 - 1
CamelotFreeImgImporter/Source/CmFreeImgImporter.cpp

@@ -127,7 +127,7 @@ namespace CamelotEngine
 		}
 	}
 
-	BaseResourceHandle FreeImgImporter::import(const String& filePath)
+	BaseResourceHandle FreeImgImporter::import(const String& filePath, ConstImportOptionsPtr importOptions)
 	{
 		DataStreamPtr fileData = FileSystem::open(filePath, true);
 

+ 8 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -203,11 +203,16 @@
     <ClInclude Include="Include\CmGpuParams.h" />
     <ClInclude Include="Include\CmGpuProgInclude.h" />
     <ClInclude Include="Include\CmGpuProgram.h" />
+    <ClInclude Include="Include\CmGpuProgramImporter.h" />
+    <ClInclude Include="Include\CmGpuProgramImportOptions.h" />
+    <ClInclude Include="Include\CmGpuProgramImportOptionsRTTI.h" />
     <ClInclude Include="Include\CmGpuProgramManager.h" />
     <ClInclude Include="Include\CmGpuProgramParams.h" />
     <ClInclude Include="Include\CmGpuProgramRTTI.h" />
     <ClInclude Include="Include\CmHardwareBuffer.h" />
     <ClInclude Include="Include\CmHardwareBufferManager.h" />
+    <ClInclude Include="Include\CmImportOptions.h" />
+    <ClInclude Include="Include\CmImportOptionsRTTI.h" />
     <ClInclude Include="Include\CmIndexBuffer.h" />
     <ClInclude Include="Include\CmMaterialManager.h" />
     <ClInclude Include="Include\CmMeshManager.h" />
@@ -298,9 +303,12 @@
     <ClCompile Include="Source\CmGpuParams.cpp" />
     <ClCompile Include="Source\CmGpuProgInclude.cpp" />
     <ClCompile Include="Source\CmGpuProgram.cpp" />
+    <ClCompile Include="Source\CmGpuProgramImporter.cpp" />
+    <ClCompile Include="Source\CmGpuProgramImportOptions.cpp" />
     <ClCompile Include="Source\CmGpuProgramManager.cpp" />
     <ClCompile Include="Source\CmGpuProgramParams.cpp" />
     <ClCompile Include="Source\CmHardwareBufferManager.cpp" />
+    <ClCompile Include="Source\CmImportOptions.cpp" />
     <ClCompile Include="Source\CmIndexBuffer.cpp" />
     <ClCompile Include="Source\CmIndexData.cpp" />
     <ClCompile Include="Source\CmMeshManager.cpp" />

+ 24 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -383,6 +383,21 @@
     <ClInclude Include="Include\CmGpuProgInclude.h">
       <Filter>Header Files\Resources</Filter>
     </ClInclude>
+    <ClInclude Include="Include\CmGpuProgramImporter.h">
+      <Filter>Header Files\Importer</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmImportOptions.h">
+      <Filter>Header Files\Importer</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmImportOptionsRTTI.h">
+      <Filter>Header Files\RTTI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmGpuProgramImportOptions.h">
+      <Filter>Header Files\Importer</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmGpuProgramImportOptionsRTTI.h">
+      <Filter>Header Files\RTTI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">
@@ -589,5 +604,14 @@
     <ClCompile Include="Source\CmGpuProgInclude.cpp">
       <Filter>Source Files\Resources</Filter>
     </ClCompile>
+    <ClCompile Include="Source\CmGpuProgramImporter.cpp">
+      <Filter>Source Files\Importer</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\CmImportOptions.cpp">
+      <Filter>Source Files\Importer</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\CmGpuProgramImportOptions.cpp">
+      <Filter>Source Files\Importer</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 1 - 1
CamelotRenderer/Include/CmGpuProgIncludeImporter.h

@@ -18,7 +18,7 @@ namespace CamelotEngine
 		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const; 
 
 		/** Inherited from SpecificImporter */
-		virtual BaseResourceHandle import(const String& filePath);
+		virtual BaseResourceHandle import(const String& filePath, ConstImportOptionsPtr importOptions);
 	private:
 	};
 }

+ 38 - 0
CamelotRenderer/Include/CmGpuProgramImportOptions.h

@@ -0,0 +1,38 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmImportOptions.h"
+#include "CmGpuProgram.h"
+
+namespace CamelotEngine
+{
+	class CM_EXPORT GpuProgramImportOptions : public ImportOptions
+	{
+	public:
+		GpuProgramImportOptions();
+
+		void setEntryPoint(const String& entryPoint) { mEntryPoint = entryPoint; }
+		void setLanguage(const String& language) { mLanguage = language; }
+		void setProfile(GpuProgramProfile profile) { mProfile = profile; }
+		void setType(GpuProgramType type) { mType = type; }
+
+		const String& getEntryPoint() const { return mEntryPoint; }
+		const String& getLanguage() const { return mLanguage; }
+		GpuProgramProfile getProfile() const { return mProfile; }
+		GpuProgramType getType() const { return mType; }
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class GpuProgramImportOptionsRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const;
+
+	private:
+		String mEntryPoint;
+		String mLanguage;
+		GpuProgramProfile mProfile;
+		GpuProgramType mType;
+	};
+}

+ 49 - 0
CamelotRenderer/Include/CmGpuProgramImportOptionsRTTI.h

@@ -0,0 +1,49 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmRTTIType.h"
+#include "CmGpuProgramImportOptions.h"
+
+namespace CamelotEngine
+{
+	class CM_EXPORT GpuProgramImportOptionsRTTI : public RTTIType<GpuProgramImportOptions, IReflectable, GpuProgramImportOptionsRTTI>
+	{
+	private:
+		String& getEntryPoint(GpuProgramImportOptions* obj) { return obj->mEntryPoint; }
+		void setEntryPoint(GpuProgramImportOptions* obj, String& value) { obj->mEntryPoint = value; }
+
+		String& getLanguage(GpuProgramImportOptions* obj) { return obj->mLanguage; }
+		void setLanguage(GpuProgramImportOptions* obj, String& value) { obj->mLanguage = value; }
+
+		GpuProgramProfile& getProfile(GpuProgramImportOptions* obj) { return obj->mProfile; }
+		void setProfile(GpuProgramImportOptions* obj, GpuProgramProfile& value) { obj->mProfile = value; }
+
+		GpuProgramType& getType(GpuProgramImportOptions* obj) { return obj->mType; }
+		void setType(GpuProgramImportOptions* obj, GpuProgramType& value) { obj->mType = value; }
+
+	public:
+		GpuProgramImportOptionsRTTI()
+		{
+			addPlainField("mEntryPoint", 0, &GpuProgramImportOptionsRTTI::getEntryPoint, &GpuProgramImportOptionsRTTI::setEntryPoint);
+			addPlainField("mLanguage", 1, &GpuProgramImportOptionsRTTI::getLanguage, &GpuProgramImportOptionsRTTI::setLanguage);
+			addPlainField("mProfile", 2, &GpuProgramImportOptionsRTTI::getProfile, &GpuProgramImportOptionsRTTI::setProfile);
+			addPlainField("mType", 3, &GpuProgramImportOptionsRTTI::getType, &GpuProgramImportOptionsRTTI::setType);
+		}
+
+		virtual const String& getRTTIName()
+		{
+			static String name = "GpuProgramImportOptions";
+			return name;
+		}
+
+		virtual UINT32 getRTTIId()
+		{
+			return TID_GpuProgramImportOptions;
+		}
+
+		virtual std::shared_ptr<IReflectable> newRTTIObject()
+		{
+			return ImportOptionsPtr(new GpuProgramImportOptions());
+		}
+	};
+}

+ 31 - 0
CamelotRenderer/Include/CmGpuProgramImporter.h

@@ -0,0 +1,31 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmSpecificImporter.h"
+
+namespace CamelotEngine
+{
+	class CM_EXPORT GpuProgramImporter : public SpecificImporter
+	{
+	public:
+		/**
+		 * @copydoc SpecificImporter::isExtensionSupported().
+		 */
+		virtual bool isExtensionSupported(const String& ext) const;
+
+		/**
+		 * @copydoc SpecificImporter::isMagicNumberSupported().
+		 */
+		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const; 
+
+		/**
+		 * @copydoc SpecificImporter::import().
+		 */
+		virtual BaseResourceHandle import(const String& filePath, ConstImportOptionsPtr importOptions);
+
+		/**
+		 * @copydoc SpecificImporter::createImportOptions().
+		 */
+		virtual ImportOptionsPtr createImportOptions() const;
+	};
+}

+ 21 - 0
CamelotRenderer/Include/CmImportOptions.h

@@ -0,0 +1,21 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmIReflectable.h"
+
+namespace CamelotEngine
+{
+	class CM_EXPORT ImportOptions : public IReflectable
+	{
+	public:
+		virtual ~ImportOptions() {}
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class ImportOptionsRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const;
+	};
+}

+ 32 - 0
CamelotRenderer/Include/CmImportOptionsRTTI.h

@@ -0,0 +1,32 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmImportOptions.h"
+#include "CmRTTIType.h"
+
+namespace CamelotEngine
+{
+	class CM_EXPORT ImportOptionsRTTI : public RTTIType<ImportOptions, IReflectable, ImportOptionsRTTI>
+	{
+	public:
+		ImportOptionsRTTI()
+		{
+		}
+
+		virtual const String& getRTTIName()
+		{
+			static String name = "ImportOptions";
+			return name;
+		}
+
+		virtual UINT32 getRTTIId()
+		{
+			return TID_ImportOptions;
+		}
+
+		virtual std::shared_ptr<IReflectable> newRTTIObject()
+		{
+			return ImportOptionsPtr(new ImportOptions());
+		}
+	};
+}

+ 23 - 3
CamelotRenderer/Include/CmImporter.h

@@ -21,16 +21,34 @@ namespace CamelotEngine
 		/**
 		 * @brief	Imports a resource at the specified location, and returns the loaded data.
 		 *
-		 * @param	inputFilePath 	Pathname of the input file.
+		 * @param	inputFilePath	Pathname of the input file.
+		 * @param	importOptions	(optional) Options for controlling the import.
 		 */
-		BaseResourceHandle import(const String& inputFilePath);
+		BaseResourceHandle import(const String& inputFilePath, ConstImportOptionsPtr importOptions = nullptr);
+
+		/**
+		 * @brief	Automatically detects the importer needed for the provided file and returns valid type of
+		 * 			import options for that importer.
+		 *
+		 * @param	inputFilePath	Pathname of the input file.
+		 *
+		 * @return	The new import options.
+		 * 			
+		 * @note	You will need to type cast the importer options to a valid type,
+		 * 			taking into consideration exact importer you expect to be used for this file type.
+		 * 			If you don't use a proper import options type, an exception will be thrown during import.
+		 * 			
+		 *			nullptr is returned if the file path is not valid, or if a valid importer cannot be found for
+		 *			the specified file.
+		 */
+		ImportOptionsPtr createImportOptions(const String& inputFilePath);
 
 		/**
 		 * @brief	Checks if we can import a file with the specified extension.
 		 *
 		 * @param	extension	The extension without leading dot.
 		 */
-		bool supportsFileType(const std::string& extension) const;
+		bool supportsFileType(const String& extension) const;
 
 		/**
 		 * @brief	Checks if we can import a file with the specified magic number.
@@ -52,5 +70,7 @@ namespace CamelotEngine
 		void registerAssetImporter(SpecificImporter* importer);
 	private:
 		vector<SpecificImporter*>::type mAssetImporters;
+
+		SpecificImporter* getImporterForFile(const String& inputFilePath) const;
 	};
 }

+ 37 - 3
CamelotRenderer/Include/CmPrerequisites.h

@@ -144,6 +144,7 @@ namespace CamelotEngine {
 	class GpuProgInclude;
 	class TextureView;
 	class CoreGpuObject;
+	class ImportOptions;
 	// Asset import
 	class SpecificImporter;
 	class Importer;
@@ -167,7 +168,10 @@ namespace CamelotEngine {
 	struct RENDER_TEXTURE_DESC;
 }
 
-/* Shared pointer typedefs*/
+/************************************************************************/
+/* 						Shared pointer typedefs	                    	*/
+/************************************************************************/
+
 namespace CamelotEngine
 {
 	typedef std::shared_ptr<GpuProgram> GpuProgramPtr;
@@ -206,9 +210,13 @@ namespace CamelotEngine
 	typedef std::shared_ptr<TextureView> TextureViewPtr;
 	typedef std::shared_ptr<Viewport> ViewportPtr;
 	typedef std::shared_ptr<GpuProgInclude> GpuProgIncludePtr;
+	typedef std::shared_ptr<ImportOptions> ImportOptionsPtr;
+	typedef std::shared_ptr<const ImportOptions> ConstImportOptionsPtr;
 }
 
-// All type IDs used for RTTI
+/************************************************************************/
+/* 									RTTI                      			*/
+/************************************************************************/
 namespace CamelotEngine
 {
 	enum TypeID_Core
@@ -249,8 +257,34 @@ namespace CamelotEngine
 		TID_BLEND_STATE_DESC = 1034,
 		TID_SHADER_DATA_PARAM_DESC = 1035,
 		TID_SHADER_OBJECT_PARAM_DESC = 1036,
-		TID_SHADER_PARAM_BLOCK_DESC = 1047
+		TID_SHADER_PARAM_BLOCK_DESC = 1047,
+		TID_ImportOptions = 1048,
+		TID_GpuProgramImportOptions = 1049
 	};
+
+	/**
+	 * @brief	Returns true if the provided object can be safely cast into type T.
+	 */
+	template<class T>
+	bool rtti_is_of_type(IReflectable* object)
+	{
+		BOOST_STATIC_ASSERT_MSG((boost::is_base_of<CamelotEngine::IReflectable, T>::value), 
+			"Invalid data type for type checking. It needs to derive from CamelotEngine::IReflectable.");
+
+		return object->getTypeId() == T::getRTTIStatic()->getRTTIId();
+	}
+
+	/**
+	 * @brief	Returns true if the provided object can be safely cast into type T.
+	 */
+	template<class T>
+	bool rtti_is_of_type(std::shared_ptr<IReflectable> object)
+	{
+		BOOST_STATIC_ASSERT_MSG((boost::is_base_of<CamelotEngine::IReflectable, T>::value), 
+			"Invalid data type for type checking. It needs to derive from CamelotEngine::IReflectable.");
+
+		return object->getTypeId() == T::getRTTIStatic()->getRTTIId();
+	}
 }
 
 /************************************************************************/

+ 18 - 1
CamelotRenderer/Include/CmSpecificImporter.h

@@ -28,6 +28,23 @@ namespace CamelotEngine
 		 *
 		 * @return	null if it fails, otherwise the loaded object.
 		 */
-		virtual BaseResourceHandle import(const String& filePath) = 0;
+		virtual BaseResourceHandle import(const String& filePath, ConstImportOptionsPtr importOptions) = 0;
+
+		/**
+		 * @brief	Creates import options specific for this importer. Import
+		 * 			options are provided when calling import() in order to customize the
+		 * 			import, and provide additional information.
+		 */
+		virtual ImportOptionsPtr createImportOptions() const;
+
+		/**
+		 * @brief	Gets the default import options.
+		 *
+		 * @return	The default import options.
+		 */
+		ConstImportOptionsPtr getDefaultImportOptions() const;
+
+	private:
+		mutable ConstImportOptionsPtr mDefaultImportOptions;
 	};
 }

+ 1 - 1
CamelotRenderer/Source/CmGpuProgIncludeImporter.cpp

@@ -29,7 +29,7 @@ namespace CamelotEngine
 		return true; // Plain-text so I don't even check for magic number
 	}
 
-	BaseResourceHandle GpuProgIncludeImporter::import(const String& filePath)
+	BaseResourceHandle GpuProgIncludeImporter::import(const String& filePath, ConstImportOptionsPtr importOptions)
 	{
 		DataStreamPtr stream = FileSystem::open(filePath);
 		String includeString = stream->getAsString();

+ 24 - 0
CamelotRenderer/Source/CmGpuProgramImportOptions.cpp

@@ -0,0 +1,24 @@
+#include "CmGpuProgramImportOptions.h"
+#include "CmGpuProgramImportOptionsRTTI.h"
+
+namespace CamelotEngine
+{
+	GpuProgramImportOptions::GpuProgramImportOptions()
+		:mProfile(GPP_NONE), mType(GPT_VERTEX_PROGRAM)
+	{
+
+	}
+
+	/************************************************************************/
+	/* 								SERIALIZATION                      		*/
+	/************************************************************************/
+	RTTITypeBase* GpuProgramImportOptions::getRTTIStatic()
+	{
+		return GpuProgramImportOptionsRTTI::instance();
+	}
+
+	RTTITypeBase* GpuProgramImportOptions::getRTTI() const
+	{
+		return GpuProgramImportOptions::getRTTIStatic();
+	}
+}

+ 49 - 0
CamelotRenderer/Source/CmGpuProgramImporter.cpp

@@ -0,0 +1,49 @@
+#include "CmGpuProgramImporter.h"
+#include "CmPath.h"
+#include "CmDataStream.h"
+#include "CmFileSystem.h"
+#include "CmGpuProgramImportOptions.h"
+#include "CmHighLevelGpuProgram.h"
+
+namespace CamelotEngine
+{
+	bool GpuProgramImporter::isExtensionSupported(const String& ext) const
+	{
+		if(ext == "gpuprog")
+			return true;
+
+		return false;
+	}
+
+	bool GpuProgramImporter::isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const
+	{
+		// Gpu program files are plain-text so no magic number
+		return true;
+	}
+
+	BaseResourceHandle GpuProgramImporter::import(const String& filePath, ConstImportOptionsPtr importOptions)
+	{
+		String ext = Path::getExtension(filePath);
+		ext = ext.substr(1, ext.size() - 1); // Remove the .
+
+		DataStreamPtr stream = FileSystem::open(filePath);
+		String shaderSource = stream->getAsString();
+
+		const GpuProgramImportOptions* gpuProgImportOptions = static_cast<const GpuProgramImportOptions*>(importOptions.get());
+
+		String entryPoint = gpuProgImportOptions->getEntryPoint();
+		GpuProgramProfile profile = gpuProgImportOptions->getProfile();
+		String language = gpuProgImportOptions->getLanguage();
+		GpuProgramType gptype = gpuProgImportOptions->getType();
+
+		HighLevelGpuProgramHandle gpuProgram = HighLevelGpuProgram::create(shaderSource, entryPoint, language, gptype, profile, nullptr);
+		gpuProgram.waitUntilLoaded();
+
+		return gpuProgram;
+	}
+
+	ImportOptionsPtr GpuProgramImporter::createImportOptions() const
+	{
+		return ImportOptionsPtr(new GpuProgramImportOptions());
+	}
+}

+ 18 - 0
CamelotRenderer/Source/CmImportOptions.cpp

@@ -0,0 +1,18 @@
+#include "CmImportOptions.h"
+#include "CmImportOptionsRTTI.h"
+
+namespace CamelotEngine
+{
+	/************************************************************************/
+	/* 								SERIALIZATION                      		*/
+	/************************************************************************/
+	RTTITypeBase* ImportOptions::getRTTIStatic()
+	{
+		return ImportOptionsRTTI::instance();
+	}
+
+	RTTITypeBase* ImportOptions::getRTTI() const
+	{
+		return ImportOptions::getRTTIStatic();
+	}
+}

+ 51 - 13
CamelotRenderer/Source/CmImporter.cpp

@@ -4,6 +4,8 @@
 #include "CmFileSystem.h"
 #include "CmSpecificImporter.h"
 #include "CmGpuProgIncludeImporter.h"
+#include "CmGpuProgramImporter.h"
+#include "CmImportOptions.h"
 #include "CmDebug.h"
 #include "CmDataStream.h"
 #include "CmException.h"
@@ -13,6 +15,7 @@ namespace CamelotEngine
 	Importer::Importer()
 	{
 		registerAssetImporter(new GpuProgIncludeImporter());
+		registerAssetImporter(new GpuProgramImporter());
 	}
 
 	Importer::~Importer()
@@ -26,7 +29,7 @@ namespace CamelotEngine
 		mAssetImporters.clear();
 	}
 
-	bool Importer::supportsFileType(const std::string& extension) const
+	bool Importer::supportsFileType(const String& extension) const
 	{
 		for(auto iter = mAssetImporters.begin(); iter != mAssetImporters.end(); ++iter)
 		{
@@ -48,7 +51,7 @@ namespace CamelotEngine
 		return false;
 	}
 
-	BaseResourceHandle Importer::import(const String& inputFilePath)
+	BaseResourceHandle Importer::import(const String& inputFilePath, ConstImportOptionsPtr importOptions)
 	{
 		if(!FileSystem::fileExists(inputFilePath))
 		{
@@ -56,28 +59,42 @@ namespace CamelotEngine
 			return BaseResourceHandle();
 		}
 
-		String ext = Path::getExtension(inputFilePath);
-		ext = ext.substr(1, ext.size() - 1); // Remove the .
-		if(!supportsFileType(ext))
-		{
-			LOGWRN("There is no importer for the provided file type. (" + inputFilePath + ")");
+		SpecificImporter* importer = getImporterForFile(inputFilePath);
+		if(importer == nullptr)
 			return BaseResourceHandle();
-		}
 
-		SpecificImporter* importer = nullptr;
-		for(auto iter = mAssetImporters.begin(); iter != mAssetImporters.end(); ++iter)
+		if(importOptions == nullptr)
+			importOptions = importer->getDefaultImportOptions();
+		else
 		{
-			if(*iter != nullptr && (*iter)->isExtensionSupported(ext))
+			ConstImportOptionsPtr defaultImportOptions = importer->getDefaultImportOptions();
+			if(importOptions->getTypeId() != defaultImportOptions->getTypeId())
 			{
-				importer = *iter;
+				CM_EXCEPT(InvalidParametersException, "Provided import options is not of valid type. " \
+					"Expected: " + defaultImportOptions->getTypeName() + ". Got: " + importOptions->getTypeName() + ".");
 			}
 		}
 
-		BaseResourceHandle importedResource = importer->import(inputFilePath);
+		BaseResourceHandle importedResource = importer->import(inputFilePath, importOptions);
 
 		return importedResource;
 	}
 
+	ImportOptionsPtr Importer::createImportOptions(const String& inputFilePath)
+	{
+		if(!FileSystem::fileExists(inputFilePath))
+		{
+			LOGWRN("Trying to import asset that doesn't exists. Asset path: " + inputFilePath);
+			return nullptr;
+		}
+
+		SpecificImporter* importer = getImporterForFile(inputFilePath);
+		if(importer == nullptr)
+			return nullptr;
+
+		return importer->createImportOptions();
+	}
+
 	void Importer::registerAssetImporter(SpecificImporter* importer)
 	{
 		if(!importer)
@@ -88,4 +105,25 @@ namespace CamelotEngine
 
 		mAssetImporters.push_back(importer);
 	}
+
+	SpecificImporter* Importer::getImporterForFile(const String& inputFilePath) const
+	{
+		String ext = Path::getExtension(inputFilePath);
+		ext = ext.substr(1, ext.size() - 1); // Remove the .
+		if(!supportsFileType(ext))
+		{
+			LOGWRN("There is no importer for the provided file type. (" + inputFilePath + ")");
+			return nullptr;
+		}
+
+		for(auto iter = mAssetImporters.begin(); iter != mAssetImporters.end(); ++iter)
+		{
+			if(*iter != nullptr && (*iter)->isExtensionSupported(ext))
+			{
+				return *iter;
+			}
+		}
+
+		return nullptr;
+	}
 }

+ 13 - 0
CamelotRenderer/Source/CmSpecificImporter.cpp

@@ -1,6 +1,19 @@
 #include "CmSpecificImporter.h"
+#include "CmImportOptions.h"
 #include "CmResources.h"
 
 namespace CamelotEngine
 {
+	ImportOptionsPtr SpecificImporter::createImportOptions() const
+	{
+		return ImportOptionsPtr(new ImportOptions());
+	}
+
+	ConstImportOptionsPtr SpecificImporter::getDefaultImportOptions() const
+	{
+		if(mDefaultImportOptions == nullptr)
+			mDefaultImportOptions = createImportOptions();
+
+		return mDefaultImportOptions;
+	}
 }

+ 3 - 4
CamelotRenderer/TODO.txt

@@ -14,7 +14,9 @@ Pass
  - A way to bind buffers to a Pass, while specifying buffer range
  - GpuParams support for bools, buffers, structs
 
-Importers for shaders.
+Shader import:
+ - Make sure none of the current shaders in CamelotClient are defined in code anymore
+ - Add include files to ImportOptions
 
 Seems there is a possible deadlock when starting the render thread, while waiting for the thread to be started
 
@@ -36,11 +38,8 @@ Can be delayed:
  - Better creation of PrimaryWindow
    - RENDERWINDOWDESC accepts a "externalWindow" flag and an "externalHandle" so when creating the primary window with RenderSystem::initialize we don't always need to create a new window
    - Actually new OpenGL seems to support creating context without a window with the help of wglCreateContextAttribsARB and wglMakeCurrent:
- - ImportOptions
-  - Make sure Gpu prog include files can get assigned here
  - Instead of doing setThisPtr on every CoreGpuObject, use intrusive shared_ptr instead?
  - OpenGL render window no longer looks for a monitor index
- - Test if async loading still works
  - Material RTTI should also serialize shared buffers (they need to be made into a resource)
    - BE CAREFUL on how this will be implemented. Likely it will have much of the same interface as a material and/or GpuParams
  - Mesh::setMeshData is currently always synced

+ 3 - 3
CamelotUtility/Include/CmIReflectable.h

@@ -31,7 +31,7 @@ namespace CamelotEngine
 		}
 
 		/**
-		 * @brief	INTERNAL USE. Called by each type deriving from IReflectable,
+		 * @brief	INTERNAL USE ONLY. Called by each type deriving from IReflectable,
 		 * 			on program load.
 		 */
 		static void registerDerivedClass(RTTITypeBase* derivedClass);
@@ -45,8 +45,8 @@ namespace CamelotEngine
 		 */
 		bool isDerivedFrom(RTTITypeBase* base);
 
-		UINT32 getTypeId();
-
+		UINT32 getTypeId() const;
+		const String& getTypeName() const;
 	protected:
 		boost::any mRTTIData; // Temporary per-instance data storage used during various RTTI operations.
 							  // Needed since there is one RTTI class instance per type and sometimes we need per-instance data.

+ 6 - 3
CamelotUtility/Include/CmRTTIType.h

@@ -303,8 +303,11 @@ namespace CamelotEngine
 	};
 
 	/**
-	 * @brief	Pretty much just an extension of RTTITypeBase. Feel free to derive from this class and return
-	 * 			the derived class from IReflectable::getRTTI. This way you can separate serialization logic from
+	 * @brief	Allows you to provide a run-time type information for a specific class, along with 
+	 * 			support for serialization/deserialization.
+	 * 			
+	 * 			Derive from this class and return the derived class from IReflectable::getRTTI. 
+	 * 			This way you can separate serialization logic from
 	 * 			the actual class you're serializing.
 	 */
 	template <typename Type, typename BaseType, typename MyRTTIType>
@@ -320,7 +323,7 @@ namespace CamelotEngine
 	public:
 		RTTIType() 
 		{
-			// Templates only actually generate code for stuff that is directly used, including static data members,
+			// Compiler will only generate code for stuff that is directly used, including static data members,
 			// so we fool it here like we're using the class directly. Otherwise compiler won't generate the code for the member
 			// and our type won't get initialized on start (Actual behavior is a bit more random)
 			initOnStart.makeSureIAmInstantiated();

+ 6 - 1
CamelotUtility/Source/CmIReflectable.cpp

@@ -80,8 +80,13 @@ namespace CamelotEngine
 		return false;
 	}
 
-	UINT32 IReflectable::getTypeId()
+	UINT32 IReflectable::getTypeId() const
 	{ 
 		return getRTTI()->getRTTIId(); 
 	}
+
+	const String& IReflectable::getTypeName() const
+	{
+		return getRTTI()->getRTTIName();
+	}
 }