private void CreateGlobalTextures()
{
if ( supportedTechniques.Count == 0 )
{
return;
}
//To make sure that we are consistent, it is demanded that all composition
//techniques define the same set of global textures.
List<string> globalTextureNames = new List<string>();
//Initialize global textures from first supported technique
CompositionTechnique firstTechnique = supportedTechniques[ 0 ];
foreach ( CompositionTechnique.TextureDefinition def in firstTechnique.TextureDefinitions )
{
if ( def.Scope == CompositionTechnique.TextureScope.Global )
{
//Check that this is a legit global texture
if ( !string.IsNullOrEmpty( def.ReferenceCompositorName ) )
{
throw new AxiomException( "Global compositor texture definition can not be a reference." );
}
if ( def.Width == 0 || def.Height == 0 )
{
throw new AxiomException( "Global compositor texture definition must have absolute size." );
}
if ( def.Pooled )
{
LogManager.Instance.Write( "Pooling global compositor textures has no effect", null );
}
globalTextureNames.Add( def.Name );
//TODO GSOC : Heavy copy-pasting from CompositorInstance. How to we solve it?
// Make the tetxure
RenderTarget renderTarget = null;
if ( def.PixelFormats.Count > 1 )
{
string MRTBaseName = "c" + autoNumber++.ToString() + "/" + _name + "/" + def.Name;
MultiRenderTarget mrt =
Root.Instance.RenderSystem.CreateMultiRenderTarget( MRTBaseName );
globalMRTs.Add( def.Name, mrt );
// create and bind individual surfaces
int atch = 0;
foreach ( PixelFormat p in def.PixelFormats )
{
string texName = MRTBaseName + "/" + atch.ToString();
Texture tex =
TextureManager.Instance.CreateManual( texName, ResourceGroupManager.InternalResourceGroupName,
TextureType.TwoD, def.Width, def.Height, 0, 0, p, TextureUsage.RenderTarget, null,
def.HwGammaWrite && !PixelUtil.IsFloatingPoint( p ), def.Fsaa ? 1 : 0 );
RenderTexture rt = tex.GetBuffer().GetRenderTarget();
rt.IsAutoUpdated = false;
mrt.BindSurface( atch, rt );
// Also add to local textures so we can look up
string mrtLocalName = GetMRTLocalName( def.Name, atch );
globalTextures.Add( mrtLocalName, tex );
}
renderTarget = mrt;
}
else
{
string texName = "c" + autoNumber++.ToString() + "/" + _name + "/" + def.Name;
// space in the name mixup the cegui in the compositor demo
// this is an auto generated name - so no spaces can't hart us.
texName = texName.Replace( " ", "_" );
Texture tex =
TextureManager.Instance.CreateManual( texName, ResourceGroupManager.InternalResourceGroupName,
TextureType.TwoD, def.Width, def.Height, 0, def.PixelFormats[ 0 ], TextureUsage.RenderTarget, null,
def.HwGammaWrite && !PixelUtil.IsFloatingPoint( def.PixelFormats[ 0 ] ), def.Fsaa ? 1 : 0 );
renderTarget = tex.GetBuffer().GetRenderTarget();
globalTextures.Add( def.Name, tex );
}
}
}
//Validate that all other supported techniques expose the same set of global textures.
foreach ( CompositionTechnique technique in supportedTechniques )
{
bool isConsistent = true;
int numGlobals = 0;
foreach ( CompositionTechnique.TextureDefinition texDef in technique.TextureDefinitions )
{
if ( texDef.Scope == CompositionTechnique.TextureScope.Global )
{
if ( !globalTextureNames.Contains( texDef.Name ) )
{
isConsistent = false;
break;
}
numGlobals++;
}
}
if ( numGlobals != globalTextureNames.Count )
{
isConsistent = false;
}
if ( !isConsistent )
{
throw new AxiomException( "Different composition techniques define different global textures." );
}
}
}