GLWrapper.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <GL/glew.h>
  2. #include <iostream>
  3. #include "rendering/wrapper/GLWrapper.h"
  4. bool GLWrapper::checkAndPrintError(const char* message) {
  5. GLenum error = glGetError();
  6. switch(error) {
  7. case GL_NO_ERROR:
  8. return false;
  9. case GL_INVALID_ENUM:
  10. std::cout << message << ": an unacceptable value is specified for an enumerated argument.\n";
  11. break;
  12. case GL_INVALID_VALUE:
  13. std::cout << message << ": a numeric argument is out of range.\n";
  14. break;
  15. case GL_INVALID_OPERATION:
  16. std::cout << message << ": the specified operation is not allowed in the current state.\n";
  17. break;
  18. case GL_INVALID_FRAMEBUFFER_OPERATION:
  19. std::cout << message << ": the framebuffer object is not complete.\n";
  20. break;
  21. case GL_OUT_OF_MEMORY:
  22. std::cout << message << ": there is not enough memory left to execute the command.\n";
  23. break;
  24. case GL_STACK_UNDERFLOW:
  25. std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to underflow.\n";
  26. break;
  27. case GL_STACK_OVERFLOW:
  28. std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to overflow.\n";
  29. break;
  30. default:
  31. std::cout << message << ": unknown OpenGL error: " << error << "\n";
  32. }
  33. return true;
  34. }
  35. void GLWrapper::enableDepthTesting() {
  36. glEnable(GL_DEPTH_TEST);
  37. }
  38. void GLWrapper::disableDepthTesting() {
  39. glDisable(GL_DEPTH_TEST);
  40. }
  41. void GLWrapper::prepareMainFramebuffer() {
  42. glBindFramebuffer(GL_FRAMEBUFFER, 0);
  43. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  44. }
  45. void GLWrapper::enableBlending() {
  46. glEnable(GL_BLEND);
  47. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  48. glBlendEquation(GL_FUNC_ADD);
  49. }
  50. void GLWrapper::disableBlending() {
  51. glDisable(GL_BLEND);
  52. }