protected static bool ParseTexture( string parameters, MaterialScriptContext context )
{
string[] values = parameters.Split( new char[] { ' ', '\t' } );
if ( values.Length > 5 )
{
LogParseError( context, "Invalid texture attribute - expecting 5 parameters or less." );
return false;
}
// use 2d as default if anything goes wrong
TextureType texType = TextureType.TwoD;
int mipmaps = (int)TextureMipmap.Default; // When passed to TextureManager::load, this means default to default number of mipmaps
bool isAlpha = false;
bool hwGamma = false;
PixelFormat desiredFormat = PixelFormat.Unknown;
for ( int p = 1; p < values.Length; p++ )
{
switch ( values[ p ].ToLower() )
{
case "1d":
texType = TextureType.OneD;
break;
case "2d":
texType = TextureType.TwoD;
break;
case "3d":
texType = TextureType.ThreeD;
break;
case "cubic":
texType = TextureType.CubeMap;
break;
case "unlimited":
mipmaps = (int)TextureMipmap.Unlimited;
break;
case "alpha":
isAlpha = true;
break;
case "gamma":
hwGamma = true;
break;
default:
int num;
if ( StringConverter.ParseInt( values[ p ], out num ) )
{
mipmaps = num;
}
else if ( ( desiredFormat = PixelUtil.GetFormatFromName( values[ p ], true, false ) ) != PixelFormat.Unknown )
{
// Nothing to do here.
}
else
{
LogParseError( context, "Invalid texture option - " + values[ p ] + "." );
}
break;
}
}
context.textureUnit.SetTextureName( values[ 0 ], texType );
context.textureUnit.MipmapCount = mipmaps;
context.textureUnit.IsAlpha = isAlpha;
context.textureUnit.DesiredFormat = desiredFormat;
context.textureUnit.IsHardwareGammaEnabled = hwGamma;
return false;
}