Example #1
0
        private static string Compile(string shaderCode, ShaderType shaderType, string shaderFileDir)
        {
            string GetIncludeCode(string includeName)
            {
                var includeFileName = Path.Combine(shaderFileDir, includeName);

                if (File.Exists(includeFileName))
                {
                    return(File.ReadAllText(includeFileName));
                }
                return($"#error include file '{includeName}' not found");
            }

            try
            {
                using (var shader = new ShaderGL(shaderType))
                {
                    var expandedCode = ShaderLoader.ResolveIncludes(shaderCode, GetIncludeCode);
                    shader.Compile(expandedCode);
                    return(shader.Log);
                }
            }
            catch (AccessViolationException)
            {
                return($"(1 1):ERROR: OpenGL shader compiler has crashed");
            }
        }
Example #2
0
 private static string CompileOnGPU(string shaderCode, string sShaderType)
 {
     if (!mappingContentTypeToShaderType.TryGetValue(sShaderType, out ShaderType shaderType))
     {
         var time = DateTime.Now.ToString("HH.mm.ss.fff");
         if (ShaderContentTypes.AutoDetect == sShaderType)
         {
             shaderType = AutoDetectShaderType(shaderCode);
             VsStatusBar.SetText($"{time} Auto detecting shader type to '{shaderType}'");
         }
         else
         {
             VsStatusBar.SetText($"{time} Unsupported shader type '{sShaderType}' by OpenTK shader compiler. Use an external compiler");
         }
     }
     try
     {
         using (var shader = new ShaderGL(shaderType))
         {
             shader.Compile(shaderCode);
             return(shader.Log);
         }
     }
     catch (AccessViolationException)
     {
         return($"(1 1):ERROR: OpenGL shader compiler has crashed");
     }
 }
Example #3
0
 private static string CompileOnGPU(string shaderCode, ShaderType shaderType)
 {
     try
     {
         using (var shader = new ShaderGL(shaderType))
         {
             shader.Compile(shaderCode);
             return(shader.Log);
         }
     }
     catch (AccessViolationException)
     {
         return($"(1 1):ERROR: OpenGL shader compiler has crashed");
     }
 }
Example #4
0
        private static string Compile(string shaderCode, ShaderType shaderType, string shaderFileDir)
        {
            string SpecialCommentReplacement(string code, string specialComment)
            {
                var lines = code.Split(new[] { '\n' }, StringSplitOptions.None);                 //if UNIX style line endings still working so do not use Envirnoment.NewLine

                for (int i = 0; i < lines.Length; ++i)
                {
                    var index = lines[i].IndexOf(specialComment);                     // search for special comment
                    if (-1 != index)
                    {
                        lines[i] = lines[i].Substring(index + specialComment.Length);                         // remove everything before special comment
                    }
                }
                return(lines.Combine("\n"));
            }

            string GetIncludeCode(string includeName)
            {
                var includeFileName = Path.Combine(shaderFileDir, includeName);

                if (File.Exists(includeFileName))
                {
                    var includeCode = File.ReadAllText(includeFileName);
                    includeCode = SpecialCommentReplacement(includeCode, "//!");
                    return(includeCode);
                }
                return($"#error include file '{includeName}' not found");
            }

            try
            {
                using (var shader = new ShaderGL(shaderType))
                {
                    shaderCode = SpecialCommentReplacement(shaderCode, "//!");
                    shaderCode = SpecialCommentReplacement(shaderCode, "//?");
                    var expandedCode = ShaderLoader.ResolveIncludes(shaderCode, GetIncludeCode);
                    shader.Compile(expandedCode);
                    return(shader.Log);
                }
            }
            catch (AccessViolationException)
            {
                return($"(1 1):ERROR: OpenGL shader compiler has crashed");
            }
        }
Example #5
0
 private static string CompileOnGPU(string shaderCode, string shaderType)
 {
     // detect shader type
     if (!mappingContentTypeToShaderType.TryGetValue(shaderType, out ShaderType glShaderType))
     {
         OutMessage.PaneAndBar($"Unsupported shader type '{shaderType}' by OpenTK shader compiler. Use an external compiler");
     }
     try
     {
         using (var shader = new ShaderGL(glShaderType))
         {
             shader.Compile(shaderCode);
             return(shader.Log);
         }
     }
     catch (AccessViolationException)
     {
         return($"(1 1):ERROR: OpenGL shader compiler has crashed");
     }
 }