Browse Source

Now textures load properly

Marko Pintera 13 years ago
parent
commit
b294baa059

+ 1 - 1
CamelotFreeImgImporter/Source/CmFreeImgImporter.cpp

@@ -305,7 +305,7 @@ namespace CamelotEngine
 		FreeImage_Unload(fiBitmap);
 		FreeImage_CloseMemory(fiMem);
 
-		TextureDataPtr texData(new TextureData(width, height, size, format, output, 1, 0, 1));
+		TextureDataPtr texData(new TextureData(width, height, size, format, output, 1, 0, 0));
 		return texData;
 	}
 }

+ 9 - 3
CamelotRenderer/Include/CmResources.h

@@ -28,12 +28,10 @@ namespace CamelotEngine
 		 * 										references to temporary resource objects because they won't
 		 * 										persist after application shut-down, but otherwise they act
 		 * 										the same as normal resources.
-		 * @param	onlyLoadIfFoundInAssetDB	(optional) If true, we disallow loading of temporary resources,
-		 * 										i.e. resources that can't be found in the asset database.
 		 *
 		 * @return	Loaded resource, or null if it cannot be found.
 		 */
-		ResourcePtr load(const String& filePath, bool onlyLoadIfFoundInAssetDB = false);
+		ResourcePtr load(const String& filePath);
 
 		/**
 		 * @brief	Loads the resource with the given uuid.
@@ -43,5 +41,13 @@ namespace CamelotEngine
 		 * @return	Loaded resource, or null if it cannot be found.
 		 */
 		ResourcePtr load(const UUID& uuid);
+
+		/**
+		 * @brief	Saves the resource at the specified location.
+		 *
+		 * @param	resource	The resource.
+		 * @param	filePath	Full pathname of the file.
+		 */
+		void save(ResourcePtr resource, const String& filePath);
 	};
 }

+ 1 - 1
CamelotRenderer/Include/CmSpecificImporter.h

@@ -9,7 +9,7 @@ namespace CamelotEngine
 	 * 			a certain asset type into an engine usable resource. 
 	 * 			(e.g. a .png file into an engine usable texture).
 	 * 			
-	 *			On initialization this class registers itself with the Importer module,
+	 *			On initialization this class must register itself with the Importer module,
 	 *			which delegates asset import calls to a specific importer.
 	 */
 	class SpecificImporter

+ 2 - 2
CamelotRenderer/Include/CmTexture.h

@@ -339,7 +339,7 @@ namespace CamelotEngine {
 		 *
 		 * @return	Texture data for the wanted face.
 		 */
-		TextureDataPtr getTextureData(int face);
+		TextureDataPtr getTextureData(UINT32 face);
 
 		/**
 		 * @brief	Sets the texture data that will be used for initializing the texture.
@@ -350,7 +350,7 @@ namespace CamelotEngine {
 		 * 						+X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
 		 * @param	textureData	Texture data for the face.
 		 */
-		void setTextureData(int face, TextureDataPtr textureData);
+		void setTextureData(UINT32 face, TextureDataPtr textureData);
 
     protected:
         size_t mHeight;

+ 2 - 0
CamelotRenderer/Source/CmImporter.cpp

@@ -1,5 +1,6 @@
 #include "CmImporter.h"
 #include "CmPath.h"
+#include "CmResource.h"
 #include "CmFileSystem.h"
 #include "CmSpecificImporter.h"
 #include "CmDebug.h"
@@ -71,6 +72,7 @@ namespace CamelotEngine
 
 		DataStreamPtr fileSteam = FileSystem::open(inputFilePath, true);
 		ResourcePtr importedResource = importer->import(fileSteam);
+		importedResource->load();
 
 		return importedResource;
 	}

+ 5 - 5
CamelotRenderer/Source/CmTexture.cpp

@@ -127,7 +127,7 @@ namespace CamelotEngine {
 		}
 	}
 	//-----------------------------------------------------------------------------
-	TextureDataPtr Texture::getTextureData(int face)
+	TextureDataPtr Texture::getTextureData(UINT32 face)
 	{
 		if(face < 0 || face >= getNumFaces())
 		{
@@ -141,7 +141,7 @@ namespace CamelotEngine {
 		UINT32 height = getHeight();
 		UINT32 depth = getDepth();
 
-		for(int j = 0; j < numMips; j++)
+		for(UINT32 j = 0; j < numMips; j++)
 		{
 			UINT32 currentMipSize = PixelUtil::getMemorySize(
 					width, height, depth, mFormat);
@@ -156,7 +156,7 @@ namespace CamelotEngine {
 		UINT8* buffer = new UINT8[totalSize]; // TextureData frees this
 		TextureDataPtr texData(new TextureData(getWidth(), getHeight(), totalSize, mFormat, buffer, getDepth(), 0, getNumMipmaps()));
 
-		for(int j = 0; j < numMips; j++)
+		for(UINT32 j = 0; j < numMips; j++)
 		{
 			PixelData pixels = texData->getPixels(j);
 			getBuffer(face, j)->blitToMemory(pixels);
@@ -165,7 +165,7 @@ namespace CamelotEngine {
 		return texData;
 	}
 	//-----------------------------------------------------------------------------
-	void Texture::setTextureData(int face, TextureDataPtr textureData)
+	void Texture::setTextureData(UINT32 face, TextureDataPtr textureData)
 	{
 		if(face < 0 || face >= getNumFaces())
 		{
@@ -235,7 +235,7 @@ namespace CamelotEngine {
 		else
 			faces = 1;
 
-		// Check wether number of faces in images exceeds number of faces
+		// Check whether number of faces in images exceeds number of faces
 		// in this texture. If so, clamp it.
 		if(faces > getNumFaces())
 			faces = getNumFaces();

+ 1 - 1
CamelotUtility/Include/CmTextureData.h

@@ -46,7 +46,7 @@ namespace CamelotEngine
 
         /** Returns true if the image has the appropriate flag set.
         */
-		bool hasFlag(const TextureDataFlags flag) const { return (mFlags & flag); }
+		bool hasFlag(const TextureDataFlags flag) const { return (mFlags & flag) != 0; }
 
         /** Gets the width of the image in pixels.
         */

+ 1 - 1
CamelotUtility/Source/CmTextureData.cpp

@@ -20,7 +20,7 @@ namespace CamelotEngine
 
 	PixelData TextureData::getPixels(UINT32 mip)
 	{
-		if(mip < 0 || mip >= mNumMipmaps)
+		if(mip < 0 || mip > mNumMipmaps)
 		{
 			CM_EXCEPT(InvalidParametersException, "Mip out of range: " + toString(mip) + ". While maximum available mip is: " + toString((mNumMipmaps)));
 		}