2012-08-16 12:04:46 +00:00
#region Using Statements
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Content.Pipeline.Graphics
{
public class MaterialContent : ContentItem
{
public MaterialContent ( )
{
2015-04-08 14:50:03 +02:00
Textures = new TextureReferenceDictionary ( ) ;
2012-08-16 12:04:46 +00:00
}
public TextureReferenceDictionary Textures
{
get ;
private set ;
}
2015-04-08 14:50:03 +02:00
//description from msdn
/// <summary>
/// Gets a reference type from the <see cref="OpaqueDataDictionary"/> collection.
/// </summary>
/// <typeparam name="T">Type of the related opaque data.</typeparam>
/// <param name="key">Key of the property being retrieved.</param>
/// <returns>The related opaque data.</returns>
2012-08-16 12:04:46 +00:00
protected T GetReferenceTypeProperty < T > ( string key ) where T : class
{
2015-04-08 14:50:03 +02:00
object result ;
if ( this . OpaqueData . TryGetValue ( key , out result ) & & result is T )
return ( T ) result ;
else
return null ;
2012-08-16 12:04:46 +00:00
}
2015-04-08 14:50:03 +02:00
/// <summary>
/// Gets a value from the <see cref="Textures"/> collection.
/// </summary>
/// <param name="key">Key of the texture being retrieved.</param>
/// <returns>Reference to a texture from the collection.</returns>
2012-08-16 12:04:46 +00:00
protected ExternalReference < TextureContent > GetTexture ( String key )
{
2015-04-08 14:50:03 +02:00
ExternalReference < TextureContent > result ;
if ( Textures . TryGetValue ( key , out result ) )
return result ;
else
return null ;
2012-08-16 12:04:46 +00:00
}
2015-04-08 14:50:03 +02:00
/// <summary>
/// Gets a value type from the <see cref="OpaqueDataDictionary"/> collection.
/// </summary>
/// <typeparam name="T">Type of the value being retrieved.</typeparam>
/// <param name="key">Key of the value type being retrieved.</param>
/// <returns>Index of the value type beng retrieved.</returns>
2012-08-16 12:04:46 +00:00
protected Nullable < T > GetValueTypeProperty < T > ( string key ) where T : struct
{
2015-04-08 14:50:03 +02:00
object result ;
if ( this . OpaqueData . TryGetValue ( key , out result ) & & result is T )
return ( T ? ) result ;
else
return null ;
2012-08-16 12:04:46 +00:00
}
2015-04-08 14:50:03 +02:00
/// <summary>
/// Sets a value in the contained <see cref="OpaqueDataDictionary"/> object.
/// If null is passed, the value is removed.
/// </summary>
/// <typeparam name="T">Type of the element being set.</typeparam>
/// <param name="key">Name of the key being modified.</param>
/// <param name="value">Value being set.</param>
2012-08-16 12:04:46 +00:00
protected void SetProperty < T > ( string key , T value )
{
2015-04-08 14:50:03 +02:00
if ( value = = null )
this . OpaqueData . Remove ( key ) ;
else
this . OpaqueData [ key ] = value ;
2012-08-16 12:04:46 +00:00
}
2015-04-08 14:50:03 +02:00
/// <summary>
/// Sets a value in the contained TextureReferenceDictionary object.
/// If null is passed, the value is removed.
/// </summary>
/// <remarks>
/// The <paramref name="key"/> value differs depending on the type of attached dictionary.
///
/// If attached to a <see cref="BasicMaterialContent"/> dictionary (which becomes a <see cref="BasicEffect"/> object at run time),
/// the value for the Texture key is used as the texture for the <see cref="BasicEffect"/> runtime object. Other keys are ignored.
///
/// If attached to a <see cref="EffectMaterialContent"/> dictionary, key names are the texture names used by the effect. These names are dependent upon the author of the effect object.
/// </remarks>
/// <param name="key">Name of the key being modified.</param>
/// <param name="value">Value being set. </param>
2012-08-16 12:04:46 +00:00
protected void SetTexture ( String key , ExternalReference < TextureContent > value )
{
2015-04-08 14:50:03 +02:00
if ( value = = null )
Textures . Remove ( key ) ;
else
Textures [ key ] = value ;
2012-08-16 12:04:46 +00:00
}
}
}