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); } }
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 ); } }