| 118 | } |
| 119 | |
| 120 | Program::Result Program::fromSources(std::string_view vert_src, std::string_view frag_src) { |
| 121 | return withGlFunctions([vert_src, frag_src](auto& functions) -> Program::Result { |
| 122 | std::string error; |
| 123 | const GLuint vert_shader = compileShader(functions, GL_VERTEX_SHADER, vert_src, "Vertex", error); |
| 124 | if (vert_shader == 0U) { |
| 125 | return error; |
| 126 | } |
| 127 | |
| 128 | const GLuint frag_shader = compileShader(functions, GL_FRAGMENT_SHADER, frag_src, "Fragment", error); |
| 129 | if (frag_shader == 0U) { |
| 130 | functions.glDeleteShader(vert_shader); |
| 131 | return error; |
| 132 | } |
| 133 | |
| 134 | const GLuint program = functions.glCreateProgram(); |
| 135 | if (program == 0U) { |
| 136 | functions.glDeleteShader(vert_shader); |
| 137 | functions.glDeleteShader(frag_shader); |
| 138 | return std::string{"Failed to create shader program"}; |
| 139 | } |
| 140 | |
| 141 | functions.glAttachShader(program, vert_shader); |
| 142 | functions.glAttachShader(program, frag_shader); |
| 143 | functions.glLinkProgram(program); |
| 144 | |
| 145 | GLint link_status = GL_FALSE; |
| 146 | functions.glGetProgramiv(program, GL_LINK_STATUS, &link_status); |
| 147 | |
| 148 | functions.glDetachShader(program, vert_shader); |
| 149 | functions.glDetachShader(program, frag_shader); |
| 150 | functions.glDeleteShader(vert_shader); |
| 151 | functions.glDeleteShader(frag_shader); |
| 152 | |
| 153 | if (link_status == GL_TRUE) { |
| 154 | return Program{program}; |
| 155 | } |
| 156 | |
| 157 | const std::string log = programInfoLog(functions, program); |
| 158 | functions.glDeleteProgram(program); |
| 159 | if (log.empty()) { |
| 160 | return std::string{"Shader program link failed"}; |
| 161 | } |
| 162 | return fmt::format("Shader program link failed:\n{}", log); |
| 163 | }); |
| 164 | } |
| 165 | |
| 166 | Program::Result Program::fromComputeSource(std::string_view comp_src) { |
| 167 | return withGlFunctions([comp_src](auto& functions) -> Program::Result { |
nothing calls this directly
no test coverage detected