Exemple #1
0
 public static SemanticShader GetSemanticShader(this CSShaderCode shaderCode, CSSLFileGroup fullnames)
 {
     if (shaderCode.GetType().IsSubclassOf(typeof(VertexCSShaderCode)))
     {
         return(new SemanticVertexShader(shaderCode, fullnames));
     }
     else if (shaderCode.GetType().IsSubclassOf(typeof(FragmentCSShaderCode)))
     {
         return(new SemanticFragmentShader(shaderCode, fullnames));
     }
     else if (shaderCode.GetType().IsSubclassOf(typeof(GeometryCSShaderCode)))
     {
         return(new SemanticGeometryShader(shaderCode, fullnames));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Exemple #2
0
 public SemanticFragmentShader(CSShaderCode shaderCode, CSSLFileGroup fullname)
     : base(shaderCode, fullname)
 {
 }
Exemple #3
0
 public SemanticGeometryShader(CSShaderCode shaderCode, CSSLFileGroup fileGroup)
     : base(shaderCode, fileGroup)
 {
 }
Exemple #4
0
        private static TranslationInfo TranslateCSharpShaderLanguage2GLSL(CSSLFileGroup fileGroup)
        {
            TranslationInfo translationInfo = new TranslationInfo()
            {
                fileGroup = fileGroup,
            };

            CSharpCodeProvider objCSharpCodePrivoder = new CSharpCodeProvider();

            CompilerParameters objCompilerParameters = new CompilerParameters();

            objCompilerParameters.ReferencedAssemblies.Add(
                typeof(CSharpShadingLanguage.CSShaderCode).Assembly.Location);
            objCompilerParameters.GenerateExecutable      = false;
            objCompilerParameters.GenerateInMemory        = true;
            objCompilerParameters.IncludeDebugInformation = true;
            CompilerResults cr = objCSharpCodePrivoder.CompileAssemblyFromFile(
                objCompilerParameters, fileGroup.ToArray());

            if (cr.Errors.HasErrors)
            {
                translationInfo.errors = cr.Errors;
            }
            else
            {
                //List<SemanticShader> semanticShaderList = new List<SemanticShader>();
                //Assembly assembly = cr.CompiledAssembly;
                //Type[] types = assembly.GetTypes();
                //foreach (var type in types)
                //{
                //    if (type.IsSubclassOf(typeof(CSShaderCode)))
                //    {
                //        CSShaderCode shaderCode = Activator.CreateInstance(type) as CSShaderCode;
                //        SemanticShader semanticShader = shaderCode.Dump(fullname);
                //        semanticShaderList.Add(semanticShader);
                //    }
                //}

                //foreach (var item in semanticShaderList)
                //{
                //    SemanticShaderInfo info = new SemanticShaderInfo();
                //    info.codeUpdated = item.Dump2File();
                //    info.shader = item;
                //    translationInfo.semanticShaderList.Add(info);
                //}

                // 下面是Linq的写法。
                var result = from semanticShader in
                             (from type in cr.CompiledAssembly.GetTypes()
                              where type.IsSubclassOf(typeof(CSShaderCode))
                              select(Activator.CreateInstance(type) as CSShaderCode).GetSemanticShader(fileGroup))
                             select new SemanticShaderInfo()
                {
                    codeUpdated = semanticShader.Dump2File(), shader = semanticShader
                };

                translationInfo.semanticShaderList = result.ToList();
            }

            return(translationInfo);
        }
 public SemanticShader(CSShaderCode shaderCode, CSSLFileGroup fileGroup)
 {
     this.shaderCode = shaderCode;
     this.fileGroup  = fileGroup;
 }
Exemple #6
0
 public SemanticVertexShader(CSShaderCode shaderCode, CSSLFileGroup fullname)
     : base(shaderCode, fullname)
 {
 }