utilities.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef __EACSMB_UTILITIES_H__
  2. #define __EACSMB_UTILITIES_H__
  3. #define USE_KHR_DEBUG
  4. #define NO_GL_GET_ERR_DEBUG
  5. // i pronounce this one like "Grexit", greece's only smart move which they won't make cause they're greedy, short-sighted and dumb. just like the rest of us.
  6. #define glexit(msg) _glexit(msg, __FILE__, __LINE__, __func__)
  7. // returns NULL for no error, a human error string otherwise. the error is printed to stderr.
  8. #define glerr(msg) _glerr(msg, __FILE__, __LINE__, __func__)
  9. #define MAX(a,b) ({ \
  10. __typeof__ (a) _a = (a); \
  11. __typeof__ (b) _b = (b); \
  12. _a > _b ? _a : _b; \
  13. })
  14. #define MIN(a,b) ({ \
  15. __typeof__ (a) _a = (a); \
  16. __typeof__ (b) _b = (b); \
  17. _a < _b ? _a : _b; \
  18. })
  19. #define MAXE(a,b) ({ \
  20. __typeof__ (a) _a = (a); \
  21. __typeof__ (b) _b = (b); \
  22. _a >= _b ? _a : _b; \
  23. })
  24. #define MINE(a,b) ({ \
  25. __typeof__ (a) _a = (a); \
  26. __typeof__ (b) _b = (b); \
  27. _a <= _b ? _a : _b; \
  28. })
  29. #define CHECK_OOM(p) \
  30. if(!(p)) { \
  31. fprintf(stderr, "OOM for %s at %s:%d. Buy more ram\n", #p, __FILE__, __LINE__); \
  32. exit(2); \
  33. }
  34. #define GOTO_OOM(p, label) \
  35. if(!(p)) { \
  36. fprintf(stderr, "OOM for %s at %s:%d. Buy more ram\n", #p, __FILE__, __LINE__); \
  37. goto label; \
  38. }
  39. #ifndef NO_TERM_COLORS
  40. #define TERM_COLOR_BLACK "\x1b[30m"
  41. #define TERM_COLOR_RED "\x1b[31m"
  42. #define TERM_COLOR_GREEN "\x1b[32m"
  43. #define TERM_COLOR_YELLOW "\x1b[33m"
  44. #define TERM_COLOR_BLUE "\x1b[34m"
  45. #define TERM_COLOR_MAGENTA "\x1b[35m"
  46. #define TERM_COLOR_CYAN "\x1b[36m"
  47. #define TERM_COLOR_GRAY "\x1b[37m"
  48. #define TERM_RESET "\x1b[0m"
  49. #define TERM_BOLD "\x1b[1m"
  50. #define TERM_NORMAL "\x1b[22m"
  51. #define TERM_BK_BLACK "\x1b[40m"
  52. #define TERM_BK_RED "\x1b[41m"
  53. #define TERM_BK_GREEN "\x1b[42m"
  54. #define TERM_BK_YELLOW "\x1b[43m"
  55. #define TERM_BK_BLUE "\x1b[44m"
  56. #define TERM_BK_MAGENTA "\x1b[45m"
  57. #define TERM_BK_CYAN "\x1b[46m"
  58. #define TERM_BK_GRAY "\x1b[47m"
  59. #else
  60. #endif
  61. char* readFile(char* path, int* srcLen);
  62. typedef struct VAOConfig {
  63. int sz;
  64. GLenum type;
  65. char normalize;
  66. } VAOConfig;
  67. int getVAOItemSize(VAOConfig* item);
  68. int getVAOStride(VAOConfig* details);
  69. GLuint makeVAO(VAOConfig* details);
  70. void initKHRDebug();
  71. size_t strlnlen(const char* s);
  72. char* strlndup(const char* s);
  73. int strlinecnt(const char* s);
  74. char* pathJoin(const char* a, const char* b);
  75. void skipWhitespace(char** s);
  76. #endif // __EACSMB_UTILITIES_H__