132 if (!
m_src.first().empty() && !
m_src.second().empty())
135 char info[1024] = {0};
141 auto v_src =
m_src.first().c_str();
142 auto f_src =
m_src.second().c_str();
145 v_id = glCreateShader(GL_VERTEX_SHADER);
146 glShaderSource(v_id, 1, &v_src,
nullptr);
147 glCompileShader(v_id);
149 glGetShaderiv(v_id, GL_COMPILE_STATUS, &success);
152 glGetShaderInfoLog(v_id, 1024,
nullptr,
info);
158 f_id = glCreateShader(GL_FRAGMENT_SHADER);
159 glShaderSource(f_id, 1, &f_src,
nullptr);
160 glCompileShader(f_id);
162 glGetShaderiv(f_id, GL_COMPILE_STATUS, &success);
165 glGetShaderInfoLog(f_id, 1024,
nullptr,
info);
173 m_id = glCreateProgram();
174 glAttachShader(
m_id, v_id);
175 glAttachShader(
m_id, f_id);
178 glGetProgramiv(
m_id, GL_LINK_STATUS, &success);
181 glGetProgramInfoLog(
m_id, 1024,
nullptr,
info);
186 GLint uniform_count = 0;
187 glGetProgramiv(
m_id, GL_ACTIVE_UNIFORMS, &uniform_count);
189 if (uniform_count != 0)
191 GLint max_name_len = 0;
192 glGetProgramiv(
m_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_len);
196 GLenum type = GL_NONE;
198 for (GLint i = 0; i < uniform_count; ++i)
200 auto uniform_name = std::make_unique<char[]>(max_name_len);
201 glGetActiveUniform(
m_id, i, max_name_len, &length, &count, &type, uniform_name.get());
203 m_cache.emplace(std::string(uniform_name.get(), length), glGetUniformLocation(
m_id, uniform_name.get()));
209 glDeleteShader(v_id);
210 glDeleteShader(f_id);
248 const auto token =
"#type";
249 const auto len = std::strlen(token);
251 auto pos = src.find(token, 0);
252 while (pos != std::string::npos)
254 const auto eol = src.find_first_of(
"\r\n", pos);
255 const auto begin = pos + len + 1;
257 auto type = src.substr(begin, eol - begin);
259 if (type ==
"vertex" || type ==
"fragment")
261 const auto next_line = src.find_first_not_of(
"\r\n", eol);
262 pos = src.find(token, next_line);
264 if (type ==
"vertex")
266 m_src.first() = (pos == std::string::npos) ? src.substr(next_line) : src.substr(next_line, pos - next_line);
270 m_src.second() = (pos == std::string::npos) ? src.substr(next_line) : src.substr(next_line, pos - next_line);