------------------------------------------------------------------------------------------------ Load a Quake 3 shader
| 106 | // ------------------------------------------------------------------------------------------------ |
| 107 | // Load a Quake 3 shader |
| 108 | bool Q3Shader::LoadShader(ShaderData &fill, const std::string &pFile, IOSystem *io) { |
| 109 | std::unique_ptr<IOStream> file(io->Open(pFile, "rt")); |
| 110 | if (!file) |
| 111 | return false; // if we can't access the file, don't worry and return |
| 112 | |
| 113 | ASSIMP_LOG_INFO("Loading Quake3 shader file ", pFile); |
| 114 | |
| 115 | // read file in memory |
| 116 | const size_t s = file->FileSize(); |
| 117 | std::vector<char> _buff(s + 1); |
| 118 | file->Read(&_buff[0], s, 1); |
| 119 | _buff[s] = 0; |
| 120 | |
| 121 | // remove comments from it (C++ style) |
| 122 | CommentRemover::RemoveLineComments("//", &_buff[0]); |
| 123 | const char *buff = &_buff[0]; |
| 124 | const char *end = buff + _buff.size(); |
| 125 | Q3Shader::ShaderDataBlock *curData = nullptr; |
| 126 | Q3Shader::ShaderMapBlock *curMap = nullptr; |
| 127 | |
| 128 | // read line per line |
| 129 | for (; SkipSpacesAndLineEnd(&buff, end); SkipLine(&buff, end)) { |
| 130 | |
| 131 | if (*buff == '{') { |
| 132 | ++buff; |
| 133 | |
| 134 | // append to last section, if any |
| 135 | if (!curData) { |
| 136 | ASSIMP_LOG_ERROR("Q3Shader: Unexpected shader section token \'{\'"); |
| 137 | return true; // still no failure, the file is there |
| 138 | } |
| 139 | |
| 140 | // read this data section |
| 141 | for (; SkipSpacesAndLineEnd(&buff, end); SkipLine(&buff, end)) { |
| 142 | if (*buff == '{') { |
| 143 | ++buff; |
| 144 | // add new map section |
| 145 | curData->maps.emplace_back(); |
| 146 | curMap = &curData->maps.back(); |
| 147 | |
| 148 | for (; SkipSpacesAndLineEnd(&buff, end); SkipLine(&buff, end)) { |
| 149 | // 'map' - Specifies texture file name |
| 150 | if (TokenMatchI(buff, "map", 3) || TokenMatchI(buff, "clampmap", 8)) { |
| 151 | curMap->name = GetNextToken(buff, end); |
| 152 | } |
| 153 | // 'blendfunc' - Alpha blending mode |
| 154 | else if (TokenMatchI(buff, "blendfunc", 9)) { |
| 155 | const std::string blend_src = GetNextToken(buff, end); |
| 156 | if (blend_src == "add") { |
| 157 | curMap->blend_src = Q3Shader::BLEND_GL_ONE; |
| 158 | curMap->blend_dest = Q3Shader::BLEND_GL_ONE; |
| 159 | } else if (blend_src == "filter") { |
| 160 | curMap->blend_src = Q3Shader::BLEND_GL_DST_COLOR; |
| 161 | curMap->blend_dest = Q3Shader::BLEND_GL_ZERO; |
| 162 | } else if (blend_src == "blend") { |
| 163 | curMap->blend_src = Q3Shader::BLEND_GL_SRC_ALPHA; |
| 164 | curMap->blend_dest = Q3Shader::BLEND_GL_ONE_MINUS_SRC_ALPHA; |
| 165 | } else { |
nothing calls this directly
no test coverage detected