A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include <stdexcept>
  3. #include <SDL_opengles2.h>
  4. #include <SDL.h>
  5. namespace Cygnet {
  6. struct SDLError: public std::exception {
  7. SDLError(std::string msg): message(std::move(msg)) {}
  8. std::string message;
  9. const char *what() const noexcept override {
  10. return message.c_str();
  11. }
  12. };
  13. struct GLError: public std::exception {
  14. GLError(std::string msg): message(std::move(msg)) {}
  15. std::string message;
  16. const char *what() const noexcept override {
  17. return message.c_str();
  18. }
  19. };
  20. inline const char *glErrorString(int err) {
  21. #define errcase(x) case x: return #x
  22. switch (err) {
  23. errcase(GL_NO_ERROR);
  24. errcase(GL_INVALID_ENUM);
  25. errcase(GL_INVALID_VALUE);
  26. errcase(GL_INVALID_OPERATION);
  27. errcase(GL_INVALID_FRAMEBUFFER_OPERATION);
  28. errcase(GL_OUT_OF_MEMORY);
  29. default: return "(unknown)";
  30. }
  31. #undef errcase
  32. }
  33. inline void sdlCheck(bool ok) {
  34. if (!ok) {
  35. throw SDLError(SDL_GetError());
  36. }
  37. }
  38. inline void glCheck() {
  39. GLenum err = glGetError();
  40. if (err != GL_NO_ERROR) {
  41. throw GLError(glErrorString(err));
  42. }
  43. }
  44. }