void InsertBuiltIn(BuiltIn b, bool asUniform) { var shaderCtrl = ActiveEditorControl(); if (shaderCtrl == null) { return; } if (asUniform) { string text = $"uniform {b.DataType} {b.Name};"; shaderCtrl.InsertText(shaderCtrl.CurrentPosition, text); } else { //layout(location = 1) in vec4 vcolor; string code = shaderCtrl.Text; code = code.Replace(" ", ""); int count = 0; int index = code.IndexOf("(location=", 0); while (index >= 0) { count++; index = code.IndexOf("(location=", index + 10); } string text = $"layout(location = {count}) in {b.DataType} {b.Name};"; shaderCtrl.InsertText(shaderCtrl.CurrentPosition, text); } }
static void Register(string name, string datatype, string description, Action <int, Rhino.Display.DisplayPipeline> setup) { if (_uniformBuiltins == null) { _uniformBuiltins = new List <BuiltIn>(); } var builtin = new BuiltIn(name, datatype, description, setup); _uniformBuiltins.Add(builtin); }
public GLSLEditorDialog(GLSLViewModel model, bool includeTessellationShaders, string componentName) { _dlgOpenCount++; _tabarea = new TabControl(); _shaderControls = new EditorPage[(int)ShaderType.Fragment + 1]; var checkCommand = new CheckCommand[_shaderControls.Length]; for (int i = 0; i < _shaderControls.Length; i++) { ShaderType st = (ShaderType)i; _shaderControls[i] = new EditorPage(_tabarea); checkCommand[i] = new CheckCommand(); checkCommand[i].DataContext = _shaderControls[i]; checkCommand[i].MenuText = st.ToString() + " Shader"; checkCommand[i].BindDataContext <bool>("Checked", "Visible"); int current = i; checkCommand[i].CheckedChanged += (s, e) => { if (checkCommand[current].Checked) { ShowTab(st); } else { HideTab(st); } }; } DataContext = model; Title = $"GLSL Shader - {componentName}"; var uniformBuiltinMenu = new ButtonMenuItem { Text = "Insert Built-In Uniform" }; foreach (var bi in BuiltIn.GetUniformBuiltIns()) { var menuitem = uniformBuiltinMenu.Items.Add(new SimpleCommand(bi.Name, () => InsertBuiltIn(bi, true))); menuitem.ToolTip = $"({bi.DataType}) {bi.Description}"; } var attributeBuiltinMenu = new ButtonMenuItem { Text = "Insert Built-In Attribute" }; foreach (var bi in BuiltIn.GetAttributeBuiltIns()) { var menuitem = attributeBuiltinMenu.Items.Add(new SimpleCommand(bi.Name, () => InsertBuiltIn(bi, false))); menuitem.ToolTip = $"({bi.DataType}) {bi.Description}"; } var functionBuiltinMenu = new ButtonMenuItem { Text = "Insert Function (glslify)" }; var glslBuiltinMenu = new ButtonMenuItem { Text = "StackGL Items" }; foreach (var package in GlslifyPackage.AvailablePackages) { MenuItem menuitem = null; bool isStackGl = package.Name.Equals("matcap", StringComparison.OrdinalIgnoreCase) || package.Name.StartsWith("glsl-", StringComparison.OrdinalIgnoreCase); if (isStackGl) { menuitem = glslBuiltinMenu.Items.Add(new SimpleCommand(package.Name, () => InsertGlslifyFunction(package))); } else { menuitem = functionBuiltinMenu.Items.Add(new SimpleCommand(package.Name, () => InsertGlslifyFunction(package))); } menuitem.ToolTip = $"{package.Description}\n{package.HomePage}"; } functionBuiltinMenu.Items.Add(glslBuiltinMenu); Menu = new MenuBar { Items = { new ButtonMenuItem { Text = "&File", Items ={ new SimpleCommand("&Save", SaveGLSL) } }, new ButtonMenuItem { Text = "&Edit", Items = { uniformBuiltinMenu, attributeBuiltinMenu, functionBuiltinMenu, new SeparatorMenuItem(), new SimpleCommand("glslify code", GlslifyCode) } }, new ButtonMenuItem { Text = "&View", Items = { checkCommand[(int)ShaderType.Vertex], checkCommand[(int)ShaderType.Geometry], checkCommand[(int)ShaderType.Fragment], } } } }; Resizable = true; Size = new Eto.Drawing.Size(600, 600); var DefaultButton = new Button() { Text = "OK", Command = new SimpleCommand("OK", () => Close()) }; var AbortButton = new Button() { Text = "Cancel", Command = new SimpleCommand("Cancel", () => { Canceled = true; Close(); }) }; var button_stack = new StackLayout { Padding = 5, Orientation = Orientation.Horizontal, Items = { null, DefaultButton, AbortButton } }; // Just show the common shaders by default ShowTab(ShaderType.Vertex); if (includeTessellationShaders) { ShowTab(ShaderType.TessellationControl); ShowTab(ShaderType.TessellationEval); } ShowTab(ShaderType.Geometry); ShowTab(ShaderType.Fragment); //ShowTab(ShaderType.TransformFeedbackVertex); _tabarea.SelectedIndex = 0; _errorList = new ListBox(); _errorList.Height = 40; Content = new StackLayout { Padding = new Eto.Drawing.Padding(5), Orientation = Orientation.Vertical, Spacing = 5, Items = { new StackLayoutItem(_tabarea, HorizontalAlignment.Stretch, true), new StackLayoutItem(_errorList, HorizontalAlignment.Stretch), new StackLayoutItem(button_stack, HorizontalAlignment.Stretch) }, }; GLShaderComponentBase.AnimationTimerEnabled = true; OnShadersCompiled(null, EventArgs.Empty); }