| 164 | } |
| 165 | |
| 166 | Program::Result Program::fromComputeSource(std::string_view comp_src) { |
| 167 | return withGlFunctions([comp_src](auto& functions) -> Program::Result { |
| 168 | std::string error; |
| 169 | const GLuint comp_shader = compileShader(functions, GL_COMPUTE_SHADER, comp_src, "Compute", error); |
| 170 | if (comp_shader == 0U) { |
| 171 | return error; |
| 172 | } |
| 173 | |
| 174 | const GLuint program = functions.glCreateProgram(); |
| 175 | if (program == 0U) { |
| 176 | functions.glDeleteShader(comp_shader); |
| 177 | return std::string{"Failed to create compute program"}; |
| 178 | } |
| 179 | |
| 180 | functions.glAttachShader(program, comp_shader); |
| 181 | functions.glLinkProgram(program); |
| 182 | |
| 183 | GLint link_status = GL_FALSE; |
| 184 | functions.glGetProgramiv(program, GL_LINK_STATUS, &link_status); |
| 185 | |
| 186 | functions.glDetachShader(program, comp_shader); |
| 187 | functions.glDeleteShader(comp_shader); |
| 188 | |
| 189 | if (link_status == GL_TRUE) { |
| 190 | return Program{program}; |
| 191 | } |
| 192 | |
| 193 | const std::string log = programInfoLog(functions, program); |
| 194 | functions.glDeleteProgram(program); |
| 195 | if (log.empty()) { |
| 196 | return std::string{"Compute program link failed"}; |
| 197 | } |
| 198 | return fmt::format("Compute program link failed:\n{}", log); |
| 199 | }); |
| 200 | } |
| 201 | |
| 202 | void Program::use() { |
| 203 | withGlFunctions([this](auto& functions) { functions.glUseProgram(id_); }); |
nothing calls this directly
no test coverage detected