1
1

common.d 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. module three.common;
  2. public import derelict.opengl3.gl3;
  3. public import derelict.glfw3.glfw3;
  4. public import derelict.anttweakbar.anttweakbar;
  5. public import derelict.freeimage.freeimage;
  6. public import derelict.freetype.ft;
  7. public import derelict.assimp3.assimp;
  8. public import std.experimental.logger;
  9. alias SoA(T) = T[];
  10. import std.traits : ReturnType;
  11. ReturnType!func glCheck(alias func, string file = __FILE__, size_t line = __LINE__, string mod = __MODULE__, string funcd = __FUNCTION__, string pretty = __PRETTY_FUNCTION__, Args...)(Args args) nothrow {
  12. import std.stdio;
  13. import std.stdio : stderr;
  14. import std.array : join;
  15. import std.range : repeat;
  16. import std.string : format;
  17. try{
  18. debug scope(exit) {
  19. GLenum err = glGetError();
  20. if(err != GL_NO_ERROR) {
  21. stderr.writeln("\n===============================");
  22. stderr.writeln("File: ", file, "\nLine: ", line, "\nModule: ",mod, "\nFunction: ",funcd, "\n",pretty);
  23. stderr.writeln("-------------------------------");
  24. stderr.writefln(`OpenGL function "%s(%s)" failed: "%s."`, func.stringof, format("%s".repeat(Args.length).join(", "), args), glErrorString(err));
  25. stderr.writeln("=============================== \n");
  26. assert(false);
  27. }
  28. }
  29. }
  30. catch(Exception e){
  31. }
  32. debug if(func is null) {
  33. try{
  34. stderr.writefln("%s is null! OpenGL loaded? Required OpenGL version not supported?".format(func.stringof));
  35. }
  36. catch(Exception e){
  37. assert(false);
  38. }
  39. assert(false);
  40. }
  41. return func(args);
  42. }
  43. string glErrorString(GLenum error) pure @safe nothrow @nogc {
  44. final switch(error) {
  45. case GL_NO_ERROR: return "no error";
  46. case GL_INVALID_ENUM: return "invalid enum";
  47. case GL_INVALID_VALUE: return "invalid value";
  48. case GL_INVALID_OPERATION: return "invalid operation";
  49. //case GL_STACK_OVERFLOW: return "stack overflow";
  50. //case GL_STACK_UNDERFLOW: return "stack underflow";
  51. case GL_INVALID_FRAMEBUFFER_OPERATION: return "invalid framebuffer operation";
  52. case GL_OUT_OF_MEMORY: return "out of memory";
  53. }
  54. assert(false, "invalid enum");
  55. }