| 14 | } |
| 15 | |
| 16 | ShaderOperationResult ShaderReader::Read(std::string_view filename) { |
| 17 | std::unique_lock<std::mutex> locker(this->m_lock); |
| 18 | |
| 19 | std::regex reg{m_regex_expression}; |
| 20 | |
| 21 | m_filestream.open(filename.data(), std::ifstream::in); |
| 22 | if (!m_filestream.is_open()) { |
| 23 | ZENGINE_CORE_ERROR("====== Shader file : {} cannot be opened ======", filename.data()); |
| 24 | return ShaderOperationResult::FAILURE; |
| 25 | } |
| 26 | |
| 27 | m_filestream.seekg(std::ifstream::beg); |
| 28 | |
| 29 | std::string current_line; |
| 30 | while (std::getline(m_filestream, current_line)) { |
| 31 | |
| 32 | if (std::regex_match(current_line, reg)) { |
| 33 | std::istringstream in(current_line); |
| 34 | std::string type; |
| 35 | in.seekg(std::string("#type ").size()); |
| 36 | in >> type; |
| 37 | |
| 38 | ShaderInformation shader_information{}; |
| 39 | shader_information.Name = type; |
| 40 | shader_information.Type = (type == "vertex") ? ShaderType::VERTEX : ShaderType::FRAGMENT; |
| 41 | shader_information.InternalType = (type == "vertex") ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER; |
| 42 | |
| 43 | m_shader_info_collection.push_back(std::move(shader_information)); |
| 44 | in.clear(); |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | const auto last = std::prev(std::end(m_shader_info_collection)); |
| 49 | last->Source.append(current_line + "\n"); |
| 50 | } |
| 51 | ZENGINE_CORE_INFO("====== Shader file : {} read succeeded ======", filename.data()); |
| 52 | m_filestream.close(); |
| 53 | return ShaderOperationResult::SUCCESS; |
| 54 | } |
| 55 | |
| 56 | std::future<ShaderOperationResult> ShaderReader::ReadAsync(std::string_view filename) { |
| 57 | auto result = co_await std::async(std::launch::async, &ShaderReader::Read, this, filename); |
nothing calls this directly
no outgoing calls
no test coverage detected