ソースを参照

Texture loading works

Marko Pintera 13 年 前
コミット
7cdfa405af

+ 0 - 3
CamelotClient/CamelotClient.cpp

@@ -15,9 +15,6 @@ int _tmain(int argc, _TCHAR* argv[])
 	gApplication().startUp("CamelotGLRenderer.dll");
 	gApplication().startUp("CamelotGLRenderer.dll");
 	//gApplication().startUp("CamelotD3D9Renderer.dll");
 	//gApplication().startUp("CamelotD3D9Renderer.dll");
 
 
-	DynLib* loadedLibrary = gDynLibManager().load("CamelotFreeImgImporter.dll"); // TODO - Load this automatically somehow
-
-
 	test();
 	test();
 
 
 	gApplication().runMainLoop();
 	gApplication().runMainLoop();

+ 15 - 19
CamelotFreeImgImporter/Include/CmFreeImgImporter.h

@@ -12,6 +12,19 @@ namespace CamelotEngine
 		FreeImgImporter();
 		FreeImgImporter();
 		virtual ~FreeImgImporter();
 		virtual ~FreeImgImporter();
 
 
+		/**
+		 * @brief	Should only be called by the plugin when its being loaded.
+		 */
+		static void startUp()
+		{
+			static FreeImgImporter* importer = nullptr;
+			if(importer == nullptr)
+			{
+				importer = new FreeImgImporter();
+				Importer::instance().registerAssetImporter(importer);
+			}
+		}
+
 		/** Inherited from SpecificImporter */
 		/** Inherited from SpecificImporter */
 		virtual bool isExtensionSupported(const String& ext) const;
 		virtual bool isExtensionSupported(const String& ext) const;
 
 
@@ -19,29 +32,12 @@ namespace CamelotEngine
 		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const; 
 		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const; 
 
 
 		/** Inherited from SpecificImporter */
 		/** Inherited from SpecificImporter */
-		virtual ResourcePtr import(DataStream* fileData);
-
+		virtual ResourcePtr import(DataStreamPtr fileData);
 	private:
 	private:
 		vector<String>::type mExtensions;
 		vector<String>::type mExtensions;
 		std::unordered_map<String, int> mExtensionToFID;
 		std::unordered_map<String, int> mExtensionToFID;
 
 
 		String magicNumToExtension(const UINT8* magic, UINT32 maxBytes) const;
 		String magicNumToExtension(const UINT8* magic, UINT32 maxBytes) const;
-		TextureDataPtr importRawImage(DataStream* fileData);
-
-		class InitOnStart
-		{
-		public:
-			InitOnStart() 
-			{ 
-				static FreeImgImporter* importer = nullptr;
-				if(importer == nullptr)
-				{
-					importer = new FreeImgImporter();
-					Importer::instance().registerAssetImporter(importer);
-				}
-			}
-		};
-
-		static InitOnStart initOnStart; // Makes sure importer is registered on program start
+		TextureDataPtr importRawImage(DataStreamPtr fileData);
 	};
 	};
 }
 }

+ 2 - 2
CamelotFreeImgImporter/Source/CmFreeImgImporter.cpp

@@ -126,7 +126,7 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	ResourcePtr FreeImgImporter::import(DataStream* fileData)
+	ResourcePtr FreeImgImporter::import(DataStreamPtr fileData)
 	{
 	{
 		TextureDataPtr imgData = importRawImage(fileData);
 		TextureDataPtr imgData = importRawImage(fileData);
 		if(imgData == nullptr || imgData->getData() == nullptr)
 		if(imgData == nullptr || imgData->getData() == nullptr)
@@ -140,7 +140,7 @@ namespace CamelotEngine
 		return newTexture;
 		return newTexture;
 	}
 	}
 
 
-	TextureDataPtr FreeImgImporter::importRawImage(DataStream* fileData)
+	TextureDataPtr FreeImgImporter::importRawImage(DataStreamPtr fileData)
 	{
 	{
 		size_t magicLen = std::min(fileData->size(), (size_t)32);
 		size_t magicLen = std::min(fileData->size(), (size_t)32);
 		UINT8 magicBuf[32];
 		UINT8 magicBuf[32];

+ 6 - 0
CamelotFreeImgImporter/Source/CmFreeImgPlugin.cpp

@@ -1,4 +1,5 @@
 #include "CmFreeImgPrerequisites.h"
 #include "CmFreeImgPrerequisites.h"
+#include "CmFreeImgImporter.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
@@ -7,4 +8,9 @@ namespace CamelotEngine
 		static String pluginName = "FreeImageImporter";
 		static String pluginName = "FreeImageImporter";
 		return pluginName;
 		return pluginName;
 	}
 	}
+
+	extern "C" CM_FREEIMG_EXPORT void loadPlugin()
+	{
+		FreeImgImporter::startUp();
+	}
 }
 }

+ 4 - 18
CamelotRenderer/Include/CmImporter.h

@@ -9,35 +9,21 @@ namespace CamelotEngine
 	 * @brief	Module responsible for importing various asset types and converting
 	 * @brief	Module responsible for importing various asset types and converting
 	 * 			them to types usable by the engine.
 	 * 			them to types usable by the engine.
 	 */
 	 */
-	class Importer : public Module<Importer>
+	class CM_EXPORT Importer : public Module<Importer>
 	{
 	{
 	public:
 	public:
 		/**
 		/**
 		 * @brief	Constructor.
 		 * @brief	Constructor.
-		 *
-		 * @param	assetDatabasePath	Pathname of the asset database file. Path should not include file extension.
-		 * 								If the database file doesn't exist it will be created in that location.
-		 * 								Meta data for imported resources will be stored in the asset database.
 		 */
 		 */
-		Importer(const String& assetDatabasePath); 
+		Importer(); 
 		~Importer(); 
 		~Importer(); 
 
 
 		/**
 		/**
-		 * @brief	Imports a resource at the specified location, and saves the imported data into the
-		 * 			output location. This data can then be loaded with Resources.load. Existing files
-		 * 			will be replaced.
+		 * @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	outputFilePath	Pathname of the output file, without extension.
-		 * @param	keepReferences	(optional) If file is being replaced we can keep all references to it and
-		 * 							just make sure they point to the new file data (default), or we can invalidate all
-		 * 							references and treat it as a completely new file. 
-		 * 							
-		 *							If you're just updating a file keep this set to true, and if you're
-		 * 							replacing a file, set it to false. 
-		 * 							In order for the references to be kept asset types must match.
 		 */
 		 */
-		void import(const String& inputFilePath, const String& outputFilePath, bool keepReferences = true);
+		ResourcePtr import(const String& inputFilePath);
 
 
 
 
 		/**
 		/**

+ 1 - 1
CamelotRenderer/Include/CmSpecificImporter.h

@@ -28,6 +28,6 @@ namespace CamelotEngine
 		 *
 		 *
 		 * @return	null if it fails, otherwise the loaded object.
 		 * @return	null if it fails, otherwise the loaded object.
 		 */
 		 */
-		virtual ResourcePtr import(DataStream* fileData) = 0;
+		virtual ResourcePtr import(DataStreamPtr fileData) = 0;
 	};
 	};
 }
 }

+ 17 - 0
CamelotRenderer/Source/CmApplication.cpp

@@ -10,7 +10,9 @@
 #include "CmViewport.h"
 #include "CmViewport.h"
 #include "CmHighLevelGpuProgram.h"
 #include "CmHighLevelGpuProgram.h"
 #include "CmHighLevelGpuProgramManager.h"
 #include "CmHighLevelGpuProgramManager.h"
+#include "CmDynLib.h"
 #include "CmDynLibManager.h"
 #include "CmDynLibManager.h"
+#include "CmImporter.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
@@ -82,6 +84,21 @@ namespace CamelotEngine
 
 
 		mVertProg = HighLevelGpuProgramManager::instance().createProgram(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 		mVertProg = HighLevelGpuProgramManager::instance().createProgram(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 		mVertProg->load();
 		mVertProg->load();
+
+
+		// IMPORTER TEST
+		Importer::startUp(new Importer());
+		DynLib* loadedLibrary = gDynLibManager().load("CamelotFreeImgImporter.dll"); // TODO - Load this automatically somehow
+
+		if(loadedLibrary != nullptr)
+		{
+			typedef const void (*LoadPluginFunc)();
+
+			LoadPluginFunc loadPluginFunc = (LoadPluginFunc)loadedLibrary->getSymbol("loadPlugin");
+			loadPluginFunc();
+		}
+
+		TexturePtr loadedTexture = std::static_pointer_cast<Texture>(Importer::instance().import("C:\\ImportTest.tga"));
 	}
 	}
 
 
 	void Application::runMainLoop()
 	void Application::runMainLoop()

+ 18 - 9
CamelotRenderer/Source/CmImporter.cpp

@@ -1,5 +1,6 @@
 #include "CmImporter.h"
 #include "CmImporter.h"
 #include "CmPath.h"
 #include "CmPath.h"
+#include "CmFileSystem.h"
 #include "CmSpecificImporter.h"
 #include "CmSpecificImporter.h"
 #include "CmDebug.h"
 #include "CmDebug.h"
 #include "CmDataStream.h"
 #include "CmDataStream.h"
@@ -7,6 +8,9 @@
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
+	Importer::Importer()
+	{ }
+
 	Importer::~Importer()
 	Importer::~Importer()
 	{
 	{
 		for(auto i = mAssetImporters.begin(); i != mAssetImporters.end(); ++i)
 		for(auto i = mAssetImporters.begin(); i != mAssetImporters.end(); ++i)
@@ -40,12 +44,12 @@ namespace CamelotEngine
 		return false;
 		return false;
 	}
 	}
 
 
-	void Importer::import(const String& inputFilePath, const String& outputFilePath, bool keepReferences)
+	ResourcePtr Importer::import(const String& inputFilePath)
 	{
 	{
 		if(!Path::exists(inputFilePath))
 		if(!Path::exists(inputFilePath))
 		{
 		{
 			LOGWRN("Trying to import asset that doesn't exists. Asset path: " + inputFilePath);
 			LOGWRN("Trying to import asset that doesn't exists. Asset path: " + inputFilePath);
-			return;
+			return nullptr;
 		}
 		}
 
 
 		String ext = Path::getExtension(inputFilePath);
 		String ext = Path::getExtension(inputFilePath);
@@ -53,17 +57,22 @@ namespace CamelotEngine
 		if(!supportsFileType(ext))
 		if(!supportsFileType(ext))
 		{
 		{
 			LOGWRN("There is no importer for the provided file type. (" + inputFilePath + ")");
 			LOGWRN("There is no importer for the provided file type. (" + inputFilePath + ")");
-			return;
+			return nullptr;
 		}
 		}
 
 
-		//SpecificImporter* importer = mAssetImporters[ext];
-
-		//FileDataStream fileSteam()
+		SpecificImporter* importer = nullptr;
+		for(auto iter = mAssetImporters.begin(); iter != mAssetImporters.end(); ++iter)
+		{
+			if(*iter != nullptr && (*iter)->isExtensionSupported(ext))
+			{
+				importer = *iter;
+			}
+		}
 
 
-		//ResourcePtr importedResource = importer->import(inputFilePath);
+		DataStreamPtr fileSteam = FileSystem::open(inputFilePath, true);
+		ResourcePtr importedResource = importer->import(fileSteam);
 
 
-		// TODO - Use AssetDatabase for loading the resource
-		// TODO - Serialize the resource to output location
+		return importedResource;
 	}
 	}
 
 
 	void Importer::registerAssetImporter(SpecificImporter* importer)
 	void Importer::registerAssetImporter(SpecificImporter* importer)

+ 2 - 1
CamelotUtility/Include/CmFileSystem.h

@@ -4,8 +4,9 @@
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	class FileSystem
+	class CM_UTILITY_EXPORT FileSystem
 	{
 	{
+	public:
 		static DataStreamPtr open(const String& fullPath, bool readOnly = true);
 		static DataStreamPtr open(const String& fullPath, bool readOnly = true);
 
 
 		static DataStreamPtr create(const String& fullPath);
 		static DataStreamPtr create(const String& fullPath);