| 32 | m_indexDepth = 0; |
| 33 | } |
| 34 | bool GLSLCompiler::Parse(ShaderType type, const std::string& source, std::string entry) |
| 35 | { |
| 36 | if (!m_isImmediate) |
| 37 | ClearDefinitions(); |
| 38 | m_gen.Reset(); |
| 39 | |
| 40 | PropertyGetter = GLSL::Swizzle; |
| 41 | ObjectConstructor = Common::DefaultConstructor; |
| 42 | |
| 43 | m_lastLineSaved = -1; |
| 44 | m_isSet = false; |
| 45 | m_usePointer = false; |
| 46 | m_caseIfDefault = false; |
| 47 | m_caseIfAddr = 0; |
| 48 | m_indexDepth = 0; |
| 49 | m_writeIndexDepth = false; |
| 50 | m_entryFunction = entry; |
| 51 | m_gen.SetHeader(0, 2); |
| 52 | |
| 53 | m_buildFuncArgPtrs(); |
| 54 | |
| 55 | int shaderType = glsl::astTU::kVertex; |
| 56 | if (type == ShaderType::Pixel) |
| 57 | shaderType = glsl::astTU::kFragment; |
| 58 | |
| 59 | std::string actualSource = source; |
| 60 | if (m_isImmediate) |
| 61 | actualSource = "void immediate() { return " + source + "; }"; // the return type doesn't matter here :P |
| 62 | |
| 63 | |
| 64 | // add the user defined macros |
| 65 | pp::MacroMap macroCopy = m_macros; |
| 66 | pp::Preprocessor preprocess; |
| 67 | for (auto& pair : m_macros) |
| 68 | preprocess.AddMacro(pair.first, pair.second); |
| 69 | if (!m_isImmediate) m_macros.clear(); |
| 70 | |
| 71 | // preprocess |
| 72 | std::stringstream sourcePreprocessed; |
| 73 | pp::TokenSequence tokSeq; |
| 74 | preprocess.Process(actualSource, "shader.hlsl", tokSeq); |
| 75 | tokSeq.Print(sourcePreprocessed); |
| 76 | actualSource = sourcePreprocessed.str(); |
| 77 | |
| 78 | // add back the user defined macros to the macro list |
| 79 | if (!m_isImmediate) { |
| 80 | m_macros = preprocess.GetMacroList(); |
| 81 | for (auto& pair : macroCopy) |
| 82 | if (m_macros.count(pair.first) == 0) |
| 83 | m_macros.insert(pair); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | glsl::parser p(actualSource.c_str(), "memory"); |
| 88 | |
| 89 | for (const auto& glob : m_immGlobals) |
| 90 | p.addGlobal(glob.first.c_str(), glob.second.first, glob.second.second.c_str()); |
| 91 | m_immGlobals.clear(); |