protected override void SolveInstance(IGH_DataAccess data)
        {
            string resourceName = "";
            string defines      = "";

            data.GetData(0, ref resourceName);
            data.GetData(1, ref defines);
            defines = defines.Replace("\\n", "\n");
            if (!resourceName.Equals(_resourceName) || !defines.Equals(_defines))
            {
                _resourceName = resourceName;
                _defines      = defines;
                _model        = new GLSLViewModel();
            }
            if (_firstTime && !string.IsNullOrWhiteSpace(_model.VertexShaderCode) && !string.IsNullOrWhiteSpace(_resourceName))
            {
                if (_model.CompileProgram())
                {
                    if (_model.ProgramId != 0)
                    {
                        RHC_UpdateShader(_resourceName, _defines, _model.ProgramId);
                        _model.RecycleCurrentProgram = false;

                        var doc = Rhino.RhinoDoc.ActiveDoc;
                        if (doc != null)
                        {
                            doc.Views.Redraw();
                        }
                        GLShaderComponentBase.RedrawViewportControl();
                    }
                }
            }
            _firstTime = false;
        }
 public ShaderEditorControl(ShaderType type, GLSLViewModel model)
     : base(CodeEditor.ScriptEditorLanguage.GLSL)
 {
     _shaderType  = type;
     _model       = model;
     Text         = model.GetCode(type);
     CharAdded   += ShaderControlCharAdded;
     TextChanged += ShaderControlTextChanged;
     MarkErrors();
     _compileTimer.Elapsed += CompileTimerTick;
     _compileTimer.Interval = 1; //every second
 }
Example #3
0
 public ShaderEditorControl(ShaderType type, GLSLViewModel model)
     : base(Eto.CodeEditor.ProgrammingLanguage.GLSL)
 {
     _shaderType  = type;
     _model       = model;
     Text         = model.GetCode(type);
     CharAdded   += ShaderControlCharAdded;
     TextChanged += ShaderControlTextChanged;
     MarkErrors();
     _compileTimer.Elapsed += CompileTimerTick;
     _compileTimer.Interval = 1; //every second
     IsFoldingMarginVisible = true;
 }
        public override void AppendAdditionalMenuItems(System.Windows.Forms.ToolStripDropDown menu)
        {
            base.AppendAdditionalMenuItems(menu);

            var tsi = new System.Windows.Forms.ToolStripMenuItem("&Edit code...", null, (sender, e) =>
            {
                OpenEditor();
            });

            tsi.Font = new System.Drawing.Font(tsi.Font, System.Drawing.FontStyle.Bold);
            menu.Items.Add(tsi);
            menu.Items.Add(new System.Windows.Forms.ToolStripMenuItem("Reset", null, (sender, e) =>
            {
                if (Rhino.UI.Dialogs.ShowMessage("Reset the code to what is built-in?", "reset", Rhino.UI.ShowMessageButton.OKCancel, Rhino.UI.ShowMessageIcon.Question) == Rhino.UI.ShowMessageResult.OK)
                {
                    _model = new GLSLViewModel();
                }
            })
                           );
        }
Example #5
0
        private void OnShadersCompiled(object sender, EventArgs e)
        {
            GLSLViewModel model = DataContext as GLSLViewModel;

            if (model != null)
            {
                var errors = model.AllCompileErrors();
                _errorList.Items.Clear();
                if (errors.Length == 0)
                {
                    _errorList.Items.Add("Compile output (no errors)");
                    _errorList.TextColor = Eto.Drawing.Colors.Gray;
                }
                else
                {
                    _errorList.TextColor = Eto.Drawing.Colors.Red;
                    foreach (var err in errors)
                    {
                        _errorList.Items.Add(err.ToString());
                    }
                }
            }
        }
Example #6
0
        public GLSLEditorDialog(GLSLViewModel model)
        {
            _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";
            Menu        = new MenuBar
            {
                Items =
                {
                    new ButtonMenuItem
                    {
                        Text  = "&File",
                        Items ={ new SimpleCommand("&Save",             SaveGLSL) }
                    },
                    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);

            DefaultButton = new Button()
            {
                Text = "OK", Command = new SimpleCommand("OK", () => Close(true))
            };
            AbortButton = new Button()
            {
                Text = "Cancel", Command = new SimpleCommand("Cancel", () => Close(false))
            };
            var button_stack = new StackLayout
            {
                Padding     = 5,
                Orientation = Orientation.Horizontal,
                Items       = { null, DefaultButton, AbortButton }
            };

            // Just show the common shaders by default
            ShowTab(ShaderType.Vertex);
            ShowTab(ShaderType.Geometry);
            ShowTab(ShaderType.Fragment);
            //ShowTab(ShaderType.TransformFeedbackVertex);
            //ShowTab(ShaderType.TessellationControl);
            //ShowTab(ShaderType.TessellationEval);
            _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);
        }
Example #7
0
 public Shader(ShaderType type, GLSLViewModel parent)
 {
     ShaderType = type;
 }
Example #8
0
        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);
        }