| 65 | } |
| 66 | |
| 67 | bool GLShader::LoadFromStringsAndFile(ArrayView<const StringView> strings, StringView filename) |
| 68 | { |
| 69 | if (strings.empty() && filename.empty()) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | SmallVector<const char*, 10> sourceStrings; |
| 74 | SmallVector<GLint, 10> sourceLengths; |
| 75 | |
| 76 | sourceStrings.push_back(CommonShaderVersion.data()); |
| 77 | sourceLengths.push_back(static_cast<GLint>(CommonShaderVersion.size())); |
| 78 | sourceStrings.push_back(CommonShaderDefines.data()); |
| 79 | sourceLengths.push_back(static_cast<GLint>(CommonShaderDefines.size())); |
| 80 | |
| 81 | for (auto string : strings) { |
| 82 | sourceStrings.push_back(string.data()); |
| 83 | sourceLengths.push_back(static_cast<GLint>(string.size())); |
| 84 | } |
| 85 | |
| 86 | String fileSource; |
| 87 | if (!filename.empty()) { |
| 88 | std::unique_ptr<Stream> fileHandle = fs::Open(filename, FileAccess::Read); |
| 89 | if (!fileHandle->IsValid()) { |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | const GLint fileLength = static_cast<int>(fileHandle->GetSize()); |
| 94 | fileSource = String{NoInit, static_cast<std::size_t>(fileLength)}; |
| 95 | fileHandle->Read(fileSource.data(), fileLength); |
| 96 | |
| 97 | sourceStrings.push_back(fileSource.data()); |
| 98 | sourceLengths.push_back(static_cast<GLint>(fileLength)); |
| 99 | |
| 100 | SetObjectLabel(filename.data()); |
| 101 | } |
| 102 | |
| 103 | std::size_t count = sourceStrings.size(); |
| 104 | glShaderSource(glHandle_, GLsizei(count), sourceStrings.data(), sourceLengths.data()); |
| 105 | return (count > 1); |
| 106 | } |
| 107 | |
| 108 | bool GLShader::LoadFromFile(StringView filename) |
| 109 | { |