115 if (!
m_src.first().empty() && !
m_src.second().empty())
118 char info[1024] = {0};
124 auto v_src =
m_src.first().c_str();
125 auto f_src =
m_src.second().c_str();
128 v_id = glCreateShader(GL_VERTEX_SHADER);
129 glShaderSource(v_id, 1, &v_src,
nullptr);
130 glCompileShader(v_id);
132 glGetShaderiv(v_id, GL_COMPILE_STATUS, &success);
135 glGetShaderInfoLog(v_id, 1024,
nullptr,
info);
141 f_id = glCreateShader(GL_FRAGMENT_SHADER);
142 glShaderSource(f_id, 1, &f_src,
nullptr);
143 glCompileShader(f_id);
145 glGetShaderiv(f_id, GL_COMPILE_STATUS, &success);
148 glGetShaderInfoLog(f_id, 1024,
nullptr,
info);
156 m_id = glCreateProgram();
157 glAttachShader(
m_id, v_id);
158 glAttachShader(
m_id, f_id);
161 glGetProgramiv(
m_id, GL_LINK_STATUS, &success);
164 glGetProgramInfoLog(
m_id, 1024,
nullptr,
info);
169 GLint uniform_count = 0;
170 glGetProgramiv(
m_id, GL_ACTIVE_UNIFORMS, &uniform_count);
172 if (uniform_count != 0)
174 GLint max_name_len = 0;
175 glGetProgramiv(
m_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_len);
179 GLenum type = GL_NONE;
181 for (GLint i = 0; i < uniform_count; ++i)
183 auto uniform_name = std::make_unique<char[]>(max_name_len);
184 glGetActiveUniform(
m_id, i, max_name_len, &length, &count, &type, uniform_name.get());
186 m_cache.emplace(std::string(uniform_name.get(), length), glGetUniformLocation(
m_id, uniform_name.get()));
192 glDeleteShader(v_id);
193 glDeleteShader(f_id);
232 const auto token =
"#type";
233 const auto len = std::strlen(token);
235 auto pos = src.find(token, 0);
236 while (pos != std::string::npos)
238 const auto eol = src.find_first_of(
"\r\n", pos);
239 const auto begin = pos + len + 1;
241 auto type = src.substr(begin, eol - begin);
243 if (type ==
"vertex" || type ==
"fragment")
245 const auto next_line = src.find_first_not_of(
"\r\n", eol);
246 pos = src.find(token, next_line);
248 if (type ==
"vertex")
250 m_src.first() = (pos == std::string::npos) ? src.substr(next_line) : src.substr(next_line, pos - next_line);
254 m_src.second() = (pos == std::string::npos) ? src.substr(next_line) : src.substr(next_line, pos - next_line);