Axiom.Graphics.CompositorInstance.FreeResources C# (CSharp) Method

FreeResources() public method

Destroy local rendertextures and other resources.
public FreeResources ( bool forResizeOnly, bool clearReservedTextures ) : void
forResizeOnly bool
clearReservedTextures bool
return void
		public void FreeResources( bool forResizeOnly, bool clearReservedTextures )
		{
			// Remove temporary textures
			// We only remove those that are not shared, shared textures are dealt with
			// based on their reference count.
			// We can also only free textures which are derived from the target size, if
			// required (saves some time & memory thrashing / fragmentation on resize)
			List<Texture> assignedTextures = new List<Texture>();
			foreach ( CompositionTechnique.TextureDefinition def in technique.TextureDefinitions )
			{
				if ( !string.IsNullOrEmpty( def.ReferenceCompositorName ) )
				{
					//This is a reference, isn't created here
					continue;
				}
				// potentially only remove this one if based on size
				if ( !forResizeOnly || def.Width == 0 | def.Height == 0 )
				{
					int subSurfaceCount = def.PixelFormats.Count;
					// Potentially many surfaces
					for ( int subSurface = 0; subSurface < subSurfaceCount; subSurface++ )
					{
						string texName = subSurfaceCount > 1 ? GetMrtTextureLocalName( def.Name, subSurface ) : def.Name;
						Texture tex = null;
						if ( localTextures.TryGetValue( texName, out tex ) )
						{
							if ( !def.Pooled && def.Scope != CompositionTechnique.TextureScope.Global )
							{
								// remove myself from central only if not pooled and not global
								TextureManager.Instance.Remove( tex.Name );
							}
							localTextures.Remove( texName );
						}
					}
					if ( subSurfaceCount > 1 )
					{
						MultiRenderTarget i = null;
						if ( localMrts.TryGetValue( def.Name, out i ) )
						{
							if ( def.Scope != CompositionTechnique.TextureScope.Global )
							{
								// remove MRT if not global
								Root.Instance.RenderSystem.DestroyRenderTarget( i.Name );
							}
							localMrts.Remove( def.Name );
						}
					}
				}
			}

			if ( clearReservedTextures )
			{
				if ( forResizeOnly )
				{
					List<CompositionTechnique.TextureDefinition> toDelete = new List<CompositionTechnique.TextureDefinition>();
					foreach ( CompositionTechnique.TextureDefinition def in reservedTextures.Keys )
					{
						if ( def.Width == 0 || def.Height == 0 )
						{
							toDelete.Add( def );
						}
					}
					// just remove the ones which would be affected by a resize
					for ( int i = 0; i < toDelete.Count; i++ )
					{
						this.reservedTextures.Remove( toDelete[ i ] );
					}
					toDelete = null;
				}
				else
				{
					// clear all
					reservedTextures.Clear();
				}
			}
			// Now we tell the central list of textures to check if its unreferenced,
			// and to remove if necessary. Anything shared that was left in the reserve textures
			// will not be released here
			CompositorManager.Instance.FreePooledTextures( true );
		}