/// <summary> /// Overrides to recover by last sample's index instead. /// </summary> /// <param name="renderer"></param> /// <param name="options"></param> protected override void Reconfigure(string renderer, Collections.NameValuePairList options) { this.LastViewCategory = this.CategoryMenu.SelectionIndex; this.LastViewTitle = this.SampleMenu.SelectionIndex; this.LastSampleIndex = -1; int index = -1; foreach (Sample i in this.LoadedSamples) { index++; if (i == CurrentSample) { this.LastSampleIndex = index; break; } } base.Reconfigure(renderer, options); }
/// <summary> /// Handles button widget events. /// </summary> /// <param name="b"></param> public void OnButtonHit( object sender, Button b ) { if ( ButtonHit != null ) { ButtonHit( sender, b ); } if ( b.Name == "StartStop" ) // start or stop sample { if ( b.Caption == "Start Sample" ) { if ( this.LoadedSamples.Count == 0 ) { this.TrayManager.ShowOkDialog( "Error!", "No sample selected!" ); } // use the sample pointer we stored inside the thumbnail else { RunSample( (Sample)( this.Thumbs[ this.SampleMenu.SelectionIndex ].UserData ) ); } } else { RunSample( null ); } } else if ( b.Name == "UnloadReload" ) // unload or reload sample plugins and update controls { if ( b.Caption == "Unload Samples" ) { if ( CurrentSample != null ) { this.TrayManager.ShowYesNoDialog( "Warning!", "This will stop the current sample. Unload anyway?" ); } else { // save off current view and try to restore it on the next reload this.LastViewTitle = this.SampleMenu.SelectionIndex; this.LastViewCategory = this.CategoryMenu.SelectionIndex; UnloadSamples(); PopulateSampleMenus(); b.Caption = "Reload Samples"; } } else { LoadSamples(); PopulateSampleMenus(); if ( !( this.LoadedSamples.Count == 0 ) ) { b.Caption = "Unload Samples"; } try // attempt to restore the last view before unloading samples { this.CategoryMenu.SelectItem( this.LastViewCategory ); this.SampleMenu.SelectItem( this.LastViewTitle ); } catch ( Exception ) { // swallowing Exception on purpose } } } else if ( b.Name == "Configure" ) // enter configuration screen { this.TrayManager.RemoveWidgetFromTray( "StartStop" ); this.TrayManager.RemoveWidgetFromTray( "UnloadReload" ); this.TrayManager.RemoveWidgetFromTray( "Configure" ); this.TrayManager.RemoveWidgetFromTray( "Quit" ); this.TrayManager.MoveWidgetToTray( "Apply", TrayLocation.Right ); this.TrayManager.MoveWidgetToTray( "Back", TrayLocation.Right ); for ( int i = 0; i < this.Thumbs.Count; i++ ) { this.Thumbs[ i ].Hide(); } while ( this.TrayManager.TrayContainer[ (int)TrayLocation.Center ].IsVisible ) { this.TrayManager.RemoveWidgetFromTray( TrayLocation.Center, 0 ); } while ( this.TrayManager.TrayContainer[ (int)TrayLocation.Left ].IsVisible ) { this.TrayManager.RemoveWidgetFromTray( TrayLocation.Left, 0 ); } this.TrayManager.MoveWidgetToTray( "ConfigLabel", TrayLocation.Left ); this.TrayManager.MoveWidgetToTray( this.RendererMenu, TrayLocation.Left ); this.TrayManager.MoveWidgetToTray( "ConfigSeparator", TrayLocation.Left ); this.RendererMenu.SelectItem( Root.RenderSystem.Name ); WindowResized( RenderWindow ); } else if ( b.Name == "Back" ) // leave configuration screen { while ( this.TrayManager.GetWidgetCount( this.RendererMenu.TrayLocation ) > 3 ) { this.TrayManager.DestroyWidget( this.RendererMenu.TrayLocation, 3 ); } while ( this.TrayManager.GetWidgetCount( TrayLocation.None ) != 0 ) { this.TrayManager.MoveWidgetToTray( TrayLocation.None, 0, TrayLocation.Left ); } this.TrayManager.RemoveWidgetFromTray( "Apply" ); this.TrayManager.RemoveWidgetFromTray( "Back" ); this.TrayManager.RemoveWidgetFromTray( "ConfigLabel" ); this.TrayManager.RemoveWidgetFromTray( this.RendererMenu ); this.TrayManager.RemoveWidgetFromTray( "ConfigSeparator" ); this.TrayManager.MoveWidgetToTray( "StartStop", TrayLocation.Right ); this.TrayManager.MoveWidgetToTray( "UnloadReload", TrayLocation.Right ); this.TrayManager.MoveWidgetToTray( "Configure", TrayLocation.Right ); this.TrayManager.MoveWidgetToTray( "Quit", TrayLocation.Right ); WindowResized( RenderWindow ); } else if ( b.Name == "Apply" ) // apply any changes made in the configuration screen { bool reset = false; string selectedRenderSystem = string.Empty; switch ( this.RendererMenu.SelectedItem ) { case "Axiom DirectX9 Rendering Subsystem": selectedRenderSystem = "DirectX9"; break; case "Axiom Xna Rendering Subsystem": selectedRenderSystem = "Xna"; break; case "Axiom OpenGL (OpenTK) Rendering Subsystem": selectedRenderSystem = "OpenGL"; break; default: throw new NotImplementedException(); } if ( selectedRenderSystem != string.Empty ) { var options = Root.RenderSystems[ selectedRenderSystem ].ConfigOptions; var newOptions = new Collections.NameValuePairList(); // collect new settings and decide if a reset is needed if ( this.RendererMenu.SelectedItem != Root.RenderSystem.Name ) { reset = true; } for ( int i = 3; i < this.TrayManager.GetWidgetCount( this.RendererMenu.TrayLocation ); i++ ) { var menu = (SelectMenu)this.TrayManager.GetWidget( this.RendererMenu.TrayLocation, i ); if ( menu.SelectedItem != options[ menu.Caption ].Value ) { reset = true; } newOptions[ menu.Caption ] = menu.SelectedItem; } // reset with new settings if necessary if ( reset ) { Reconfigure( selectedRenderSystem, newOptions ); } } } else { Root.QueueEndRendering(); // exit browser } }
/// <summary> /// /// </summary> /// <param name="menu"></param> public virtual void ItemSelected(SelectMenu menu) { if (menu == this.CategoryMenu) // category changed, so update the sample menu, carousel, and slider { for (int i = 0; i < this.Thumbs.Count; i++) // destroy all thumbnails in carousel { MaterialManager.Instance.Remove(this.Thumbs[i].Name); Widget.NukeOverlayElement(this.Thumbs[i]); } this.Thumbs.Clear(); OverlayManager om = OverlayManager.Instance; String selectedCategory = string.Empty; if (menu.SelectionIndex != -1) { selectedCategory = menu.SelectedItem; } else { this.TitleLabel.Caption = ""; this.DescBox.Text = ""; } bool all = selectedCategory == "All"; var sampleTitles = new List <string>(); var templateMat = (Material)MaterialManager.Instance.GetByName("SampleThumbnail"); // populate the sample menu and carousel with filtered samples foreach (Sample i in this.LoadedSamples) { Collections.NameValuePairList info = i.Metadata; if (all || info["Category"] == selectedCategory) { String name = "SampleThumb" + sampleTitles.Count + 1; // clone a new material for sample thumbnail Material newMat = templateMat.Clone(name); TextureUnitState tus = newMat.GetTechnique(0).GetPass(0).GetTextureUnitState(0); if (ResourceGroupManager.Instance.ResourceExists("Essential", info["Thumbnail"])) { tus.SetTextureName(info["Thumbnail"]); } else { tus.SetTextureName("thumb_error.png"); } // create sample thumbnail overlay var bp = (Overlays.Elements.BorderPanel)om.Elements.CreateElementFromTemplate("SdkTrays/Picture", "BorderPanel", name); bp.HorizontalAlignment = HorizontalAlignment.Right; bp.VerticalAlignment = VerticalAlignment.Center; bp.MaterialName = name; bp.UserData = i; this.TrayManager.TraysLayer.AddElement(bp); // add sample thumbnail and title this.Thumbs.Add(bp); sampleTitles.Add(i.Metadata["Title"]); } } this.CarouselPlace = 0; // reset carousel this.SampleMenu.Items = sampleTitles; if (this.SampleMenu.ItemsCount != 0) { ItemSelected(this.SampleMenu); } this.SampleSlider.SetRange(1, sampleTitles.Count, sampleTitles.Count); } else if (menu == this.SampleMenu) // sample changed, so update slider, label and description { if (this.SampleSlider.Value != menu.SelectionIndex + 1) { this.SampleSlider.Value = menu.SelectionIndex + 1; } var s = (Sample)(this.Thumbs[menu.SelectionIndex].UserData); this.TitleLabel.Caption = menu.SelectedItem; this.DescBox.Text = "Category: " + s.Metadata["Category"] + "\nDescription: " + s.Metadata["Description"]; if (CurrentSample != s) { ((Button)this.TrayManager.GetWidget("StartStop")).Caption = "Start Sample"; } else { ((Button)this.TrayManager.GetWidget("StartStop")).Caption = "Stop Sample"; } } else if (menu == this.RendererMenu) // renderer selected, so update all settings { while (this.TrayManager.GetWidgetCount(this.RendererMenu.TrayLocation) > 3) { this.TrayManager.DestroyWidget(this.RendererMenu.TrayLocation, 3); } var options = Root.RenderSystems[menu.SelectionIndex].ConfigOptions; int i = 0; // create all the config option select menus foreach (Configuration.ConfigOption it in options) { SelectMenu optionMenu = this.TrayManager.CreateLongSelectMenu(TrayLocation.Left, "ConfigOption" + i++, it.Name, 450, 240, 10); optionMenu.Items = (List <string>)it.PossibleValues.Values.ToList(); // if the current config value is not in the menu, add it try { optionMenu.SelectItem(it.Value); } catch (Exception) { optionMenu.AddItem(it.Value); optionMenu.SelectItem(it.Value); } } WindowResized(RenderWindow); } }
/// <summary> /// Handles button widget events. /// </summary> /// <param name="b"></param> public void OnButtonHit(object sender, Button b) { ButtonHit?.Invoke(sender, b); if (b.Name == "StartStop") // start or stop sample { if (b.Caption == "Start Sample") { if (this.LoadedSamples.Count == 0) { this.TrayManager.ShowOkDialog("Error!", "No sample selected!"); } // use the sample pointer we stored inside the thumbnail else { RunSample((Sample)(this.Thumbs[this.SampleMenu.SelectionIndex].UserData)); } } else { RunSample(null); } } else if (b.Name == "UnloadReload") // unload or reload sample plugins and update controls { if (b.Caption == "Unload Samples") { if (CurrentSample != null) { this.TrayManager.ShowYesNoDialog("Warning!", "This will stop the current sample. Unload anyway?"); } else { // save off current view and try to restore it on the next reload this.LastViewTitle = this.SampleMenu.SelectionIndex; this.LastViewCategory = this.CategoryMenu.SelectionIndex; UnloadSamples(); PopulateSampleMenus(); b.Caption = "Reload Samples"; } } else { LoadSamples(); PopulateSampleMenus(); if (!(this.LoadedSamples.Count == 0)) { b.Caption = "Unload Samples"; } try // attempt to restore the last view before unloading samples { this.CategoryMenu.SelectItem(this.LastViewCategory); this.SampleMenu.SelectItem(this.LastViewTitle); } catch (Exception) { // swallowing Exception on purpose } } } else if (b.Name == "Configure") // enter configuration screen { this.TrayManager.RemoveWidgetFromTray("StartStop"); this.TrayManager.RemoveWidgetFromTray("UnloadReload"); this.TrayManager.RemoveWidgetFromTray("Configure"); this.TrayManager.RemoveWidgetFromTray("Quit"); this.TrayManager.MoveWidgetToTray("Apply", TrayLocation.Right); this.TrayManager.MoveWidgetToTray("Back", TrayLocation.Right); for (int i = 0; i < this.Thumbs.Count; i++) { this.Thumbs[i].Hide(); } while (this.TrayManager.TrayContainer[(int)TrayLocation.Center].IsVisible) { this.TrayManager.RemoveWidgetFromTray(TrayLocation.Center, 0); } while (this.TrayManager.TrayContainer[(int)TrayLocation.Left].IsVisible) { this.TrayManager.RemoveWidgetFromTray(TrayLocation.Left, 0); } this.TrayManager.MoveWidgetToTray("ConfigLabel", TrayLocation.Left); this.TrayManager.MoveWidgetToTray(this.RendererMenu, TrayLocation.Left); this.TrayManager.MoveWidgetToTray("ConfigSeparator", TrayLocation.Left); this.RendererMenu.SelectItem(Root.RenderSystem.Name); WindowResized(RenderWindow); } else if (b.Name == "Back") // leave configuration screen { while (this.TrayManager.GetWidgetCount(this.RendererMenu.TrayLocation) > 3) { this.TrayManager.DestroyWidget(this.RendererMenu.TrayLocation, 3); } while (this.TrayManager.GetWidgetCount(TrayLocation.None) != 0) { this.TrayManager.MoveWidgetToTray(TrayLocation.None, 0, TrayLocation.Left); } this.TrayManager.RemoveWidgetFromTray("Apply"); this.TrayManager.RemoveWidgetFromTray("Back"); this.TrayManager.RemoveWidgetFromTray("ConfigLabel"); this.TrayManager.RemoveWidgetFromTray(this.RendererMenu); this.TrayManager.RemoveWidgetFromTray("ConfigSeparator"); this.TrayManager.MoveWidgetToTray("StartStop", TrayLocation.Right); this.TrayManager.MoveWidgetToTray("UnloadReload", TrayLocation.Right); this.TrayManager.MoveWidgetToTray("Configure", TrayLocation.Right); this.TrayManager.MoveWidgetToTray("Quit", TrayLocation.Right); WindowResized(RenderWindow); } else if (b.Name == "Apply") // apply any changes made in the configuration screen { bool reset = false; string selectedRenderSystem = string.Empty; switch (this.RendererMenu.SelectedItem) { case "Axiom DirectX9 Rendering Subsystem": selectedRenderSystem = "DirectX9"; break; case "Axiom Xna Rendering Subsystem": selectedRenderSystem = "Xna"; break; case "Axiom OpenGL (OpenTK) Rendering Subsystem": selectedRenderSystem = "OpenGL"; break; default: throw new NotImplementedException(); } if (selectedRenderSystem != string.Empty) { var options = Root.RenderSystems[selectedRenderSystem].ConfigOptions; var newOptions = new Collections.NameValuePairList(); // collect new settings and decide if a reset is needed if (this.RendererMenu.SelectedItem != Root.RenderSystem.Name) { reset = true; } for (int i = 3; i < this.TrayManager.GetWidgetCount(this.RendererMenu.TrayLocation); i++) { var menu = (SelectMenu)this.TrayManager.GetWidget(this.RendererMenu.TrayLocation, i); if (menu.SelectedItem != options[menu.Caption].Value) { reset = true; } newOptions[menu.Caption] = menu.SelectedItem; } // reset with new settings if necessary if (reset) { Reconfigure(selectedRenderSystem, newOptions); } } } else { Root.QueueEndRendering(); // exit browser } }
private GpuProgram CreateGpuProgram(Program shaderProgram, ProgramWriter programWriter, string language, string profiles, string[] profilesList, string cachePath) { StreamWriter sourceCodeStringStream = null; int programHashCode; string programName; //Generate source code programWriter.WriteSourceCode(sourceCodeStringStream, shaderProgram); programHashCode = sourceCodeStringStream.GetHashCode(); //Generate program name programName = programHashCode.ToString(); if (shaderProgram.Type == GpuProgramType.Vertex) { programName += "_VS"; } else if (shaderProgram.Type == GpuProgramType.Fragment) { programName += "_FS"; } HighLevelGpuProgram gpuProgram; //Try to get program by name gpuProgram = (HighLevelGpuProgram)HighLevelGpuProgramManager.Instance.GetByName(programName); //Case the program doesn't exist yet if (gpuProgram == null) { //Create new GPU program. gpuProgram = HighLevelGpuProgramManager.Instance.CreateProgram(programName, ResourceGroupManager. DefaultResourceGroupName, language, shaderProgram.Type); //Case cache directory specified -> create program from file if (cachePath == string.Empty) { string programFullName = programName + "." + language; string programFileName = cachePath + programFullName; bool writeFile = true; //Check if program file already exists if (File.Exists(programFileName)) { writeFile = true; } else { writeFile = false; } if (writeFile) { var outFile = new StreamWriter(programFileName); outFile.Write(sourceCodeStringStream); outFile.Close(); } gpuProgram.SourceFile = programFullName; } else // no cache directory specified -> create program from system memory { //TODO // gpuProgram.Source = sourceCodeStringStream; } var gpuParams = new Collections.NameValuePairList(); gpuParams.Add("entry_point", shaderProgram.EntryPointFunction.Name); gpuProgram.SetParameters(gpuParams); gpuParams.Clear(); // HLSL program requires specific target profile settings - we have to split the profile string. if (language == "hlsl") { foreach (var it in profilesList) { if (GpuProgramManager.Instance.IsSyntaxSupported(it)) { gpuParams.Add("target", it); gpuProgram.SetParameters(gpuParams); gpuParams.Clear(); break; } } } gpuParams.Add("profiles", profiles); gpuProgram.SetParameters(gpuParams); gpuProgram.Load(); //Case an error occurred if (gpuProgram.HasCompileError) { gpuProgram = null; return(gpuProgram); } //Add the created GPU prgram to local cache if (gpuProgram.Type == GpuProgramType.Vertex) { this.vertexShaderMap[programName] = gpuProgram; } else if (gpuProgram.Type == GpuProgramType.Fragment) { this.fragmentShaderMap[programName] = gpuProgram; } } return(gpuProgram); }
private GpuProgram CreateGpuProgram( Program shaderProgram, ProgramWriter programWriter, string language, string profiles, string[] profilesList, string cachePath ) { StreamWriter sourceCodeStringStream = null; int programHashCode; string programName; //Generate source code programWriter.WriteSourceCode( sourceCodeStringStream, shaderProgram ); programHashCode = sourceCodeStringStream.GetHashCode(); //Generate program name programName = programHashCode.ToString(); if ( shaderProgram.Type == GpuProgramType.Vertex ) { programName += "_VS"; } else if ( shaderProgram.Type == GpuProgramType.Fragment ) { programName += "_FS"; } HighLevelGpuProgram gpuProgram; //Try to get program by name gpuProgram = (HighLevelGpuProgram)HighLevelGpuProgramManager.Instance.GetByName( programName ); //Case the program doesn't exist yet if ( gpuProgram == null ) { //Create new GPU program. gpuProgram = HighLevelGpuProgramManager.Instance.CreateProgram( programName, ResourceGroupManager. DefaultResourceGroupName, language, shaderProgram.Type ); //Case cache directory specified -> create program from file if ( cachePath == string.Empty ) { string programFullName = programName + "." + language; string programFileName = cachePath + programFullName; bool writeFile = true; //Check if program file already exists if ( File.Exists( programFileName ) ) { writeFile = true; } else { writeFile = false; } if ( writeFile ) { var outFile = new StreamWriter( programFileName ); outFile.Write( sourceCodeStringStream ); outFile.Close(); } gpuProgram.SourceFile = programFullName; } else // no cache directory specified -> create program from system memory { //TODO // gpuProgram.Source = sourceCodeStringStream; } var gpuParams = new Collections.NameValuePairList(); gpuParams.Add( "entry_point", shaderProgram.EntryPointFunction.Name ); gpuProgram.SetParameters( gpuParams ); gpuParams.Clear(); // HLSL program requires specific target profile settings - we have to split the profile string. if ( language == "hlsl" ) { foreach ( var it in profilesList ) { if ( GpuProgramManager.Instance.IsSyntaxSupported( it ) ) { gpuParams.Add( "target", it ); gpuProgram.SetParameters( gpuParams ); gpuParams.Clear(); break; } } } gpuParams.Add( "profiles", profiles ); gpuProgram.SetParameters( gpuParams ); gpuProgram.Load(); //Case an error occurred if ( gpuProgram.HasCompileError ) { gpuProgram = null; return gpuProgram; } //Add the created GPU prgram to local cache if ( gpuProgram.Type == GpuProgramType.Vertex ) { this.vertexShaderMap[ programName ] = gpuProgram; } else if ( gpuProgram.Type == GpuProgramType.Fragment ) { this.fragmentShaderMap[ programName ] = gpuProgram; } } return gpuProgram; }
protected override Resource _create(string name, ulong handle, string group, bool isManual, IManualResourceLoader loader, Collections.NameValuePairList createParams) { string paramSyntax = string.Empty; string paramType = string.Empty; if (createParams == null || createParams.ContainsKey("syntax") == false || createParams.ContainsKey("type") == false) { throw new AxiomException("You must supply 'syntax' and 'type' parameters"); } else { paramSyntax = createParams["syntax"]; paramType = createParams["type"]; } CreateGpuProgramDelegate iter = null; if (this._programMap.ContainsKey(paramSyntax)) { iter = this._programMap[paramSyntax]; } else { // No factory, this is an unsupported syntax code, probably for another rendersystem // Create a basic one, it doesn't matter what it is since it won't be used return(new GLES2GpuProgram(this, name, handle, group, isManual, loader)); } GpuProgramType gpt; if (paramType == "vertex_program") { gpt = GpuProgramType.Vertex; } else { gpt = GpuProgramType.Fragment; } return(iter(this, name, handle, group, isManual, loader, gpt, paramSyntax)); }
protected override Resource _create(string name, ulong handle, string group, bool isManual, IManualResourceLoader loader, Collections.NameValuePairList createParams) { return(new GLES2Texture(this, name, handle, group, isManual, loader, this.glSupport)); }
/// <summary> /// </summary> /// <param name="name"> </param> /// <param name="handle"> </param> /// <param name="group"> </param> /// <param name="isManual"> </param> /// <param name="loader"> </param> /// <param name="createParams"> </param> /// <returns> </returns> protected override Resource _create(string name, ulong handle, string group, bool isManual, IManualResourceLoader loader, Collections.NameValuePairList createParams) { if (createParams == null || !createParams.ContainsKey("syntax") || !createParams.ContainsKey("type")) { throw new NotImplementedException("You must supply 'syntax' and 'type' parameters"); } GpuProgramType gpt = 0; CreateGpuProgramDelegate iter = this._programMap[createParams["syntax"]]; if (iter == null) { return(null); } string syntaxcode = string.Empty; foreach (var pair in this._programMap) { if (pair.Value == iter) { syntaxcode = pair.Key; break; } } if (createParams["type"] == "vertex_program") { gpt = GpuProgramType.Vertex; } else if (createParams["type"] == "fragment_program") { gpt = GpuProgramType.Fragment; } else { throw new AxiomException("Unknown GpuProgramType : " + createParams["type"]); } return(iter(this, name, handle, group, isManual, loader, gpt, syntaxcode)); }