Ejemplo n.º 1
0
 public RenderTexture(HardwarePixelBuffer buffer, int zOffset)
 {
     pixelBuffer  = buffer;
     this.zOffset = zOffset;
     priority     = RenderTargetPriority.High;
     width        = buffer.Width;
     height       = buffer.Height;
     colorDepth   = PixelUtil.GetNumElemBits(buffer.Format);
 }
 public RenderTexture(HardwarePixelBuffer buffer, int zOffset)
 {
     pixelBuffer = buffer;
     this.zOffset = zOffset;
     priority = RenderTargetPriority.High;
     width = buffer.Width;
     height = buffer.Height;
     colorDepth = PixelUtil.GetNumElemBits(buffer.Format);
 }
Ejemplo n.º 3
0
		public RenderTexture( string name, HardwarePixelBuffer buffer, int zOffset )
			: base( name )
		{
			pixelBuffer = buffer;
			this.zOffset = zOffset;
			Priority = RenderTargetPriority.RenderToTexture;
			width = buffer.Width;
			height = buffer.Height;
			colorDepth = PixelUtil.GetNumElemBits( buffer.Format );
		}
Ejemplo n.º 4
0
        public virtual void Blit(HardwarePixelBuffer src, BasicBox srcBox, BasicBox dstBox)
        {
            if (IsLocked || src.IsLocked)
            {
                throw new AxiomException("Source and destination buffer may not be locked!");
            }

            if (src == this)
            {
                throw new AxiomException("Source must not be the same object.");
            }

            var srclock = src.Lock(srcBox, BufferLocking.ReadOnly);

            var method = BufferLocking.Normal;

            if (dstBox.Left == 0 && dstBox.Top == 0 && dstBox.Front == 0 && dstBox.Right == this.width &&
                dstBox.Bottom == this.height &&
                dstBox.Back == this.depth)
            {
                // Entire buffer -- we can discard the previous contents
                method = BufferLocking.Discard;
            }

            var dstlock = Lock(dstBox, method);

            if (dstlock.Width != srclock.Width || dstlock.Height != srclock.Height || dstlock.Depth != srclock.Depth)
            {
                // Scaling desired
                Image.Scale(srclock, dstlock);
            }
            else
            {
                // No scaling needed
                PixelConverter.BulkPixelConversion(srclock, dstlock);
            }

            Unlock();
            src.Unlock();
        }
Ejemplo n.º 5
0
		public override void CreateScene()
		{
			// Create dynamic texture
			ptex = TextureManager.Instance.CreateManual( "DynaTex", ResourceGroupManager.DefaultResourceGroupName, TextureType.TwoD, reactorExtent - 2, reactorExtent - 2, 0, PixelFormat.A8R8G8B8, TextureUsage.DynamicWriteOnly );
			buffer = ptex.GetBuffer( 0, 0 );

			// Set ambient light
			scene.AmbientLight = new ColorEx( 0.6F, 0.6F, 0.6F );
			scene.SetSkyBox( true, "SkyBox/Space", 50 );

			//mRoot->getRenderSystem()->clearFrameBuffer(FBT_COLOUR, ColourValue(255,255,255,0));

			// Create a light
			Light l = scene.CreateLight( "MainLight" );
			l.Diffuse = new ColorEx( 0.75F, 0.75F, 0.80F );
			l.Specular = new ColorEx( 0.9F, 0.9F, 1F );
			l.Position = new Vector3( -100, 80, 50 );
			scene.RootSceneNode.AttachObject( l );


			Entity planeEnt = scene.CreateEntity( "TexPlane1", PrefabEntity.Plane );
			// Give the plane a texture
			planeEnt.MaterialName = "Examples/DynaTest";

			SceneNode node = scene.RootSceneNode.CreateChildSceneNode( new Vector3( -100, -40, -100 ) );
			node.AttachObject( planeEnt );
			node.Scale = new Vector3( 3.0f, 3.0f, 3.0f );

			// Create objects
			SceneNode blaNode = scene.RootSceneNode.CreateChildSceneNode( new Vector3( -200, 0, 50 ) );
			Entity ent2 = scene.CreateEntity( "knot", "knot.mesh" );
			ent2.MaterialName = "Examples/DynaTest4";
			blaNode.AttachObject( ent2 );

			blaNode = scene.RootSceneNode.CreateChildSceneNode( new Vector3( 200, -90, 50 ) );
			ent2 = scene.CreateEntity( "knot2", "knot.mesh" );
			ent2.MaterialName = "Examples/DynaTest2";
			blaNode.AttachObject( ent2 );
			blaNode = scene.RootSceneNode.CreateChildSceneNode( new Vector3( -110, 200, 50 ) );

			// Cloaked fish
			ent2 = scene.CreateEntity( "knot3", "fish.mesh" );
			ent2.MaterialName = "Examples/DynaTest3";
			swim = ent2.GetAnimationState( "swim" );
			swim.IsEnabled = true;
			blaNode.AttachObject( ent2 );
			blaNode.Scale = new Vector3( 50.0f, 50.0f, 50.0f );

			LogManager.Instance.Write( "HardwarePixelBuffer {0} {1} {2} ", buffer.Width, buffer.Height, buffer.Depth );

			buffer.Lock( BufferLocking.Normal );
			PixelBox pb = buffer.CurrentLock;

			LogManager.Instance.Write( "PixelBox {0} {1} {2} {3} {4} {5} {6}", pb.Width, pb.Height, pb.Depth, pb.RowPitch, pb.SlicePitch, pb.Data, pb.Format );
			buffer.Unlock();

			// show GUI
			overlay = OverlayManager.Instance.GetByName( "Example/DynTexOverlay" );
			overlay.Show();
		}
Ejemplo n.º 6
0
		public void Blit( HardwarePixelBuffer src )
		{
			Blit( src, new BasicBox( 0, 0, 0, src.Width, src.Height, src.Depth ),
			      new BasicBox( 0, 0, 0, this.width, this.height, this.depth ) );
		}
Ejemplo n.º 7
0
		public virtual void Blit( HardwarePixelBuffer src, BasicBox srcBox, BasicBox dstBox )
		{
			if ( IsLocked || src.IsLocked )
			{
				throw new AxiomException( "Source and destination buffer may not be locked!" );
			}

			if ( src == this )
			{
				throw new AxiomException( "Source must not be the same object." );
			}

			var srclock = src.Lock( srcBox, BufferLocking.ReadOnly );

			var method = BufferLocking.Normal;
			if ( dstBox.Left == 0 && dstBox.Top == 0 && dstBox.Front == 0 && dstBox.Right == this.width &&
			     dstBox.Bottom == this.height &&
			     dstBox.Back == this.depth )
			{
				// Entire buffer -- we can discard the previous contents
				method = BufferLocking.Discard;
			}

			var dstlock = Lock( dstBox, method );
			if ( dstlock.Width != srclock.Width || dstlock.Height != srclock.Height || dstlock.Depth != srclock.Depth )
			{
				// Scaling desired
				Image.Scale( srclock, dstlock );
			}
			else
			{
				// No scaling needed
				PixelConverter.BulkPixelConversion( srclock, dstlock );
			}

			Unlock();
			src.Unlock();
		}
Ejemplo n.º 8
0
		public override void Blit( HardwarePixelBuffer src, BasicBox srcBox, BasicBox dstBox )
		{
			var srct = ( src as GLES2TextureBuffer );
			//Ogre TODO: Check for FBO support first
			//Destination texture must be 2D or Cube
			//Source texture must be 2D
			//Todo: src.Usage is a BufferUsage, but Ogre uses it as a TextureUsage
			if ( false && ( srct.target == All.Texture2D ) )
			{
				this.BlitFromTexture( srct, srcBox, dstBox );
			}
			else
			{
				base.Blit( src, srcBox, dstBox );
			}
		}
Ejemplo n.º 9
0
        public XnaRenderTexture( string name, HardwarePixelBuffer buffer )
            : base( buffer, 0 )
        {
			base.name = name;
        }
Ejemplo n.º 10
0
		protected void Blit( D3D9.Device d3d9Device, HardwarePixelBuffer rsrc, BasicBox srcBox, BasicBox dstBox,
		                     BufferResources srcBufferResources, BufferResources dstBufferResources )
		{
			if ( dstBufferResources.Surface != null && srcBufferResources.Surface != null )
			{
				// Surface-to-surface
				var dsrcRect = ToD3DRectangle( srcBox );
				var ddestRect = ToD3DRectangle( dstBox );

				var srcDesc = srcBufferResources.Surface.Description;

				// If we're blitting from a RTT, try GetRenderTargetData
				// if we're going to try to use GetRenderTargetData, need to use system mem pool

				// romeoxbm: not used even in Ogre
				//var tryGetRenderTargetData = false;

				if ( ( srcDesc.Usage & D3D9.Usage.RenderTarget ) != 0 && srcDesc.MultiSampleType == D3D9.MultisampleType.None )
				{
					// Temp texture
					var tmptex = new D3D9.Texture( d3d9Device, srcDesc.Width, srcDesc.Height, 1,
					                               // 1 mip level ie topmost, generate no mipmaps
					                               0, srcDesc.Format, D3D9.Pool.SystemMemory );

					var tmpsurface = tmptex.GetSurfaceLevel( 0 );

					if ( d3d9Device.GetRenderTargetData( srcBufferResources.Surface, tmpsurface ).Success )
					{
						// Hey, it worked
						// Copy from this surface instead
						var res = D3D9.Surface.FromSurface( dstBufferResources.Surface, tmpsurface, D3D9.Filter.Default, 0, dsrcRect,
						                                    ddestRect );
						if ( res.Failure )
						{
							tmpsurface.SafeDispose();
							tmptex.SafeDispose();
							throw new AxiomException( "D3D9.Surface.FromSurface failed in D3D9HardwarePixelBuffer.Blit" );
						}
						tmpsurface.SafeDispose();
						tmptex.SafeDispose();
						return;
					}
				}

				// Otherwise, try the normal method
				var res2 = D3D9.Surface.FromSurface( dstBufferResources.Surface, srcBufferResources.Surface, D3D9.Filter.Default, 0,
				                                     dsrcRect, ddestRect );
				if ( res2.Failure )
				{
					throw new AxiomException( "D3D9.Surface.FromSurface failed in D3D9HardwarePixelBuffer.Blit" );
				}
			}
			else if ( dstBufferResources.Volume != null && srcBufferResources.Volume != null )
			{
				// Volume-to-volume
				var dsrcBox = ToD3DBox( srcBox );
				var ddestBox = ToD3DBox( dstBox );

				var res = D3D9.Volume.FromVolume( dstBufferResources.Volume, srcBufferResources.Volume, D3D9.Filter.Default, 0,
				                                  dsrcBox, ddestBox );
				if ( res.Failure )
				{
					throw new AxiomException( "D3D9.Volume.FromVolume failed in D3D9HardwarePixelBuffer.Blit" );
				}
			}
			else
			{
				// Software fallback
				base.Blit( rsrc, srcBox, dstBox );
			}
		}
Ejemplo n.º 11
0
		protected override void SetupContent()
		{
			SceneManager.SetSkyBox( true, "Examples/StormySkyBox", 5000 ); // add a skybox

			// setup some basic lighting for our scene
			SceneManager.AmbientLight = new ColorEx( 0.5f, 0.5f, 0.5f );
			SceneManager.CreateLight( "DynTexLight1" ).Position = new Vector3( 20, 80, 50 );

			// set initial camera position
			CameraManager.setStyle( CameraStyle.Manual );
			Camera.Position = new Vector3( 0, 0, 200 );

			TrayManager.ShowCursor();

			// create our dynamic texture with 8-bit luminance texels
			var tex = TextureManager.Instance.CreateManual( "thaw", ResourceGroupManager.DefaultResourceGroupName,
			                                                TextureType.TwoD, TEXTURE_SIZE, TEXTURE_SIZE, 0, PixelFormat.L8,
			                                                TextureUsage.DynamicWriteOnly );

			this.mTexBuf = tex.GetBuffer(); // save off the texture buffer

			// initialise the texture to have full luminance
			this.mTexBuf.Lock( BufferLocking.Discard );
			Memory.Set( this.mTexBuf.CurrentLock.Data, 0xff, this.mTexBuf.Size );
			this.mTexBuf.Unlock();

			// create a penguin and attach him to our penguin node
			var penguin = SceneManager.CreateEntity( "Penguin", "penguin.mesh" );
			this.mPenguinNode = SceneManager.RootSceneNode.CreateChildSceneNode();
			this.mPenguinNode.AttachObject( penguin );

			// get and enable the penguin idle animation
			this.mPenguinAnimState = penguin.GetAnimationState( "amuse" );
			this.mPenguinAnimState.IsEnabled = true;

			// create a snowstorm over the scene, and fast forward it a little
			var ps = ParticleSystemManager.Instance.CreateSystem( "Snow", "Examples/Snow" );
			SceneManager.RootSceneNode.AttachObject( ps );
			ps.FastForward( 30 );

			// create a frosted screen in front of the camera, using our dynamic texture to "thaw" certain areas
			var ent = SceneManager.CreateEntity( "Plane", PrefabEntity.Plane );
			ent.MaterialName = "Examples/Frost";
			var node = SceneManager.RootSceneNode.CreateChildSceneNode();
			node.Position = new Vector3( 0, 0, 50 );
			node.AttachObject( ent );

			this.mPlaneSize = ent.BoundingBox.Size.x; // remember the size of the plane

			this.mCursorQuery = SceneManager.CreateRayQuery( new Ray() ); // create a ray scene query for the cursor

			this.mTimeSinceLastFreeze = 0;
			this.mWiping = false;
		}
Ejemplo n.º 12
0
		public RenderTexture( HardwarePixelBuffer buffer, int zOffset )
            :this(string.Empty, buffer, zOffset)
		{
		}
Ejemplo n.º 13
0
		///<summary>
		///    Copies a box from another PixelBuffer to a region of the
		///    this PixelBuffer.
		///</summary>
		///<param name="src">Source/dest pixel buffer</param>
		///<param name="srcBox">Image.BasicBox describing the source region in this buffer</param>
		///<param name="dstBox">Image.BasicBox describing the destination region in this buffer</param>
		///<remarks>
		///    The source and destination regions dimensions don't have to match, in which
		///    case scaling is done. This scaling is generally done using a bilinear filter in hardware,
		///    but it is faster to pass the source image in the right dimensions.
		///    Only call this function when both buffers are unlocked.
		///</remarks>
		public override void Blit( HardwarePixelBuffer src, BasicBox srcBox, BasicBox dstBox )
		{
			D3DHardwarePixelBuffer _src = (D3DHardwarePixelBuffer)src;
			if ( surface != null && _src.surface != null )
			{
				// Surface-to-surface
				System.Drawing.Rectangle dsrcRect = ToD3DRectangle( srcBox );
				System.Drawing.Rectangle ddestRect = ToD3DRectangle( dstBox );
				// D3DXLoadSurfaceFromSurface
				D3D.Surface.FromSurface( surface, _src.surface, D3D.Filter.None, 0, dsrcRect, ddestRect );
			}
			else if ( volume != null && _src.volume != null )
			{
				// Volume-to-volume
				D3D.Box dsrcBox = ToD3DBox( srcBox );
				D3D.Box ddestBox = ToD3DBox( dstBox );
				// D3DXLoadVolumeFromVolume
				D3D.Volume.FromVolume( volume, _src.volume, D3D.Filter.None, 0, dsrcBox, ddestBox );
			}
			else
				// Software fallback
				base.Blit( _src, srcBox, dstBox );
		}
Ejemplo n.º 14
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="src"></param>
		/// <param name="srcBox"></param>
		/// <param name="dstBox"></param>
		public override void Blit( HardwarePixelBuffer src, BasicBox srcBox, BasicBox dstBox )
		{
			GLESTextureBuffer srct = (GLESTextureBuffer)src;
			/// TODO: Check for FBO support first
			/// Destination texture must be 2D
			/// Source texture must be 2D
			if ( ( ( (int)src.Usage & (int)TextureUsage.RenderTarget ) != (int)TextureUsage.RenderTarget ) && ( srct._target == All.Texture2D ) )
			{
				BlitFromTexture( srct, srcBox, dstBox );
			}
			else
			{
				base.Blit( src, srcBox, dstBox );
			}
		}
Ejemplo n.º 15
0
		public TerrainLayerBlendMap( Terrain parent, byte layerIdx, HardwarePixelBuffer buf )
		{
			this.mParent = parent;
			this.mLayerIdx = layerIdx;
			this.mChannel = (byte)( ( this.mLayerIdx - 1 )%4 );
			this.mDirty = false;
			this.mBuffer = buf;
			this.mData = new float[this.mBuffer.Width*this.mBuffer.Height*sizeof ( float )];

			// we know which of RGBA we need to look at, now find it in the format
			// because we can't guarantee what precise format the RS gives us
			PixelFormat fmt = this.mBuffer.Format;
			var rgbaShift = PixelUtil.GetBitShifts( fmt );
			this.mChannelOffset = (byte)( rgbaShift[ this.mChannel ]/8 ); // /8 convert to bytes
#if AXIOM_BIG_ENDIAN
	// invert (dealing bytewise)
			mChannelOffset = (byte)( PixelUtil.GetNumElemBytes( fmt ) - mChannelOffset - 1 );
#endif
			Download();
		}
Ejemplo n.º 16
0
 public void Blit(HardwarePixelBuffer src)
 {
     Blit(src, new BasicBox(0, 0, 0, src.Width, src.Height, src.Depth),
          new BasicBox(0, 0, 0, this.width, this.height, this.depth));
 }
Ejemplo n.º 17
0
		public override void Blit( HardwarePixelBuffer rsrc, BasicBox srcBox, BasicBox dstBox )
		{
			//Entering critical section
			LockDeviceAccess();

			var _src = (D3D9HardwarePixelBuffer)rsrc;
			foreach ( var it in this.mapDeviceToBufferResources )
			{
				var srcBufferResources = ( (D3D9HardwarePixelBuffer)rsrc ).GetBufferResources( it.Key );
				var dstBufferResources = it.Value;

				if ( srcBufferResources == null )
				{
					throw new AxiomException( "There are no matching resources attached to the source pixel buffer !!" );
				}

				Blit( it.Key, rsrc, srcBox, dstBox, srcBufferResources, dstBufferResources );
			}

			//Leaving critical section
			UnlockDeviceAccess();
		}
        ///<summary>
        ///    Copies a box from another PixelBuffer to a region of the 
        ///    this PixelBuffer. 
        ///</summary>
        ///<param name="src">Source/dest pixel buffer</param>
        ///<param name="srcBox">Image.BasicBox describing the source region in this buffer</param>
        ///<param name="dstBox">Image.BasicBox describing the destination region in this buffer</param>
        ///<remarks>
        ///    The source and destination regions dimensions don't have to match, in which
        ///    case scaling is done. This scaling is generally done using a bilinear filter in hardware,
        ///    but it is faster to pass the source image in the right dimensions.
        ///    Only call this function when both  buffers are unlocked. 
        ///</remarks>
        public virtual void Blit(HardwarePixelBuffer src, BasicBox srcBox, BasicBox dstBox)
        {
            if(IsLocked || src.IsLocked)
                throw new Exception("Source and destination buffer may not be locked!  In HardwarePixelBuffer.Blit");
            if(src == this)
                throw new Exception("Source must not be the same object, in HardwarePixelBuffer.Blit");

            PixelBox srclock = src.Lock(srcBox, BufferLocking.ReadOnly);

            BufferLocking method = BufferLocking.Normal;
            if(dstBox.Left == 0 && dstBox.Top == 0 && dstBox.Front == 0 &&
               dstBox.Right == width && dstBox.Bottom == height &&
               dstBox.Back == depth)
                // Entire buffer -- we can discard the previous contents
                method = BufferLocking.Discard;

            PixelBox dstlock = Lock(dstBox, method);
            if(dstlock.Width != srclock.Width || dstlock.Height != srclock.Height || dstlock.Depth != srclock.Depth)
                // Scaling desired
                throw new Exception("Image scaling not yet implemented; in HardwarePixelBuffer.Blit");
                // Image.Scale(srclock, dstlock);
            else
                // No scaling needed
                PixelUtil.BulkPixelConversion(srclock, dstlock);

            Unlock();
            src.Unlock();
        }
 public D3DRenderTexture(string name, HardwarePixelBuffer buffer)
     : base(buffer, 0)
 {
     this.name = name;
 }
 ///<summary>
 ///    @copydoc HardwarePixelBuffer.Blit
 ///</summary>
 public override void Blit(HardwarePixelBuffer _src, BasicBox srcBox, BasicBox dstBox)
 {
     D3DHardwarePixelBuffer src = (D3DHardwarePixelBuffer)_src;
     if (surface != null && src.surface != null) {
         // Surface-to-surface
         Rectangle dsrcRect = ToD3DRectangle(srcBox);
         Rectangle ddestRect = ToD3DRectangle(dstBox);
         // D3DXLoadSurfaceFromSurface
         SurfaceLoader.FromSurface(surface, ddestRect, src.surface, dsrcRect, Filter.None, 0);
     } else if (volume != null && src.volume != null) {
         // Volume-to-volume
         Box dsrcBox = ToD3DBox(srcBox);
         Box ddestBox = ToD3DBox(dstBox);
         // D3DXLoadVolumeFromVolume
         VolumeLoader.FromVolume(volume, ddestBox, src.volume, dsrcBox, Filter.None, 0);
     } else
         // Software fallback
         base.Blit(_src, srcBox, dstBox);
 }