Example #1
0
 public bool CheckForShaderChange()
 {
     //test if we even have file -> no files nothing to be done
     if (ReferenceEquals(null, shaderWatcherVertex) || ReferenceEquals(null, shaderWatcherFragment))
     {
         return(false);
     }
     //test if any file is dirty
     if (!shaderWatcherVertex.Dirty && !shaderWatcherFragment.Dirty)
     {
         return(false);
     }
     try
     {
         shader = ShaderLoader.FromFiles(shaderWatcherVertex.FullPath, shaderWatcherFragment.FullPath);
         shaderWatcherVertex.Dirty   = false;
         shaderWatcherFragment.Dirty = false;
         //ShaderLoaded?.Invoke();
         return(true);
     }
     catch (IOException e)
     {
         var exception = new ShaderException(e.Message, string.Empty);
         ShowDebugDialog(exception);
     }
     catch (ShaderException e)
     {
         ShowDebugDialog(e);
     }
     return(false);
 }
Example #2
0
        private void ShowExceptionForm(ShaderException e, string resourceName)
        {
            var name = contentManager.GetFilePath(resourceName);

            name = string.IsNullOrEmpty(name) ? resourceName : name;
            new FormShaderExceptionFacade().ShowModal(e, name);
        }
Example #3
0
 /// <summary>
 /// Extracts the name of the file.
 /// </summary>
 /// <param name="e">The e.</param>
 /// <returns></returns>
 public static string ExtractFileName(this ShaderException e)
 {
     if (e.Data.Contains(ExceptionDataFileName))
     {
         return(e.Data[ExceptionDataFileName] as string);
     }
     return(string.Empty);
 }
Example #4
0
        /// <summary>
        /// Shows the modal.
        /// </summary>
        /// <param name="e">The e.</param>
        /// <returns></returns>
        public string ShowModal(ShaderException e)
        {
            form = new FormShaderException
            {
                Text = e.Message
            };
            var compileException = e as ShaderCompileException;

            if (compileException is null)
            {
                form.ShaderSourceCode = string.Empty;
            }
            else
            {
                form.ShaderSourceCode = compileException.ShaderCode;
            }
            //load error list after source code is loaded for highlighting of error to work
            form.Errors.Clear();
            var log = new ShaderLog(e.ShaderLog);

            foreach (var logLine in log.Lines)
            {
                form.Errors.Add(logLine);
            }
            var shaderFileName = e.ExtractFileName();

            if (string.IsNullOrEmpty(shaderFileName))
            {
                foreach (var logLine in log.Lines)
                {
                    Debug.Print(shaderFileName + "(" + logLine.LineNumber + "): " + logLine.Message);
                }
            }
            form.Select(0);
            form.TopMost = true;
            var oldSource = form.ShaderSourceCode;

            closeOnFileChange = true;
            var result = form.ShowDialog();

            closeOnFileChange = false;
            var newShaderSourceCode = DialogResult.OK == result ? form.ShaderSourceCode : oldSource;

            form = null;

            if (compileException is null)
            {
                return(newShaderSourceCode);
            }
            if (newShaderSourceCode != compileException.ShaderCode && !string.IsNullOrEmpty(shaderFileName))
            {
                //save changed code to shader file
                File.WriteAllText(shaderFileName, newShaderSourceCode);
            }
            return(newShaderSourceCode);
        }
Example #5
0
        /// <summary>
        /// Shows the modal.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="name">Name or file name of the shader</param>
        public void ShowModal(ShaderException exception, string name)
        {
            form = new FormShaderException
            {
                Text = $"'{name}': {exception.GetType()}"
            };
            var compileException = exception as ShaderCompileException;

            if (compileException is null)
            {
                form.ShaderSourceCode = string.Empty;
            }
            else
            {
                form.Text            += " for shader type " + compileException.ShaderType;
                form.ShaderSourceCode = compileException.ShaderSourceCode;
            }
            //load error list after source code is loaded for highlighting of error to work
            form.Errors.Clear();
            var log = new ShaderLogParser(exception.Message);

            foreach (var logLine in log.Lines)
            {
                form.Errors.Add(logLine);
            }
            foreach (var logLine in log.Lines)
            {
                Debug.Print(name + "(" + logLine.LineNumber + "): " + logLine.Message);
            }
            form.Select(0);
            form.TopMost = true;
            var oldSource = form.ShaderSourceCode;

            closeOnFileChange = true;
            var result = form.ShowDialog();

            closeOnFileChange = false;
            var newShaderSourceCode = DialogResult.OK == result ? form.ShaderSourceCode : oldSource;

            form = null;

            if (compileException is null)
            {
                return;
            }
            if (newShaderSourceCode != compileException.ShaderSourceCode && File.Exists(name))
            {
                //save changed code to shader file
                File.WriteAllText(name, newShaderSourceCode);
            }
        }
Example #6
0
 private void ShowDebugDialog(ShaderException exception)
 {
     var newShaderCode = form.ShowModal(exception);
 }
Example #7
0
 private void ShaderErrorHandling(ShaderException e)
 {
     e.Data[ShaderLoader.ExceptionDataFileName] = contentManager.LastChangedFilePath; //TODO: make cleaner after removal of old stuff
     new FormShaderExceptionFacade().ShowModal(e);
 }