Browse Source

Some more work on textures

Marko Pintera 13 years ago
parent
commit
45b9d39a3e

+ 0 - 8
CamelotClient/TestingGround.cpp

@@ -9,15 +9,7 @@ using namespace CamelotEngine;
 
 
 void test()
 void test()
 {
 {
-	Resource* dbgResource = new Resource();
-	UINT32 size = 5;
-	dbgResource->getSerializable()->setPlainValue(dbgResource, "Size", size);
-
 	FileSerializer fs;
 	FileSerializer fs;
-	fs.encode(dbgResource, "C:\\ResourceTest.res");
-
-	ResourcePtr loadedResource(new Resource());
-	fs.decode(loadedResource, "C:\\ResourceTest.res");
 
 
 	TexturePtr dbgTexture = TextureManager::instance().create(TEX_TYPE_2D, 128, 128, 1, PF_A8B8G8R8);
 	TexturePtr dbgTexture = TextureManager::instance().create(TEX_TYPE_2D, 128, 128, 1, PF_A8B8G8R8);
 	dbgTexture->setFSAA(0, "test");
 	dbgTexture->setFSAA(0, "test");

+ 7 - 14
CamelotD3D9Renderer/Include/CmD3D9Texture.h

@@ -79,11 +79,11 @@ namespace CamelotEngine {
 		DWORD mFSAAQuality;
 		DWORD mFSAAQuality;
 
 
 		/// internal method, load a cube texture
 		/// internal method, load a cube texture
-		//void _loadCubeTex(IDirect3DDevice9* d3d9Device, const vector<DataStreamPtr>::type& imageDataStreams);
+		void _loadCubeTex(IDirect3DDevice9* d3d9Device);
 		/// internal method, load a normal texture
 		/// internal method, load a normal texture
-		//void _loadNormTex(IDirect3DDevice9* d3d9Device, const vector<DataStreamPtr>::type& imageDataStreams);
+		void _loadNormTex(IDirect3DDevice9* d3d9Device);
 		/// internal method, load a volume texture
 		/// internal method, load a volume texture
-		//void _loadVolumeTex(IDirect3DDevice9* d3d9Device, const vector<DataStreamPtr>::type& imageDataStreams);
+		void _loadVolumeTex(IDirect3DDevice9* d3d9Device);
 
 
 		/// internal method, create a blank normal 1D/2D texture		
 		/// internal method, create a blank normal 1D/2D texture		
 		void _createNormTex(IDirect3DDevice9* d3d9Device);
 		void _createNormTex(IDirect3DDevice9* d3d9Device);
@@ -128,11 +128,9 @@ namespace CamelotEngine {
 		/// internal method, create D3D9HardwarePixelBuffers for every face and
 		/// internal method, create D3D9HardwarePixelBuffers for every face and
 		/// mipmap level. This method must be called after the D3D texture object was created
 		/// mipmap level. This method must be called after the D3D texture object was created
 		void _createSurfaceList(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
 		void _createSurfaceList(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
-
-        /// overriden from Resource
-        void loadImpl();		 
+	 
 		/// Loads this texture into the specified device.
 		/// Loads this texture into the specified device.
-		void loadImpl(IDirect3DDevice9* d3d9Device);
+		void load(IDirect3DDevice9* d3d9Device);
 
 
 		/// gets the texture resources attached to the given device.
 		/// gets the texture resources attached to the given device.
 		TextureResources* getTextureResources(IDirect3DDevice9* d3d9Device);
 		TextureResources* getTextureResources(IDirect3DDevice9* d3d9Device);
@@ -148,13 +146,6 @@ namespace CamelotEngine {
 
 
 		void determinePool();
 		void determinePool();
 
 
-        /** Vector of pointers to streams that were pulled from disk by
-            prepareImpl  but have yet to be pushed into texture memory
-            by loadImpl.  Should be cleared on load and on unprepare.
-        */
-		// TODO PORT - Loading tex from streams not supported
-        //LoadedStreams mLoadedStreams;
-
 		friend class D3D9HardwarePixelBuffer;
 		friend class D3D9HardwarePixelBuffer;
 	public:
 	public:
 		/// constructor 
 		/// constructor 
@@ -165,6 +156,8 @@ namespace CamelotEngine {
 		/// overridden from Texture
 		/// overridden from Texture
 		void copyToTexture( TexturePtr& target );
 		void copyToTexture( TexturePtr& target );
 
 
+		/// overriden from Resource
+		void load();	
 
 
 		/// @copydoc Texture::getBuffer
 		/// @copydoc Texture::getBuffer
 		HardwarePixelBufferPtr getBuffer(size_t face, size_t mipmap);
 		HardwarePixelBufferPtr getBuffer(size_t face, size_t mipmap);

+ 70 - 436
CamelotD3D9Renderer/Source/CmD3D9Texture.cpp

@@ -36,6 +36,7 @@ THE SOFTWARE.
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9ResourceManager.h"
 #include "CmD3D9ResourceManager.h"
 #include "CmRenderSystemManager.h"
 #include "CmRenderSystemManager.h"
+#include "CmTextureData.h"
 
 
 namespace CamelotEngine 
 namespace CamelotEngine 
 {
 {
@@ -180,7 +181,7 @@ namespace CamelotEngine
 		}		
 		}		
 	}
 	}
 	/****************************************************************************************/
 	/****************************************************************************************/
-	void D3D9Texture::loadImpl()
+	void D3D9Texture::load()
 	{
 	{
 		if (!mInternalResourcesCreated)
 		if (!mInternalResourcesCreated)
 		{
 		{
@@ -196,12 +197,12 @@ namespace CamelotEngine
 		{
 		{
 			IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getResourceCreationDevice(i);
 			IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getResourceCreationDevice(i);
 
 
-			loadImpl(d3d9Device);
+			load(d3d9Device);
 		}		
 		}		
 	}
 	}
 
 
 	/****************************************************************************************/
 	/****************************************************************************************/
-	void D3D9Texture::loadImpl(IDirect3DDevice9* d3d9Device)
+	void D3D9Texture::load(IDirect3DDevice9* d3d9Device)
 	{		
 	{		
 		if (mUsage & TU_RENDERTARGET)
 		if (mUsage & TU_RENDERTARGET)
 		{
 		{
@@ -209,41 +210,22 @@ namespace CamelotEngine
 			return;
 			return;
 		}
 		}
 
 
-		// TODO PORT - Loading tex from streams not supported
-		//// Make sure streams prepared.
-		//if (mLoadedStreams.isNull())
-		//{
-		//	prepareImpl();
-		//}
-		//
-
-		//// Set reading positions of loaded streams to the beginning.
-		//for (UINT32 i = 0; i < mLoadedStreams->size(); ++i)
-		//{
-		//	MemoryDataStreamPtr curDataStream = (*mLoadedStreams)[i];
-
-		//	curDataStream->seek(0);
-		//}
-
-		//// only copy is on the stack so well-behaved if exception thrown
-		//LoadedStreams loadedStreams = mLoadedStreams;
-	
-		//// load based on tex.type
-		//switch (getTextureType())
-		//{
-		//case TEX_TYPE_1D:
-		//case TEX_TYPE_2D:
-		//	_loadNormTex(d3d9Device, loadedStreams);
-		//	break;
-		//case TEX_TYPE_3D:
-		//	_loadVolumeTex(d3d9Device, loadedStreams);
-		//	break;
-		//case TEX_TYPE_CUBE_MAP:
-		//	_loadCubeTex(d3d9Device, loadedStreams);
-		//	break;
-		//default:
-		//	OGRE_EXCEPT( Exception::ERR_INTERNAL_ERROR, "Unknown texture type", "D3D9Texture::loadImpl" );
-		//}				
+		// load based on tex.type
+		switch (getTextureType())
+		{
+		case TEX_TYPE_1D:
+		case TEX_TYPE_2D:
+			_loadNormTex(d3d9Device);
+			break;
+		case TEX_TYPE_3D:
+			_loadVolumeTex(d3d9Device);
+			break;
+		case TEX_TYPE_CUBE_MAP:
+			_loadCubeTex(d3d9Device);
+			break;
+		default:
+			CM_EXCEPT(InternalErrorException, "Unknown texture type");
+		}				
 	}
 	}
 
 
 	/****************************************************************************************/
 	/****************************************************************************************/
@@ -331,406 +313,58 @@ namespace CamelotEngine
 	}
 	}
 
 
 	/****************************************************************************************/
 	/****************************************************************************************/
-	// TODO PORT - Loading tex from streams not supported
-//	void D3D9Texture::_loadCubeTex(IDirect3DDevice9* d3d9Device, const D3D9Texture::LoadedStreams &loadedStreams)
-//	{
-		
-		//assert(getTextureType() == TEX_TYPE_CUBE_MAP);
-
-  //      // DDS load?
-		//if (getSourceFileType() == "dds")
-		//{
-  //          // find & load resource data
-  //          assert(loadedStreams->size()==1);
-
-		//	DWORD usage = 0;
-		//	UINT numMips = (mNumRequestedMipmaps == MIP_UNLIMITED) ?
-		//		D3DX_DEFAULT : mNumRequestedMipmaps + 1;
-		//	
-		//	D3D9Device* device = D3D9RenderSystem::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
-		//	const D3DCAPS9& rkCurCaps = device->getD3D9DeviceCaps();			
-
-		//	// check if mip map volume textures are supported	
-		//	if (!(rkCurCaps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP))
-		//	{
-		//		// no mip map support for this kind of textures :(
-		//		mNumMipmaps = 0;
-		//		numMips = 1;
-		//	}
-
-  //          // Determine D3D pool to use
-  //          D3DPOOL pool;
-  //          if (useDefaultPool())
-  //          {
-  //              pool = D3DPOOL_DEFAULT;
-  //          }
-  //          else
-  //          {
-  //              pool = D3DPOOL_MANAGED;
-  //          }
-		//		
-		//	TextureResources* textureResources;			
-		//
-		//	// Get or create new texture resources structure.
-		//	textureResources = getTextureResources(d3d9Device);
-		//	if (textureResources != NULL)
-		//		freeTextureResources(d3d9Device, textureResources);
-		//	else
-		//		textureResources = allocateTextureResources(d3d9Device);
-
-		//	HRESULT hr;
-
-		//	hr = D3DXCreateCubeTextureFromFileInMemoryEx(
-		//		d3d9Device,
-		//		(*loadedStreams)[0]->getPtr(),
-		//		static_cast<UINT>((*loadedStreams)[0]->size()),
-		//		D3DX_DEFAULT, // dims (square)
-		//		numMips,
-		//		usage,
-		//		D3DFMT_UNKNOWN,
-		//		pool,
-		//		D3DX_DEFAULT,
-		//		D3DX_DEFAULT,
-		//		0,  // colour key
-		//		NULL, // src box
-		//		NULL, // palette
-		//		&textureResources->pCubeTex); 
-
-  //          if (FAILED(hr))
-		//    {
-		//		freeInternalResources();
-		//		OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't create cube texture: " + String(DXGetErrorDescription(hr)), 
-		//			"D3D9Texture::_loadCubeTex" );
-		//    }
-
-  //          hr = textureResources->pCubeTex->QueryInterface(IID_IDirect3DBaseTexture9, (void **)&textureResources->pBaseTex);
-
-  //          if (FAILED(hr))
-		//    {
-		//		freeInternalResources();
-		//		OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't get base texture: " + String(DXGetErrorDescription(hr)), 
-		//			"D3D9Texture::_loadCubeTex" );
-		//    }
-
-  //          D3DSURFACE_DESC texDesc;
-  //          textureResources->pCubeTex->GetLevelDesc(0, &texDesc);
-  //          mD3DPool = texDesc.Pool;
-  //          // set src and dest attributes to the same, we can't know
-  //          _setSrcAttributes(texDesc.Width, texDesc.Height, 1, D3D9Mappings::_getPF(texDesc.Format));
-  //          _setFinalAttributes(d3d9Device, textureResources, 
-		//		texDesc.Width, texDesc.Height, 1,  D3D9Mappings::_getPF(texDesc.Format));
-
-		//	if( mHwGamma )
-		//	{
-		//		mHwGammaReadSupported = _canUseHardwareGammaCorrection( d3d9Device, texDesc.Usage,
-		//																D3DRTYPE_CUBETEXTURE,
-		//																texDesc.Format, false);
-		//	}
-
-		//	mInternalResourcesCreated = true;
-  //      }
-  //      else
-  //      {
-  //          assert(loadedStreams->size()==6);
-
-		//	String  ext;
-		//	size_t pos = mName.find_last_of(".");
-		//	if ( pos != String::npos )
-		//		ext = mName.substr(pos+1);
-
-		//	vector<Image>::type images(6);
-		//	ConstImagePtrList imagePtrs;
-
-		//	for(size_t i = 0; i < 6; i++)
-		//	{
-		//		DataStreamPtr stream((*loadedStreams)[i]);
-		//		images[i].load(stream, ext);
-
-		//		imagePtrs.push_back(&images[i]);
-		//	}
-
-  //          _loadImages( imagePtrs );
-  //      }
-//	}
+	void D3D9Texture::_loadCubeTex(IDirect3DDevice9* d3d9Device)
+	{
+		assert(getTextureType() == TEX_TYPE_CUBE_MAP);
+		assert(mTextureData.size() == 6);
+
+        initializeFromTextureData();
+	}
 	/****************************************************************************************/
 	/****************************************************************************************/
-// TODO PORT - Loading tex from streams not supported
-//	void D3D9Texture::_loadVolumeTex(IDirect3DDevice9* d3d9Device, const D3D9Texture::LoadedStreams &loadedStreams)
-//	{
-		// TODO PORT - Loading tex from streams not supported
-		//assert(getTextureType() == TEX_TYPE_3D);
-		//// DDS load?
-		//if (getSourceFileType() == "dds")
-		//{
-		//	// find & load resource data
-  //          assert(loadedStreams->size()==1);
-	
-		//	DWORD usage = 0;
-		//	UINT numMips = (mNumRequestedMipmaps == MIP_UNLIMITED) ?
-		//		D3DX_DEFAULT : mNumRequestedMipmaps + 1;
-		//				
-		//	D3D9Device* device = D3D9RenderSystem::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
-		//	const D3DCAPS9& rkCurCaps = device->getD3D9DeviceCaps();			
-
-		//	// check if mip map volume textures are supported
-		//	if (!(rkCurCaps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
-		//	{
-		//		// no mip map support for this kind of textures :(
-		//		mNumMipmaps = 0;
-		//		numMips = 1;
-		//	}
-
-  //          // Determine D3D pool to use
-  //          D3DPOOL pool;
-  //          if (useDefaultPool())
-  //          {
-  //              pool = D3DPOOL_DEFAULT;
-  //          }
-  //          else
-  //          {
-  //              pool = D3DPOOL_MANAGED;
-  //          }
-		//	
-		//	TextureResources* textureResources;			
-		//	
-		//	// Get or create new texture resources structure.
-		//	textureResources = getTextureResources(d3d9Device);
-		//	if (textureResources != NULL)
-		//		freeTextureResources(d3d9Device, textureResources);
-		//	else
-		//		textureResources = allocateTextureResources(d3d9Device);
-
-		//	HRESULT hr;
-
-		//	hr = D3DXCreateVolumeTextureFromFileInMemoryEx(
-		//		d3d9Device,
-		//		(*loadedStreams)[0]->getPtr(),
-		//		static_cast<UINT>((*loadedStreams)[0]->size()),
-		//		D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, // dims
-		//		numMips,
-		//		usage,
-		//		D3DFMT_UNKNOWN,
-		//		pool,
-		//		D3DX_DEFAULT,
-		//		D3DX_DEFAULT,
-		//		0,  // colour key
-		//		NULL, // src box
-		//		NULL, // palette
-		//		&textureResources->pVolumeTex); 
-	
-		//	if (FAILED(hr))
-		//	{
-		//		OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
-		//			"Unable to load volume texture from: " + String(DXGetErrorDescription(hr)),
-		//			"D3D9Texture::_loadVolumeTex");
-		//	}
-	
-		//	hr = textureResources->pVolumeTex->QueryInterface(IID_IDirect3DBaseTexture9, (void **)&textureResources->pBaseTex);
-	
-		//	if (FAILED(hr))
-		//	{
-		//		freeInternalResources();
-		//		OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't get base texture: " + String(DXGetErrorDescription(hr)), 
-		//			"D3D9Texture::_loadVolumeTex" );
-		//	}
-	
-		//	D3DVOLUME_DESC texDesc;
-		//	hr = textureResources->pVolumeTex->GetLevelDesc(0, &texDesc);
-  //          mD3DPool = texDesc.Pool;
-		//	// set src and dest attributes to the same, we can't know
-		//	_setSrcAttributes(texDesc.Width, texDesc.Height, texDesc.Depth, D3D9Mappings::_getPF(texDesc.Format));
-		//	_setFinalAttributes(d3d9Device, textureResources, 
-		//		texDesc.Width, texDesc.Height, texDesc.Depth, D3D9Mappings::_getPF(texDesc.Format));
-
-		//	if( mHwGamma )
-		//	{
-		//		mHwGammaReadSupported = _canUseHardwareGammaCorrection( d3d9Device, texDesc.Usage,
-		//																D3DRTYPE_VOLUMETEXTURE,
-		//																texDesc.Format, false);
-		//	}
-
-		//	mInternalResourcesCreated = true;
-  //      }
-		//else
-		//{
-		//	Image img;
-
-  //          assert(loadedStreams->size()==1);
-
-		//	size_t pos = mName.find_last_of(".");
-		//	String ext;
-		//	if ( pos != String::npos )
-		//		ext = mName.substr(pos+1);
-	
-		//	DataStreamPtr stream((*loadedStreams)[0]);
-		//	img.load(stream, ext);
-
-		//	if (img.getHeight() == 0)
-		//	{
-		//		OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
-		//			"Image height == 0 in " + getName(),
-		//			"D3D9Texture::_loadVolumeTex");
-		//	}
-
-		//	if (img.getWidth() == 0)
-		//	{
-		//		OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
-		//			"Image width == 0 in " + getName(),
-		//			"D3D9Texture::_loadVolumeTex");
-		//	}
-
-		//	if (img.getDepth() == 0)
-		//	{
-		//		OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
-		//			"Image depth == 0 in " + getName(),
-		//			"D3D9Texture::_loadVolumeTex");
-		//	}
-		//	// Call internal _loadImages, not loadImage since that's external and 
-		//	// will determine load status etc again
-		//	ConstImagePtrList imagePtrs;
-		//	imagePtrs.push_back(&img);
-		//	_loadImages( imagePtrs );
-		//}
-//    }
+	void D3D9Texture::_loadVolumeTex(IDirect3DDevice9* d3d9Device)
+	{
+		assert(getTextureType() == TEX_TYPE_3D);
+        assert(mTextureData.size()==1);
+
+		TextureDataPtr texData = mTextureData[0];
+
+		if (texData->getHeight() == 0)
+		{
+			CM_EXCEPT(InternalErrorException, "Image height == 0");
+		}
+
+		if (texData->getWidth() == 0)
+		{
+			CM_EXCEPT(InternalErrorException, "Image width == 0");
+		}
+
+		if (texData->getDepth() == 0)
+		{
+			CM_EXCEPT(InternalErrorException, "Image depth == 0");
+		}
+			
+		initializeFromTextureData();
+    }
 	/****************************************************************************************/
 	/****************************************************************************************/
- 
-	//void D3D9Texture::_loadNormTex(IDirect3DDevice9* d3d9Device, const vector<DataStreamPtr>::type& imageDataStreams)
-	//{
-	//	assert(getTextureType() == TEX_TYPE_1D || getTextureType() == TEX_TYPE_2D);
-	//	// DDS load?
-	//	if (getSourceFileType() == "dds")
-	//	{
-	//		// Use D3DX
- //           assert(imageDataStreams->size()==1);
-	//
-	//		DWORD usage = 0;
-	//		UINT numMips;
-
-	//		if (mNumRequestedMipmaps == MIP_UNLIMITED)
-	//			numMips = D3DX_DEFAULT;
-	//		else if (mNumRequestedMipmaps == 0)			
-	//			numMips = D3DX_FROM_FILE;
-	//		else
-	//			numMips = static_cast<UINT>(mNumRequestedMipmaps + 1);
-	//			
-	//		D3D9Device* device = D3D9RenderSystem::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
-	//		const D3DCAPS9& rkCurCaps = device->getD3D9DeviceCaps();			
-
-
-	//		// check if mip map volume textures are supported
-	//		if (!(rkCurCaps.TextureCaps & D3DPTEXTURECAPS_MIPMAP))
-	//		{
-	//			// no mip map support for this kind of textures :(
-	//			mNumMipmaps = 0;
-	//			numMips = 1;
-	//		}
-
- //           // Determine D3D pool to use
- //           D3DPOOL pool;
- //           if (useDefaultPool())
- //           {
- //               pool = D3DPOOL_DEFAULT;
- //           }
- //           else
- //           {
- //               pool = D3DPOOL_MANAGED;
- //           }
-	//					
-	//		TextureResources* textureResources;			
-	//		
-	//		// Get or create new texture resources structure.
-	//		textureResources = getTextureResources(d3d9Device);
-	//		if (textureResources != NULL)
-	//			freeTextureResources(d3d9Device, textureResources);
-	//		else
-	//			textureResources = allocateTextureResources(d3d9Device);
-
-	//		HRESULT hr;
-
-	//		hr = D3DXCreateTextureFromFileInMemoryEx(
-	//			d3d9Device,
-	//			(*loadedStreams)[0]->getPtr(),
-	//			static_cast<UINT>((*loadedStreams)[0]->size()),
-	//			D3DX_DEFAULT, D3DX_DEFAULT, // dims
-	//			numMips,
-	//			usage,
-	//			D3DFMT_UNKNOWN,
-	//			pool,
-	//			D3DX_DEFAULT,
-	//			D3DX_DEFAULT,
-	//			0,  // colour key
-	//			NULL, // src box
-	//			NULL, // palette
-	//			&textureResources->pNormTex); 
-	//
-	//		if (FAILED(hr))
-	//		{
-	//			OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
-	//				"Unable to load texture from :" + String(DXGetErrorDescription(hr)),
-	//				"D3D9Texture::_loadNormTex");
-	//		}
-	//
-	//		hr = textureResources->pNormTex->QueryInterface(IID_IDirect3DBaseTexture9, (void **)&textureResources->pBaseTex);
-	//
-	//		if (FAILED(hr))
-	//		{
-	//			freeInternalResources();
-	//			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't get base texture: " + String(DXGetErrorDescription(hr)), 
-	//				"D3D9Texture::_loadNormTex" );
-	//		}
-	//
-	//		D3DSURFACE_DESC texDesc;
-	//		textureResources->pNormTex->GetLevelDesc(0, &texDesc);
- //           mD3DPool = texDesc.Pool;
-	//		// set src and dest attributes to the same, we can't know
-	//		_setSrcAttributes(texDesc.Width, texDesc.Height, 1, D3D9Mappings::_getPF(texDesc.Format));
-	//		_setFinalAttributes(d3d9Device, textureResources, 
-	//			texDesc.Width, texDesc.Height, 1, D3D9Mappings::_getPF(texDesc.Format));
-
-	//		if( mHwGamma )
-	//		{
-	//			mHwGammaReadSupported = _canUseHardwareGammaCorrection( d3d9Device, texDesc.Usage,
-	//																	D3DRTYPE_TEXTURE,
-	//																	texDesc.Format, false);
-	//		}
-	//		mInternalResourcesCreated = true;
- //       }
-	//	else
-	//	{
-	//		Image img;
- //          	// find & load resource data intro stream to allow resource
-	//		// group changes if required
- //           assert(loadedStreams->size()==1);
-	//
-	//		size_t pos = mName.find_last_of(".");
-	//		String ext; 
-	//		if ( pos != String::npos )
-	//			ext = mName.substr(pos+1);
-
-	//		DataStreamPtr stream((*loadedStreams)[0]);
-	//		img.load(stream, ext);
-
-	//		if (img.getHeight() == 0)
-	//		{
-	//			OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
-	//				"Image height == 0 in " + getName(),
-	//				"D3D9Texture::_loadNormTex");
-	//		}
-
-	//		if (img.getWidth() == 0)
-	//		{
-	//			OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
-	//				"Image width == 0 in " + getName(),
-	//				"D3D9Texture::_loadNormTex");
-	//		}
-
-	//		// Call internal _loadImages, not loadImage since that's external and 
-	//		// will determine load status etc again
-	//		ConstImagePtrList imagePtrs;
-	//		imagePtrs.push_back(&img);
-	//		_loadImages( imagePtrs );
-	//	}
-
-	//}
+	void D3D9Texture::_loadNormTex(IDirect3DDevice9* d3d9Device)
+	{
+		assert(getTextureType() == TEX_TYPE_1D || getTextureType() == TEX_TYPE_2D);
+		assert(mTextureData.size()==1);
+
+		TextureDataPtr texData = mTextureData[0];
+
+		if (texData->getHeight() == 0)
+		{
+			CM_EXCEPT(InternalErrorException, "Image height == 0");
+		}
+
+		if (texData->getWidth() == 0)
+		{
+			CM_EXCEPT(InternalErrorException, "Image width == 0");
+		}
+
+		initializeFromTextureData();
+	}
 
 
 	/****************************************************************************************/
 	/****************************************************************************************/
 	size_t D3D9Texture::calculateSize(void) const
 	size_t D3D9Texture::calculateSize(void) const

+ 7 - 1
CamelotFreeImgImporter/Source/CmFreeImgImporter.cpp

@@ -4,6 +4,8 @@
 #include "CmDataStream.h"
 #include "CmDataStream.h"
 #include "CmPath.h"
 #include "CmPath.h"
 #include "CmTextureData.h"
 #include "CmTextureData.h"
+#include "CmTextureManager.h"
+#include "CmTexture.h"
 
 
 #include "FreeImage.h"
 #include "FreeImage.h"
 
 
@@ -130,8 +132,12 @@ namespace CamelotEngine
 		if(imgData == nullptr || imgData->getData() == nullptr)
 		if(imgData == nullptr || imgData->getData() == nullptr)
 			return nullptr;
 			return nullptr;
 
 
+		TexturePtr newTexture = TextureManager::instance().create(TEX_TYPE_2D, 
+			imgData->getWidth(), imgData->getHeight(), imgData->getNumMipmaps(), imgData->getFormat());
 
 
-		return nullptr;
+		newTexture->setTextureData(0, imgData);
+
+		return newTexture;
 	}
 	}
 
 
 	TextureDataPtr FreeImgImporter::importRawImage(DataStream* fileData)
 	TextureDataPtr FreeImgImporter::importRawImage(DataStream* fileData)

+ 3 - 6
CamelotGLRenderer/Include/CmGLTexture.h

@@ -60,15 +60,12 @@ namespace CamelotEngine {
 		
 		
 		void getCustomAttribute(const String& name, void* pData);
 		void getCustomAttribute(const String& name, void* pData);
 
 
+		/// @copydoc Resource::load
+		void load();
+
     protected:
     protected:
 		/// @copydoc Texture::createInternalResourcesImpl
 		/// @copydoc Texture::createInternalResourcesImpl
 		void createInternalResourcesImpl(void);
 		void createInternalResourcesImpl(void);
-        /// @copydoc Resource::prepareImpl
-        void prepareImpl(void);
-        /// @copydoc Resource::unprepareImpl
-        void unprepareImpl(void);
-        /// @copydoc Resource::loadImpl
-        void loadImpl(void);
         /// @copydoc Resource::freeInternalResourcesImpl
         /// @copydoc Resource::freeInternalResourcesImpl
         void freeInternalResourcesImpl(void);
         void freeInternalResourcesImpl(void);
 
 

+ 3 - 97
CamelotGLRenderer/Source/CmGLTexture.cpp

@@ -246,89 +246,7 @@ namespace CamelotEngine {
         createInternalResources();
         createInternalResources();
     }
     }
 
 
-	// TODO PORT - Not supported in port. Not sure what its used for
-  //  static inline void do_image_io(const String &name, const String &group,
-  //                                 const String &ext,
-  //                                 vector<Image>::type &images,
-  //                                 Resource *r)
-  //  {
-		//size_t imgIdx = images.size();
-  //      images.push_back(Image());
-
-  //      DataStreamPtr dstream = 
-  //          ResourceGroupManager::getSingleton().openResource(
-  //              name, group, true, r);
-
-  //      images[imgIdx].load(dstream, ext);
-  //  }
-
-	
-    void GLTexture::prepareImpl()
-    {
-        if( mUsage & TU_RENDERTARGET ) return;
-
-		// TODO PORT - Image loading not supported
-
-        //String baseName, ext;
-        //size_t pos = mName.find_last_of(".");
-        //baseName = mName.substr(0, pos);
-        //if( pos != String::npos )
-        //    ext = mName.substr(pos+1);
-
-        //LoadedImages loadedImages = LoadedImages(new vector<Image>::type());
-
-        //if(mTextureType == TEX_TYPE_1D || mTextureType == TEX_TYPE_2D || 
-        //    mTextureType == TEX_TYPE_3D)
-        //{
-
-        //    do_image_io(mName, mGroup, ext, *loadedImages, this);
-
-
-        //    // If this is a cube map, set the texture type flag accordingly.
-        //    if ((*loadedImages)[0].hasFlag(IF_CUBEMAP))
-        //        mTextureType = TEX_TYPE_CUBE_MAP;
-        //    // If this is a volumetric texture set the texture type flag accordingly.
-        //    if((*loadedImages)[0].getDepth() > 1)
-        //        mTextureType = TEX_TYPE_3D;
-
-        //}
-        //else if (mTextureType == TEX_TYPE_CUBE_MAP)
-        //{
-        //    if(getSourceFileType() == "dds")
-        //    {
-        //        // XX HACK there should be a better way to specify whether 
-        //        // all faces are in the same file or not
-        //        do_image_io(mName, mGroup, ext, *loadedImages, this);
-        //    }
-        //    else
-        //    {
-        //        vector<Image>::type images(6);
-        //        ConstImagePtrList imagePtrs;
-        //        static const String suffixes[6] = {"_rt", "_lf", "_up", "_dn", "_fr", "_bk"};
-
-        //        for(size_t i = 0; i < 6; i++)
-        //        {
-        //            String fullName = baseName + suffixes[i];
-        //            if (!ext.empty())
-        //                fullName = fullName + "." + ext;
-        //            // find & load resource data intro stream to allow resource
-        //            // group changes if required
-        //            do_image_io(fullName,mGroup,ext,*loadedImages,this);
-        //        }
-        //    }
-        //}
-        //else
-        //    OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED, "**** Unknown texture type ****", "GLTexture::prepare" );
-
-        //mLoadedImages = loadedImages;
-    }
-	
-    void GLTexture::unprepareImpl()
-    {
-        //mLoadedImages.setNull();
-    }
-
-    void GLTexture::loadImpl()
+    void GLTexture::load()
     {
     {
         if( mUsage & TU_RENDERTARGET )
         if( mUsage & TU_RENDERTARGET )
         {
         {
@@ -336,21 +254,9 @@ namespace CamelotEngine {
             return;
             return;
         }
         }
 
 
-		// TODO PORT - Image loading not supported
-        //// Now the only copy is on the stack and will be cleaned in case of
-        //// exceptions being thrown from _loadImages
-        //LoadedImages loadedImages = mLoadedImages;
-        //mLoadedImages.setNull();
-
-        //// Call internal _loadImages, not loadImage since that's external and 
-        //// will determine load status etc again
-        //ConstImagePtrList imagePtrs;
-        //for (size_t i=0 ; i<loadedImages->size() ; ++i) {
-        //    imagePtrs.push_back(&(*loadedImages)[i]);
-        //}
-
-        //_loadImages(imagePtrs);
+		initializeFromTextureData();
 
 
+		mTextureData.clear();
     }
     }
 
 
 	//*************************************************************************
 	//*************************************************************************

+ 2 - 10
CamelotRenderer/Include/CmResource.h

@@ -17,14 +17,10 @@ namespace CamelotEngine
 		{}
 		{}
 		virtual ~Resource() {};
 		virtual ~Resource() {};
 
 
-		//public 
+		virtual void load() = 0;
 
 
 	protected:
 	protected:
 		friend class Resources;
 		friend class Resources;
-
-
-
-		//virtual void load() = 0;
 		//virtual void unload() = 0;
 		//virtual void unload() = 0;
 
 
 		//virtual void calculateSize() = 0;
 		//virtual void calculateSize() = 0;
@@ -40,10 +36,6 @@ namespace CamelotEngine
 		friend class ResourceST;
 		friend class ResourceST;
 
 
 		virtual SerializableType* getSerializable() const;
 		virtual SerializableType* getSerializable() const;
-
-		static Resource* newObject()
-		{
-			return new Resource();
-		}
+		static Resource* newObject();
 	};
 	};
 }
 }

+ 1 - 1
CamelotRenderer/Include/CmTexture.h

@@ -394,7 +394,7 @@ namespace CamelotEngine {
 
 
 		/**
 		/**
 		 * @brief	Initializes the texture from texture data array that was previously populated using
 		 * @brief	Initializes the texture from texture data array that was previously populated using
-		 * 			setTextureData. Array is cleared after this method finished.
+		 * 			setTextureData.
 		 *
 		 *
 		 * @param	textureData	Array with texture data for each face of the texture.
 		 * @param	textureData	Array with texture data for each face of the texture.
 		 */
 		 */

+ 6 - 0
CamelotRenderer/Source/CmResource.cpp

@@ -52,4 +52,10 @@ namespace CamelotEngine
 		static ResourceST serializableType;
 		static ResourceST serializableType;
 		return &serializableType;
 		return &serializableType;
 	}
 	}
+
+
+	Resource* newObject()
+	{
+		CM_EXCEPT(InternalErrorException, "Cannot instantiate an abstract class.");
+	}
 }
 }

+ 0 - 2
CamelotRenderer/Source/CmTexture.cpp

@@ -279,8 +279,6 @@ namespace CamelotEngine {
 		}
 		}
 		// Update size (the final size, not including temp space)
 		// Update size (the final size, not including temp space)
 		mSize = getNumFaces() * PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);
 		mSize = getNumFaces() * PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);
-
-		mTextureData.clear();
 	}
 	}
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
 	void Texture::unloadImpl(void)
 	void Texture::unloadImpl(void)