/// <see cref="Translator.Translate"/> public override void Translate( ScriptCompiler compiler, AbstractNode node ) { ObjectAbstractNode obj = (ObjectAbstractNode)node; Pass pass = (Pass)obj.Parent.Context; _textureunit = pass.CreateTextureUnitState(); obj.Context = _textureunit; // Get the name of the technique if ( !string.IsNullOrEmpty( obj.Name ) ) _textureunit.Name = obj.Name; // Set the properties for the material foreach ( AbstractNode i in obj.Children ) { if ( i is PropertyAbstractNode ) { PropertyAbstractNode prop = (PropertyAbstractNode)i; switch ( (Keywords)prop.Id ) { #region ID_TEXTURE_ALIAS case Keywords.ID_TEXTURE_ALIAS: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "texture_alias must have at most 1 argument" ); } else { string val; if ( getString( prop.Values[ 0 ], out val ) ) _textureunit.TextureNameAlias = val; else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not a valid texture alias" ); } break; #endregion ID_TEXTURE_ALIAS #region ID_TEXTURE case Keywords.ID_TEXTURE: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 5 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "texture must have at most 5 arguments" ); } else { AbstractNode j = getNodeAt( prop.Values, 0 ); int index = 1; string val; if ( getString( j, out val ) ) { TextureType texType = TextureType.TwoD; bool isAlpha = false; bool sRGBRead = false; PixelFormat format = PixelFormat.Unknown; int mipmaps = -1;//MIP_DEFAULT; while ( j != null ) { if ( j is AtomAbstractNode ) { AtomAbstractNode atom = (AtomAbstractNode)j; switch ( (Keywords)atom.Id ) { case Keywords.ID_1D: texType = TextureType.OneD; break; case Keywords.ID_2D: texType = TextureType.TwoD; break; case Keywords.ID_3D: texType = TextureType.ThreeD; break; case Keywords.ID_CUBIC: texType = TextureType.CubeMap; break; case Keywords.ID_UNLIMITED: mipmaps = 0x7FFFFFFF;//MIP_UNLIMITED; break; case Keywords.ID_ALPHA: isAlpha = true; break; case Keywords.ID_GAMMA: sRGBRead = true; break; default: if ( atom.IsNumber ) mipmaps = (int)atom.Number; else format = PixelUtil.GetFormatFromName( atom.Value, true ); break; } } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, j.Value + " is not a supported argument to the texture property" ); } j = getNodeAt( prop.Values, index++ ); } ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.Texture, val ); compiler._fireEvent( ref evt ); string textureName = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name; _textureunit.SetTextureName( textureName, texType ); _textureunit.DesiredFormat = format; _textureunit.IsAlpha = isAlpha; _textureunit.MipmapCount = mipmaps; _textureunit.IsHardwareGammaEnabled = sRGBRead; } else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, j.Value + " is not a valid texture name" ); } break; #endregion ID_TEXTURE #region ID_ANIM_TEXTURE case Keywords.ID_ANIM_TEXTURE: if ( prop.Values.Count < 3 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else { AbstractNode i1 = getNodeAt( prop.Values, 1 ); if ( i1 is AtomAbstractNode && ( (AtomAbstractNode)i ).IsNumber ) { // Short form AbstractNode i0 = getNodeAt( prop.Values, 0 ), i2 = getNodeAt( prop.Values, 2 ); if ( i0 is AtomAbstractNode ) { string val0; int val1; Real val2; if ( getString( i0, out val0 ) && getInt( i1, out val1 ) && getReal( i2, out val2 ) ) { ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.Texture, val0 ); compiler._fireEvent( ref evt ); string evtName = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name; _textureunit.SetAnimatedTextureName( evtName, val1, val2 ); } else { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line, "anim_texture short form requires a texture name, number of frames, and animation duration" ); } } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "anim_texture short form requires a texture name, number of frames, and animation duration" ); } } else { // Long form has n number of frames Real duration = 0; AbstractNode inNode = getNodeAt( prop.Values, prop.Values.Count - 1 ); if ( getReal( inNode, out duration ) ) { string[] names = new string[ prop.Values.Count - 1 ]; int n = 0; AbstractNode j = prop.Values[ 0 ]; int index = 0; while ( j != inNode ) { if ( j is AtomAbstractNode ) { string name = ( (AtomAbstractNode)j ).Value; #warning check this if statement // Run the name through the listener if ( compiler.Listener != null ) { ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.Texture, name ); compiler._fireEvent( ref evt ); names[ n++ ] = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name; } else { names[ n++ ] = name; } } else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, j.Value + " is not supported as a texture name" ); ++index; j = prop.Values[ index ]; } _textureunit.SetAnimatedTextureName( names, n, duration ); } else { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line, inNode.Value + " is not supported for the duration argument" ); } } } break; #endregion ID_ANIM_TEXTURE #region ID_CUBIC_TEXTURE case Keywords.ID_CUBIC_TEXTURE: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count == 2 ) { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ); if ( i0 is AtomAbstractNode && i1 is AtomAbstractNode ) { AtomAbstractNode atom0 = (AtomAbstractNode)i0, atom1 = (AtomAbstractNode)i1; ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.Texture, atom0.Value ); compiler._fireEvent( ref evt ); string evtName = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name; _textureunit.SetCubicTextureName( evtName, atom1.Id == (uint)Keywords.ID_COMBINED_UVW ); } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } else if ( prop.Values.Count == 7 ) { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ), i2 = getNodeAt( prop.Values, 2 ), i3 = getNodeAt( prop.Values, 3 ), i4 = getNodeAt( prop.Values, 4 ), i5 = getNodeAt( prop.Values, 5 ), i6 = getNodeAt( prop.Values, 6 ); if ( i0 is AtomAbstractNode && i1 is AtomAbstractNode && i2 is AtomAbstractNode && i3 is AtomAbstractNode && i4 is AtomAbstractNode && i5 is AtomAbstractNode && i6 is AtomAbstractNode ) { AtomAbstractNode atom0 = (AtomAbstractNode)i0, atom1 = (AtomAbstractNode)i1, atom2 = (AtomAbstractNode)i2, atom3 = (AtomAbstractNode)i3, atom4 = (AtomAbstractNode)i4, atom5 = (AtomAbstractNode)i5, atom6 = (AtomAbstractNode)i6; string[] names = new string[ 6 ]; names[ 0 ] = atom0.Value; names[ 1 ] = atom1.Value; names[ 2 ] = atom2.Value; names[ 3 ] = atom3.Value; names[ 4 ] = atom4.Value; names[ 5 ] = atom5.Value; if ( compiler.Listener != null ) { // Run each name through the listener for ( int j = 0; j < 6; ++j ) { ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.Texture, names[ j ] ); compiler._fireEvent( ref evt ); names[ j ] = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name; } } _textureunit.SetCubicTextureName( names, atom6.Id == (uint)Keywords.ID_COMBINED_UVW ); } } else { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "cubic_texture must have at most 7 arguments" ); } break; #endregion ID_CUBIC_TEXTURE #region ID_TEX_COORD_SET case Keywords.ID_TEX_COORD_SET: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "tex_coord_set must have at most 1 argument" ); } else { int val = 0; if ( getInt( prop.Values[ 0 ], out val ) ) _textureunit.TextureCoordSet = val; else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not supported as an integer argument" ); } break; #endregion ID_TEX_COORD_SET #region ID_TEX_ADDRESS_MODE case Keywords.ID_TEX_ADDRESS_MODE: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ), i2 = getNodeAt( prop.Values, 2 ); UVWAddressing mode = new UVWAddressing( TextureAddressing.Wrap ); if ( i0 != null && i0 is AtomAbstractNode ) { AtomAbstractNode atom = (AtomAbstractNode)i0; switch ( (Keywords)atom.Id ) { case Keywords.ID_WRAP: mode.U = TextureAddressing.Wrap; break; case Keywords.ID_CLAMP: mode.U = TextureAddressing.Clamp; break; case Keywords.ID_MIRROR: mode.U = TextureAddressing.Mirror; break; case Keywords.ID_BORDER: mode.U = TextureAddressing.Border; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i0.Value + " not supported as first argument (must be \"wrap\", \"clamp\", \"mirror\", or \"border\")" ); break; } } mode.V = mode.U; mode.W = mode.U; if ( i1 != null && i1 is AtomAbstractNode ) { AtomAbstractNode atom = (AtomAbstractNode)i1; switch ( (Keywords)atom.Id ) { case Keywords.ID_WRAP: mode.V = TextureAddressing.Wrap; break; case Keywords.ID_CLAMP: mode.V = TextureAddressing.Clamp; break; case Keywords.ID_MIRROR: mode.V = TextureAddressing.Mirror; break; case Keywords.ID_BORDER: mode.V = TextureAddressing.Border; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i0.Value + " not supported as second argument (must be \"wrap\", \"clamp\", \"mirror\", or \"border\")" ); break; } } if ( i2 != null && i2 is AtomAbstractNode ) { AtomAbstractNode atom = (AtomAbstractNode)i2; switch ( (Keywords)atom.Id ) { case Keywords.ID_WRAP: mode.W = TextureAddressing.Wrap; break; case Keywords.ID_CLAMP: mode.W = TextureAddressing.Clamp; break; case Keywords.ID_MIRROR: mode.W = TextureAddressing.Mirror; break; case Keywords.ID_BORDER: mode.W = TextureAddressing.Border; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i0.Value + " not supported as third argument (must be \"wrap\", \"clamp\", \"mirror\", or \"border\")" ); break; } } _textureunit.SetTextureAddressingMode( mode ); } break; #endregion ID_TEX_ADDRESS_MODE #region ID_TEX_BORDER_COLOUR case Keywords.ID_TEX_BORDER_COLOUR: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else { ColorEx val; if ( getColor( prop.Values, 0, out val ) ) _textureunit.TextureBorderColor = val; else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "tex_border_colour only accepts a colour argument" ); } break; #endregion ID_TEX_BORDER_COLOUR #region ID_FILTERING case Keywords.ID_FILTERING: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count == 1 ) { if ( prop.Values[ 0 ] is AtomAbstractNode ) { AtomAbstractNode atom = (AtomAbstractNode)prop.Values[ 0 ]; switch ( (Keywords)atom.Id ) { case Keywords.ID_NONE: _textureunit.SetTextureFiltering( TextureFiltering.None ); break; case Keywords.ID_BILINEAR: _textureunit.SetTextureFiltering( TextureFiltering.Bilinear ); break; case Keywords.ID_TRILINEAR: _textureunit.SetTextureFiltering( TextureFiltering.Trilinear ); break; case Keywords.ID_ANISOTROPIC: _textureunit.SetTextureFiltering( TextureFiltering.Anisotropic ); break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " not supported as first argument (must be \"none\", \"bilinear\", \"trilinear\", or \"anisotropic\")" ); break; } } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " not supported as first argument (must be \"none\", \"bilinear\", \"trilinear\", or \"anisotropic\")" ); } } else if ( prop.Values.Count == 3 ) { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ), i2 = getNodeAt( prop.Values, 2 ); if ( i0 is AtomAbstractNode && i1 is AtomAbstractNode && i2 is AtomAbstractNode ) { AtomAbstractNode atom0 = (AtomAbstractNode)i0, atom1 = (AtomAbstractNode)i1, atom2 = (AtomAbstractNode)i2; FilterOptions tmin = FilterOptions.None, tmax = FilterOptions.None, tmip = FilterOptions.None; switch ( (Keywords)atom0.Id ) { case Keywords.ID_NONE: tmin = FilterOptions.None; break; case Keywords.ID_POINT: tmin = FilterOptions.Point; break; case Keywords.ID_LINEAR: tmin = FilterOptions.Linear; break; case Keywords.ID_ANISOTROPIC: tmin = FilterOptions.Anisotropic; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i0.Value + " not supported as first argument (must be \"none\", \"point\", \"linear\", or \"anisotropic\")" ); break; } switch ( (Keywords)atom1.Id ) { case Keywords.ID_NONE: tmax = FilterOptions.None; break; case Keywords.ID_POINT: tmax = FilterOptions.Point; break; case Keywords.ID_LINEAR: tmax = FilterOptions.Linear; break; case Keywords.ID_ANISOTROPIC: tmax = FilterOptions.Anisotropic; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i0.Value + " not supported as second argument (must be \"none\", \"point\", \"linear\", or \"anisotropic\")" ); break; } switch ( (Keywords)atom2.Id ) { case Keywords.ID_NONE: tmip = FilterOptions.None; break; case Keywords.ID_POINT: tmip = FilterOptions.Point; break; case Keywords.ID_LINEAR: tmip = FilterOptions.Linear; break; case Keywords.ID_ANISOTROPIC: tmip = FilterOptions.Anisotropic; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i0.Value + " not supported as third argument (must be \"none\", \"point\", \"linear\", or \"anisotropic\")" ); break; } _textureunit.SetTextureFiltering( tmin, tmax, tmip ); } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } else { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "filtering must have either 1 or 3 arguments" ); } break; #endregion ID_FILTERING #region ID_MAX_ANISOTROPY case Keywords.ID_MAX_ANISOTROPY: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "max_anisotropy must have at most 1 argument" ); } else { int val = 0; if ( getInt( prop.Values[ 0 ], out val ) ) _textureunit.TextureAnisotropy = val; else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not a valid integer argument" ); } break; #endregion ID_MAX_ANISOTROPY #region ID_MIPMAP_BIAS case Keywords.ID_MIPMAP_BIAS: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "mipmap_bias must have at most 1 argument" ); } else { throw new NotImplementedException(); #if UNREACHABLE_CODE Real val = 0.0f; if ( getReal( prop.Values[ 0 ], out val ) ) { /*mUnit->setTextureMipmapBias(val);*/ } else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not a valid number argument" ); #endif } break; #endregion ID_MIPMAP_BIAS #region ID_COLOUR_OP case Keywords.ID_COLOUR_OP: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "colour_op must have at most 1 argument" ); } else { if ( prop.Values[ 0 ] is AtomAbstractNode ) { AtomAbstractNode atom = (AtomAbstractNode)prop.Values[ 0 ]; switch ( (Keywords)atom.Id ) { case Keywords.ID_REPLACE: _textureunit.ColorOperation = LayerBlendOperation.Replace; break; case Keywords.ID_ADD: _textureunit.ColorOperation = LayerBlendOperation.Add; break; case Keywords.ID_MODULATE: _textureunit.ColorOperation = LayerBlendOperation.Modulate; break; case Keywords.ID_ALPHA_BLEND: _textureunit.ColorOperation = LayerBlendOperation.AlphaBlend; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not a valid argument (must be \"replace\", \"add\", \"modulate\", or \"alpha_blend\")" ); break; } } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not a valid argument (must be \"replace\", \"add\", \"modulate\", or \"alpha_blend\")" ); } } break; #endregion ID_COLOUR_OP #region ID_COLOUR_OP_EX case Keywords.ID_COLOUR_OP_EX: if ( prop.Values.Count < 3 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line, "colour_op_ex must have at least 3 arguments" ); } else if ( prop.Values.Count > 10 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "colour_op_ex must have at most 10 arguments" ); } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ), i2 = getNodeAt( prop.Values, 2 ); if ( i0 is AtomAbstractNode && i1 is AtomAbstractNode && i2 is AtomAbstractNode ) { AtomAbstractNode atom0 = (AtomAbstractNode)i0, atom1 = (AtomAbstractNode)i1, atom2 = (AtomAbstractNode)i2; LayerBlendOperationEx op = LayerBlendOperationEx.Add; LayerBlendSource source1 = LayerBlendSource.Current, source2 = LayerBlendSource.Texture; ColorEx arg1 = ColorEx.White, arg2 = ColorEx.White; Real manualBlend = 0.0f; switch ( (Keywords)atom0.Id ) { case Keywords.ID_SOURCE1: op = LayerBlendOperationEx.Source1; break; case Keywords.ID_SOURCE2: op = LayerBlendOperationEx.Source2; break; case Keywords.ID_MODULATE: op = LayerBlendOperationEx.Modulate; break; case Keywords.ID_MODULATE_X2: op = LayerBlendOperationEx.ModulateX2; break; case Keywords.ID_MODULATE_X4: op = LayerBlendOperationEx.ModulateX4; break; case Keywords.ID_ADD: op = LayerBlendOperationEx.Add; break; case Keywords.ID_ADD_SIGNED: op = LayerBlendOperationEx.AddSigned; break; case Keywords.ID_ADD_SMOOTH: op = LayerBlendOperationEx.AddSmooth; break; case Keywords.ID_SUBTRACT: op = LayerBlendOperationEx.Subtract; break; case Keywords.ID_BLEND_DIFFUSE_ALPHA: op = LayerBlendOperationEx.BlendDiffuseAlpha; break; case Keywords.ID_BLEND_TEXTURE_ALPHA: op = LayerBlendOperationEx.BlendTextureAlpha; break; case Keywords.ID_BLEND_CURRENT_ALPHA: op = LayerBlendOperationEx.BlendCurrentAlpha; break; case Keywords.ID_BLEND_MANUAL: op = LayerBlendOperationEx.BlendManual; break; case Keywords.ID_DOT_PRODUCT: op = LayerBlendOperationEx.DotProduct; break; case Keywords.ID_BLEND_DIFFUSE_COLOUR: op = LayerBlendOperationEx.BlendDiffuseColor; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i0.Value + " is not a valid first argument (must be \"source1\", \"source2\", \"modulate\", \"modulate_x2\", \"modulate_x4\", \"add\", \"add_signed\", \"add_smooth\", \"subtract\", \"blend_diffuse_alpha\", \"blend_texture_alpha\", \"blend_current_alpha\", \"blend_manual\", \"dot_product\", or \"blend_diffuse_colour\")" ); break; } switch ( (Keywords)atom1.Id ) { case Keywords.ID_SRC_CURRENT: source1 = LayerBlendSource.Current; break; case Keywords.ID_SRC_TEXTURE: source1 = LayerBlendSource.Texture; break; case Keywords.ID_SRC_DIFFUSE: source1 = LayerBlendSource.Diffuse; break; case Keywords.ID_SRC_SPECULAR: source1 = LayerBlendSource.Specular; break; case Keywords.ID_SRC_MANUAL: source1 = LayerBlendSource.Manual; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i1.Value + " is not a valid second argument (must be \"src_current\", \"src_texture\", \"src_diffuse\", \"src_specular\", or \"src_manual\")" ); break; } switch ( (Keywords)atom2.Id ) { case Keywords.ID_SRC_CURRENT: source2 = LayerBlendSource.Current; break; case Keywords.ID_SRC_TEXTURE: source2 = LayerBlendSource.Texture; break; case Keywords.ID_SRC_DIFFUSE: source2 = LayerBlendSource.Diffuse; break; case Keywords.ID_SRC_SPECULAR: source2 = LayerBlendSource.Specular; break; case Keywords.ID_SRC_MANUAL: source2 = LayerBlendSource.Manual; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i2.Value + " is not a valid third argument (must be \"src_current\", \"src_texture\", \"src_diffuse\", \"src_specular\", or \"src_manual\")" ); break; } if ( op == LayerBlendOperationEx.BlendManual ) { AbstractNode i3 = getNodeAt( prop.Values, 3 ); if ( i3 != null ) { if ( !getReal( i3, out manualBlend ) ) compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i3.Value + " is not a valid number argument" ); } else { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line, "fourth argument expected when blend_manual is used" ); } } AbstractNode j = getNodeAt( prop.Values, 3 ); int index = 3; if ( op == LayerBlendOperationEx.BlendManual ) j = getNodeAt( prop.Values, ++index ); if ( source1 == LayerBlendSource.Manual ) { if ( j != null ) { if ( !getColor( prop.Values, 3, out arg1, 3 ) ) compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "valid colour expected when src_manual is used" ); } else { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line, "valid colour expected when src_manual is used" ); } } if ( source2 == LayerBlendSource.Manual ) { if ( j != null ) { if ( !getColor( prop.Values, 3, out arg2, 3 ) ) compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "valid colour expected when src_manual is used" ); } else { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line, "valid colour expected when src_manual is used" ); } } _textureunit.SetColorOperationEx( op, source1, source2, arg1, arg2, manualBlend ); } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } break; #endregion ID_COLOUR_OP_EX #region ID_COLOUR_OP_MULTIPASS_FALLBACK case Keywords.ID_COLOUR_OP_MULTIPASS_FALLBACK: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 2 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "colour_op_multiplass_fallback must have at most 2 arguments" ); } else if ( prop.Values.Count == 1 ) { if ( prop.Values[ 0 ] is AtomAbstractNode ) { AtomAbstractNode atom = (AtomAbstractNode)prop.Values[ 0 ]; switch ( (Keywords)atom.Id ) { case Keywords.ID_ADD: _textureunit.SetColorOpMultipassFallback( SceneBlendFactor.One, SceneBlendFactor.One ); break; case Keywords.ID_MODULATE: _textureunit.SetColorOpMultipassFallback( SceneBlendFactor.DestColor, SceneBlendFactor.Zero ); break; case Keywords.ID_COLOUR_BLEND: _textureunit.SetColorOpMultipassFallback( SceneBlendFactor.SourceColor, SceneBlendFactor.OneMinusSourceColor ); break; case Keywords.ID_ALPHA_BLEND: _textureunit.SetColorOpMultipassFallback( SceneBlendFactor.SourceAlpha, SceneBlendFactor.OneMinusSourceAlpha ); break; case Keywords.ID_REPLACE: _textureunit.SetColorOpMultipassFallback( SceneBlendFactor.One, SceneBlendFactor.Zero ); break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "argument must be a valid scene blend type (add, modulate, colour_blend, alpha_blend, or replace)" ); break; } } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "argument must be a valid scene blend type (add, modulate, colour_blend, alpha_blend, or replace)" ); } } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ); SceneBlendFactor sbf0, sbf1; if ( getEnumeration<SceneBlendFactor>( i0, compiler, out sbf0 ) && getEnumeration<SceneBlendFactor>( i1, compiler, out sbf1 ) ) _textureunit.SetColorOpMultipassFallback( sbf0, sbf1 ); else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "arguments must be valid scene blend factors" ); } break; #endregion ID_COLOUR_OP_MULTIPASS_FALLBACK #region ID_ALPHA_OP_EX case Keywords.ID_ALPHA_OP_EX: if ( prop.Values.Count < 3 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line, "alpha_op_ex must have at least 3 arguments" ); } else if ( prop.Values.Count > 6 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "alpha_op_ex must have at most 6 arguments" ); } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ), i2 = getNodeAt( prop.Values, 2 ); if ( i0 is AtomAbstractNode && i1 is AtomAbstractNode && i2 is AtomAbstractNode ) { AtomAbstractNode atom0 = (AtomAbstractNode)i0, atom1 = (AtomAbstractNode)i1, atom2 = (AtomAbstractNode)i2; LayerBlendOperationEx op = LayerBlendOperationEx.Add; LayerBlendSource source1 = LayerBlendSource.Current, source2 = LayerBlendSource.Texture; Real arg1 = 0.0f, arg2 = 0.0f; Real manualBlend = 0.0f; switch ( (Keywords)atom0.Id ) { case Keywords.ID_SOURCE1: op = LayerBlendOperationEx.Source1; break; case Keywords.ID_SOURCE2: op = LayerBlendOperationEx.Source2; break; case Keywords.ID_MODULATE: op = LayerBlendOperationEx.Modulate; break; case Keywords.ID_MODULATE_X2: op = LayerBlendOperationEx.ModulateX2; break; case Keywords.ID_MODULATE_X4: op = LayerBlendOperationEx.ModulateX4; break; case Keywords.ID_ADD: op = LayerBlendOperationEx.Add; break; case Keywords.ID_ADD_SIGNED: op = LayerBlendOperationEx.AddSigned; break; case Keywords.ID_ADD_SMOOTH: op = LayerBlendOperationEx.AddSmooth; break; case Keywords.ID_SUBTRACT: op = LayerBlendOperationEx.Subtract; break; case Keywords.ID_BLEND_DIFFUSE_ALPHA: op = LayerBlendOperationEx.BlendDiffuseAlpha; break; case Keywords.ID_BLEND_TEXTURE_ALPHA: op = LayerBlendOperationEx.BlendTextureAlpha; break; case Keywords.ID_BLEND_CURRENT_ALPHA: op = LayerBlendOperationEx.BlendCurrentAlpha; break; case Keywords.ID_BLEND_MANUAL: op = LayerBlendOperationEx.BlendManual; break; case Keywords.ID_DOT_PRODUCT: op = LayerBlendOperationEx.DotProduct; break; case Keywords.ID_BLEND_DIFFUSE_COLOUR: op = LayerBlendOperationEx.BlendDiffuseColor; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i0.Value + " is not a valid first argument (must be \"source1\", \"source2\", \"modulate\", \"modulate_x2\", \"modulate_x4\", \"add\", \"add_signed\", \"add_smooth\", \"subtract\", \"blend_diffuse_alpha\", \"blend_texture_alpha\", \"blend_current_alpha\", \"blend_manual\", \"dot_product\", or \"blend_diffuse_colour\")" ); break; } switch ( (Keywords)atom1.Id ) { case Keywords.ID_SRC_CURRENT: source1 = LayerBlendSource.Current; break; case Keywords.ID_SRC_TEXTURE: source1 = LayerBlendSource.Texture; break; case Keywords.ID_SRC_DIFFUSE: source1 = LayerBlendSource.Diffuse; break; case Keywords.ID_SRC_SPECULAR: source1 = LayerBlendSource.Specular; break; case Keywords.ID_SRC_MANUAL: source1 = LayerBlendSource.Manual; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i1.Value + " is not a valid second argument (must be \"src_current\", \"src_texture\", \"src_diffuse\", \"src_specular\", or \"src_manual\")" ); break; } switch ( (Keywords)atom2.Id ) { case Keywords.ID_SRC_CURRENT: source2 = LayerBlendSource.Current; break; case Keywords.ID_SRC_TEXTURE: source2 = LayerBlendSource.Texture; break; case Keywords.ID_SRC_DIFFUSE: source2 = LayerBlendSource.Diffuse; break; case Keywords.ID_SRC_SPECULAR: source2 = LayerBlendSource.Specular; break; case Keywords.ID_SRC_MANUAL: source2 = LayerBlendSource.Manual; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i2.Value + " is not a valid third argument (must be \"src_current\", \"src_texture\", \"src_diffuse\", \"src_specular\", or \"src_manual\")" ); break; } if ( op == LayerBlendOperationEx.BlendManual ) { AbstractNode i3 = getNodeAt( prop.Values, 3 ); if ( i3 != null ) { if ( !getReal( i3, out manualBlend ) ) compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "valid number expected when blend_manual is used" ); } else { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line, "valid number expected when blend_manual is used" ); } } AbstractNode j = getNodeAt( prop.Values, 3 ); int index = 3; if ( op == LayerBlendOperationEx.BlendManual ) j = getNodeAt( prop.Values, ++index ); if ( source1 == LayerBlendSource.Manual ) { if ( j != null ) { if ( !getReal( j, out arg1 ) ) compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "valid colour expected when src_manual is used" ); else j = getNodeAt( prop.Values, ++index ); } else { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line, "valid colour expected when src_manual is used" ); } } if ( source2 == LayerBlendSource.Manual ) { if ( j != null ) { if ( !getReal( j, out arg2 ) ) compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "valid colour expected when src_manual is used" ); } else { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line, "valid colour expected when src_manual is used" ); } } _textureunit.SetAlphaOperation( op, source1, source2, arg1, arg2, manualBlend ); } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } break; #endregion ID_ALPHA_OP_EX #region ID_ENV_MAP case Keywords.ID_ENV_MAP: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "env_map must have at most 1 argument" ); } else { if ( prop.Values[ 0 ] is AtomAbstractNode ) { AtomAbstractNode atom = (AtomAbstractNode)prop.Values[ 0 ]; switch ( atom.Id ) { case (uint)BuiltIn.ID_OFF: _textureunit.SetEnvironmentMap( false ); break; case (uint)Keywords.ID_SPHERICAL: _textureunit.SetEnvironmentMap( true, EnvironmentMap.Curved ); break; case (uint)Keywords.ID_PLANAR: _textureunit.SetEnvironmentMap( true, EnvironmentMap.Planar ); break; case (uint)Keywords.ID_CUBIC_REFLECTION: _textureunit.SetEnvironmentMap( true, EnvironmentMap.Reflection ); break; case (uint)Keywords.ID_CUBIC_NORMAL: _textureunit.SetEnvironmentMap( true, EnvironmentMap.Normal ); break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not a valid argument (must be \"off\", \"spherical\", \"planar\", \"cubic_reflection\", or \"cubic_normal\")" ); break; } } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not a valid argument (must be \"off\", \"spherical\", \"planar\", \"cubic_reflection\", or \"cubic_normal\")" ); } } break; #endregion ID_ENV_MAP #region ID_SCROLL case Keywords.ID_SCROLL: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 2 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "scroll must have at most 2 arguments" ); } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ); Real x, y; if ( getReal( i0, out x ) && getReal( i1, out y ) ) _textureunit.SetTextureScroll( x, y ); else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i0.Value + " and/or " + i1.Value + " is invalid; both must be numbers" ); } break; #endregion ID_SCROLL #region ID_SCROLL_ANIM case Keywords.ID_SCROLL_ANIM: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 2 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "scroll_anim must have at most 2 arguments" ); } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ); Real x, y; if ( getReal( i0, out x ) && getReal( i1, out y ) ) _textureunit.SetScrollAnimation( x, y ); else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, i0.Value + " and/or " + i1.Value + " is invalid; both must be numbers" ); } break; #endregion ID_SCROLL_ANIM #region ID_ROTATE case Keywords.ID_ROTATE: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "rotate must have at most 1 argument" ); } else { Real angle; if ( getReal( prop.Values[ 0 ], out angle ) ) #warning check this statement //mUnit->setTextureRotate(Degree(angle)); _textureunit.SetTextureRotate( angle ); else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not a valid number value" ); } break; #endregion ID_ROTATE #region ID_ROTATE_ANIM case Keywords.ID_ROTATE_ANIM: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "rotate_anim must have at most 1 argument" ); } else { Real angle; if ( getReal( prop.Values[ 0 ], out angle ) ) _textureunit.SetRotateAnimation( angle ); else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not a valid number value" ); } break; #endregion ID_ROTATE_ANIM #region ID_SCALE case Keywords.ID_SCALE: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 2 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "scale must have at most 2 arguments" ); } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ); Real x, y; if ( getReal( i0, out x ) && getReal( i1, out y ) ) _textureunit.SetTextureScale( x, y ); else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "first and second arguments must both be valid number values (received " + i0.Value + ", " + i1.Value + ")" ); } break; #endregion ID_SCALE #region ID_WAVE_XFORM case Keywords.ID_WAVE_XFORM: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 6 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "wave_xform must have at most 6 arguments" ); } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ), i2 = getNodeAt( prop.Values, 2 ), i3 = getNodeAt( prop.Values, 3 ), i4 = getNodeAt( prop.Values, 4 ), i5 = getNodeAt( prop.Values, 5 ); if ( i0 is AtomAbstractNode && i1 is AtomAbstractNode && i2 is AtomAbstractNode && i3 is AtomAbstractNode && i4 is AtomAbstractNode && i5 is AtomAbstractNode ) { AtomAbstractNode atom0 = (AtomAbstractNode)i0, atom1 = (AtomAbstractNode)i1; TextureTransform type = TextureTransform.Rotate; WaveformType wave = WaveformType.Sine; Real baseVal = 0.0f, freq = 0.0f, phase = 0.0f, amp = 0.0f; switch ( (Keywords)atom0.Id ) { case Keywords.ID_SCROLL_X: type = TextureTransform.TranslateU; break; case Keywords.ID_SCROLL_Y: type = TextureTransform.TranslateV; break; case Keywords.ID_SCALE_X: type = TextureTransform.ScaleU; break; case Keywords.ID_SCALE_Y: type = TextureTransform.ScaleV; break; case Keywords.ID_ROTATE: type = TextureTransform.Rotate; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, atom0.Value + " is not a valid transform type (must be \"scroll_x\", \"scroll_y\", \"scale_x\", \"scale_y\", or \"rotate\")" ); break; } switch ( (Keywords)atom1.Id ) { case Keywords.ID_SINE: wave = WaveformType.Sine; break; case Keywords.ID_TRIANGLE: wave = WaveformType.Triangle; break; case Keywords.ID_SQUARE: wave = WaveformType.Square; break; case Keywords.ID_SAWTOOTH: wave = WaveformType.Sawtooth; break; case Keywords.ID_INVERSE_SAWTOOTH: wave = WaveformType.InverseSawtooth; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, atom1.Value + " is not a valid waveform type (must be \"sine\", \"triangle\", \"square\", \"sawtooth\", or \"inverse_sawtooth\")" ); break; } if ( !getReal( i2, out baseVal ) || !getReal( i3, out freq ) || !getReal( i4, out phase ) || !getReal( i5, out amp ) ) compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "arguments 3, 4, 5, and 6 must be valid numbers; received " + i2.Value + ", " + i3.Value + ", " + i4.Value + ", " + i5.Value ); _textureunit.SetTransformAnimation( type, wave, baseVal, freq, phase, amp ); } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } break; #endregion ID_WAVE_XFORM #region ID_TRANSFORM case Keywords.ID_TRANSFORM: { throw new NotImplementedException(); #if UNREACHABLE_CODE Matrix4 m; if ( getMatrix4( prop.Values, 0, out m ) ) { /*mUnit->setTextureTransform(m);*/ } else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } break; #else } #endif #endregion ID_TRANSFORM #region ID_BINDING_TYPE case Keywords.ID_BINDING_TYPE: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "binding_type must have at most 1 argument" ); } else { if ( prop.Values[ 0 ] is AtomAbstractNode ) { AtomAbstractNode atom = (AtomAbstractNode)prop.Values[ 0 ]; switch ( (Keywords)atom.Id ) { case Keywords.ID_VERTEX: _textureunit.BindingType = TextureBindingType.Vertex; break; case Keywords.ID_FRAGMENT: _textureunit.BindingType = TextureBindingType.Fragment; break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, atom.Value + " is not a valid binding type (must be \"vertex\" or \"fragment\")" ); break; } } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not a valid binding type" ); } } break; #endregion ID_BINDING_TYPE #region ID_CONTENT_TYPE case Keywords.ID_CONTENT_TYPE: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 4 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "content_type must have at most 4 arguments" ); } else { if ( prop.Values[ 0 ] is AtomAbstractNode ) { throw new NotImplementedException(); #if UNREACHABLE_CODE AtomAbstractNode atom = (AtomAbstractNode)prop.Values[ 0 ]; switch ( (Keywords)atom.Id ) { case Keywords.ID_NAMED: //mUnit->setContentType(TextureUnitState::CONTENT_NAMED); break; case Keywords.ID_SHADOW: //mUnit->setContentType(TextureUnitState::CONTENT_SHADOW); break; case Keywords.ID_COMPOSITOR: //mUnit->setContentType(TextureUnitState::CONTENT_COMPOSITOR); if ( prop.Values.Count >= 3 ) { string compositorName; getString( getNodeAt( prop.Values, 1 ), out compositorName ); string textureName; getString( getNodeAt( prop.Values, 2 ), out textureName ); if ( prop.Values.Count == 4 ) { uint mrtIndex; getUInt( getNodeAt( prop.Values, 3 ), out mrtIndex ); //mUnit->setCompositorReference(compositorName, textureName, mrtIndex); } else { //mUnit->setCompositorReference(compositorName, textureName); } } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "content_type compositor must have an additional 2 or 3 parameters" ); } break; default: compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, atom.Value + " is not a valid content type (must be \"named\" or \"shadow\" or \"compositor\")" ); break; } #endif } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, prop.Values[ 0 ].Value + " is not a valid content type" ); } } break;
/// <see cref="Translator.Translate"/> public override void Translate( ScriptCompiler compiler, AbstractNode node ) { var obj = (ObjectAbstractNode)node; var target = (CompositionTargetPass)obj.Parent.Context; this._Pass = target.CreatePass(); obj.Context = this._Pass; // The name is the type of the pass if ( obj.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, obj.File, obj.Line ); return; } var type = string.Empty; if ( !getString( obj.Values[ 0 ], out type ) ) { compiler.AddError( CompileErrorCode.InvalidParameters, obj.File, obj.Line ); return; } this._Pass.Type = (CompositorPassType)ScriptEnumAttribute.Lookup( type, typeof ( CompositorPassType ) ); if ( this._Pass.Type == CompositorPassType.RenderCustom ) { var customType = string.Empty; //This is the ugly one liner for safe access to the second parameter. if ( obj.Values.Count < 2 || !getString( obj.Values[ 1 ], out customType ) ) { compiler.AddError( CompileErrorCode.StringExpected, obj.File, obj.Line ); return; } this._Pass.CustomType = customType; } else { compiler.AddError( CompileErrorCode.InvalidParameters, obj.File, obj.Line, "pass types must be \"clear\", \"stencil\", \"render_quad\", \"render_scene\" or \"render_custom\"." ); return; } foreach ( var i in obj.Children ) { if ( i is ObjectAbstractNode ) { processNode( compiler, i ); } else if ( i is PropertyAbstractNode ) { var prop = (PropertyAbstractNode)i; switch ( (Keywords)prop.Id ) { #region ID_MATERIAL case Keywords.ID_MATERIAL: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); return; } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line ); return; } else { var val = string.Empty; if ( getString( prop.Values[ 0 ], out val ) ) { ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.Material, val ); compiler._fireEvent( ref evt ); this._Pass.MaterialName = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name; } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } break; #endregion ID_MATERIAL #region ID_INPUT case Keywords.ID_INPUT: if ( prop.Values.Count < 2 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); return; } else if ( prop.Values.Count > 3 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line ); return; } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ), i2 = getNodeAt( prop.Values, 2 ); var id = 0; var name = string.Empty; if ( getInt( i0, out id ) && getString( i1, out name ) ) { var index = 0; if ( !getInt( i2, out index ) ) { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line ); return; } this._Pass.SetInput( id, name, index ); } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } break; #endregion ID_INPUT #region ID_IDENTIFIER case Keywords.ID_IDENTIFIER: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); return; } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line ); return; } else { uint val; if ( getUInt( prop.Values[ 0 ], out val ) ) { this._Pass.Identifier = val; } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } break; #endregion ID_IDENTIFIER #region ID_FIRST_RENDER_QUEUE case Keywords.ID_FIRST_RENDER_QUEUE: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); return; } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line ); return; } else { uint val; if ( getUInt( prop.Values[ 0 ], out val ) ) { this._Pass.FirstRenderQueue = (RenderQueueGroupID)val; } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } break; #endregion ID_FIRST_RENDER_QUEUE #region ID_LAST_RENDER_QUEUE case Keywords.ID_LAST_RENDER_QUEUE: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); return; } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line ); return; } else { uint val; if ( getUInt( prop.Values[ 0 ], out val ) ) { this._Pass.LastRenderQueue = (RenderQueueGroupID)val; } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } break; #endregion ID_LAST_RENDER_QUEUE #region ID_MATERIAL_SCHEME case Keywords.ID_MATERIAL_SCHEME: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); return; } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line ); return; } else { string val; if ( getString( prop.Values[ 0 ], out val ) ) { this._Pass.MaterialScheme = val; } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } break; #endregion ID_MATERIAL_SCHEME #region ID_QUAD_NORMALS case Keywords.ID_QUAD_NORMALS: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); return; } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line ); return; } else { if ( prop.Values[ 0 ] is AtomAbstractNode ) { var atom = (AtomAbstractNode)prop.Values[ 0 ]; if ( atom.Id == (uint)Keywords.ID_CAMERA_FAR_CORNERS_VIEW_SPACE ) { this._Pass.SetQuadFarCorners( true, true ); } else if ( atom.Id == (uint)Keywords.ID_CAMERA_FAR_CORNERS_WORLD_SPACE ) { this._Pass.SetQuadFarCorners( true, false ); } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } break; #endregion ID_QUAD_NORMALS default: compiler.AddError( CompileErrorCode.UnexpectedToken, prop.File, prop.Line, "token \"" + prop.Name + "\" is not recognized" ); break; } } } }
/// <see cref="Translator.Translate"/> public override void Translate( ScriptCompiler compiler, AbstractNode node ) { ObjectAbstractNode obj = (ObjectAbstractNode)node; // Create the technique from the material Material material = (Material)obj.Parent.Context; _technique = material.CreateTechnique(); obj.Context = _technique; // Get the name of the technique if ( !string.IsNullOrEmpty( obj.Name ) ) _technique.Name = obj.Name; // Set the properties for the technique foreach ( AbstractNode i in obj.Children ) { if ( i is PropertyAbstractNode ) { PropertyAbstractNode prop = (PropertyAbstractNode)i; switch ( (Keywords)prop.Id ) { #region ID_SCHEME case Keywords.ID_SCHEME: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "scheme only supports 1 argument" ); } else { string scheme; if ( getString( prop.Values[ 0 ], out scheme ) ) _technique.Scheme = scheme; else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "scheme must have 1 string argument" ); } break; #endregion ID_SCHEME #region ID_LOD_INDEX case Keywords.ID_LOD_INDEX: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "lod_index only supports 1 argument" ); } else { int val; if ( getInt( prop.Values[ 0 ], out val ) ) _technique.LodIndex = val; else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "lod_index cannot accept argument \"" + prop.Values[ 0 ].Value + "\"" ); } break; #endregion ID_LOD_INDEX #region ID_SHADOW_CASTER_MATERIAL case Keywords.ID_SHADOW_CASTER_MATERIAL: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "shadow_caster_material only accepts 1 argument" ); } else { string matName; if ( getString( prop.Values[ 0 ], out matName ) ) { string evtMatName = string.Empty; ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.Material, matName ); compiler._fireEvent( ref evt ); evtMatName = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name; _technique.ShadowCasterMaterial = (Material)MaterialManager.Instance[ evtMatName ]; // Use the processed name } else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "shadow_caster_material cannot accept argument \"" + prop.Values[ 0 ].Value + "\"" ); } break; #endregion ID_SHADOW_CASTER_MATERIAL #region ID_SHADOW_RECEIVER_MATERIAL case Keywords.ID_SHADOW_RECEIVER_MATERIAL: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "shadow_receiver_material only accepts 1 argument" ); } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ); string matName = string.Empty; if ( getString( i0, out matName ) ) { string evtName = string.Empty; ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.Material, matName ); compiler._fireEvent( ref evt ); evtName = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name; _technique.ShadowReceiverMaterial = (Material)MaterialManager.Instance[ evtName ]; } else compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "shadow_receiver_material_name cannot accept argument \"" + i0.Value + "\"" ); } break; #endregion ID_SHADOW_RECEIVER_MATERIAL #region ID_GPU_VENDOR_RULE case Keywords.ID_GPU_VENDOR_RULE: if ( prop.Values.Count < 2 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line, "gpu_vendor_rule must have 2 arguments" ); } else if ( prop.Values.Count > 2 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "gpu_vendor_rule must have 2 arguments" ); } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ); AbstractNode i1 = getNodeAt( prop.Values, 1 ); Technique.GPUVendorRule rule = new Technique.GPUVendorRule(); if ( i0 is AtomAbstractNode ) { AtomAbstractNode atom0 = (AtomAbstractNode)i0; Keywords atom0Id = (Keywords)atom0.Id; if ( atom0Id == Keywords.ID_INCLUDE ) { rule.Include = true; } else if ( atom0Id == Keywords.ID_EXCLUDE ) { rule.Include = false; } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_vendor_rule cannot accept \"" + i0.Value + "\" as first argument" ); } string vendor = string.Empty; if ( !getString( i1, out vendor ) ) { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_vendor_rule cannot accept \"" + i1.Value + "\" as second argument" ); } rule.Vendor = RenderSystemCapabilities.VendorFromString( vendor ); if ( rule.Vendor != GPUVendor.Unknown ) { _technique.AddGPUVenderRule( rule ); } } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_vendor_rule cannot accept \"" + i0.Value + "\" as first argument" ); } } break; #endregion ID_GPU_VENDOR_RULE #region ID_GPU_DEVICE_RULE case Keywords.ID_GPU_DEVICE_RULE: if ( prop.Values.Count < 2 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line, "gpu_device_rule must have at least 2 arguments" ); } else if ( prop.Values.Count > 3 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "gpu_device_rule must have at most 3 arguments" ); } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ); AbstractNode i1 = getNodeAt( prop.Values, 1 ); Technique.GPUDeviceNameRule rule = new Technique.GPUDeviceNameRule(); if ( i0 is AtomAbstractNode ) { AtomAbstractNode atom0 = (AtomAbstractNode)i0; Keywords atom0Id = (Keywords)atom0.Id; if ( atom0Id == Keywords.ID_INCLUDE ) { rule.Include = true; } else if ( atom0Id == Keywords.ID_EXCLUDE ) { rule.Include = false; } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule cannot accept \"" + i0.Value + "\" as first argument" ); } if ( !getString( i1, out rule.DevicePattern ) ) { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule cannot accept \"" + i1.Value + "\" as second argument" ); } if ( prop.Values.Count == 3 ) { AbstractNode i2 = getNodeAt( prop.Values, 2 ); if ( !getBoolean( i2, out rule.CaseSensitive ) ) { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule third argument must be \"true\", \"false\", \"yes\", \"no\", \"on\", or \"off\"" ); } } _technique.AddGPUDeviceNameRule( rule ); } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule cannot accept \"" + i0.Value + "\" as first argument" ); } } break; #endregion ID_GPU_DEVICE_RULE default: compiler.AddError( CompileErrorCode.UnexpectedToken, prop.File, prop.Line, "token \"" + prop.Name + "\" is not recognized" ); break; } //end of switch statement } // end of if ( i is PropertyAbstractNode ) else if ( i is ObjectAbstractNode ) { _processNode( compiler, i ); } } }
private Pass _commonProgramChecks( ScriptCompiler compiler, ObjectAbstractNode node, out string createdProgramName ) { createdProgramName = string.Empty; if ( string.IsNullOrEmpty( node.Name ) ) { compiler.AddError( CompileErrorCode.ObjectNameExpected, node.File, node.Line ); return null; } ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.GpuProgram, node.Name ); compiler._fireEvent( ref evt ); createdProgramName = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name; if ( GpuProgramManager.Instance.GetByName( createdProgramName ) == null ) { compiler.AddError( CompileErrorCode.ReferenceToaNonExistingObject, node.File, node.Line ); return null; } Pass pass = (Pass)node.Parent.Context; return pass; }
/// <see cref="Translator.Translate"/> public override void Translate(ScriptCompiler compiler, AbstractNode node) { var obj = (ObjectAbstractNode)node; var target = (CompositionTargetPass)obj.Parent.Context; this._Pass = target.CreatePass(); obj.Context = this._Pass; // The name is the type of the pass if (obj.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, obj.File, obj.Line); return; } var type = string.Empty; if (!getString(obj.Values[0], out type)) { compiler.AddError(CompileErrorCode.InvalidParameters, obj.File, obj.Line); return; } this._Pass.Type = (CompositorPassType)ScriptEnumAttribute.Lookup(type, typeof(CompositorPassType)); if (this._Pass.Type == CompositorPassType.RenderCustom) { var customType = string.Empty; //This is the ugly one liner for safe access to the second parameter. if (obj.Values.Count < 2 || !getString(obj.Values[1], out customType)) { compiler.AddError(CompileErrorCode.StringExpected, obj.File, obj.Line); return; } this._Pass.CustomType = customType; } else { compiler.AddError(CompileErrorCode.InvalidParameters, obj.File, obj.Line, "pass types must be \"clear\", \"stencil\", \"render_quad\", \"render_scene\" or \"render_custom\"."); return; } foreach (var i in obj.Children) { if (i is ObjectAbstractNode) { processNode(compiler, i); } else if (i is PropertyAbstractNode) { var prop = (PropertyAbstractNode)i; switch ((Keywords)prop.Id) { #region ID_MATERIAL case Keywords.ID_MATERIAL: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { var val = string.Empty; if (getString(prop.Values[0], out val)) { ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent(ProcessResourceNameScriptCompilerEvent.ResourceType.Material, val); compiler._fireEvent(ref evt); this._Pass.MaterialName = ((ProcessResourceNameScriptCompilerEvent)evt).Name; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_MATERIAL #region ID_INPUT case Keywords.ID_INPUT: if (prop.Values.Count < 2) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 3) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { AbstractNode i0 = getNodeAt(prop.Values, 0), i1 = getNodeAt(prop.Values, 1), i2 = getNodeAt(prop.Values, 2); var id = 0; var name = string.Empty; if (getInt(i0, out id) && getString(i1, out name)) { var index = 0; if (!getInt(i2, out index)) { compiler.AddError(CompileErrorCode.NumberExpected, prop.File, prop.Line); return; } this._Pass.SetInput(id, name, index); } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_INPUT #region ID_IDENTIFIER case Keywords.ID_IDENTIFIER: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { uint val; if (getUInt(prop.Values[0], out val)) { this._Pass.Identifier = val; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_IDENTIFIER #region ID_FIRST_RENDER_QUEUE case Keywords.ID_FIRST_RENDER_QUEUE: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { uint val; if (getUInt(prop.Values[0], out val)) { this._Pass.FirstRenderQueue = (RenderQueueGroupID)val; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_FIRST_RENDER_QUEUE #region ID_LAST_RENDER_QUEUE case Keywords.ID_LAST_RENDER_QUEUE: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { uint val; if (getUInt(prop.Values[0], out val)) { this._Pass.LastRenderQueue = (RenderQueueGroupID)val; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_LAST_RENDER_QUEUE #region ID_MATERIAL_SCHEME case Keywords.ID_MATERIAL_SCHEME: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { string val; if (getString(prop.Values[0], out val)) { this._Pass.MaterialScheme = val; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_MATERIAL_SCHEME #region ID_QUAD_NORMALS case Keywords.ID_QUAD_NORMALS: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { if (prop.Values[0] is AtomAbstractNode) { var atom = (AtomAbstractNode)prop.Values[0]; if (atom.Id == (uint)Keywords.ID_CAMERA_FAR_CORNERS_VIEW_SPACE) { this._Pass.SetQuadFarCorners(true, true); } else if (atom.Id == (uint)Keywords.ID_CAMERA_FAR_CORNERS_WORLD_SPACE) { this._Pass.SetQuadFarCorners(true, false); } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_QUAD_NORMALS default: compiler.AddError(CompileErrorCode.UnexpectedToken, prop.File, prop.Line, "token \"" + prop.Name + "\" is not recognized"); break; } } } }
protected void _translateUnifiedGpuProgram(ScriptCompiler compiler, ObjectAbstractNode obj) { var customParameters = new NameValuePairList(); AbstractNode parameters = null; foreach (var i in obj.Children) { if (i is PropertyAbstractNode) { var prop = (PropertyAbstractNode)i; if (prop.Name == "delegate") { var value = string.Empty; if (prop.Values.Count != 0 && prop.Values[0] is AtomAbstractNode) { value = ((AtomAbstractNode)prop.Values[0]).Value; } ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent(ProcessResourceNameScriptCompilerEvent.ResourceType.GpuProgram, value); compiler._fireEvent(ref evt); customParameters["delegate"] = ((ProcessResourceNameScriptCompilerEvent)evt).Name; } else { var name = prop.Name; var value = string.Empty; var first = true; foreach (var it in prop.Values) { if (it is AtomAbstractNode) { if (!first) { value += " "; } else { first = false; } value += ((AtomAbstractNode)it).Value; } } customParameters.Add(name, value); } } else if (i is ObjectAbstractNode) { if (((ObjectAbstractNode)i).Id == (uint)Keywords.ID_DEFAULT_PARAMS) { parameters = i; } else { processNode(compiler, i); } } } // Allocate the program Object progObj; HighLevelGpuProgram prog = null; ScriptCompilerEvent evnt = new CreateHighLevelGpuProgramScriptCompilerEvent(obj.File, obj.Name, compiler.ResourceGroup, string.Empty, "unified", _translateIDToGpuProgramType(obj.Id)); var processed = compiler._fireEvent(ref evnt, out progObj); if (!processed) { prog = (HighLevelGpuProgram) (HighLevelGpuProgramManager.Instance.CreateProgram(obj.Name, compiler.ResourceGroup, "unified", _translateIDToGpuProgramType(obj.Id))); } else { prog = (HighLevelGpuProgram)progObj; } // Check that allocation worked if (prog == null) { compiler.AddError(CompileErrorCode.ObjectAllocationError, obj.File, obj.Line, "gpu program \"" + obj.Name + "\" could not be created"); return; } obj.Context = prog; prog.IsMorphAnimationIncluded = false; prog.PoseAnimationCount = 0; prog.IsSkeletalAnimationIncluded = false; prog.IsVertexTextureFetchRequired = false; prog.Origin = obj.File; // Set the custom parameters prog.SetParameters(customParameters); // Set up default parameters if (prog.IsSupported && parameters != null) { var ptr = prog.DefaultParameters; GpuProgramTranslator.TranslateProgramParameters(compiler, ptr, (ObjectAbstractNode)parameters); } }
/// <see cref="Translator.Translate"/> public override void Translate(ScriptCompiler compiler, AbstractNode node) { var obj = (ObjectAbstractNode)node; // Create the technique from the material var material = (Material)obj.Parent.Context; this._technique = material.CreateTechnique(); obj.Context = this._technique; // Get the name of the technique if (!string.IsNullOrEmpty(obj.Name)) { this._technique.Name = obj.Name; } // Set the properties for the technique foreach (var i in obj.Children) { if (i is PropertyAbstractNode) { var prop = (PropertyAbstractNode)i; switch ((Keywords)prop.Id) { #region ID_SCHEME case Keywords.ID_SCHEME: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "scheme only supports 1 argument"); } else { string scheme; if (getString(prop.Values[0], out scheme)) { this._technique.Scheme = scheme; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "scheme must have 1 string argument"); } } break; #endregion ID_SCHEME #region ID_LOD_INDEX case Keywords.ID_LOD_INDEX: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "lod_index only supports 1 argument"); } else { int val; if (getInt(prop.Values[0], out val)) { this._technique.LodIndex = val; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "lod_index cannot accept argument \"" + prop.Values[0].Value + "\""); } } break; #endregion ID_LOD_INDEX #region ID_SHADOW_CASTER_MATERIAL case Keywords.ID_SHADOW_CASTER_MATERIAL: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "shadow_caster_material only accepts 1 argument"); } else { string matName; if (getString(prop.Values[0], out matName)) { var evtMatName = string.Empty; ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent(ProcessResourceNameScriptCompilerEvent.ResourceType.Material, matName); compiler._fireEvent(ref evt); evtMatName = ((ProcessResourceNameScriptCompilerEvent)evt).Name; this._technique.ShadowCasterMaterial = (Material)MaterialManager.Instance[evtMatName]; // Use the processed name } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "shadow_caster_material cannot accept argument \"" + prop.Values[0].Value + "\""); } } break; #endregion ID_SHADOW_CASTER_MATERIAL #region ID_SHADOW_RECEIVER_MATERIAL case Keywords.ID_SHADOW_RECEIVER_MATERIAL: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "shadow_receiver_material only accepts 1 argument"); } else { var i0 = getNodeAt(prop.Values, 0); var matName = string.Empty; if (getString(i0, out matName)) { var evtName = string.Empty; ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent(ProcessResourceNameScriptCompilerEvent.ResourceType.Material, matName); compiler._fireEvent(ref evt); evtName = ((ProcessResourceNameScriptCompilerEvent)evt).Name; this._technique.ShadowReceiverMaterial = (Material)MaterialManager.Instance[evtName]; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "shadow_receiver_material_name cannot accept argument \"" + i0.Value + "\""); } } break; #endregion ID_SHADOW_RECEIVER_MATERIAL #region ID_GPU_VENDOR_RULE case Keywords.ID_GPU_VENDOR_RULE: if (prop.Values.Count < 2) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line, "gpu_vendor_rule must have 2 arguments"); } else if (prop.Values.Count > 2) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "gpu_vendor_rule must have 2 arguments"); } else { var i0 = getNodeAt(prop.Values, 0); var i1 = getNodeAt(prop.Values, 1); var rule = new Technique.GPUVendorRule(); if (i0 is AtomAbstractNode) { var atom0 = (AtomAbstractNode)i0; var atom0Id = (Keywords)atom0.Id; if (atom0Id == Keywords.ID_INCLUDE) { rule.Include = true; } else if (atom0Id == Keywords.ID_EXCLUDE) { rule.Include = false; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_vendor_rule cannot accept \"" + i0.Value + "\" as first argument"); } var vendor = string.Empty; if (!getString(i1, out vendor)) { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_vendor_rule cannot accept \"" + i1.Value + "\" as second argument"); } rule.Vendor = RenderSystemCapabilities.VendorFromString(vendor); if (rule.Vendor != GPUVendor.Unknown) { this._technique.AddGPUVenderRule(rule); } } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_vendor_rule cannot accept \"" + i0.Value + "\" as first argument"); } } break; #endregion ID_GPU_VENDOR_RULE #region ID_GPU_DEVICE_RULE case Keywords.ID_GPU_DEVICE_RULE: if (prop.Values.Count < 2) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line, "gpu_device_rule must have at least 2 arguments"); } else if (prop.Values.Count > 3) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "gpu_device_rule must have at most 3 arguments"); } else { var i0 = getNodeAt(prop.Values, 0); var i1 = getNodeAt(prop.Values, 1); var rule = new Technique.GPUDeviceNameRule(); if (i0 is AtomAbstractNode) { var atom0 = (AtomAbstractNode)i0; var atom0Id = (Keywords)atom0.Id; if (atom0Id == Keywords.ID_INCLUDE) { rule.Include = true; } else if (atom0Id == Keywords.ID_EXCLUDE) { rule.Include = false; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule cannot accept \"" + i0.Value + "\" as first argument"); } if (!getString(i1, out rule.DevicePattern)) { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule cannot accept \"" + i1.Value + "\" as second argument"); } if (prop.Values.Count == 3) { var i2 = getNodeAt(prop.Values, 2); if (!getBoolean(i2, out rule.CaseSensitive)) { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule third argument must be \"true\", \"false\", \"yes\", \"no\", \"on\", or \"off\""); } } this._technique.AddGPUDeviceNameRule(rule); } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule cannot accept \"" + i0.Value + "\" as first argument"); } } break; #endregion ID_GPU_DEVICE_RULE default: compiler.AddError(CompileErrorCode.UnexpectedToken, prop.File, prop.Line, "token \"" + prop.Name + "\" is not recognized"); break; } //end of switch statement } // end of if ( i is PropertyAbstractNode ) else if (i is ObjectAbstractNode) { processNode(compiler, i); } } }
/// <see cref="Translator.Translate"/> public override void Translate( ScriptCompiler compiler, AbstractNode node ) { var obj = (ObjectAbstractNode)node; // Find the name if ( obj != null ) { if ( string.IsNullOrEmpty( obj.Name ) ) { compiler.AddError( CompileErrorCode.ObjectNameExpected, obj.File, obj.Line ); return; } } else { compiler.AddError( CompileErrorCode.ObjectNameExpected, obj.File, obj.Line ); return; } // Allocate the particle system object sysObject; ScriptCompilerEvent evt = new CreateParticleSystemScriptCompilerEvent( obj.File, obj.Name, compiler.ResourceGroup ); var processed = compiler._fireEvent( ref evt, out sysObject ); if ( !processed ) { this._System = ParticleSystemManager.Instance.CreateTemplate( obj.Name, compiler.ResourceGroup ); } else { this._System = (ParticleSystem)sysObject; } if ( this._System == null ) { compiler.AddError( CompileErrorCode.ObjectAllocationError, obj.File, obj.Line ); return; } this._System.Origin = obj.File; this._System.RemoveAllEmitters(); this._System.RemoveAllAffectors(); obj.Context = this._System; foreach ( var i in obj.Children ) { if ( i is PropertyAbstractNode ) { var prop = (PropertyAbstractNode)i; switch ( (Keywords)prop.Id ) { case Keywords.ID_MATERIAL: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); return; } else { if ( prop.Values[ 0 ] is AtomAbstractNode ) { var name = ( (AtomAbstractNode)prop.Values[ 0 ] ).Value; ScriptCompilerEvent locEvt = new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.Material, name ); compiler._fireEvent( ref locEvt ); var locEvtName = ( (ProcessResourceNameScriptCompilerEvent)locEvt ).Name; if ( !this._System.SetParameter( "material", locEvtName ) ) { if ( this._System.Renderer != null ) { if ( !this._System.Renderer.SetParameter( "material", locEvtName ) ) { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "material property could not be set with material \"" + locEvtName + "\"" ); } } } } } break; default: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); return; } else { string name = prop.Name, value = string.Empty; // Glob the values together foreach ( var it in prop.Values ) { if ( it is AtomAbstractNode ) { if ( string.IsNullOrEmpty( value ) ) { value = ( (AtomAbstractNode)it ).Value; } else { value = value + " " + ( (AtomAbstractNode)it ).Value; } } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); return; } } if ( !this._System.SetParameter( name, value ) ) { if ( this._System.Renderer != null ) { if ( !this._System.Renderer.SetParameter( name, value ) ) { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line ); } } } } break; } } else { processNode( compiler, i ); } } }
/// <see cref="Translator.Translate"/> public override void Translate(ScriptCompiler compiler, AbstractNode node) { var obj = (ObjectAbstractNode)node; // Find the name if (obj != null) { if (string.IsNullOrEmpty(obj.Name)) { compiler.AddError(CompileErrorCode.ObjectNameExpected, obj.File, obj.Line); return; } } else { compiler.AddError(CompileErrorCode.ObjectNameExpected, obj.File, obj.Line); return; } // Allocate the particle system object sysObject; ScriptCompilerEvent evt = new CreateParticleSystemScriptCompilerEvent(obj.File, obj.Name, compiler.ResourceGroup); var processed = compiler._fireEvent(ref evt, out sysObject); if (!processed) { this._System = ParticleSystemManager.Instance.CreateTemplate(obj.Name, compiler.ResourceGroup); } else { this._System = (ParticleSystem)sysObject; } if (this._System == null) { compiler.AddError(CompileErrorCode.ObjectAllocationError, obj.File, obj.Line); return; } this._System.Origin = obj.File; this._System.RemoveAllEmitters(); this._System.RemoveAllAffectors(); obj.Context = this._System; foreach (var i in obj.Children) { if (i is PropertyAbstractNode) { var prop = (PropertyAbstractNode)i; switch ((Keywords)prop.Id) { case Keywords.ID_MATERIAL: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else { if (prop.Values[0] is AtomAbstractNode) { var name = ((AtomAbstractNode)prop.Values[0]).Value; ScriptCompilerEvent locEvt = new ProcessResourceNameScriptCompilerEvent(ProcessResourceNameScriptCompilerEvent.ResourceType.Material, name); compiler._fireEvent(ref locEvt); var locEvtName = ((ProcessResourceNameScriptCompilerEvent)locEvt).Name; if (!this._System.SetParameter("material", locEvtName)) { if (this._System.Renderer != null) { if (!this._System.Renderer.SetParameter("material", locEvtName)) { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "material property could not be set with material \"" + locEvtName + "\""); } } } } } break; default: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else { string name = prop.Name, value = string.Empty; // Glob the values together foreach (var it in prop.Values) { if (it is AtomAbstractNode) { if (string.IsNullOrEmpty(value)) { value = ((AtomAbstractNode)it).Value; } else { value = value + " " + ((AtomAbstractNode)it).Value; } } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); return; } } if (!this._System.SetParameter(name, value)) { if (this._System.Renderer != null) { if (!this._System.Renderer.SetParameter(name, value)) { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } } } break; } } else { processNode(compiler, i); } } }
protected void _translateUnifiedGpuProgram( ScriptCompiler compiler, ObjectAbstractNode obj ) { var customParameters = new NameValuePairList(); AbstractNode parameters = null; foreach ( var i in obj.Children ) { if ( i is PropertyAbstractNode ) { var prop = (PropertyAbstractNode)i; if ( prop.Name == "delegate" ) { var value = string.Empty; if ( prop.Values.Count != 0 && prop.Values[ 0 ] is AtomAbstractNode ) { value = ( (AtomAbstractNode)prop.Values[ 0 ] ).Value; } ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.GpuProgram, value ); compiler._fireEvent( ref evt ); customParameters[ "delegate" ] = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name; } else { var name = prop.Name; var value = string.Empty; var first = true; foreach ( var it in prop.Values ) { if ( it is AtomAbstractNode ) { if ( !first ) { value += " "; } else { first = false; } value += ( (AtomAbstractNode)it ).Value; } } customParameters.Add( name, value ); } } else if ( i is ObjectAbstractNode ) { if ( ( (ObjectAbstractNode)i ).Id == (uint)Keywords.ID_DEFAULT_PARAMS ) { parameters = i; } else { processNode( compiler, i ); } } } // Allocate the program Object progObj; HighLevelGpuProgram prog = null; ScriptCompilerEvent evnt = new CreateHighLevelGpuProgramScriptCompilerEvent( obj.File, obj.Name, compiler.ResourceGroup, string.Empty, "unified", _translateIDToGpuProgramType( obj.Id ) ); var processed = compiler._fireEvent( ref evnt, out progObj ); if ( !processed ) { prog = (HighLevelGpuProgram) ( HighLevelGpuProgramManager.Instance.CreateProgram( obj.Name, compiler.ResourceGroup, "unified", _translateIDToGpuProgramType( obj.Id ) ) ); } else { prog = (HighLevelGpuProgram)progObj; } // Check that allocation worked if ( prog == null ) { compiler.AddError( CompileErrorCode.ObjectAllocationError, obj.File, obj.Line, "gpu program \"" + obj.Name + "\" could not be created" ); return; } obj.Context = prog; prog.IsMorphAnimationIncluded = false; prog.PoseAnimationCount = 0; prog.IsSkeletalAnimationIncluded = false; prog.IsVertexTextureFetchRequired = false; prog.Origin = obj.File; // Set the custom parameters prog.SetParameters( customParameters ); // Set up default parameters if ( prog.IsSupported && parameters != null ) { var ptr = prog.DefaultParameters; GpuProgramTranslator.TranslateProgramParameters( compiler, ptr, (ObjectAbstractNode)parameters ); } }