public override void BlitFromMemory( PixelBox src, BasicBox dstBox )
		{
			// Fall back to normal GLHardwarePixelBuffer::blitFromMemory in case 
			// - FBO is not supported
			// - Either source or target is luminance due doesn't looks like supported by hardware
			// - the source dimensions match the destination ones, in which case no scaling is needed
			//Ogre TODO: Check that extension is NOT available
			if ( PixelUtil.IsLuminance( src.Format ) || PixelUtil.IsLuminance( this.format ) || ( src.Width == dstBox.Width && src.Height == dstBox.Height && src.Depth == dstBox.Depth ) )
			{
				base.BlitFromMemory( src, dstBox );
				return;
			}

			if ( !Buffer.Contains( dstBox ) )
			{
				throw new ArgumentOutOfRangeException( "dstBox", "Destination box out of range" );
			}

			//For scoped deletion of conversion buffer

			PixelBox srcPB;
			BufferBase buf;
			//first, convert the srcbox to a OpenGL compatible pixel format
			if ( GLES2PixelUtil.GetGLOriginFormat( src.Format ) == 0 )
			{
				//Conver to buffer intenral format
				buf = BufferBase.Wrap( new byte[ PixelUtil.GetMemorySize( src.Width, src.Height, src.Depth, this.format ) ] );

				srcPB = new PixelBox( src.Width, src.Height, src.Depth, this.format, buf );
				PixelConverter.BulkPixelConversion( src, srcPB );
			}
			else
			{
				//No conversion needed
				srcPB = src;
			}

			//Create temporary texture to store source data
			int id = 0;
			All target = All.Texture2D;
			int width = GLES2PixelUtil.OptionalPO2( src.Width );
			int height = GLES2PixelUtil.OptionalPO2( src.Height );
			All format = GLES2PixelUtil.GetClosestGLInternalFormat( src.Format );
			All datatype = GLES2PixelUtil.GetGLOriginDataType( src.Format );

			//Generate texture name
			GL.GenTextures( 1, ref id );
			GLES2Config.GlCheckError( this );

			//Set texture type
			GL.BindTexture( target, id );
			GLES2Config.GlCheckError( this );

			//Allocate texture memory
			GL.TexImage2D( target, 0, (int) format, width, height, 0, format, datatype, IntPtr.Zero );
			GLES2Config.GlCheckError( this );

			var tex = new GLES2TextureBuffer( string.Empty, target, id, width, height, format, (All) src.Format, 0, 0, BufferUsage.StaticWriteOnly, false, false, 0 );

			//Upload data to 0,0,0 in temprary texture
			var tempTarget = new BasicBox( 0, 0, 0, srcPB.Width, srcPB.Height, srcPB.Depth );
			tex.Upload( srcPB, tempTarget );

			//Blit
			this.BlitFromTexture( tex, tempTarget, dstBox );
			GLES2Config.GlCheckError( this );
		}
Beispiel #2
0
        public override void BlitFromMemory(PixelBox src, BasicBox dstBox)
        {
            // Fall back to normal GLHardwarePixelBuffer::blitFromMemory in case
            // - FBO is not supported
            // - Either source or target is luminance due doesn't looks like supported by hardware
            // - the source dimensions match the destination ones, in which case no scaling is needed
            //Ogre TODO: Check that extension is NOT available
            if (PixelUtil.IsLuminance(src.Format) || PixelUtil.IsLuminance(this.format) || (src.Width == dstBox.Width && src.Height == dstBox.Height && src.Depth == dstBox.Depth))
            {
                base.BlitFromMemory(src, dstBox);
                return;
            }

            if (!Buffer.Contains(dstBox))
            {
                throw new ArgumentOutOfRangeException("dstBox", "Destination box out of range");
            }

            //For scoped deletion of conversion buffer

            PixelBox   srcPB;
            BufferBase buf;

            //first, convert the srcbox to a OpenGL compatible pixel format
            if (GLES2PixelUtil.GetGLOriginFormat(src.Format) == 0)
            {
                //Conver to buffer intenral format
                buf = BufferBase.Wrap(new byte[PixelUtil.GetMemorySize(src.Width, src.Height, src.Depth, this.format)]);

                srcPB = new PixelBox(src.Width, src.Height, src.Depth, this.format, buf);
                PixelConverter.BulkPixelConversion(src, srcPB);
            }
            else
            {
                //No conversion needed
                srcPB = src;
            }

            //Create temporary texture to store source data
            int id       = 0;
            All target   = All.Texture2D;
            int width    = GLES2PixelUtil.OptionalPO2(src.Width);
            int height   = GLES2PixelUtil.OptionalPO2(src.Height);
            All format   = GLES2PixelUtil.GetClosestGLInternalFormat(src.Format);
            All datatype = GLES2PixelUtil.GetGLOriginDataType(src.Format);

            //Generate texture name
            GL.GenTextures(1, ref id);
            GLES2Config.GlCheckError(this);

            //Set texture type
            GL.BindTexture(target, id);
            GLES2Config.GlCheckError(this);

            //Allocate texture memory
            GL.TexImage2D(target, 0, (int)format, width, height, 0, format, datatype, IntPtr.Zero);
            GLES2Config.GlCheckError(this);

            var tex = new GLES2TextureBuffer(string.Empty, target, id, width, height, format, (All)src.Format, 0, 0, BufferUsage.StaticWriteOnly, false, false, 0);

            //Upload data to 0,0,0 in temprary texture
            var tempTarget = new BasicBox(0, 0, 0, srcPB.Width, srcPB.Height, srcPB.Depth);

            tex.Upload(srcPB, tempTarget);

            //Blit
            this.BlitFromTexture(tex, tempTarget, dstBox);
            GLES2Config.GlCheckError(this);
        }