protected override HlslCompiledShaders Read(ContentReader input, HlslCompiledShaders existingInstance)
        {
            HlslCompiledShaders compiledShaders = new HlslCompiledShaders();
            int numCompiledShaders = input.ReadInt32();

            for (int i = 0; i < numCompiledShaders; ++i)
            {
                string             entryPoint     = input.ReadString();
                int                codeSize       = input.ReadInt32();
                byte[]             shaderCode     = input.ReadBytes(codeSize);
                HlslCompiledShader compiledShader = new HlslCompiledShader(entryPoint, shaderCode);
                compiledShaders.Add(compiledShader);
            }
            return(compiledShaders);
        }
示例#2
0
        public override TOutput Process(TInput input, ContentProcessorContext context)
        {
#if !XNA4
            // Populate preprocessor defines
            string stringBuffer          = string.Empty;
            List <CompilerMacro> defines = new List <CompilerMacro>();
            if (preprocessorDefines != string.Empty)
            {
                stringBuffer = preprocessorDefines;

                // Split preprocessor defines and build up macro array

                if (stringBuffer.Contains(","))
                {
                    string[] definesArr = stringBuffer.Split(',');
                    foreach (string def in definesArr)
                    {
                        CompilerMacro macro = new CompilerMacro();
                        macro.Definition = "1\0";
                        macro.Name       = def + "\0";
                        defines.Add(macro);
                    }
                }
            }

            CompiledShader shader = ShaderCompiler.CompileFromSource(input, defines.ToArray(), includeHandler,
                                                                     CompilerOptions.PackMatrixRowMajor,
                                                                     entryPoint, shaderProfile,
                                                                     context.TargetPlatform);
            if (!shader.Success)
            {
                throw new InvalidContentException(shader.ErrorsAndWarnings);
            }

            HlslCompiledShader compiledShader = new HlslCompiledShader(entryPoint, shader.GetShaderCode());
#else
            throw new NotImplementedException();
            //var shader = new EffectProcessor().Process(new EffectContent { EffectCode = input }, context);
            HlslCompiledShader compiledShader = new HlslCompiledShader(entryPoint, /**/ null /*/shader.GetEffectCode()/**/);
#endif
            HlslCompiledShaders compiledShaders = new HlslCompiledShaders();
            compiledShaders.Add(compiledShader);
            return(compiledShaders);
        }