Horizon
gl_util.hpp
1 #include <epoxy/gl.h>
2 #include <string>
3 #include <sstream>
4 
5 namespace horizon {
6 // GLuint gl_create_shader (int type, char *src);
7 GLuint gl_create_program_from_resource(const char *vertex_resource, const char *fragment_resource,
8  const char *geometry_resource);
9 
10 void gl_show_error(const std::string &s);
11 void gl_color_to_uniform_3f(GLuint loc, const class Color &c);
12 void gl_color_to_uniform_4f(GLuint loc, const class Color &c, float alpha = 1);
13 GLint gl_clamp_samples(GLint samples);
14 
15 #define GET_LOC(d, loc) \
16  do { \
17  d->loc##_loc = glGetUniformLocation(d->program, #loc); \
18  } while (0);
19 
20 #define GET_LOC2(d, loc) \
21  do { \
22  (d).loc##_loc = glGetUniformLocation((d).program, #loc); \
23  } while (0);
24 
25 #define GL_CHECK_ERROR \
26  if (int e = glGetError()) { \
27  std::stringstream ss; \
28  ss << "gl error " << e << " in " << __FILE__ << ":" << __LINE__; \
29  gl_show_error(ss.str()); \
30  abort(); \
31  }
32 } // namespace horizon