32 glShaderSource(shader, 1, &src, NULL);
33 glCompileShader(shader);
35 glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
36 if (status == GL_FALSE) {
38 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);
39 GLchar *info =
new GLchar[
length];
40 glGetShaderInfoLog(shader, length, NULL, info);
41 LOGE(
"Error compiling shader: %s\n", info);
50 for (
unsigned int i = 0; i < shaders.size(); ++i)
51 glAttachShader(program, shaders[i]);
53 glLinkProgram(program);
55 for (
unsigned int i = 0; i < shaders.size(); ++i)
56 glDetachShader(program, shaders[i]);
59 glGetProgramiv(program, GL_LINK_STATUS, &status);
60 if (status == GL_FALSE) {
62 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
63 GLchar *info =
new GLchar[
length];
64 glGetProgramInfoLog(program, length, NULL, info);
65 LOGE(
"Error linking program: %s\n", info);
74 m_id = glCreateProgram();
76 for (
int i = 0; i <
count; ++i)
78 GLuint shader = glCreateShader(types[i]);
88 string sources[] = { vs_src, fs_src };
89 GLenum types[] = { GL_VERTEX_SHADER, GL_FRAGMENT_SHADER };
95 m_id = glCreateProgram();
97 for (
int i = 0; i <
count; ++i)
99 GLuint shader = glCreateShader(types[i]);
112 string paths[] = { vs_path, fs_path };
113 GLenum types[] = { GL_VERTEX_SHADER, GL_FRAGMENT_SHADER };
119 string paths[] = { cs_path };
133 for (
int i = 0; i <
m_shaders.size(); ++i)
135 glDeleteProgram(
m_id);
150 std::unordered_map<std::string, GLint>::iterator it =
m_uniforms.find(name);
157 GLint
location = glGetUniformLocation(
m_id, name.c_str());
158 string msg =
"Invalid shader uniform [" + name +
"]";
159 ASSERT(location >= 0, msg.c_str());
167 std::unordered_map<std::string, GLint>::iterator it =
m_attributes.find(name);
174 GLint
location = glGetAttribLocation(
m_id, name.c_str());
175 string msg =
"Invalid shader attribute [" + name +
"]";
176 ASSERT(location >= 0, msg.c_str());
186 glEnableVertexAttribArray(loc);
187 glVertexAttribPointer(
193 (
void*)(offset *
sizeof(
GLfloat))
void set_attribfv(string name, GLsizei num_components, GLsizei stride, GLsizei offset)
bool load_compute_from_file(string cs_path)
bool load_from_file(const string *paths, GLenum *types, int count)
GLenum GLuint GLintptr offset
std::vector< GLuint > m_shaders
GLsizei const GLuint * paths
GLenum GLenum GLsizei count
const float * value_ptr() const
bool read_file(const std::string &path, std::string &dest)
bool link_program(GLuint program, std::vector< GLuint > shaders)
bool load_from_src(const string *sources, GLenum *types, int count)
bool compile_shader(GLuint shader, GLenum type, const char *source)
GLsizei GLsizei GLchar * source
std::unordered_map< string, GLint > m_attributes
void set_uniform(string name, const mat4 &v)
GLsizei GLenum GLenum * types
GLint get_attribute_location(string name)
GLint get_uniform_location(string name)
GLenum GLuint GLenum GLsizei length
const void GLsizei GLsizei stride
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
std::unordered_map< string, GLint > m_uniforms
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
void unset_attrib(string name)