gl-helpers.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #ifndef GL_HELPERS_H
  15. #define GL_HELPERS_H
  16. /*
  17. * Okay, so GL error handling is.. unclean to work with. I don't want
  18. * to have to keep typing out the same stuff over and over again do I'll just
  19. * make a bunch of helper functions to make it a bit easier to handle errors
  20. */
  21. static inline bool gl_success(const char *funcname)
  22. {
  23. GLenum errorcode = glGetError();
  24. if (errorcode != GL_NO_ERROR) {
  25. blog(LOG_ERROR, "%s failed, glGetError returned %u",
  26. funcname, errorcode);
  27. return false;
  28. }
  29. return true;
  30. }
  31. static inline bool gl_gen_textures(GLsizei num_texture, GLuint *textures)
  32. {
  33. glGenTextures(num_texture, textures);
  34. return gl_success("glGenTextures");
  35. }
  36. static inline bool gl_bind_texture(GLenum target, GLuint texture)
  37. {
  38. glBindTexture(target, texture);
  39. return gl_success("glBindTexture");
  40. }
  41. static inline bool gl_gen_buffers(GLsizei num_buffers, GLuint *buffers)
  42. {
  43. glGenBuffers(num_buffers, buffers);
  44. return gl_success("glGenBuffers");
  45. }
  46. static inline bool gl_bind_buffer(GLenum target, GLuint buffer)
  47. {
  48. glBindBuffer(target, buffer);
  49. return gl_success("glBindBuffer");
  50. }
  51. static inline bool gl_bind_renderbuffer(GLenum target, GLuint buffer)
  52. {
  53. glBindRenderbuffer(target, buffer);
  54. return gl_success("glBindRendebuffer");
  55. }
  56. extern bool upload_face(GLenum type, uint32_t num_levels,
  57. GLenum format, GLint internal_format, bool compressed,
  58. uint32_t width, uint32_t height, uint32_t size, void ***p_data);
  59. #endif