source/Irrlicht/COGLES2Texture.cpp
//! copies the texture into an opengl-es2 texture.

copies the texture into an opengl-es2 texture.
copies the texture into an opengl - es2 texture .
void COGLES2Texture::copyTexture( bool newTexture )
	{
#ifndef GL_BGRA
		if (Driver->queryOpenGLFeature(COGLES2ExtensionHandler::IRR_IMG_texture_format_BGRA8888) ||
			Driver->queryOpenGLFeature(COGLES2ExtensionHandler::IRR_EXT_texture_format_BGRA8888))
			GL_BGRA = 0x80E1;
		else
			GL_BGRA = GL_RGBA;
#endif
		if ( !Image )
		{
			os::Printer::log( "No image for OGLES2 texture to upload", ELL_ERROR );
			return;
		}
		void( *convert )( const void*, s32, void* ) = 0;
		switch ( Image->getColorFormat() )
		{
			case ECF_A1R5G5B5:
				InternalFormat = GL_RGBA;
				PixelFormat = GL_RGBA;
				PixelType = GL_UNSIGNED_SHORT_5_5_5_1;
				convert = CColorConverter::convert_A1R5G5B5toR5G5B5A1;
				break;
			case ECF_R5G6B5:
				InternalFormat = GL_RGB;
				PixelFormat = GL_RGB;
				PixelType = GL_UNSIGNED_SHORT_5_6_5;
				break;
			case ECF_R8G8B8:
				InternalFormat = GL_RGB;
				PixelFormat = GL_RGB;
				PixelType = GL_UNSIGNED_BYTE;
				convert = CColorConverter::convert_R8G8B8toB8G8R8;
				break;
			case ECF_A8R8G8B8:
				PixelType = GL_UNSIGNED_BYTE;
				if (Driver->queryOpenGLFeature(COGLES2ExtensionHandler::IRR_IMG_texture_format_BGRA8888) ||
					Driver->queryOpenGLFeature( COGLES2ExtensionHandler::IRR_EXT_texture_format_BGRA8888))
				{
					InternalFormat = GL_BGRA;
					PixelFormat = GL_BGRA;
				}
				else
				{
					convert = CColorConverter::convert_A8R8G8B8toA8B8G8R8;
					InternalFormat = GL_RGBA;
					PixelFormat = GL_RGBA;
				}
				break;
			default:
				os::Printer::log( "Unsupported texture format", ELL_ERROR );
				break;
		}
		{char msg[512]; sprintf(msg, "test %s %d", __FILE__, __LINE__); os::Printer::print(msg);};
		glBindTexture( GL_TEXTURE_2D, TextureName );
		if ( Driver->testGLError() )
			os::Printer::log( "Could not bind Texture", ELL_ERROR );
		if ( newTexture )
		{
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
		}
		void* source = 0;
		IImage* tmpImage = 0;
		source = Image->lock();
		if ( convert )
		{
			tmpImage = new CImage( Image->getColorFormat(), Image->getDimension() );
			void* dest = tmpImage->lock();
			convert( source, Image->getDimension().getArea(), dest );
			Image->unlock();
			source = dest;
		}
		if ( newTexture )
			glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, Image->getDimension().Width,
						Image->getDimension().Height, 0, PixelFormat, PixelType, source);
		else
			glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Image->getDimension().Width,
							 Image->getDimension().Height, PixelFormat, PixelType, source);
		if ( convert )
		{
			tmpImage->unlock();
			tmpImage->drop();
		}
		else
			Image->unlock();
		if ( Driver->testGLError() )
			os::Printer::log( "Could not glTexImage2D", ELL_ERROR );
		if ( newTexture )
		{
#ifndef DISABLE_MIPMAPPING
			{
				AutomaticMipmapUpdate = false;
				regenerateMipMapLevels();
			}
#else
			HasMipMaps = false;
			os::Printer::log( "Did not create OGLES2 texture mip maps.", ELL_ERROR );
#endif
		}
	}
void COGLES2Texture :: copyTexture ( bool newTexture ) { #ifndef GL_BGRA if ( Driver -> queryOpenGLFeature ( COGLES2ExtensionHandler :: IRR_IMG_texture_format_BGRA8888 ) || Driver -> queryOpenGLFeature ( COGLES2ExtensionHandler :: IRR_EXT_texture_format_BGRA8888 ) ) GL_BGRA = 0x80E1 ; else GL_BGRA = GL_RGBA ; #endif if ( ! Image ) { os :: Printer :: log ( " " , ELL_ERROR ) ; return ; } void ( * convert ) ( const void * , s32 , void * ) = 0 ; switch ( Image -> getColorFormat ( ) ) { case ECF_A1R5G5B5 : InternalFormat = GL_RGBA ; PixelFormat = GL_RGBA ; PixelType = GL_UNSIGNED_SHORT_5_5_5_1 ; convert = CColorConverter :: convert_A1R5G5B5toR5G5B5A1 ; break ; case ECF_R5G6B5 : InternalFormat = GL_RGB ; PixelFormat = GL_RGB ; PixelType = GL_UNSIGNED_SHORT_5_6_5 ; break ; case ECF_R8G8B8 : InternalFormat = GL_RGB ; PixelFormat = GL_RGB ; PixelType = GL_UNSIGNED_BYTE ; convert = CColorConverter :: convert_R8G8B8toB8G8R8 ; break ; case ECF_A8R8G8B8 : PixelType = GL_UNSIGNED_BYTE ; if ( Driver -> queryOpenGLFeature ( COGLES2ExtensionHandler :: IRR_IMG_texture_format_BGRA8888 ) || Driver -> queryOpenGLFeature ( COGLES2ExtensionHandler :: IRR_EXT_texture_format_BGRA8888 ) ) { InternalFormat = GL_BGRA ; PixelFormat = GL_BGRA ; } else { convert = CColorConverter :: convert_A8R8G8B8toA8B8G8R8 ; InternalFormat = GL_RGBA ; PixelFormat = GL_RGBA ; } break ; default : os :: Printer :: log ( " " , ELL_ERROR ) ; break ; } { char msg [ 512 ] ; sprintf ( msg , " " , __FILE__ , __LINE__ ) ; os :: Printer :: print ( msg ) ; } ; glBindTexture ( GL_TEXTURE_2D , TextureName ) ; if ( Driver -> testGLError ( ) ) os :: Printer :: log ( " " , ELL_ERROR ) ; if ( newTexture ) { glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ; } void * source = 0 ; IImage * tmpImage = 0 ; source = Image -> lock ( ) ; if ( convert ) { tmpImage = new CImage ( Image -> getColorFormat ( ) , Image -> getDimension ( ) ) ; void * dest = tmpImage -> lock ( ) ; convert ( source , Image -> getDimension ( ) . getArea ( ) , dest ) ; Image -> unlock ( ) ; source = dest ; } if ( newTexture ) glTexImage2D ( GL_TEXTURE_2D , 0 , InternalFormat , Image -> getDimension ( ) . Width , Image -> getDimension ( ) . Height , 0 , PixelFormat , PixelType , source ) ; else glTexSubImage2D ( GL_TEXTURE_2D , 0 , 0 , 0 , Image -> getDimension ( ) . Width , Image -> getDimension ( ) . Height , PixelFormat , PixelType , source ) ; if ( convert ) { tmpImage -> unlock ( ) ; tmpImage -> drop ( ) ; } else Image -> unlock ( ) ; if ( Driver -> testGLError ( ) ) os :: Printer :: log ( " " , ELL_ERROR ) ; if ( newTexture ) { #ifndef DISABLE_MIPMAPPING { AutomaticMipmapUpdate = false ; regenerateMipMapLevels ( ) ; } #else HasMipMaps = false ; os :: Printer :: log ( " " , ELL_ERROR ) ; #endif } }
copies the texture into an opengl-es2 texture.
copies the texture into an opengl - es2 texture .
// whoa, pretty badly implemented extension...
 // enable bilinear filter without mipmaps
