bool GLES2UPTexture::SetParameter(const GLuint program, const str_type::string& name, const Platform::FileLogger& logger)
{
	ActiveTexture(texturePass);
	BindTexture2D(texture);
	const int location = GetLocation(program, name, logger);
	//if (!IsEqualToAlreadyDefinedParam(program, location, this, logger))
	{
		//AddParam(program, location, GLES2UniformParameterPtr(new GLES2UPTexture(texturePass, texture, unit, GS_L(""))));
		glUniform1i(location, unit);
		//GLES2Video::CheckGLError(name + ": uniform parameter not found with glUniform1i", logger);
	}
	return true;
}
// constructor for DDS textures
void COpenGLTexture::updateDDSTexture(ISGPImage* surface)
{
	COpenGLConfig* pOpenGLConfig = COpenGLConfig::getInstance();
	SGPImageDDS *pSurface = static_cast<SGPImageDDS*>(surface);
	InternalFormat = pSurface->getInternalFormat();
	PixelFormat = pSurface->getExternalFormat();
	PixelType = pSurface->getPixelType();	

	ImageSize = surface->getDimension();
	TextureSize = ImageSize.getOptimalSize( !RenderDevice->queryDriverFeature(SGPVDF_TEXTURE_NPOT) );
	m_ColorFormat = getColorFormatFromInternalFormat(InternalFormat);

	glGenTextures(1, &OpenGLTextureID);

	// Loading a volume texture: 3D Texture
	if( pSurface->isVolume() )
	{
		TextureTarget = GL_TEXTURE_3D;
		bool bindsucceed = BindTexture3D(0);
		if( !bindsucceed || RenderDevice->testGLError() )
			Logger::getCurrentLogger()->writeToLog(String("Could not bind Texture"), ELL_ERROR);

		glTexImage3D(GL_TEXTURE_3D, 0, InternalFormat, 
			pSurface->getMipmapSize(0).Width, 
			pSurface->getMipmapSize(0).Height,
			pSurface->getMipmapDepth(0), 0, PixelFormat, 
			pSurface->getPixelType(), pSurface->getMipmapData(0));
		
		HasMipMaps = false;
		if( !pOpenGLConfig->Force_Disable_MIPMAPPING )
		{
			for(int i = 1; i < pSurface->getNumberOfMipmaps(); i++)
			{	
				HasMipMaps = true;
				glTexImage3D(GL_TEXTURE_3D, i, InternalFormat, 
					pSurface->getMipmapSize(i).Width, 
					pSurface->getMipmapSize(i).Height, 
					pSurface->getMipmapDepth(i), 0, PixelFormat, 
					pSurface->getPixelType(), pSurface->getMipmapData(i));
			}
			MipMapLevels = pSurface->getNumberOfMipmaps();
		}
		//unBindTexture3D(0);
	}
	else if( pSurface->isCubemap() )
	{
		TextureTarget = GL_TEXTURE_CUBE_MAP_ARB;
		//uncompressed cubemap texture
		bool bindsucceed = BindTextureCubeMap(0);
		if( !bindsucceed || RenderDevice->testGLError() )
			Logger::getCurrentLogger()->writeToLog(String("Could not bind Texture"), ELL_ERROR);
		
		uint32 MipMapNum = pSurface->getNumberOfMipmaps() / 6;

		for(int n = 0; n < 6; n++)
		{
			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB+n, 0, InternalFormat,
				pSurface->getMipmapSize(0).Width, 
				pSurface->getMipmapSize(0).Height,
				0, PixelFormat, pSurface->getPixelType(), 
				pSurface->getCubemap(n));

			HasMipMaps = false;
			if( !pOpenGLConfig->Force_Disable_MIPMAPPING )
			{
				for(uint32 i = 1; i < MipMapNum; i++)
				{
					HasMipMaps = true;
					glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB+n, i, InternalFormat, 
						pSurface->getMipmapSize(n*MipMapNum+i).Width, 
						pSurface->getMipmapSize(n*MipMapNum+i).Height,
						0, PixelFormat, pSurface->getPixelType(),
						pSurface->getMipmapData(n*MipMapNum+i));
				}
				MipMapLevels = MipMapNum;
			}
		}
		//unBindTextureCubeMap(0);
	}
	else	// 2D texture
	{
		TextureTarget = GL_TEXTURE_2D;
		bool bindsucceed = BindTexture2D(0);
		if( !bindsucceed || RenderDevice->testGLError() )
			Logger::getCurrentLogger()->writeToLog(String("Could not bind Texture"), ELL_ERROR);

		if( pSurface->isCompressed() )
		{
			RenderDevice->extGlCompressedTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, 
				pSurface->getMipmapSize(0).Width,
				pSurface->getMipmapSize(0).Height, 0, 
				pSurface->getMipmapDataBytes(0), 
				pSurface->getMipmapData(0));

			HasMipMaps = false;
			if( !pOpenGLConfig->Force_Disable_MIPMAPPING )
			{
				for (int i = 1; i < pSurface->getNumberOfMipmaps(); i++)
				{
					HasMipMaps = true;
					RenderDevice->extGlCompressedTexImage2D(GL_TEXTURE_2D, i, InternalFormat, 
						pSurface->getMipmapSize(i).Width,
						pSurface->getMipmapSize(i).Height, 0, 
						pSurface->getMipmapDataBytes(i), 
						pSurface->getMipmapData(i));
				}
				MipMapLevels = pSurface->getNumberOfMipmaps();
			}
		}
		else
		{
			if( pSurface->isSwap() )
				glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_TRUE );

			glPixelStorei( GL_UNPACK_ROW_LENGTH, pSurface->getMipmapSize(0).Width );
			glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, 
				pSurface->getMipmapSize(0).Width, 
				pSurface->getMipmapSize(0).Height, 0,
				PixelFormat, pSurface->getPixelType(), 
				pSurface->getMipmapData(0));

			HasMipMaps = false;
			if( !pOpenGLConfig->Force_Disable_MIPMAPPING )
			{
				for(int i = 1; i < pSurface->getNumberOfMipmaps(); i++)
				{
					HasMipMaps = true;
					glPixelStorei( GL_UNPACK_ROW_LENGTH, pSurface->getMipmapSize(i).Width );
					glTexImage2D(GL_TEXTURE_2D, i, InternalFormat, 
						pSurface->getMipmapSize(i).Width,
						pSurface->getMipmapSize(i).Height, 0,
						PixelFormat, pSurface->getPixelType(), 
						pSurface->getMipmapData(i));
				}
				MipMapLevels = pSurface->getNumberOfMipmaps();
			}
			glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_FALSE );
			glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
		}

		if( HasMipMaps )
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, pSurface->getNumberOfMipmaps()-1 );
		
		//unBindTexture2D(0);
	}

	setFiltering(TEXTURE_FILTER_MAG_BILINEAR, TEXTURE_FILTER_MIN_TRILINEAR);
	//if( HasMipMaps )
	//	MaxMinificationLevel = TEXTURE_FILTER_MIN_TRILINEAR;
}
//! copies the the texture into an open gl texture.
void COpenGLTexture::uploadTexture()
{
	COpenGLConfig* pOpenGLConfig = COpenGLConfig::getInstance();

	// check which image needs to be uploaded
	ISGPImage* image = m_Image;
	if( !image )
	{
		Logger::getCurrentLogger()->writeToLog(String("No image for OpenGL texture to upload"), ELL_ERROR);
		return;
	}

	// get correct opengl color data values
	
	GLint filtering;
	InternalFormat = getOpenGLFormatAndParametersFromColorFormat(m_ColorFormat, filtering, PixelFormat, PixelType);
	

	bool bindsucceed = BindTexture2D(0);
	if( !bindsucceed || RenderDevice->testGLError() )
		Logger::getCurrentLogger()->writeToLog(String("Could not bind Texture"), ELL_ERROR);


	glPixelStorei(GL_PACK_ALIGNMENT, 1);

	// now get image data and upload to GPU
	void* source = image->lock();

	glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, image->getDimension().Width,
		image->getDimension().Height, 0, PixelFormat, PixelType, source);

	image->unlock();

	if (RenderDevice->testGLError())
		Logger::getCurrentLogger()->writeToLog(String("Could not glTexImage2D"), ELL_ERROR);


	if( pOpenGLConfig->Force_Disable_MIPMAPPING )
		HasMipMaps = false;
	if( HasMipMaps )
	{
/*	IMPORTANT NOTE:
		if OpenGL >= 3.0, use glGenerateMipmap
		else if OpenGL >= 1.4, use glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
		else video card is pretty old at this point, fall back to gluBuild2DMipmaps?
		else cut off support
*/
		if( RenderDevice->queryDriverFeature(SGPVDF_MIP_MAP_GEN_HW) )
		{
			RenderDevice->extGlGenerateMipmap(GL_TEXTURE_2D);

			{
				uint32 width = image->getDimension().Width;
				uint32 height = image->getDimension().Height;
				uint32 i=0;
				do
				{
					if(width>1)
						width>>=1;
					if(height>1)
						height>>=1;
					++i;
				}
				while (width!=1 || height!=1);
				MipMapLevels = i;
			}
		}
		else