Browse Source

Refactored Textures part #1

Marko Pintera 13 years ago
parent
commit
7970ff490b

+ 6 - 6
CamelotClient/CamelotClient.cpp

@@ -58,7 +58,7 @@ int _tmain(int argc, _TCHAR* argv[])
 	//						return color;										\
 	//						return color;										\
 	//						}";
 	//						}";
 
 
-	//fragProg =  HighLevelGpuProgramManager::instance().createProgram(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
+	//fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
 	//fragProg->load();
 	//fragProg->load();
 
 
 	//String vertShaderCode = "float4x4 matViewProjection;	\
 	//String vertShaderCode = "float4x4 matViewProjection;	\
@@ -72,7 +72,7 @@ int _tmain(int argc, _TCHAR* argv[])
 	//						oUv = uv;											\
 	//						oUv = uv;											\
 	//						}";
 	//						}";
 
 
-	//vertProg =  HighLevelGpuProgramManager::instance().createProgram(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
+	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 	//vertProg->load();
 	//vertProg->load();
 
 
 
 
@@ -85,7 +85,7 @@ int _tmain(int argc, _TCHAR* argv[])
 							return color;										\
 							return color;										\
 							}";
 							}";
 
 
-	fragProg =  HighLevelGpuProgramManager::instance().createProgram(fragShaderCode, "ps_main", "cg", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
+	fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "cg", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
 	fragProg->init();
 	fragProg->init();
 
 
 	String vertShaderCode = "float4x4 matViewProjection;	\
 	String vertShaderCode = "float4x4 matViewProjection;	\
@@ -99,7 +99,7 @@ int _tmain(int argc, _TCHAR* argv[])
 							oUv = uv;											\
 							oUv = uv;											\
 							}";
 							}";
 
 
-	vertProg =  HighLevelGpuProgramManager::instance().createProgram(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
+	vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 	vertProg->init();
 	vertProg->init();
 
 
 	HighLevelGpuProgramHandle vertProgRef(vertProg);
 	HighLevelGpuProgramHandle vertProgRef(vertProg);
@@ -120,7 +120,7 @@ int _tmain(int argc, _TCHAR* argv[])
 	//							  gl_FragColor = texColor; \
 	//							  gl_FragColor = texColor; \
 	//							  }";
 	//							  }";
 
 
-	//fragProg = HighLevelGpuProgramManager::instance().createProgram(fragShaderCode, "main", "glsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
+	//fragProg = HighLevelGpuProgram::create(fragShaderCode, "main", "glsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
 	//fragProg->load();
 	//fragProg->load();
 
 
 	//// TODO - Ogres GLSL parsing requires some strict parameter naming, can that be avoided?
 	//// TODO - Ogres GLSL parsing requires some strict parameter naming, can that be avoided?
@@ -132,7 +132,7 @@ int _tmain(int argc, _TCHAR* argv[])
 	//							  gl_Position = matViewProjection * vertex; \
 	//							  gl_Position = matViewProjection * vertex; \
 	//							  }";
 	//							  }";
 
 
-	//vertProg = HighLevelGpuProgramManager::instance().createProgram(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
+	//vertProg = HighLevelGpuProgram::create(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 	//vertProg->load();
 	//vertProg->load();
 
 
 	ShaderPtr testShader = ShaderPtr(new Shader("TestShader"));
 	ShaderPtr testShader = ShaderPtr(new Shader("TestShader"));

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9HLSLProgramRTTI.h

@@ -27,7 +27,7 @@ namespace CamelotEngine
 
 
 		virtual std::shared_ptr<IReflectable> newRTTIObject()
 		virtual std::shared_ptr<IReflectable> newRTTIObject()
 		{
 		{
-			return HighLevelGpuProgramManager::instance().createProgram("hlsl");
+			return HighLevelGpuProgramManager::instance().create("hlsl");
 		}
 		}
 	};
 	};
 }
 }

+ 0 - 2
CamelotD3D9Renderer/Include/CmD3D9Texture.h

@@ -107,8 +107,6 @@ namespace CamelotEngine {
 		void createInternalResourcesImpl(IDirect3DDevice9* d3d9Device);
 		void createInternalResourcesImpl(IDirect3DDevice9* d3d9Device);
 		/// free internal resources
 		/// free internal resources
 		void freeInternalResourcesImpl(void);
 		void freeInternalResourcesImpl(void);
-		/// internal method, set Texture class source image protected attributes
-		void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
 		/// internal method, set Texture class final texture protected attributes
 		/// internal method, set Texture class final texture protected attributes
 		void _setFinalAttributes(IDirect3DDevice9* d3d9Device, TextureResources* textureResources, 
 		void _setFinalAttributes(IDirect3DDevice9* d3d9Device, TextureResources* textureResources, 
 			unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
 			unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);

+ 35 - 123
CamelotD3D9Renderer/Source/CmD3D9Texture.cpp

@@ -416,14 +416,6 @@ namespace CamelotEngine
 		if (textureResources != NULL && textureResources->pBaseTex != NULL)
 		if (textureResources != NULL && textureResources->pBaseTex != NULL)
 			return;
 			return;
 		
 		
-
-		// If mSrcWidth and mSrcHeight are zero, the requested extents have probably been set
-		// through setWidth and setHeight, which set mWidth and mHeight. Take those values.
-		if(mSrcWidth == 0 || mSrcHeight == 0) {
-			mSrcWidth = mWidth;
-			mSrcHeight = mHeight;
-		}
-
 		// load based on tex.type
 		// load based on tex.type
 		switch (getTextureType())
 		switch (getTextureType())
 		{
 		{
@@ -447,7 +439,7 @@ namespace CamelotEngine
 	void D3D9Texture::_createNormTex(IDirect3DDevice9* d3d9Device)
 	void D3D9Texture::_createNormTex(IDirect3DDevice9* d3d9Device)
 	{
 	{
 		// we must have those defined here
 		// we must have those defined here
-		assert(mSrcWidth > 0 || mSrcHeight > 0);
+		assert(mWidth > 0 || mHeight > 0);
 
 
 		// determine wich D3D9 pixel format we'll use
 		// determine wich D3D9 pixel format we'll use
 		HRESULT hr;
 		HRESULT hr;
@@ -458,8 +450,8 @@ namespace CamelotEngine
 
 
 		// Use D3DX to help us create the texture, this way it can adjust any relevant sizes
 		// Use D3DX to help us create the texture, this way it can adjust any relevant sizes
 		DWORD usage = (mUsage & TU_RENDERTARGET) ? D3DUSAGE_RENDERTARGET : 0;
 		DWORD usage = (mUsage & TU_RENDERTARGET) ? D3DUSAGE_RENDERTARGET : 0;
-		UINT numMips = (mNumRequestedMipmaps == MIP_UNLIMITED) ? 
-				D3DX_DEFAULT : mNumRequestedMipmaps + 1;
+		UINT numMips = (mNumMipmaps == MIP_UNLIMITED) ? 
+				D3DX_DEFAULT : mNumMipmaps + 1;
 		// Check dynamic textures
 		// Check dynamic textures
 		if (mUsage & TU_DYNAMIC)
 		if (mUsage & TU_DYNAMIC)
 		{
 		{
@@ -496,23 +488,8 @@ namespace CamelotEngine
 		D3D9Device* device = D3D9RenderSystem::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
 		D3D9Device* device = D3D9RenderSystem::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
 		const D3DCAPS9& rkCurCaps = device->getD3D9DeviceCaps();			
 		const D3DCAPS9& rkCurCaps = device->getD3D9DeviceCaps();			
 
 
-
 		// check if mip maps are supported on hardware
 		// check if mip maps are supported on hardware
-		mMipmapsHardwareGenerated = false;
-		if (rkCurCaps.TextureCaps & D3DPTEXTURECAPS_MIPMAP)
-		{
-			if (mUsage & TU_AUTOMIPMAP && mNumRequestedMipmaps != 0)
-			{
-				// use auto.gen. if available, and if desired
-				mMipmapsHardwareGenerated = _canAutoGenMipmaps(d3d9Device, usage, D3DRTYPE_TEXTURE, d3dPF);
-				if (mMipmapsHardwareGenerated)
-				{
-					usage |= D3DUSAGE_AUTOGENMIPMAP;
-					numMips = 0;
-				}
-			}
-		}
-		else
+		if (!(rkCurCaps.TextureCaps & D3DPTEXTURECAPS_MIPMAP))
 		{
 		{
 			// no mip map support for this kind of textures :(
 			// no mip map support for this kind of textures :(
 			mNumMipmaps = 0;
 			mNumMipmaps = 0;
@@ -535,8 +512,8 @@ namespace CamelotEngine
 		// create the texture
 		// create the texture
 		hr = D3DXCreateTexture(	
 		hr = D3DXCreateTexture(	
 				d3d9Device,								// device
 				d3d9Device,								// device
-				static_cast<UINT>(mSrcWidth),			// width
-				static_cast<UINT>(mSrcHeight),			// height
+				static_cast<UINT>(mWidth),				// width
+				static_cast<UINT>(mHeight),				// height
 				numMips,								// number of mip map levels
 				numMips,								// number of mip map levels
 				usage,									// usage
 				usage,									// usage
 				d3dPF,									// pixel format
 				d3dPF,									// pixel format
@@ -585,23 +562,12 @@ namespace CamelotEngine
 
 
 		_setFinalAttributes(d3d9Device, textureResources, 
 		_setFinalAttributes(d3d9Device, textureResources, 
 			desc.Width, desc.Height, 1, D3D9Mappings::_getPF(desc.Format));
 			desc.Width, desc.Height, 1, D3D9Mappings::_getPF(desc.Format));
-		
-		// Set best filter type
-		if(mMipmapsHardwareGenerated)
-		{
-			hr = textureResources->pBaseTex->SetAutoGenFilterType(_getBestFilterMethod(d3d9Device));
-			if(FAILED(hr))
-			{
-				CM_EXCEPT(RenderingAPIException, "Could not set best autogen filter type: "  + String(DXGetErrorDescription(hr)));
-			}
-		}
-
 	}
 	}
 	/****************************************************************************************/
 	/****************************************************************************************/
 	void D3D9Texture::_createCubeTex(IDirect3DDevice9* d3d9Device)
 	void D3D9Texture::_createCubeTex(IDirect3DDevice9* d3d9Device)
 	{
 	{
 		// we must have those defined here
 		// we must have those defined here
-		assert(mSrcWidth > 0 || mSrcHeight > 0);
+		assert(mWidth > 0 || mHeight > 0);
 
 
 		// determine wich D3D9 pixel format we'll use
 		// determine wich D3D9 pixel format we'll use
 		HRESULT hr;
 		HRESULT hr;
@@ -612,8 +578,8 @@ namespace CamelotEngine
 
 
 		// Use D3DX to help us create the texture, this way it can adjust any relevant sizes
 		// Use D3DX to help us create the texture, this way it can adjust any relevant sizes
 		DWORD usage = (mUsage & TU_RENDERTARGET) ? D3DUSAGE_RENDERTARGET : 0;
 		DWORD usage = (mUsage & TU_RENDERTARGET) ? D3DUSAGE_RENDERTARGET : 0;
-		UINT numMips = (mNumRequestedMipmaps == MIP_UNLIMITED) ? 
-			D3DX_DEFAULT : mNumRequestedMipmaps + 1;
+		UINT numMips = (mNumMipmaps == MIP_UNLIMITED) ? 
+			D3DX_DEFAULT : mNumMipmaps + 1;
 		// Check dynamic textures
 		// Check dynamic textures
 		if (mUsage & TU_DYNAMIC)
 		if (mUsage & TU_DYNAMIC)
 		{
 		{
@@ -651,21 +617,7 @@ namespace CamelotEngine
 		const D3DCAPS9& rkCurCaps = device->getD3D9DeviceCaps();			
 		const D3DCAPS9& rkCurCaps = device->getD3D9DeviceCaps();			
 		
 		
 		// check if mip map cube textures are supported
 		// check if mip map cube textures are supported
-		mMipmapsHardwareGenerated = false;
-		if (rkCurCaps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP)
-		{
-			if (mUsage & TU_AUTOMIPMAP && mNumRequestedMipmaps != 0)
-			{
-				// use auto.gen. if available
-				mMipmapsHardwareGenerated = _canAutoGenMipmaps(d3d9Device, usage, D3DRTYPE_CUBETEXTURE, d3dPF);
-				if (mMipmapsHardwareGenerated)
-				{
-					usage |= D3DUSAGE_AUTOGENMIPMAP;
-					numMips = 0;
-				}
-			}
-		}
-		else
+		if (!(rkCurCaps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP))
 		{
 		{
 			// no mip map support for this kind of textures :(
 			// no mip map support for this kind of textures :(
 			mNumMipmaps = 0;
 			mNumMipmaps = 0;
@@ -687,7 +639,7 @@ namespace CamelotEngine
 		// create the texture
 		// create the texture
 		hr = D3DXCreateCubeTexture(	
 		hr = D3DXCreateCubeTexture(	
 				d3d9Device,									// device
 				d3d9Device,									// device
-				static_cast<UINT>(mSrcWidth),		 		// dimension
+				static_cast<UINT>(mWidth),		 			// dimension
 				numMips,							 		// number of mip map levels
 				numMips,							 		// number of mip map levels
 				usage,								 		// usage
 				usage,								 		// usage
 				d3dPF,								 		// pixel format
 				d3dPF,								 		// pixel format
@@ -735,17 +687,6 @@ namespace CamelotEngine
 
 
 		_setFinalAttributes(d3d9Device, textureResources, 
 		_setFinalAttributes(d3d9Device, textureResources, 
 			desc.Width, desc.Height, 1, D3D9Mappings::_getPF(desc.Format));
 			desc.Width, desc.Height, 1, D3D9Mappings::_getPF(desc.Format));
-
-		// Set best filter type
-		if(mMipmapsHardwareGenerated)
-		{
-			hr = textureResources->pBaseTex->SetAutoGenFilterType(_getBestFilterMethod(d3d9Device));
-			if(FAILED(hr))
-			{
-				CM_EXCEPT(RenderingAPIException, "Could not set best autogen filter type: " + String(DXGetErrorDescription(hr)));
-			}
-		}
-
 	}
 	}
 	/****************************************************************************************/
 	/****************************************************************************************/
 	void D3D9Texture::_createVolumeTex(IDirect3DDevice9* d3d9Device)
 	void D3D9Texture::_createVolumeTex(IDirect3DDevice9* d3d9Device)
@@ -766,8 +707,8 @@ namespace CamelotEngine
 
 
 		// Use D3DX to help us create the texture, this way it can adjust any relevant sizes
 		// Use D3DX to help us create the texture, this way it can adjust any relevant sizes
 		DWORD usage = (mUsage & TU_RENDERTARGET) ? D3DUSAGE_RENDERTARGET : 0;
 		DWORD usage = (mUsage & TU_RENDERTARGET) ? D3DUSAGE_RENDERTARGET : 0;
-		UINT numMips = (mNumRequestedMipmaps == MIP_UNLIMITED) ? 
-			D3DX_DEFAULT : mNumRequestedMipmaps + 1;
+		UINT numMips = (mNumMipmaps == MIP_UNLIMITED) ? 
+			D3DX_DEFAULT : mNumMipmaps + 1;
 		// Check dynamic textures
 		// Check dynamic textures
 		if (mUsage & TU_DYNAMIC)
 		if (mUsage & TU_DYNAMIC)
 		{
 		{
@@ -794,21 +735,7 @@ namespace CamelotEngine
 
 
 
 
 		// check if mip map volume textures are supported
 		// check if mip map volume textures are supported
-		mMipmapsHardwareGenerated = false;
-		if (rkCurCaps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP)
-		{
-			if (mUsage & TU_AUTOMIPMAP && mNumRequestedMipmaps != 0)
-			{
-				// use auto.gen. if available
-				mMipmapsHardwareGenerated = _canAutoGenMipmaps(d3d9Device, usage, D3DRTYPE_VOLUMETEXTURE, d3dPF);
-				if (mMipmapsHardwareGenerated)
-				{
-					usage |= D3DUSAGE_AUTOGENMIPMAP;
-					numMips = 0;
-				}
-			}
-		}
-		else
+		if (!(rkCurCaps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
 		{
 		{
 			// no mip map support for this kind of textures :(
 			// no mip map support for this kind of textures :(
 			mNumMipmaps = 0;
 			mNumMipmaps = 0;
@@ -864,16 +791,6 @@ namespace CamelotEngine
 		}
 		}
 		_setFinalAttributes(d3d9Device, textureResources,
 		_setFinalAttributes(d3d9Device, textureResources,
 			desc.Width, desc.Height, desc.Depth, D3D9Mappings::_getPF(desc.Format));
 			desc.Width, desc.Height, desc.Depth, D3D9Mappings::_getPF(desc.Format));
-		
-		// Set best filter type
-		if(mMipmapsHardwareGenerated)
-		{
-			hr = textureResources->pBaseTex->SetAutoGenFilterType(_getBestFilterMethod(d3d9Device));
-			if(FAILED(hr))
-			{
-				CM_EXCEPT(RenderingAPIException, "Could not set best autogen filter type: " + String(DXGetErrorDescription(hr)));
-			}
-		}
 	}
 	}
 
 
 	/****************************************************************************************/
 	/****************************************************************************************/
@@ -882,26 +799,24 @@ namespace CamelotEngine
 		unsigned long width, unsigned long height, 
 		unsigned long width, unsigned long height, 
         unsigned long depth, PixelFormat format)
         unsigned long depth, PixelFormat format)
 	{ 
 	{ 
-		// set target texture attributes
-		mHeight = height; 
-		mWidth = width; 
-        mDepth = depth;
-		mFormat = format; 
+		if(width != mWidth || height != mHeight || depth != mDepth)
+		{
+			CM_EXCEPT(InternalErrorException, "Wanted and created textures sizes don't match!" \
+				"Width: " + toString(width) + "/" + toString(mWidth) +
+				"Height: " + toString(height) + "/" + toString(mHeight) +
+				"Depth: " + toString(depth) + "/" + toString(mDepth));
+		}
+
+		if(mFormat != format)
+		{
+			CM_EXCEPT(InternalErrorException, "Wanted and created texture format doesn't match: " + 
+				toString(format) + "/" + toString(mFormat));
+		}
 		
 		
 		// Create list of subsurfaces for getBuffer()
 		// Create list of subsurfaces for getBuffer()
 		_createSurfaceList(d3d9Device, textureResources);
 		_createSurfaceList(d3d9Device, textureResources);
 	}
 	}
 	/****************************************************************************************/
 	/****************************************************************************************/
-	void D3D9Texture::_setSrcAttributes(unsigned long width, unsigned long height, 
-        unsigned long depth, PixelFormat format)
-	{ 
-		// set source image attributes
-		mSrcWidth = width; 
-		mSrcHeight = height; 
-		mSrcDepth = depth;
-        mSrcFormat = format;
-	}
-	/****************************************************************************************/
 	D3DTEXTUREFILTERTYPE D3D9Texture::_getBestFilterMethod(IDirect3DDevice9* d3d9Device)
 	D3DTEXTUREFILTERTYPE D3D9Texture::_getBestFilterMethod(IDirect3DDevice9* d3d9Device)
 	{
 	{
 		D3D9Device* device = D3D9RenderSystem::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
 		D3D9Device* device = D3D9RenderSystem::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
@@ -1092,7 +1007,14 @@ namespace CamelotEngine
 		assert(textureResources != NULL);
 		assert(textureResources != NULL);
 		assert(textureResources->pBaseTex);
 		assert(textureResources->pBaseTex);
 		// Make sure number of mips is right
 		// Make sure number of mips is right
-		mNumMipmaps = textureResources->pBaseTex->GetLevelCount() - 1;
+		size_t numCreatedMips = textureResources->pBaseTex->GetLevelCount() - 1;
+
+		if(numCreatedMips != mNumMipmaps)
+		{
+			CM_EXCEPT(InternalErrorException, "Number of created and wanted mip map levels doesn't match: " + 
+				toString(numCreatedMips) + "/" + toString(mNumMipmaps));
+		}
+
 		// Need to know static / dynamic
 		// Need to know static / dynamic
 		unsigned int bufusage;
 		unsigned int bufusage;
 		if ((mUsage & TU_DYNAMIC) && mDynamicTextures)
 		if ((mUsage & TU_DYNAMIC) && mDynamicTextures)
@@ -1138,9 +1060,6 @@ namespace CamelotEngine
 
 
 				D3D9HardwarePixelBuffer* currPixelBuffer = GETLEVEL(0, mip);
 				D3D9HardwarePixelBuffer* currPixelBuffer = GETLEVEL(0, mip);
 								
 								
-				if (mip == 0 && mNumRequestedMipmaps != 0 && (mUsage & TU_AUTOMIPMAP))
-					currPixelBuffer->_setMipmapping(true, mMipmapsHardwareGenerated);
-
 				currPixelBuffer->bind(d3d9Device, surface, textureResources->pFSAASurface,
 				currPixelBuffer->bind(d3d9Device, surface, textureResources->pFSAASurface,
 					mHwGammaWriteSupported, mFSAA, "PortNoName", textureResources->pBaseTex);
 					mHwGammaWriteSupported, mFSAA, "PortNoName", textureResources->pBaseTex);
 
 
@@ -1161,10 +1080,6 @@ namespace CamelotEngine
 						CM_EXCEPT(RenderingAPIException, "Get cubemap surface failed");
 						CM_EXCEPT(RenderingAPIException, "Get cubemap surface failed");
 
 
 					D3D9HardwarePixelBuffer* currPixelBuffer = GETLEVEL(face, mip);
 					D3D9HardwarePixelBuffer* currPixelBuffer = GETLEVEL(face, mip);
-					
-					
-					if (mip == 0 && mNumRequestedMipmaps != 0 && (mUsage & TU_AUTOMIPMAP))
-						currPixelBuffer->_setMipmapping(true, mMipmapsHardwareGenerated);
 
 
 					currPixelBuffer->bind(d3d9Device, surface, textureResources->pFSAASurface,
 					currPixelBuffer->bind(d3d9Device, surface, textureResources->pFSAASurface,
 						mHwGammaWriteSupported, mFSAA, "NoNamePort", textureResources->pBaseTex);
 						mHwGammaWriteSupported, mFSAA, "NoNamePort", textureResources->pBaseTex);
@@ -1187,9 +1102,6 @@ namespace CamelotEngine
 
 
 				currPixelBuffer->bind(d3d9Device, volume, textureResources->pBaseTex);
 				currPixelBuffer->bind(d3d9Device, volume, textureResources->pBaseTex);
 
 
-				if (mip == 0 && mNumRequestedMipmaps != 0 && (mUsage & TU_AUTOMIPMAP))
-					currPixelBuffer->_setMipmapping(true, mMipmapsHardwareGenerated);
-
 				// decrement reference count, the GetSurfaceLevel call increments this
 				// decrement reference count, the GetSurfaceLevel call increments this
 				// this is safe because the pixel buffer keeps a reference as well
 				// this is safe because the pixel buffer keeps a reference as well
 				volume->Release();
 				volume->Release();

+ 1 - 1
CamelotFreeImgImporter/Source/CmFreeImgImporter.cpp

@@ -135,7 +135,7 @@ namespace CamelotEngine
 		if(imgData == nullptr || imgData->getData() == nullptr)
 		if(imgData == nullptr || imgData->getData() == nullptr)
 			return nullptr;
 			return nullptr;
 
 
-		TextureHandle newTexture(TextureManager::instance().create(TEX_TYPE_2D, 
+		TextureHandle newTexture(Texture::create(TEX_TYPE_2D, 
 			imgData->getWidth(), imgData->getHeight(), imgData->getNumMipmaps(), imgData->getFormat()));
 			imgData->getWidth(), imgData->getHeight(), imgData->getNumMipmaps(), imgData->getFormat()));
 
 
 		newTexture->setTextureData(0, imgData);
 		newTexture->setTextureData(0, imgData);

+ 1 - 1
CamelotGLRenderer/Include/CmGLSLProgramRTTI.h

@@ -27,7 +27,7 @@ namespace CamelotEngine
 
 
 		virtual std::shared_ptr<IReflectable> newRTTIObject()
 		virtual std::shared_ptr<IReflectable> newRTTIObject()
 		{
 		{
-			return HighLevelGpuProgramManager::instance().createProgram("glsl");
+			return HighLevelGpuProgramManager::instance().create("glsl");
 		}
 		}
 	};
 	};
 }
 }

+ 5 - 27
CamelotGLRenderer/Source/CmGLHardwarePixelBuffer.cpp

@@ -621,22 +621,10 @@ void GLTextureBuffer::blitFromTexture(GLTextureBuffer *src, const Box &srcBox, c
     }
     }
     else
     else
     {
     {
-        /// Dimensions don't match -- use bi or trilinear filtering depending on the
-        /// source texture.
-        if(src->mUsage & TU_AUTOMIPMAP)
-        {
-            /// Automatic mipmaps, we can safely use trilinear filter which
-            /// brings greatly imporoved quality for minimisation.
-            glTexParameteri(src->mTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-            glTexParameteri(src->mTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);    
-        }
-        else
-        {
-            /// Manual mipmaps, stay safe with bilinear filtering so that no
-            /// intermipmap leakage occurs.
-            glTexParameteri(src->mTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-            glTexParameteri(src->mTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-        }
+        /// Manual mipmaps, stay safe with bilinear filtering so that no
+        /// intermipmap leakage occurs.
+        glTexParameteri(src->mTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        glTexParameteri(src->mTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     }
     }
     /// Clamp to edge (fastest)
     /// Clamp to edge (fastest)
     glTexParameteri(src->mTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     glTexParameteri(src->mTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -737,16 +725,6 @@ void GLTextureBuffer::blitFromTexture(GLTextureBuffer *src, const Box &srcBox, c
             }
             }
         }
         }
     }
     }
-    /// Finish up 
-    if(!tempTex)
-    {
-        /// Generate mipmaps
-        if(mUsage & TU_AUTOMIPMAP)
-        {
-            glBindTexture(mTarget, mTextureID);
-            glGenerateMipmapEXT(mTarget);
-        }
-    }
 
 
     /// Reset source texture to sane state
     /// Reset source texture to sane state
     glBindTexture(src->mTarget, src->mTextureID);
     glBindTexture(src->mTarget, src->mTextureID);
@@ -830,7 +808,7 @@ void GLTextureBuffer::blitFromMemory(const PixelData &src_orig, const Box &dstBo
         glTexImage2D(target, 0, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
         glTexImage2D(target, 0, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
 
 
     /// GL texture buffer
     /// GL texture buffer
-    GLTextureBuffer tex(StringUtil::BLANK, target, id, 0, 0, (Usage)(TU_AUTOMIPMAP|HBU_STATIC_WRITE_ONLY), false, false, 0);
+    GLTextureBuffer tex(StringUtil::BLANK, target, id, 0, 0, (Usage)(HBU_STATIC_WRITE_ONLY), false, false, 0);
     
     
     /// Upload data to 0,0,0 in temporary texture
     /// Upload data to 0,0,0 in temporary texture
 	Box tempTarget(0, 0, 0, src.getWidth(), src.getHeight(), src.getDepth());
 	Box tempTarget(0, 0, 0, src.getWidth(), src.getHeight(), src.getDepth());

+ 1 - 32
CamelotGLRenderer/Source/CmGLTexture.cpp

@@ -100,7 +100,6 @@ namespace CamelotEngine {
 		
 		
 		// Check requested number of mipmaps
 		// Check requested number of mipmaps
 		size_t maxMips = GLPixelUtil::getMaxMipmaps(mWidth, mHeight, mDepth, mFormat);
 		size_t maxMips = GLPixelUtil::getMaxMipmaps(mWidth, mHeight, mDepth, mFormat);
-		mNumMipmaps = mNumRequestedMipmaps;
 		if(mNumMipmaps>maxMips)
 		if(mNumMipmaps>maxMips)
 			mNumMipmaps = maxMips;
 			mNumMipmaps = maxMips;
 		
 		
@@ -123,29 +122,6 @@ namespace CamelotEngine {
 			glTexParameteri(getGLTextureTarget(), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 			glTexParameteri(getGLTextureTarget(), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 		}
 		}
 		
 		
-		// If we can do automip generation and the user desires this, do so
-		mMipmapsHardwareGenerated = 
-			CamelotEngine::RenderSystemManager::getActive()->getCapabilities_internal()->hasCapability(RSC_AUTOMIPMAP);
-		// NVIDIA 175.16 drivers break hardware mip generation for non-compressed
-		// textures - disable until fixed
-		// Leave hardware gen on compressed textures since that's the only way we
-		// can realistically do it since GLU doesn't support DXT
-		// However DON'T do this on Apple, their drivers aren't subject to this
-		// problem yet and in fact software generation appears to cause a crash 
-		// in some cases which I've yet to track down
-#if CM_PLATFORM != CM_PLATFORM_APPLE
-		if (CamelotEngine::RenderSystemManager::getActive()->getCapabilities_internal()->getVendor() == GPU_NVIDIA
-			&& !PixelUtil::isCompressed(mFormat))
-		{
-			mMipmapsHardwareGenerated = false;
-		}
-#endif
-		if((mUsage & TU_AUTOMIPMAP) &&
-		    mNumRequestedMipmaps && mMipmapsHardwareGenerated)
-        {
-            glTexParameteri( getGLTextureTarget(), GL_GENERATE_MIPMAP, GL_TRUE );
-        }
-		
 		// Allocate internal buffer so that glTexSubImageXD can be used
 		// Allocate internal buffer so that glTexSubImageXD can be used
 		// Internal format
 		// Internal format
 		GLenum format = GLPixelUtil::getClosestGLInternalFormat(mFormat, mHwGamma);
 		GLenum format = GLPixelUtil::getClosestGLInternalFormat(mFormat, mHwGamma);
@@ -273,19 +249,12 @@ namespace CamelotEngine {
 	{
 	{
 		mSurfaceList.clear();
 		mSurfaceList.clear();
 		
 		
-		// For all faces and mipmaps, store surfaces as HardwarePixelBufferPtr
-		bool wantGeneratedMips = (mUsage & TU_AUTOMIPMAP)!=0;
-		
-		// Do mipmapping in software? (uses GLU) For some cards, this is still needed. Of course,
-		// only when mipmap generation is desired.
-		bool doSoftware = wantGeneratedMips && !mMipmapsHardwareGenerated && getNumMipmaps(); 
-		
 		for(size_t face=0; face<getNumFaces(); face++)
 		for(size_t face=0; face<getNumFaces(); face++)
 		{
 		{
 			for(size_t mip=0; mip<=getNumMipmaps(); mip++)
 			for(size_t mip=0; mip<=getNumMipmaps(); mip++)
 			{
 			{
                 GLHardwarePixelBuffer *buf = new GLTextureBuffer("", getGLTextureTarget(), mTextureID, face, mip,
                 GLHardwarePixelBuffer *buf = new GLTextureBuffer("", getGLTextureTarget(), mTextureID, face, mip,
-						static_cast<HardwareBuffer::Usage>(mUsage), doSoftware && mip==0, mHwGamma, mFSAA);
+						static_cast<HardwareBuffer::Usage>(mUsage), false, mHwGamma, mFSAA);
 				mSurfaceList.push_back(HardwarePixelBufferPtr(buf));
 				mSurfaceList.push_back(HardwarePixelBufferPtr(buf));
                 
                 
                 /// Check for error
                 /// Check for error

+ 0 - 2
CamelotRenderer/Include/CmCamera.h

@@ -167,14 +167,12 @@ namespace CamelotEngine {
         virtual void updateWorldSpaceCorners(void) const;
         virtual void updateWorldSpaceCorners(void) const;
 		/// Implementation of updateWorldSpaceCorners (called if out of date)
 		/// Implementation of updateWorldSpaceCorners (called if out of date)
 		virtual void updateWorldSpaceCornersImpl(void) const;
 		virtual void updateWorldSpaceCornersImpl(void) const;
-        virtual void updateVertexData(void) const;
 		virtual void updateView(void) const;
 		virtual void updateView(void) const;
         virtual bool isFrustumOutOfDate(void) const;
         virtual bool isFrustumOutOfDate(void) const;
         /// Signal to update frustum information.
         /// Signal to update frustum information.
         virtual void invalidateFrustum(void) const;
         virtual void invalidateFrustum(void) const;
 
 
         mutable AxisAlignedBox mBoundingBox;
         mutable AxisAlignedBox mBoundingBox;
-        mutable VertexData mVertexData;
 
 
         mutable Vector3 mWorldSpaceCorners[8];
         mutable Vector3 mWorldSpaceCorners[8];
 
 

+ 1 - 1
CamelotRenderer/Include/CmCgProgramRTTI.h

@@ -27,7 +27,7 @@ namespace CamelotEngine
 
 
 		virtual std::shared_ptr<IReflectable> newRTTIObject()
 		virtual std::shared_ptr<IReflectable> newRTTIObject()
 		{
 		{
-			return HighLevelGpuProgramManager::instance().createProgram("cg");
+			return HighLevelGpuProgramManager::instance().create("cg");
 		}
 		}
 	};
 	};
 }
 }

+ 6 - 0
CamelotRenderer/Include/CmHighLevelGpuProgram.h

@@ -120,6 +120,12 @@ namespace CamelotEngine {
 
 
 		/// Override GpuProgram::getNamedConstants to ensure built
 		/// Override GpuProgram::getNamedConstants to ensure built
 		const GpuNamedConstants& getNamedConstants() const { return getConstantDefinitions(); }
 		const GpuNamedConstants& getNamedConstants() const { return getConstantDefinitions(); }
+
+		/************************************************************************/
+		/* 								STATICS		                     		*/
+		/************************************************************************/
+		static HighLevelGpuProgramPtr create(const String& source, const String& entryPoint, 
+			const String& language, GpuProgramType gptype, GpuProgramProfile profile);
     };
     };
 
 
 	/** @} */
 	/** @} */

+ 2 - 2
CamelotRenderer/Include/CmHighLevelGpuProgramManager.h

@@ -101,7 +101,7 @@ namespace CamelotEngine {
 		@param language Code of the language to use (e.g. "cg")
 		@param language Code of the language to use (e.g. "cg")
 		@param gptype The type of program to create
 		@param gptype The type of program to create
 		*/
 		*/
-		HighLevelGpuProgramPtr createProgram(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile);
+		HighLevelGpuProgramPtr create(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile);
 
 
 		/** Create a new, unloaded HighLevelGpuProgram. 
 		/** Create a new, unloaded HighLevelGpuProgram. 
 		@par
 		@par
@@ -109,7 +109,7 @@ namespace CamelotEngine {
 			properties like source, entry point, type, profile manually.
 			properties like source, entry point, type, profile manually.
 		@param language Code of the language to use (e.g. "cg")
 		@param language Code of the language to use (e.g. "cg")
 		*/
 		*/
-		HighLevelGpuProgramPtr createProgram(const String& language);
+		HighLevelGpuProgramPtr create(const String& language);
 	};
 	};
 	/** @} */
 	/** @} */
 	/** @} */
 	/** @} */

+ 6 - 0
CamelotRenderer/Include/CmMesh.h

@@ -57,5 +57,11 @@ namespace CamelotEngine
 		friend class MeshRTTI;
 		friend class MeshRTTI;
 		static RTTITypeBase* getRTTIStatic();
 		static RTTITypeBase* getRTTIStatic();
 		virtual RTTITypeBase* getRTTI() const;
 		virtual RTTITypeBase* getRTTI() const;
+
+		/************************************************************************/
+		/* 								STATICS		                     		*/
+		/************************************************************************/
+	public:
+		static MeshPtr create();
 	};
 	};
 }
 }

+ 6 - 6
CamelotRenderer/Include/CmResourceHandle.h

@@ -2,12 +2,6 @@
 
 
 #include "CmIReflectable.h"
 #include "CmIReflectable.h"
 
 
-template<class _Ty>
-struct CM_Bool_struct
-{
-	int _Member;
-};
-
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
 	template <typename T>
 	template <typename T>
@@ -121,6 +115,12 @@ namespace CamelotEngine
 
 
 		std::shared_ptr<T> getInternalPtr() { if(!isResolved()) return nullptr; return std::static_pointer_cast<T>(mData->mPtr); }
 		std::shared_ptr<T> getInternalPtr() { if(!isResolved()) return nullptr; return std::static_pointer_cast<T>(mData->mPtr); }
 
 
+		template<class _Ty>
+		struct CM_Bool_struct
+		{
+			int _Member;
+		};
+
 		// Conversion to bool
 		// Conversion to bool
 		// (Why not just directly convert to bool? Because then we can assign pointer to bool and that's weird)
 		// (Why not just directly convert to bool? Because then we can assign pointer to bool and that's weird)
 		operator int CM_Bool_struct<T>::*() const
 		operator int CM_Bool_struct<T>::*() const

+ 49 - 183
CamelotRenderer/Include/CmTexture.h

@@ -52,13 +52,11 @@ namespace CamelotEngine {
 		TU_STATIC_WRITE_ONLY = HardwareBuffer::HBU_STATIC_WRITE_ONLY, 
 		TU_STATIC_WRITE_ONLY = HardwareBuffer::HBU_STATIC_WRITE_ONLY, 
 		TU_DYNAMIC_WRITE_ONLY = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY,
 		TU_DYNAMIC_WRITE_ONLY = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY,
 		TU_DYNAMIC_WRITE_ONLY_DISCARDABLE = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE,
 		TU_DYNAMIC_WRITE_ONLY_DISCARDABLE = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE,
-		/// mipmaps will be automatically generated for this texture
-		TU_AUTOMIPMAP = 0x100,
 		/// this texture will be a render target, i.e. used as a target for render to texture
 		/// this texture will be a render target, i.e. used as a target for render to texture
-		/// setting this flag will ignore all other texture usages except TU_AUTOMIPMAP
+		/// setting this flag will ignore all other texture usages
 		TU_RENDERTARGET = 0x200,
 		TU_RENDERTARGET = 0x200,
 		/// default to automatic mipmap generation static textures
 		/// default to automatic mipmap generation static textures
-		TU_DEFAULT = TU_AUTOMIPMAP | TU_STATIC_WRITE_ONLY
+		TU_DEFAULT = TU_STATIC_WRITE_ONLY
         
         
     };
     };
 
 
@@ -81,9 +79,7 @@ namespace CamelotEngine {
 	enum TextureMipmap
 	enum TextureMipmap
 	{
 	{
 		/// Generate mipmaps up to 1x1
 		/// Generate mipmaps up to 1x1
-		MIP_UNLIMITED = 0x7FFFFFFF,
-		/// Use TextureManager default
-		MIP_DEFAULT = -1
+		MIP_UNLIMITED = 0x7FFFFFFF
 	};
 	};
 
 
     /** Abstract class representing a Texture resource.
     /** Abstract class representing a Texture resource.
@@ -100,10 +96,6 @@ namespace CamelotEngine {
     public:
     public:
         Texture();
         Texture();
 
 
-        /** Sets the type of texture; can only be changed before load() 
-        */
-        virtual void setTextureType(TextureType ttype ) { mTextureType = ttype; }
-
         /** Gets the type of texture 
         /** Gets the type of texture 
         */
         */
         virtual TextureType getTextureType(void) const { return mTextureType; }
         virtual TextureType getTextureType(void) const { return mTextureType; }
@@ -112,66 +104,11 @@ namespace CamelotEngine {
         */
         */
         virtual size_t getNumMipmaps(void) const {return mNumMipmaps;}
         virtual size_t getNumMipmaps(void) const {return mNumMipmaps;}
 
 
-		/** Sets the number of mipmaps to be used for this texture.
-            @note
-                Must be set before calling any 'load' method.
-        */
-        virtual void setNumMipmaps(size_t num) {mNumRequestedMipmaps = mNumMipmaps = num;}
-
-		/** Are mipmaps hardware generated?
-		@remarks
-			Will only be accurate after texture load, or createInternalResources
-		*/
-		virtual bool getMipmapsHardwareGenerated(void) const { return mMipmapsHardwareGenerated; }
-
-        /** Returns the gamma adjustment factor applied to this texture on loading.
-        */
-        virtual float getGamma(void) const { return mGamma; }
-
-        /** Sets the gamma adjustment factor applied to this texture on loading the
-			data.
-            @note
-                Must be called before any 'load' method. This gamma factor will
-				be premultiplied in and may reduce the precision of your textures.
-				You can use setHardwareGamma if supported to apply gamma on 
-				sampling the texture instead.
-        */
-        virtual void setGamma(float g) { mGamma = g; }
-
-		/** Sets whether this texture will be set up so that on sampling it, 
-			hardware gamma correction is applied.
-		@remarks
-			24-bit textures are often saved in gamma colour space; this preserves
-			precision in the 'darks'. However, if you're performing blending on 
-			the sampled colours, you really want to be doing it in linear space. 
-			One way is to apply a gamma correction value on loading (see setGamma),
-			but this means you lose precision in those dark colours. An alternative
-			is to get the hardware to do the gamma correction when reading the 
-			texture and converting it to a floating point value for the rest of
-			the pipeline. This option allows you to do that; it's only supported
-			in relatively recent hardware (others will ignore it) but can improve
-			the quality of colour reproduction.
-		@note
-			Must be called before any 'load' method since it may affect the
-			construction of the underlying hardware resources.
-			Also note this only useful on textures using 8-bit colour channels.
-		*/
-		virtual void setHardwareGammaEnabled(bool enabled) { mHwGamma = enabled; }
-
 		/** Gets whether this texture will be set up so that on sampling it, 
 		/** Gets whether this texture will be set up so that on sampling it, 
 		hardware gamma correction is applied.
 		hardware gamma correction is applied.
 		*/
 		*/
 		virtual bool isHardwareGammaEnabled() const { return mHwGamma; }
 		virtual bool isHardwareGammaEnabled() const { return mHwGamma; }
 
 
-		/** Set the level of multisample AA to be used if this texture is a 
-			rendertarget.
-		@note This option will be ignored if TU_RENDERTARGET is not part of the
-			usage options on this texture, or if the hardware does not support it. 
-		@param fsaa The number of samples
-		@param fsaaHint Any hinting text (@see Root::createRenderWindow)
-		*/
-		virtual void setFSAA(UINT32 fsaa, const String& fsaaHint) { mFSAA = fsaa; mFSAAHint = fsaaHint; }
-
 		/** Get the level of multisample AA to be used if this texture is a 
 		/** Get the level of multisample AA to be used if this texture is a 
 		rendertarget.
 		rendertarget.
 		*/
 		*/
@@ -193,120 +130,16 @@ namespace CamelotEngine {
         */
         */
         virtual size_t getDepth(void) const { return mDepth; }
         virtual size_t getDepth(void) const { return mDepth; }
 
 
-        /** Returns the height of the original input texture (may differ due to hardware requirements).
-        */
-        virtual size_t getSrcHeight(void) const { return mSrcHeight; }
-
-        /** Returns the width of the original input texture (may differ due to hardware requirements).
-        */
-        virtual size_t getSrcWidth(void) const { return mSrcWidth; }
-
-        /** Returns the original depth of the input texture (only applicable for 3D textures).
-        */
-        virtual size_t getSrcDepth(void) const { return mSrcDepth; }
-
-        /** Set the height of the texture; can only do this before load();
-        */
-        virtual void setHeight(size_t h) { mHeight = mSrcHeight = h; }
-
-        /** Set the width of the texture; can only do this before load();
-        */
-        virtual void setWidth(size_t w) { mWidth = mSrcWidth = w; }
-
-        /** Set the depth of the texture (only applicable for 3D textures);
-            ; can only do this before load();
-        */
-        virtual void setDepth(size_t d)  { mDepth = mSrcDepth = d; }
-
         /** Returns the TextureUsage indentifier for this Texture
         /** Returns the TextureUsage indentifier for this Texture
         */
         */
-        virtual int getUsage() const
-        {
-            return mUsage;
-        }
-
-        /** Sets the TextureUsage indentifier for this Texture; only useful before load()
-			
-			@param u is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY 
-				TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are
-            	strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to 
-            	update regularly, consider HBU_DYNAMIC_WRITE_ONLY.
-        */
-        virtual void setUsage(int u) { mUsage = u; }
-
-        /** Creates the internal texture resources for this texture. 
-        @remarks
-            This method creates the internal texture resources (pixel buffers, 
-            texture surfaces etc) required to begin using this texture. You do
-            not need to call this method directly unless you are manually creating
-            a texture, in which case something must call it, after having set the
-            size and format of the texture (e.g. the ManualResourceLoader might
-            be the best one to call it). If you are not defining a manual texture,
-            or if you use one of the self-contained load...() methods, then it will be
-            called for you.
-        */
-        virtual void createInternalResources(void);
-
-        /** Frees internal texture resources for this texture. 
-        */
-        virtual void freeInternalResources(void);
-        
-		/** Copies (and maybe scales to fit) the contents of this texture to
-			another texture. */
-		virtual void copyToTexture( TexturePtr& target );
+        virtual int getUsage() const { return mUsage; }
 
 
 		/** Returns the pixel format for the texture surface. */
 		/** Returns the pixel format for the texture surface. */
-		virtual PixelFormat getFormat() const
-		{
-			return mFormat;
-		}
-
-        /** Returns the desired pixel format for the texture surface. */
-        virtual PixelFormat getDesiredFormat(void) const
-        {
-            return mDesiredFormat;
-        }
-
-        /** Returns the pixel format of the original input texture (may differ due to
-            hardware requirements and pixel format convertion).
-        */
-        virtual PixelFormat getSrcFormat(void) const
-        {
-            return mSrcFormat;
-        }
-
-        /** Sets the pixel format for the texture surface; can only be set before load(). */
-        virtual void setFormat(PixelFormat pf);
+		virtual PixelFormat getFormat() const { return mFormat; }
 
 
         /** Returns true if the texture has an alpha layer. */
         /** Returns true if the texture has an alpha layer. */
         virtual bool hasAlpha(void) const;
         virtual bool hasAlpha(void) const;
 
 
-        /** Sets desired bit depth for integer pixel format textures.
-        @note
-            Available values: 0, 16 and 32, where 0 (the default) means keep original format
-            as it is. This value is number of bits for the pixel.
-        */
-        virtual void setDesiredIntegerBitDepth(UINT16 bits);
-
-        /** gets desired bit depth for integer pixel format textures.
-        */
-        virtual UINT16 getDesiredIntegerBitDepth(void) const;
-
-        /** Sets desired bit depth for float pixel format textures.
-        @note
-            Available values: 0, 16 and 32, where 0 (the default) means keep original format
-            as it is. This value is number of bits for a channel of the pixel.
-        */
-        virtual void setDesiredFloatBitDepth(UINT16 bits);
-
-        /** gets desired bit depth for float pixel format textures.
-        */
-        virtual UINT16 getDesiredFloatBitDepth(void) const;
-
-        /** Sets desired bit depth for integer and float pixel format.
-        */
-        virtual void setDesiredBitDepths(UINT16 integerBits, UINT16 floatBits);
-
         /** Return the number of faces this texture has. This will be 6 for a cubemap
         /** Return the number of faces this texture has. This will be 6 for a cubemap
         	texture and 1 for a 1D, 2D or 3D one.
         	texture and 1 for a 1D, 2D or 3D one.
         */
         */
@@ -352,15 +185,18 @@ namespace CamelotEngine {
 		 */
 		 */
 		void setTextureData(UINT32 face, TextureDataPtr textureData);
 		void setTextureData(UINT32 face, TextureDataPtr textureData);
 
 
+		/** Copies (and maybe scales to fit) the contents of this texture to
+			another texture. */
+		virtual void copyToTexture( TexturePtr& target );
+
     protected:
     protected:
+		friend class TextureManager;
+
         size_t mHeight;
         size_t mHeight;
         size_t mWidth;
         size_t mWidth;
         size_t mDepth;
         size_t mDepth;
 
 
-        size_t mNumRequestedMipmaps;
 		size_t mNumMipmaps;
 		size_t mNumMipmaps;
-		bool mMipmapsHardwareGenerated;
-        float mGamma;
 		bool mHwGamma;
 		bool mHwGamma;
 		UINT32 mFSAA;
 		UINT32 mFSAA;
 		String mFSAAHint;
 		String mFSAAHint;
@@ -369,21 +205,39 @@ namespace CamelotEngine {
 		PixelFormat mFormat;
 		PixelFormat mFormat;
         int mUsage; // Bit field, so this can't be TextureUsage
         int mUsage; // Bit field, so this can't be TextureUsage
 
 
-        PixelFormat mSrcFormat;
-        size_t mSrcWidth, mSrcHeight, mSrcDepth;
-
-        PixelFormat mDesiredFormat;
-        unsigned short mDesiredIntegerBitDepth;
-        unsigned short mDesiredFloatBitDepth;
-
 		bool mInternalResourcesCreated;
 		bool mInternalResourcesCreated;
 
 
 		public:
 		public:
 		vector<TextureDataPtr>::type mTextureData;
 		vector<TextureDataPtr>::type mTextureData;
 		protected:
 		protected:
+
+		/**
+		 * @brief	Initializes the texture. This must be called right after the texture is constructed. Normally called by TextureManager
+		 * 			upon texture creation.
+		 */
+		void initialize(TextureType textureType, size_t width, size_t height, size_t depth, size_t numMipmaps, 
+			PixelFormat format, int usage, bool hwGamma, UINT32 fsaa, const String& fsaaHint);
+		
 		/// @copydoc Resource::calculateSize
 		/// @copydoc Resource::calculateSize
 		size_t calculateSize(void) const;
 		size_t calculateSize(void) const;
-		
+
+        /** Creates the internal texture resources for this texture. 
+        @remarks
+            This method creates the internal texture resources (pixel buffers, 
+            texture surfaces etc) required to begin using this texture. You do
+            not need to call this method directly unless you are manually creating
+            a texture, in which case something must call it, after having set the
+            size and format of the texture (e.g. the ManualResourceLoader might
+            be the best one to call it). If you are not defining a manual texture,
+            or if you use one of the self-contained load...() methods, then it will be
+            called for you.
+        */
+        virtual void createInternalResources(void);
+
+        /** Frees internal texture resources for this texture. 
+        */
+        virtual void freeInternalResources(void);
+
 		/** Implementation of creating internal texture resources 
 		/** Implementation of creating internal texture resources 
 		*/
 		*/
 		virtual void createInternalResourcesImpl(void) = 0;
 		virtual void createInternalResourcesImpl(void) = 0;
@@ -410,6 +264,18 @@ namespace CamelotEngine {
 		friend class TextureRTTI;
 		friend class TextureRTTI;
 		static RTTITypeBase* getRTTIStatic();
 		static RTTITypeBase* getRTTIStatic();
 		virtual RTTITypeBase* getRTTI() const;
 		virtual RTTITypeBase* getRTTI() const;
+
+		/************************************************************************/
+		/* 								STATICS		                     		*/
+		/************************************************************************/
+	public:
+		static TexturePtr create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
+			int num_mips, PixelFormat format, int usage = TU_DEFAULT,
+			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
+
+		static TexturePtr create(TextureType texType, UINT32 width, UINT32 height, int num_mips,
+			PixelFormat format, int usage = TU_DEFAULT,
+			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
     };
     };
 
 
 	/** @} */
 	/** @} */

+ 0 - 52
CamelotRenderer/Include/CmTextureManager.h

@@ -162,38 +162,6 @@ namespace CamelotEngine {
 				num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 				num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 		}
 		}
 
 
-        /** Sets preferred bit depth for integer pixel format textures.
-        @param
-            bits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep
-            original format as it is. This value is number of bits for the pixel.
-        */
-        virtual void setPreferredIntegerBitDepth(UINT16 bits);
-
-        /** gets preferred bit depth for integer pixel format textures.
-        */
-        virtual UINT16 getPreferredIntegerBitDepth(void) const;
-
-        /** Sets preferred bit depth for float pixel format textures.
-        @param
-            bits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep
-            original format as it is. This value is number of bits for a channel of the pixel.
-        */
-        virtual void setPreferredFloatBitDepth(UINT16 bits);
-
-        /** gets preferred bit depth for float pixel format textures.
-        */
-        virtual UINT16 getPreferredFloatBitDepth(void) const;
-
-        /** Sets preferred bit depth for integer and float pixel format.
-        @param
-            integerBits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep
-            original format as it is. This value is number of bits for the pixel.
-        @param
-            floatBits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep
-            original format as it is. This value is number of bits for a channel of the pixel.
-        */
-        virtual void setPreferredBitDepths(UINT16 integerBits, UINT16 floatBits);
-
 		/** Returns whether this render system can natively support the precise texture 
 		/** Returns whether this render system can natively support the precise texture 
 			format requested with the given usage options.
 			format requested with the given usage options.
 		@remarks
 		@remarks
@@ -264,28 +232,8 @@ namespace CamelotEngine {
         virtual bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
         virtual bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
             bool preciseFormatOnly = false) = 0;
             bool preciseFormatOnly = false) = 0;
 
 
-        /** Sets the default number of mipmaps to be used for loaded textures, for when textures are
-            loaded automatically (e.g. by Material class) or when 'load' is called with the default
-            parameters by the application.
-			If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
-				level, 1x1x1.
-            @note
-                The default value is 0.
-        */
-        virtual void setDefaultNumMipmaps(size_t num);
-
-        /** Gets the default number of mipmaps to be used for loaded textures.
-        */
-        virtual size_t getDefaultNumMipmaps()
-        {
-            return mDefaultNumMipmaps;
-        }
-
     protected:
     protected:
 
 
-        UINT16 mPreferredIntegerBitDepth;
-        UINT16 mPreferredFloatBitDepth;
-        size_t mDefaultNumMipmaps;
     };
     };
 	/** @} */
 	/** @} */
 	/** @} */
 	/** @} */

+ 8 - 20
CamelotRenderer/Include/CmTextureRTTI.h

@@ -19,19 +19,13 @@ namespace CamelotEngine
 		CM_SETGET_MEMBER(mHeight, UINT32, Texture)
 		CM_SETGET_MEMBER(mHeight, UINT32, Texture)
 		CM_SETGET_MEMBER(mWidth, UINT32, Texture)
 		CM_SETGET_MEMBER(mWidth, UINT32, Texture)
 		CM_SETGET_MEMBER(mDepth, UINT32, Texture)
 		CM_SETGET_MEMBER(mDepth, UINT32, Texture)
-		CM_SETGET_MEMBER(mNumRequestedMipmaps, UINT32, Texture)
 		CM_SETGET_MEMBER(mNumMipmaps, UINT32, Texture)
 		CM_SETGET_MEMBER(mNumMipmaps, UINT32, Texture)
-		CM_SETGET_MEMBER(mMipmapsHardwareGenerated, bool, Texture)
-		CM_SETGET_MEMBER(mGamma, float, Texture)
 		CM_SETGET_MEMBER(mHwGamma, bool, Texture)
 		CM_SETGET_MEMBER(mHwGamma, bool, Texture)
 		CM_SETGET_MEMBER(mFSAA, UINT32, Texture)
 		CM_SETGET_MEMBER(mFSAA, UINT32, Texture)
 		CM_SETGET_MEMBER(mFSAAHint, String, Texture)
 		CM_SETGET_MEMBER(mFSAAHint, String, Texture)
 		CM_SETGET_MEMBER(mTextureType, TextureType, Texture)
 		CM_SETGET_MEMBER(mTextureType, TextureType, Texture)
 		CM_SETGET_MEMBER(mFormat, PixelFormat, Texture)
 		CM_SETGET_MEMBER(mFormat, PixelFormat, Texture)
 		CM_SETGET_MEMBER(mUsage, INT32, Texture)
 		CM_SETGET_MEMBER(mUsage, INT32, Texture)
-		CM_SETGET_MEMBER(mDesiredFormat, PixelFormat, Texture)
-		CM_SETGET_MEMBER(mDesiredIntegerBitDepth, UINT16, Texture)
-		CM_SETGET_MEMBER(mDesiredFloatBitDepth, UINT16, Texture)
 
 
 		std::shared_ptr<TextureData> getTextureData(Texture* obj, UINT32 face)
 		std::shared_ptr<TextureData> getTextureData(Texture* obj, UINT32 face)
 		{
 		{
@@ -61,19 +55,13 @@ namespace CamelotEngine
 			CM_ADD_PLAINFIELD(mHeight, 2, TextureRTTI)
 			CM_ADD_PLAINFIELD(mHeight, 2, TextureRTTI)
 			CM_ADD_PLAINFIELD(mWidth, 3, TextureRTTI)
 			CM_ADD_PLAINFIELD(mWidth, 3, TextureRTTI)
 			CM_ADD_PLAINFIELD(mDepth, 4, TextureRTTI)
 			CM_ADD_PLAINFIELD(mDepth, 4, TextureRTTI)
-			CM_ADD_PLAINFIELD(mNumRequestedMipmaps, 5, TextureRTTI)
-			CM_ADD_PLAINFIELD(mNumMipmaps, 6, TextureRTTI)
-			CM_ADD_PLAINFIELD(mMipmapsHardwareGenerated, 7, TextureRTTI)
-			CM_ADD_PLAINFIELD(mGamma, 8, TextureRTTI)
-			CM_ADD_PLAINFIELD(mHwGamma, 9, TextureRTTI)
-			CM_ADD_PLAINFIELD(mFSAA, 10, TextureRTTI)
-			CM_ADD_PLAINFIELD(mFSAAHint, 11, TextureRTTI)
-			CM_ADD_PLAINFIELD(mTextureType, 12, TextureRTTI)
-			CM_ADD_PLAINFIELD(mFormat, 13, TextureRTTI)
-			CM_ADD_PLAINFIELD(mUsage, 14, TextureRTTI)
-			CM_ADD_PLAINFIELD(mDesiredFormat, 15, TextureRTTI)
-			CM_ADD_PLAINFIELD(mDesiredIntegerBitDepth, 16, TextureRTTI)
-			CM_ADD_PLAINFIELD(mDesiredFloatBitDepth, 17, TextureRTTI)
+			CM_ADD_PLAINFIELD(mNumMipmaps, 5, TextureRTTI)
+			CM_ADD_PLAINFIELD(mHwGamma, 6, TextureRTTI)
+			CM_ADD_PLAINFIELD(mFSAA, 7, TextureRTTI)
+			CM_ADD_PLAINFIELD(mFSAAHint, 8, TextureRTTI)
+			CM_ADD_PLAINFIELD(mTextureType, 9, TextureRTTI)
+			CM_ADD_PLAINFIELD(mFormat, 10, TextureRTTI)
+			CM_ADD_PLAINFIELD(mUsage, 11, TextureRTTI)
 
 
 			addReflectablePtrArrayField("mTextureData", 18, &TextureRTTI::getTextureData, &TextureRTTI::getTextureDataArraySize, 
 			addReflectablePtrArrayField("mTextureData", 18, &TextureRTTI::getTextureData, &TextureRTTI::getTextureDataArraySize, 
 				&TextureRTTI::setTextureData, &TextureRTTI::setTextureDataArraySize);
 				&TextureRTTI::setTextureData, &TextureRTTI::setTextureDataArraySize);
@@ -93,7 +81,7 @@ namespace CamelotEngine
 		virtual std::shared_ptr<IReflectable> newRTTIObject()
 		virtual std::shared_ptr<IReflectable> newRTTIObject()
 		{
 		{
 			// DEBUG ONLY - Remove this after I implement RTTI types for specific texture types
 			// DEBUG ONLY - Remove this after I implement RTTI types for specific texture types
-			return TextureManager::instance().create(TEX_TYPE_2D, 128, 128, 1, PF_A8B8G8R8);
+			return Texture::create(TEX_TYPE_2D, 128, 128, 1, PF_A8B8G8R8);
 
 
 			//CM_EXCEPT(InternalErrorException, "Cannot instantiate abstract class!");
 			//CM_EXCEPT(InternalErrorException, "Cannot instantiate abstract class!");
 		}
 		}

+ 0 - 101
CamelotRenderer/Source/CmCamera.cpp

@@ -541,107 +541,6 @@ namespace CamelotEngine {
 			updateFrustumImpl();
 			updateFrustumImpl();
 		}
 		}
 	}
 	}
-
-	//-----------------------------------------------------------------------
-	void Camera::updateVertexData(void) const
-	{
-		if (mRecalcVertexData)
-		{
-			if (mVertexData.vertexBufferBinding->getBufferCount() <= 0)
-			{
-				// Initialise vertex & index data
-				mVertexData.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
-				mVertexData.vertexCount = 32;
-				mVertexData.vertexStart = 0;
-				mVertexData.vertexBufferBinding->setBinding( 0,
-					HardwareBufferManager::instance().createVertexBuffer(
-					sizeof(float)*3, 32, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY) );
-			}
-
-			// Note: Even though we can dealing with general projection matrix here,
-			//       but because it's incompatibly with infinite far plane, thus, we
-			//       still need to working with projection parameters.
-
-			// Calc near plane corners
-			float vpLeft, vpRight, vpBottom, vpTop;
-			calcProjectionParameters(vpLeft, vpRight, vpBottom, vpTop);
-
-			// Treat infinite fardist as some arbitrary far value
-			float farDist = (mFarDist == 0) ? 100000 : mFarDist;
-
-			// Calc far plane corners
-			float radio = mProjType == PT_PERSPECTIVE ? farDist / mNearDist : 1;
-			float farLeft = vpLeft * radio;
-			float farRight = vpRight * radio;
-			float farBottom = vpBottom * radio;
-			float farTop = vpTop * radio;
-
-			// Calculate vertex positions (local)
-			// 0 is the origin
-			// 1, 2, 3, 4 are the points on the near plane, top left first, clockwise
-			// 5, 6, 7, 8 are the points on the far plane, top left first, clockwise
-			HardwareVertexBufferPtr vbuf = mVertexData.vertexBufferBinding->getBuffer(0);
-			float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
-
-			// near plane (remember frustum is going in -Z direction)
-			*pFloat++ = vpLeft;  *pFloat++ = vpTop;    *pFloat++ = -mNearDist;
-			*pFloat++ = vpRight; *pFloat++ = vpTop;    *pFloat++ = -mNearDist;
-
-			*pFloat++ = vpRight; *pFloat++ = vpTop;    *pFloat++ = -mNearDist;
-			*pFloat++ = vpRight; *pFloat++ = vpBottom; *pFloat++ = -mNearDist;
-
-			*pFloat++ = vpRight; *pFloat++ = vpBottom; *pFloat++ = -mNearDist;
-			*pFloat++ = vpLeft;  *pFloat++ = vpBottom; *pFloat++ = -mNearDist;
-
-			*pFloat++ = vpLeft;  *pFloat++ = vpBottom; *pFloat++ = -mNearDist;
-			*pFloat++ = vpLeft;  *pFloat++ = vpTop;    *pFloat++ = -mNearDist;
-
-			// far plane (remember frustum is going in -Z direction)
-			*pFloat++ = farLeft;  *pFloat++ = farTop;    *pFloat++ = -farDist;
-			*pFloat++ = farRight; *pFloat++ = farTop;    *pFloat++ = -farDist;
-
-			*pFloat++ = farRight; *pFloat++ = farTop;    *pFloat++ = -farDist;
-			*pFloat++ = farRight; *pFloat++ = farBottom; *pFloat++ = -farDist;
-
-			*pFloat++ = farRight; *pFloat++ = farBottom; *pFloat++ = -farDist;
-			*pFloat++ = farLeft;  *pFloat++ = farBottom; *pFloat++ = -farDist;
-
-			*pFloat++ = farLeft;  *pFloat++ = farBottom; *pFloat++ = -farDist;
-			*pFloat++ = farLeft;  *pFloat++ = farTop;    *pFloat++ = -farDist;
-
-			// Sides of the pyramid
-			*pFloat++ = 0.0f;    *pFloat++ = 0.0f;   *pFloat++ = 0.0f;
-			*pFloat++ = vpLeft;  *pFloat++ = vpTop;  *pFloat++ = -mNearDist;
-
-			*pFloat++ = 0.0f;    *pFloat++ = 0.0f;   *pFloat++ = 0.0f;
-			*pFloat++ = vpRight; *pFloat++ = vpTop;    *pFloat++ = -mNearDist;
-
-			*pFloat++ = 0.0f;    *pFloat++ = 0.0f;   *pFloat++ = 0.0f;
-			*pFloat++ = vpRight; *pFloat++ = vpBottom; *pFloat++ = -mNearDist;
-
-			*pFloat++ = 0.0f;    *pFloat++ = 0.0f;   *pFloat++ = 0.0f;
-			*pFloat++ = vpLeft;  *pFloat++ = vpBottom; *pFloat++ = -mNearDist;
-
-			// Sides of the box
-
-			*pFloat++ = vpLeft;  *pFloat++ = vpTop;  *pFloat++ = -mNearDist;
-			*pFloat++ = farLeft;  *pFloat++ = farTop;  *pFloat++ = -farDist;
-
-			*pFloat++ = vpRight; *pFloat++ = vpTop;    *pFloat++ = -mNearDist;
-			*pFloat++ = farRight; *pFloat++ = farTop;    *pFloat++ = -farDist;
-
-			*pFloat++ = vpRight; *pFloat++ = vpBottom; *pFloat++ = -mNearDist;
-			*pFloat++ = farRight; *pFloat++ = farBottom; *pFloat++ = -farDist;
-
-			*pFloat++ = vpLeft;  *pFloat++ = vpBottom; *pFloat++ = -mNearDist;
-			*pFloat++ = farLeft;  *pFloat++ = farBottom; *pFloat++ = -farDist;
-
-
-			vbuf->unlock();
-
-			mRecalcVertexData = false;
-		}
-	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
 	bool Camera::isFrustumOutOfDate(void) const
 	bool Camera::isFrustumOutOfDate(void) const
 	{
 	{

+ 1 - 1
CamelotRenderer/Source/CmCgProgram.cpp

@@ -166,7 +166,7 @@ namespace CamelotEngine {
 
 
 				// Create a high-level program, give it the same name as us
 				// Create a high-level program, give it the same name as us
 				HighLevelGpuProgramPtr vp = 
 				HighLevelGpuProgramPtr vp = 
-					HighLevelGpuProgramManager::instance().createProgram(
+					HighLevelGpuProgramManager::instance().create(
 					hlslSourceFromCg, "main", "hlsl", mType, mProfile);
 					hlslSourceFromCg, "main", "hlsl", mType, mProfile);
 
 
 				vp->init();
 				vp->init();

+ 7 - 0
CamelotRenderer/Source/CmHighLevelGpuProgram.cpp

@@ -26,6 +26,7 @@ THE SOFTWARE.
 -----------------------------------------------------------------------------
 -----------------------------------------------------------------------------
 */
 */
 #include "CmHighLevelGpuProgram.h"
 #include "CmHighLevelGpuProgram.h"
+#include "CmHighLevelGpuProgramManager.h"
 #include "CmException.h"
 #include "CmException.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -145,4 +146,10 @@ namespace CamelotEngine
 		// also set logical / physical maps for programs which use this
 		// also set logical / physical maps for programs which use this
 		params->_setLogicalIndexes(mFloatLogicalToPhysical, mIntLogicalToPhysical, mSamplerLogicalToPhysical);
 		params->_setLogicalIndexes(mFloatLogicalToPhysical, mIntLogicalToPhysical, mSamplerLogicalToPhysical);
 	}
 	}
+	//---------------------------------------------------------------------
+	HighLevelGpuProgramPtr HighLevelGpuProgram::create(const String& source, const String& entryPoint, 
+		const String& language, GpuProgramType gptype, GpuProgramProfile profile)
+	{
+		return HighLevelGpuProgramManager::instance().create(source, entryPoint, language, gptype, profile);
+	}
 }
 }

+ 2 - 2
CamelotRenderer/Source/CmHighLevelGpuProgramManager.cpp

@@ -145,7 +145,7 @@ namespace CamelotEngine {
 
 
 	}
 	}
     //---------------------------------------------------------------------------
     //---------------------------------------------------------------------------
-    HighLevelGpuProgramPtr HighLevelGpuProgramManager::createProgram(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile)
+    HighLevelGpuProgramPtr HighLevelGpuProgramManager::create(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile)
     {
     {
         HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(getFactory(language)->create(source, entryPoint, profile));
         HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(getFactory(language)->create(source, entryPoint, profile));
 
 
@@ -156,7 +156,7 @@ namespace CamelotEngine {
         return prg;
         return prg;
     }
     }
 	//---------------------------------------------------------------------------
 	//---------------------------------------------------------------------------
-	HighLevelGpuProgramPtr HighLevelGpuProgramManager::createProgram(const String& language)
+	HighLevelGpuProgramPtr HighLevelGpuProgramManager::create(const String& language)
 	{
 	{
 		HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(getFactory(language)->create());
 		HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(getFactory(language)->create());
 
 

+ 9 - 0
CamelotRenderer/Source/CmMesh.cpp

@@ -300,4 +300,13 @@ namespace CamelotEngine
 	{
 	{
 		return Mesh::getRTTIStatic();
 		return Mesh::getRTTIStatic();
 	}
 	}
+
+	/************************************************************************/
+	/* 								STATICS		                     		*/
+	/************************************************************************/
+
+	MeshPtr Mesh::create()
+	{
+		return MeshPtr(new Mesh());
+	}
 }
 }

+ 42 - 88
CamelotRenderer/Source/CmTexture.cpp

@@ -40,64 +40,36 @@ namespace CamelotEngine {
             mHeight(512),
             mHeight(512),
             mWidth(512),
             mWidth(512),
             mDepth(1),
             mDepth(1),
-			mNumRequestedMipmaps(0),
             mNumMipmaps(0),
             mNumMipmaps(0),
-			mMipmapsHardwareGenerated(false),
-            mGamma(1.0f),
 			mHwGamma(false),
 			mHwGamma(false),
 			mFSAA(0),
 			mFSAA(0),
             mTextureType(TEX_TYPE_2D),            
             mTextureType(TEX_TYPE_2D),            
             mFormat(PF_UNKNOWN),
             mFormat(PF_UNKNOWN),
             mUsage(TU_DEFAULT),
             mUsage(TU_DEFAULT),
-            mSrcFormat(PF_UNKNOWN),
-            mSrcWidth(0),
-            mSrcHeight(0), 
-            mSrcDepth(0),
-            mDesiredFormat(PF_UNKNOWN),
-            mDesiredIntegerBitDepth(0),
-            mDesiredFloatBitDepth(0),
             mInternalResourcesCreated(false)
             mInternalResourcesCreated(false)
     {
     {
         
         
     }
     }
-    //--------------------------------------------------------------------------
-    void Texture::setFormat(PixelFormat pf)
-    {
-        mFormat = pf;
-        mDesiredFormat = pf;
-        mSrcFormat = pf;
-    }
+	//-------------------------------------------------------------------------
+	void Texture::initialize(TextureType textureType, size_t width, size_t height, size_t depth, size_t numMipmaps, 
+		PixelFormat format, int usage, bool hwGamma, UINT32 fsaa, const String& fsaaHint)
+	{
+		mTextureType = textureType;
+		mWidth = width;
+		mHeight = height;
+		mDepth = depth;
+		mNumMipmaps = numMipmaps;
+		mFormat = format;
+		mUsage = usage;
+		mHwGamma = hwGamma;
+		mFSAA = fsaa;
+		mFSAAHint = fsaaHint;
+	}
     //--------------------------------------------------------------------------
     //--------------------------------------------------------------------------
     bool Texture::hasAlpha(void) const
     bool Texture::hasAlpha(void) const
     {
     {
         return PixelUtil::hasAlpha(mFormat);
         return PixelUtil::hasAlpha(mFormat);
     }
     }
-    //--------------------------------------------------------------------------
-    void Texture::setDesiredIntegerBitDepth(UINT16 bits)
-    {
-        mDesiredIntegerBitDepth = bits;
-    }
-    //--------------------------------------------------------------------------
-    UINT16 Texture::getDesiredIntegerBitDepth(void) const
-    {
-        return mDesiredIntegerBitDepth;
-    }
-    //--------------------------------------------------------------------------
-    void Texture::setDesiredFloatBitDepth(UINT16 bits)
-    {
-        mDesiredFloatBitDepth = bits;
-    }
-    //--------------------------------------------------------------------------
-    UINT16 Texture::getDesiredFloatBitDepth(void) const
-    {
-        return mDesiredFloatBitDepth;
-    }
-    //--------------------------------------------------------------------------
-    void Texture::setDesiredBitDepths(UINT16 integerBits, UINT16 floatBits)
-    {
-        mDesiredIntegerBitDepth = integerBits;
-        mDesiredFloatBitDepth = floatBits;
-    }
     //--------------------------------------------------------------------------
     //--------------------------------------------------------------------------
 	size_t Texture::calculateSize(void) const
 	size_t Texture::calculateSize(void) const
 	{
 	{
@@ -197,32 +169,19 @@ namespace CamelotEngine {
 		}
 		}
 
 
 		// Set desired texture size and properties from images[0]
 		// Set desired texture size and properties from images[0]
-		mSrcWidth = mWidth = mTextureData[0]->getWidth();
-		mSrcHeight = mHeight = mTextureData[0]->getHeight();
-		mSrcDepth = mDepth = mTextureData[0]->getDepth();
+		mWidth = mTextureData[0]->getWidth();
+		mHeight = mTextureData[0]->getHeight();
+		mDepth = mTextureData[0]->getDepth();
 
 
 		// Get source image format and adjust if required
 		// Get source image format and adjust if required
-		mSrcFormat = mTextureData[0]->getFormat();
-
-		if (mDesiredFormat != PF_UNKNOWN)
-		{
-			// If have desired format, use it
-			mFormat = mDesiredFormat;
-		}
-		else
-		{
-			// Get the format according with desired bit depth
-			mFormat = PixelUtil::getFormatForBitDepths(mSrcFormat, mDesiredIntegerBitDepth, mDesiredFloatBitDepth);
-		}
+		PixelFormat srcFormat = mTextureData[0]->getFormat();
 
 
 		// The custom mipmaps in the image have priority over everything
 		// The custom mipmaps in the image have priority over everything
 		size_t imageMips = mTextureData[0]->getNumMipmaps();
 		size_t imageMips = mTextureData[0]->getNumMipmaps();
 
 
 		if(imageMips > 0)
 		if(imageMips > 0)
 		{
 		{
-			mNumMipmaps = mNumRequestedMipmaps = mTextureData[0]->getNumMipmaps();
-			// Disable flag for auto mip generation
-			mUsage &= ~TU_AUTOMIPMAP;
+			mNumMipmaps = mTextureData[0]->getNumMipmaps();
 		}
 		}
 
 
 		// Create the texture
 		// Create the texture
@@ -249,32 +208,11 @@ namespace CamelotEngine {
 				PixelData src = mTextureData[i]->getPixels(mip);
 				PixelData src = mTextureData[i]->getPixels(mip);
 
 
 				// Sets to treated format in case is difference
 				// Sets to treated format in case is difference
-				src.format = mSrcFormat;
-
-				if(mGamma != 1.0f) {
-					// Apply gamma correction
-					// Do not overwrite original image but do gamma correction in temporary buffer
-					MemoryDataStreamPtr buf(new MemoryDataStream(
-						PixelUtil::getMemorySize(
-						src.getWidth(), src.getHeight(), src.getDepth(), src.format)));
-
-					PixelData corrected = PixelData(src.getWidth(), src.getHeight(), src.getDepth(), src.format, buf->getPtr());
-					PixelUtil::bulkPixelConversion(src, corrected);
-
-					PixelUtil::applyGamma(static_cast<UINT8*>(corrected.data), mGamma, corrected.getConsecutiveSize(), 
-						static_cast<UINT8>(PixelUtil::getNumElemBits(src.format)));
-
-					// Destination: entire texture. blitFromMemory does the scaling to
-					// a power of two for us when needed
-					getBuffer(i, mip)->blitFromMemory(corrected);
-				}
-				else 
-				{
-					// Destination: entire texture. blitFromMemory does the scaling to
-					// a power of two for us when needed
-					getBuffer(i, mip)->blitFromMemory(src);
-				}
+				src.format = srcFormat;
 
 
+				// Destination: entire texture. blitFromMemory does the scaling to
+				// a power of two for us when needed
+				getBuffer(i, mip)->blitFromMemory(src);
 			}
 			}
 		}
 		}
 		// Update size (the final size, not including temp space)
 		// Update size (the final size, not including temp space)
@@ -293,9 +231,8 @@ namespace CamelotEngine {
             CM_EXCEPT(InvalidParametersException, 
             CM_EXCEPT(InvalidParametersException, 
                 "Texture types must match");
                 "Texture types must match");
         }
         }
+
         size_t numMips = std::min(getNumMipmaps(), target->getNumMipmaps());
         size_t numMips = std::min(getNumMipmaps(), target->getNumMipmaps());
-        if((mUsage & TU_AUTOMIPMAP) || (target->getUsage()&TU_AUTOMIPMAP))
-            numMips = 0;
         for(unsigned int face=0; face<getNumFaces(); face++)
         for(unsigned int face=0; face<getNumFaces(); face++)
         {
         {
             for(unsigned int mip=0; mip<=numMips; mip++)
             for(unsigned int mip=0; mip<=numMips; mip++)
@@ -318,4 +255,21 @@ namespace CamelotEngine {
 	{
 	{
 		return Texture::getRTTIStatic();
 		return Texture::getRTTIStatic();
 	}
 	}
+
+	/************************************************************************/
+	/* 								STATICS	                      			*/
+	/************************************************************************/
+	TexturePtr Texture::create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
+		int num_mips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 fsaa, const String& fsaaHint)
+	{
+		return TextureManager::instance().create(texType, 
+			width, height, depth, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
+	}
+	
+	TexturePtr Texture::create(TextureType texType, UINT32 width, UINT32 height, 
+		int num_mips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 fsaa, const String& fsaaHint)
+	{
+		return TextureManager::instance().create(texType, 
+			width, height, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
+	}
 }
 }

+ 2 - 47
CamelotRenderer/Source/CmTextureManager.cpp

@@ -32,18 +32,13 @@ THE SOFTWARE.
 namespace CamelotEngine {
 namespace CamelotEngine {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     TextureManager::TextureManager(void)
     TextureManager::TextureManager(void)
-         : mPreferredIntegerBitDepth(0)
-         , mPreferredFloatBitDepth(0)
-         , mDefaultNumMipmaps(MIP_UNLIMITED)
     {
     {
-
         // Subclasses should register (when this is fully constructed)
         // Subclasses should register (when this is fully constructed)
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     TextureManager::~TextureManager()
     TextureManager::~TextureManager()
     {
     {
         // subclasses should unregister with resource group manager
         // subclasses should unregister with resource group manager
-
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     TexturePtr TextureManager::create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, int numMipmaps,
     TexturePtr TextureManager::create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, int numMipmaps,
@@ -51,49 +46,10 @@ namespace CamelotEngine {
 		UINT32 fsaa, const String& fsaaHint)
 		UINT32 fsaa, const String& fsaaHint)
     {
     {
         TexturePtr ret = TexturePtr(createImpl());
         TexturePtr ret = TexturePtr(createImpl());
-        ret->setTextureType(texType);
-        ret->setWidth(width);
-        ret->setHeight(height);
-		ret->setDepth(depth);
-        ret->setNumMipmaps((numMipmaps == MIP_DEFAULT)? mDefaultNumMipmaps :
-			static_cast<size_t>(numMipmaps));
-        ret->setFormat(format);
-        ret->setUsage(usage);
-		ret->setHardwareGammaEnabled(hwGamma);
-		ret->setFSAA(fsaa, fsaaHint);
+		ret->initialize(texType, width, height, depth, static_cast<size_t>(numMipmaps), format, usage, hwGamma, fsaa, fsaaHint);
+
 		return ret;
 		return ret;
     }
     }
-    //-----------------------------------------------------------------------
-    void TextureManager::setPreferredIntegerBitDepth(UINT16 bits)
-    {
-        mPreferredIntegerBitDepth = bits;
-    }
-    //-----------------------------------------------------------------------
-    UINT16 TextureManager::getPreferredIntegerBitDepth(void) const
-    {
-        return mPreferredIntegerBitDepth;
-    }
-    //-----------------------------------------------------------------------
-    void TextureManager::setPreferredFloatBitDepth(UINT16 bits)
-    {
-        mPreferredFloatBitDepth = bits;
-    }
-    //-----------------------------------------------------------------------
-    UINT16 TextureManager::getPreferredFloatBitDepth(void) const
-    {
-        return mPreferredFloatBitDepth;
-    }
-    //-----------------------------------------------------------------------
-    void TextureManager::setPreferredBitDepths(UINT16 integerBits, UINT16 floatBits)
-    {
-        mPreferredIntegerBitDepth = integerBits;
-        mPreferredFloatBitDepth = floatBits;
-    }
-    //-----------------------------------------------------------------------
-    void TextureManager::setDefaultNumMipmaps( size_t num )
-    {
-        mDefaultNumMipmaps = num;
-    }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
 	bool TextureManager::isFormatSupported(TextureType ttype, PixelFormat format, int usage)
 	bool TextureManager::isFormatSupported(TextureType ttype, PixelFormat format, int usage)
 	{
 	{
@@ -106,6 +62,5 @@ namespace CamelotEngine {
 
 
 		// Assume that same or greater number of bits means quality not degraded
 		// Assume that same or greater number of bits means quality not degraded
 		return PixelUtil::getNumElemBits(supportedFormat) >= PixelUtil::getNumElemBits(format);
 		return PixelUtil::getNumElemBits(supportedFormat) >= PixelUtil::getNumElemBits(format);
-		
 	}
 	}
 }
 }

+ 1 - 0
CamelotUtility/CamelotUtility.vcxproj

@@ -100,6 +100,7 @@
     <ClInclude Include="Include\CmInt2.h" />
     <ClInclude Include="Include\CmInt2.h" />
     <ClInclude Include="Include\CmIReflectable.h" />
     <ClInclude Include="Include\CmIReflectable.h" />
     <ClInclude Include="Include\CmKeyValuePair.h" />
     <ClInclude Include="Include\CmKeyValuePair.h" />
+    <ClInclude Include="Include\CmLockedPtr.h" />
     <ClInclude Include="Include\CmLog.h" />
     <ClInclude Include="Include\CmLog.h" />
     <ClInclude Include="Include\CmManagedDataBlock.h" />
     <ClInclude Include="Include\CmManagedDataBlock.h" />
     <ClInclude Include="Include\CmMathAsm.h" />
     <ClInclude Include="Include\CmMathAsm.h" />

+ 3 - 0
CamelotUtility/CamelotUtility.vcxproj.filters

@@ -201,6 +201,9 @@
     <ClInclude Include="Include\CmAsyncOp.h">
     <ClInclude Include="Include\CmAsyncOp.h">
       <Filter>Header Files\Threading</Filter>
       <Filter>Header Files\Threading</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmLockedPtr.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Include\CmAxisAlignedBox.cpp">
     <ClCompile Include="Include\CmAxisAlignedBox.cpp">

+ 65 - 0
CamelotUtility/Include/CmLockedPtr.h

@@ -0,0 +1,65 @@
+#pragma once
+
+#include "CmPrerequisitesUtil.h"
+
+#if CM_DEBUG_MODE
+#include "CmException.h"
+#endif
+
+namespace CamelotEngine
+{
+	/**
+	 * @brief	A pointer that once locked will not allow its value to be accessed.
+	 * 			
+	 * @note	This is useful with multithreading where you need to pass along some value to a different
+	 * 			thread, but want to ensure that no other thread can modify the value (without actually creating a copy
+	 * 			of all the data).
+	 * 			
+	 *			LockedPtr MUST be the exclusive owner of the data it is pointing to. 
+	 */
+	template <class T>
+	class LockedPtr
+	{
+	public:
+		explicit LockedPtr(T* data)
+			:mLocked(false)
+		{
+			mData = new std::shared_ptr<T>(data);
+		}
+
+		T* operator->() const 
+		{ 
+			throwIfLocked();
+			return !mLocked ? mData.get() : nullptr; 
+		}
+
+		void lock() { mLocked = true; }
+
+		template<class _Ty>
+		struct CM_Bool_struct
+		{
+			int _Member;
+		};
+
+		// Conversion to bool
+		// (Why not just directly convert to bool? Because then we can assign pointer to bool and that's weird)
+		operator int CM_Bool_struct<T>::*() const
+		{
+			return ((mData.get() != 0) ? &CM_Bool_struct<T>::_Member : 0);
+		}
+
+	private:
+		std::shared_ptr<T> mData;
+		bool mLocked;
+
+#if CM_DEBUG_MODE
+		void throwIfLocked() const
+		{
+			if(mLocked)
+			{
+				CM_EXCEPT(InternalErrorException, "Attempting to access locked data!");
+			}
+		}
+	};
+#endif
+}