Beispiel #1
0
        /// <summary>
        /// Internal method, create GLHardwarePixelBuffers for every face and mipmap level.
        /// This method must be called after the GL texture object was created, the number of mipmaps
        /// was set (Axiom.Configuration.Config.MaxTextureLayers) and glTexImageXD was called
        /// to allocate the buffer
        /// </summary>te
        private void CreateSurfaceList()
        {
            this.surfaceList.Clear();

            //For all faces and mipmaps, store surfaces as HardwarePixelBuffer
            bool wantGeneratedMips = (usage & TextureUsage.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 && !mipmapsHardwareGenerated && MipmapCount > 0;

            for (int face = 0; face < FaceCount; face++)
            {
                int width  = Width;
                int height = Height;

                for (int mip = 0; mip <= MipmapCount; mip++)
                {
                    GLES2HardwarePixelBuffer buf = new GLES2TextureBuffer(_name, this.GLES2TextureTarget, this.textureID, width, height, GLES2PixelUtil.GetClosestGLInternalFormat(format, hwGamma), (GLenum)GLES2PixelUtil.GetGLOriginDataType(format), face, mip, (BufferUsage)(usage), doSoftware && mip == 0, hwGamma, fsaa);

                    this.surfaceList.Add(buf);

                    //check for error
                    if (buf.Width == 0 || buf.Height == 0 || buf.Depth == 0)
                    {
                        throw new AxiomException("Zero sized texture surface on texture " + Name + " face " + face.ToString() + " mipmap " + mip.ToString() + ". The GL driver probably refused to create the texture.");
                    }
                }
            }
        }
Beispiel #2
0
 ///<summary>
 ///  // Very fast texture-to-texture blitter and hardware bi/trilinear scaling implementation using FBO Destination texture must be 1D, 2D, 3D, or Cube Source texture must be 1D, 2D or 3D Supports compressed formats as both source and destination format, it will use the hardware DXT compressor if available. @author W.J. van der Laan
 ///</summary>
 ///<param name="src"> </param>
 ///<param name="srcBox"> </param>
 ///<param name="dstBox"> </param>
 private void BlitFromTexture(GLES2TextureBuffer src, BasicBox srcBox, BasicBox dstBox)
 {
     /*Port notes
      * Ogre immediately returns void, yet much code is provided below
      * The remaining code will ported if/when Ogre makes use of it
      */
     return;             //Ogre todo add a shader attach...
 }
		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 );
		}
		///<summary>
		///  // Very fast texture-to-texture blitter and hardware bi/trilinear scaling implementation using FBO Destination texture must be 1D, 2D, 3D, or Cube Source texture must be 1D, 2D or 3D Supports compressed formats as both source and destination format, it will use the hardware DXT compressor if available. @author W.J. van der Laan
		///</summary>
		///<param name="src"> </param>
		///<param name="srcBox"> </param>
		///<param name="dstBox"> </param>
		private void BlitFromTexture( GLES2TextureBuffer src, BasicBox srcBox, BasicBox dstBox )
		{
			/*Port notes
			 * Ogre immediately returns void, yet much code is provided below
			 * The remaining code will ported if/when Ogre makes use of it
			 */
			return; //Ogre todo add a shader attach...
		}
Beispiel #5
0
		/// <summary>
		/// Internal method, create GLHardwarePixelBuffers for every face and mipmap level.
		/// This method must be called after the GL texture object was created, the number of mipmaps 
		/// was set (Axiom.Configuration.Config.MaxTextureLayers) and glTexImageXD was called
		/// to allocate the buffer
		/// </summary>te
		private void CreateSurfaceList()
		{
			this.surfaceList.Clear();

			//For all faces and mipmaps, store surfaces as HardwarePixelBuffer
			bool wantGeneratedMips = ( usage & TextureUsage.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 && !mipmapsHardwareGenerated && MipmapCount > 0;

			for ( int face = 0; face < FaceCount; face++ )
			{
				int width = Width;
				int height = Height;

				for ( int mip = 0; mip <= MipmapCount; mip++ )
				{
					GLES2HardwarePixelBuffer buf = new GLES2TextureBuffer( _name, this.GLES2TextureTarget, this.textureID, width, height, GLES2PixelUtil.GetClosestGLInternalFormat( format, hwGamma ), (GLenum) GLES2PixelUtil.GetGLOriginDataType( format ), face, mip, (BufferUsage) ( usage ), doSoftware && mip == 0, hwGamma, fsaa );

					this.surfaceList.Add( buf );

					//check for error
					if ( buf.Width == 0 || buf.Height == 0 || buf.Depth == 0 )
					{
						throw new AxiomException( "Zero sized texture surface on texture " + Name + " face " + face.ToString() + " mipmap " + mip.ToString() + ". The GL driver probably refused to create the texture." );
					}
				}
			}
		}
Beispiel #6
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);
        }