Beispiel #1
0
 /// <summary>
 /// Replaces the old filters with the new list of filters.
 /// </summary>
 /// <param name="models">new filter configuration</param>
 /// <param name="statisticsPoint">index of the statistics point</param>
 /// <param name="context"></param>
 /// <param name="changed">This indicates which image equations were changed by the new filter configuration</param>
 public void Apply(List <FilterModel> models, int statisticsPoint, OpenGlContext context, bool[] changed)
 {
     DisposeUnusedFilter(models, filter, context);
     filter = models;
     Debug.Assert(statisticsPoint >= 0 && statisticsPoint <= filter.Count);
     StatisticsPoint = statisticsPoint;
     OnChanged(changed);
 }
Beispiel #2
0
            public void Dispose(OpenGlContext context)
            {
                var disable = context.Enable();

                Parameters.Dispose();
                Model.Dispose();
                if (disable)
                {
                    context.Disable();
                }
            }
Beispiel #3
0
        private void HandleTexture(string[] pars, OpenGlContext glContext)
        {
            if (pars.Length < 2)
            {
                throw new Exception("not enough arguments for #texture provided");
            }
            var name = pars[0];

            if (!variableRegex.IsMatch(pars[1]))
            {
                throw new Exception("invalid function name (only alphanumeric characters allowed)");
            }

            if (TextureParameters.Count + 1 >= glContext.MaxTextureUnits)
            {
                throw new Exception($"Too many texture bindings. Only {glContext.MaxTextureUnits} texture bindings are available on this GPU");
            }

            TextureParameters.Add(new FilterTextureParameterModel(name, pars[1]));
        }
Beispiel #4
0
        /// <summary>
        /// disposes all filters from old list which are no longer used in new list
        /// </summary>
        /// <param name="newList"></param>
        /// <param name="oldList"></param>
        /// <param name="context"></param>
        public static void DisposeUnusedFilter(IReadOnlyList <FilterModel> newList, IReadOnlyList <FilterModel> oldList, OpenGlContext context)
        {
            var disable = context.Enable();

            foreach (var old in oldList)
            {
                // delete if the filter is not used in new list
                if (newList.All(newFilter => !ReferenceEquals(newFilter, old)))
                {
                    old.Dispose();
                }
            }

            if (disable)
            {
                context.Disable();
            }
        }
Beispiel #5
0
        public FilterLoader(string filename, OpenGlContext glContext)
        {
            this.Filename = filename;
            Name          = filename;
            Description   = "";
            int lineNumber = 1;

            // Read the file and display it line by line.
            System.IO.StreamReader file =
                new System.IO.StreamReader(filename);

            try
            {
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    if (line.StartsWith("#paramprop"))
                    {
                        HandleParamprop(GetParameters(line.Substring("#paramprop".Length)));
                        ShaderSource += "\n"; // remember line for error information
                    }
                    else if (line.StartsWith("#param"))
                    {
                        HandleParam(GetParameters(line.Substring("#param".Length)));
                        ShaderSource += "\n"; // remember line for error information
                    }
                    else if (line.StartsWith("#texture"))
                    {
                        HandleTexture(GetParameters(line.Substring("#texture".Length)), glContext);
                        ShaderSource += "\n"; // remember line for error information
                    }
                    else if (line.StartsWith("#setting"))
                    {
                        var whole      = line.Substring("#setting".Length);
                        var parameters = GetParameters(whole);
                        // get the second parameter as one string (without , seperation)
                        try
                        {
                            var idx = whole.IndexOf(",", StringComparison.Ordinal);
                            whole = whole.Substring(idx + 1);
                        }
                        catch (Exception)
                        {
                            // no second parameter available
                            whole = "";
                        }

                        whole = whole.TrimStart(' ');
                        whole = whole.TrimEnd(' ');

                        HandleSetting(parameters, whole);
                        ShaderSource += "\n"; // remember line for error information
                    }
                    else if (line.StartsWith("#keybinding"))
                    {
                        HandleKeybinding(GetParameters(line.Substring("#keybinding".Length)));
                        ShaderSource += "\n"; // remember line for error information
                    }
                    else
                    {
                        ShaderSource += line + "\n";
                    }
                    ++lineNumber;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message + " at line " + lineNumber);
            }
            finally
            {
                file.Close();
            }
        }